Skip to content

Commit

Permalink
Fix error when a column with no value is selected to show in the vuln…
Browse files Browse the repository at this point in the history
…erabilities inventory table (#6179)

* Fix inventory columns table visibility error

* Update CHANGELOG

* Fix CHANGELOG
  • Loading branch information
Machi3mfl authored Nov 30, 2023
1 parent e21fb9c commit a61d777
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added the ability to check if there are available updates from the UI. [#6093](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6093)
- Added remember server address check [#5791](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5791)
- Added the ssl_agent_ca configuration to the SSL Settings form [#6083](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6083)
- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896)
- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896) [#6179](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6179)
- Added an agent selector to the IT Hygiene application [#5840](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5840)
- Added query results limit when the search exceed 10000 hits [#6106](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6106)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const parseData = (resultsHits: SearchResponse['hits']['hits']): any[] =>
}


export const getFieldFormatted = (rowIndex, columnId, indexPattern, rowsParsed) => {
export const getFieldValueFormatted = (rowIndex, columnId, indexPattern, rowsParsed) => {
const field = indexPattern.fields.find((field) => field.name === columnId);
let fieldValue = null;
if (columnId.includes('.')) {
Expand All @@ -93,13 +93,19 @@ export const getFieldFormatted = (rowIndex, columnId, indexPattern, rowsParsed)
fieldValue = fieldValue[field];
}
});

} else {
fieldValue = rowsParsed[rowIndex][columnId].formatted
? rowsParsed[rowIndex][columnId].formatted
: rowsParsed[rowIndex][columnId];
const rowValue = rowsParsed[rowIndex];
// when not exist the column in the row value then the value is null
if(!rowValue.hasOwnProperty(columnId)){
fieldValue = null;
}else{
fieldValue = rowValue[columnId]?.formatted || rowValue[columnId];
}
}
// when fieldValue is null or undefined then return a empty string
if (fieldValue === null || fieldValue === undefined) {
return '';
}

// if is date field
if (field?.type === 'date') {
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EuiDataGridCellValueElementProps, EuiDataGridColumn, EuiDataGridProps,
import { useEffect, useMemo, useState, Fragment } from "react";
import { SearchResponse } from "@opensearch-project/opensearch/api/types";
import { IFieldType, IndexPattern } from "../../../../../../../src/plugins/data/common";
import { parseData, getFieldFormatted } from '../dashboards/inventory/inventory_service';
import { parseData, getFieldValueFormatted } from '../dashboards/inventory/inventory_service';
import { MAX_ENTRIES_PER_QUERY } from "../dashboards/inventory/config";

type tDataGridProps = {
Expand Down Expand Up @@ -72,7 +72,7 @@ export const useDataGrid = (props: tDataGridProps): EuiDataGridProps => {
// then the rowIndex is relative to the current page
const relativeRowIndex = rowIndex % pagination.pageSize;
return rowsParsed.hasOwnProperty(relativeRowIndex)
? getFieldFormatted(relativeRowIndex, columnId, indexPattern, rowsParsed)
? getFieldValueFormatted(relativeRowIndex, columnId, indexPattern, rowsParsed)
: null;
};

Expand Down

0 comments on commit a61d777

Please sign in to comment.