Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render nested field rows in security alerts table #4428

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ All notable changes to the Wazuh app project will be documented in this file.

- Changed the HTTP verb from `GET` to `POST` in the requests to login to the Wazuh API [#4103](https:/wazuh/wazuh-kibana-app/pull/4103)

### Fixed

- Fixed nested field rendering in security alerts table details [#4428](https:/wazuh/wazuh-kibana-app/pull/4428)

## Wazuh v4.3.7 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4308

### Fixed
Expand Down
17 changes: 16 additions & 1 deletion public/components/common/modules/discover/discover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,19 @@ div.euiPanel.euiComboBoxOptionsList.euiComboBoxOptionsList {

.hover-row{
background-color: #fbfcfd;
}
}

.module-discover-table .module-discover-table-details {
td {
vertical-align: text-bottom;

.wzDocViewer__value {
display: inline-block;
word-break: break-all;
word-wrap: break-word;
white-space: pre-wrap;
vertical-align: top;
padding-top: 2px;
}
}
}
1 change: 1 addition & 0 deletions public/components/common/modules/discover/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export const Discover = compose(
addFilterOut={(filter) => this.addFilterOut(filter)}
toggleColumn={(id) => this.addColumn(id)}
rowDetailsFields={rowDetailsFields}
indexPattern={this.indexPattern}
/>
</div>
);
Expand Down
54 changes: 46 additions & 8 deletions public/components/common/modules/discover/row-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* Find more information about this on the LICENSE file.
*/

import React, { Component, Fragment } from 'react';
import React, { Component } from 'react';
import {
EuiCodeBlock,
EuiPanel,
EuiTitle,
EuiSpacer,
EuiIcon,
Expand All @@ -31,6 +30,9 @@ import {
EuiBadge,
EuiAccordion,
} from '@elastic/eui';
import classNames from 'classnames';
import { DocViewTableRowBtnCollapse } from '../../../../kibana-integrations/discover/application/components/table/table_row_btn_collapse';
import { arrayContainsObjects, trimAngularSpan } from '../../../../kibana-integrations/discover/application/components/table/table_helper';
import './discover.scss';
import { EuiFlexItem } from '@elastic/eui';
import { WzRequest } from '../../../../react-services/wz-request';
Expand All @@ -46,7 +48,8 @@ export class RowDetails extends Component {
items: Array<any>,
totalItems: Number
},
hover: string
hover: string,
isCollapsed: boolean,
};

complianceEquivalences: Object
Expand All @@ -72,6 +75,7 @@ export class RowDetails extends Component {
items: [],
totalItems: 0,
},
isCollapsed: true,
hover: ''
}

Expand Down Expand Up @@ -153,7 +157,9 @@ export class RowDetails extends Component {
</EuiToolTip>)
}


onToggleCollapse = () => {
this.setState({ isCollapsed: !this.state.isCollapsed });
}

renderRows() {
// By default show all available fields, otherwise show the fields specified in rowDetailsFields string array
Expand Down Expand Up @@ -222,13 +228,34 @@ export class RowDetails extends Component {

cells.push(keyCell);

const formattedValue = Array.isArray(value) ? value.join(', ') : value.toString();
const formattedValue = Array.isArray(value) ? this.renderArrayValue(value) : value.toString();

// If the field is an array of objects, show the collapse button to show the nested fields
const showCollapseButton = Array.isArray(value) && arrayContainsObjects(value);

const valueClassName = classNames({
// eslint-disable-next-line @typescript-eslint/naming-convention
wzDocViewer__value: true,
'truncate-by-height': showCollapseButton && this.state.isCollapsed,
"hover-row": this.state.hover === key
});

const valueCell = <EuiTableRowCell
className={this.state.hover === key ? "hover-row" : " "}
className={valueClassName}
style={{ borderTop: 0, borderBottom: 0, padding: 0, margin: 0 }}
key={key + "2"}>
{<div>{formattedValue}</div>}
{ showCollapseButton && (
<DocViewTableRowBtnCollapse onClick={this.onToggleCollapse} isCollapsed={this.state.isCollapsed} />
)}
<div
data-test-subj={`tableDocViewRow-${key}-value`}
/*
* Justification for dangerouslySetInnerHTML:
* We just use values encoded by our field formatters
*/
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: formattedValue as string }}
/>
</EuiTableRowCell>

cells.push(valueCell);
Expand All @@ -250,11 +277,22 @@ export class RowDetails extends Component {
return rows;
}

// Render the row value column supporting nested fields
renderArrayValue = (value) => {
if (arrayContainsObjects(value)) {
const formatted = this.props?.indexPattern?.formatHit({ _index: value }, 'html')?._index;
return trimAngularSpan(String(formatted));
}
else {
return value.join(', ')
}
}

getTable() {
return (
<div>
<div>
<EuiTable style={{ marginTop: 0 }}>
<EuiTable style={{ marginTop: 0 }} className='module-discover-table-details'>
<EuiTableBody style={{ marginTop: 0 }}>{this.renderRows()}</EuiTableBody>
</EuiTable>
</div>
Expand Down