Skip to content

Commit

Permalink
Apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Machi3mfl committed Sep 26, 2024
1 parent 8b4d854 commit 4af0b41
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 155 deletions.
20 changes: 10 additions & 10 deletions plugins/main/public/components/common/data-grid/use-data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface PaginationOptions
extends Pick<
EuiDataGridPaginationProps,
'pageIndex' | 'pageSize' | 'pageSizeOptions'
> { }
> {}

type SortingColumns = EuiDataGridSorting['columns'];

Expand Down Expand Up @@ -70,7 +70,7 @@ export const useDataGrid = (props: tDataGridProps): EuiDataGridProps => {
useDefaultPagination = false,
pagination: paginationProps = {},
filters = [],
setFilters = () => { },
setFilters = () => {},
} = props;
const [columnVisibility, setVisibility] = useState(() =>
columns.map(({ id }) => id),
Expand All @@ -86,11 +86,11 @@ export const useDataGrid = (props: tDataGridProps): EuiDataGridProps => {
);
return defaultSort
? [
{
id: defaultSort.id,
direction: defaultSort.defaultSortDirection || 'desc',
},
]
{
id: defaultSort.id,
direction: defaultSort.defaultSortDirection || 'desc',
},
]
: [];
};
const defaultSorting: SortingColumns = getDefaultSorting();
Expand All @@ -105,9 +105,9 @@ export const useDataGrid = (props: tDataGridProps): EuiDataGridProps => {
useDefaultPagination
? DEFAULT_PAGINATION_OPTIONS
: {
...DEFAULT_PAGINATION_OPTIONS,
...paginationProps,
},
...DEFAULT_PAGINATION_OPTIONS,
...paginationProps,
},
);

const onChangeItemsPerPage = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class PatternDataSourceFilterManager
static createFilter(
type: FILTER_OPERATOR,
key: string,
value: string | string[] | any,
value: string | string[] | any,
indexPatternId: string,
controlledBy?: string,
) {
Expand Down
21 changes: 12 additions & 9 deletions plugins/main/public/components/common/search-bar/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ export const WzSearchBar = ({
{fixedFilters?.map((filter, idx) => (
<EuiFlexItem grow={false} key={idx}>
<EuiBadge className='globalFilterItem' color='hollow'>
{`${filter.meta.key}: ${typeof filter.meta.value === 'function'
? filter.meta.value()
: filter.meta.value
}`}
{`${filter.meta.key}: ${
typeof filter.meta.value === 'function'
? filter.meta.value()
: filter.meta.value
}`}
</EuiBadge>
</EuiFlexItem>
))}
{postFixedFilters ? postFixedFilters.map((Filter, idx) => (
<EuiFlexItem grow={false} key={idx}>
<Filter />
</EuiFlexItem>
)) : null}
{postFixedFilters
? postFixedFilters.map((Filter, idx) => (
<EuiFlexItem grow={false} key={idx}>
<Filter />
</EuiFlexItem>
))
: null}
</EuiFlexGroup>
</EuiFlexItem>
)}
Expand Down
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;
}
}
}
}
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;
Loading

0 comments on commit 4af0b41

Please sign in to comment.