-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add visualization of vulnerabilities evaluation status count (#6968)
* chore: rename use-data-grid.ts file * fix: use the field formatter to render the fields in the WzDataGrid * feat: add the wazuh.vulnerability.under_evaluation field to the vulnerabilities sample data tool * feat(vulnerabilities): add visualization related to evaluation status to the dashboard * changelog: add entry * fix(changelog): rephrase * Change visualization to only pending * Add post fixed filter place to render components * Add under evaluation filter component * Apply under evaluation filter in vuls tabs * Add style to button group in filter * Apply prettier * Apply prettier * Fix style in dark and light theme * Added changelog --------- Co-authored-by: Chantal Belén kelm <99441266+chantal-kelm@users.noreply.github.com> Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com> Co-authored-by: Maximiliano Ibarra <maximiliano.ibarra@wazuh.com>
- Loading branch information
1 parent
8076575
commit 930e5d5
Showing
12 changed files
with
376 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...n/public/components/overview/vulnerabilities/common/components/vuls-evaluation-filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { EuiButtonGroup } from '@elastic/eui'; | ||
import { | ||
FILTER_OPERATOR, | ||
PatternDataSourceFilterManager, | ||
} from '../../../../common/data-source'; | ||
import { Filter } from '../../../../../../../../src/plugins/data/common'; | ||
|
||
type VulsEvaluatedFilterProps = { | ||
setValue: (underEvaluation: boolean | null) => void; | ||
value: boolean | null; | ||
}; | ||
|
||
const UNDER_EVALUATION_FIELD = 'wazuh.vulnerability.under_evaluation'; | ||
|
||
export const getUnderEvaluationFilterValue = ( | ||
filters: Filter[], | ||
): boolean | null => { | ||
const underEvaluationFilter = filters.find( | ||
f => f.meta?.key === UNDER_EVALUATION_FIELD, | ||
); | ||
if (underEvaluationFilter) { | ||
return underEvaluationFilter.meta?.params.query as boolean; | ||
} | ||
return null; | ||
}; | ||
|
||
export const excludeUnderEvaluationFilter = (filters: Filter[]): Filter[] => { | ||
return filters.filter(f => f.meta?.key !== UNDER_EVALUATION_FIELD); | ||
}; | ||
|
||
export const createUnderEvaluationFilter = ( | ||
underEvaluation: boolean, | ||
indexPatternId: string, | ||
): Filter => { | ||
return PatternDataSourceFilterManager.createFilter( | ||
FILTER_OPERATOR.IS, | ||
UNDER_EVALUATION_FIELD, | ||
underEvaluation, | ||
indexPatternId, | ||
); | ||
}; | ||
|
||
const VulsEvaluationFilter = ({ | ||
setValue, | ||
value, | ||
}: VulsEvaluatedFilterProps) => { | ||
const toggleButtons = [ | ||
{ | ||
id: 'evaluated', | ||
label: 'Evaluated', | ||
}, | ||
{ | ||
id: 'underEvaluation', | ||
label: 'Under evaluation', | ||
}, | ||
]; | ||
|
||
const getDefaultValue = () => { | ||
if (value === true) { | ||
return { underEvaluation: true, evaluated: false }; | ||
} else if (value === false) { | ||
return { underEvaluation: false, evaluated: true }; | ||
} else { | ||
return {}; | ||
} | ||
}; | ||
|
||
const [toggleIdToSelectedMap, setToggleIdToSelectedMap] = useState( | ||
getDefaultValue(), | ||
); | ||
|
||
useEffect(() => { | ||
setToggleIdToSelectedMap(getDefaultValue()); | ||
}, [value]); | ||
|
||
const handleChange = (optionId: string) => { | ||
let newToggleIdToSelectedMap = {}; | ||
if (!toggleIdToSelectedMap[optionId]) { | ||
newToggleIdToSelectedMap = { [optionId]: true }; | ||
} | ||
setToggleIdToSelectedMap(newToggleIdToSelectedMap); | ||
if (optionId === 'underEvaluation' && newToggleIdToSelectedMap[optionId]) { | ||
setValue(true); | ||
} else if (optionId === 'evaluated' && newToggleIdToSelectedMap[optionId]) { | ||
setValue(false); | ||
} else { | ||
setValue(null); | ||
} | ||
}; | ||
|
||
return ( | ||
<EuiButtonGroup | ||
className='button-group-filter' | ||
type='multi' | ||
idToSelectedMap={toggleIdToSelectedMap} | ||
options={toggleButtons} | ||
onChange={id => handleChange(id)} | ||
buttonSize='compressed' | ||
/> | ||
); | ||
}; | ||
|
||
export default VulsEvaluationFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.