-
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.
- Loading branch information
Showing
7 changed files
with
201 additions
and
155 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
34 changes: 18 additions & 16 deletions
34
.../public/components/overview/vulnerabilities/common/components/vuls-evaluation-filter.scss
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
.button-group-filter { | ||
border-radius: 2px; | ||
|
||
.euiButton__content, | ||
.euiButton__text { | ||
font-size: 12px; | ||
font-weight: 500; | ||
} | ||
border-radius: 2px; | ||
|
||
.euiButton__content, | ||
.euiButton__text { | ||
font-size: 12px; | ||
font-weight: 500; | ||
} | ||
|
||
.euiButtonGroup__buttons { | ||
height: 30px; | ||
border-radius: 2px; | ||
box-shadow: 0 1px 1px -1px rgba(0, 0, 0, 0.2), 0 3px 2px -2px rgba(0, 0, 0, 0.2), inset 0 0 0 1px #424752 !important; | ||
border: none !important; | ||
.euiButtonGroup__buttons { | ||
height: 30px; | ||
border-radius: 2px; | ||
box-shadow: | ||
0 1px 1px -1px rgba(0, 0, 0, 0.2), | ||
0 3px 2px -2px rgba(0, 0, 0, 0.2), | ||
inset 0 0 0 1px #424752 !important; | ||
border: none !important; | ||
|
||
.euiButtonGroupButton { | ||
line-height: 28px; | ||
} | ||
.euiButtonGroupButton { | ||
line-height: 28px; | ||
} | ||
} | ||
} | ||
} |
180 changes: 95 additions & 85 deletions
180
...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 |
---|---|---|
@@ -1,94 +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"; | ||
import "./vuls-evaluation-filter.scss"; | ||
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'; | ||
import './vuls-evaluation-filter.scss'; | ||
|
||
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; | ||
} | ||
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 {}; | ||
} | ||
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()); | ||
const [toggleIdToSelectedMap, setToggleIdToSelectedMap] = | ||
useState(getDefaultValue()); | ||
|
||
useEffect(() => { | ||
setToggleIdToSelectedMap(getDefaultValue()); | ||
}, [value]); | ||
|
||
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); | ||
} | ||
|
||
const handleChange = (optionId: string) => { | ||
let newToggleIdToSelectedMap = {}; | ||
if (!toggleIdToSelectedMap[optionId]) { | ||
newToggleIdToSelectedMap = { [optionId]: true }; | ||
} | ||
|
||
return ( | ||
<EuiButtonGroup | ||
className="button-group-filter" | ||
type="multi" | ||
idToSelectedMap={toggleIdToSelectedMap} | ||
options={toggleButtons} | ||
onChange={(id) => handleChange(id)} | ||
buttonSize="compressed" | ||
/> | ||
) | ||
} | ||
|
||
export default VulsEvaluationFilter; | ||
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; |
Oops, something went wrong.