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

Fix error when a column with no value is selected to show in the vulnerabilities inventory table #6179

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading