From 48b25d7515d9a61350c8083b1cc19da3bcdba494 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 13:55:59 -0300 Subject: [PATCH 01/54] Refactor filter button actions in DocViewer --- .../common/data-grid/data-grid-service.ts | 8 +- .../common/doc-viewer/doc-viewer.tsx | 51 ++++++++++- .../doc-viewer/table_row_btn_filter_add.tsx | 75 +++++++++++++++++ .../table_row_btn_filter_exists.tsx | 84 +++++++++++++++++++ .../table_row_btn_filter_remove.tsx | 75 +++++++++++++++++ .../document-view-table-and-json.tsx | 9 +- .../common/wazuh-discover/wz-discover.tsx | 2 + 7 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 plugins/main/public/components/common/doc-viewer/table_row_btn_filter_add.tsx create mode 100644 plugins/main/public/components/common/doc-viewer/table_row_btn_filter_exists.tsx create mode 100644 plugins/main/public/components/common/doc-viewer/table_row_btn_filter_remove.tsx diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index bdd6cace7e..de3967cef9 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -192,16 +192,12 @@ export const exportSearchToCSV = async ( } }; -const onFilterCellActions = ( +export const onFilterCellActions = ( indexPatternId: string, filters: Filter[], setFilters: (filters: Filter[]) => void, ) => { - return ( - columndId: string, - value: any, - operation: FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, - ) => { + return (columndId: string, value: any, operation: FILTER_OPERATOR) => { const newFilter = PatternDataSourceFilterManager.createFilter( operation, columndId, diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index f0249a1eaf..5b8bf9970c 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -4,6 +4,12 @@ import { escapeRegExp } from 'lodash'; import { i18n } from '@osd/i18n'; import { FieldIcon } from '../../../../../../src/plugins/opensearch_dashboards_react/public'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { onFilterCellActions } from '../data-grid'; +import { Filter } from '../../../../../../src/plugins/data/common'; +import { FILTER_OPERATOR } from '../data-source'; +import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; +import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; +import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; const COLLAPSE_LINE_LENGTH = 350; const DOT_PREFIX_RE = /(.).+?\./g; @@ -15,6 +21,8 @@ export type tDocViewerProps = { mapping: any; indexPattern: any; docJSON: any; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; }; /** @@ -82,8 +90,16 @@ const DocViewer = (props: tDocViewerProps) => { const [fieldRowOpen, setFieldRowOpen] = useState( {} as Record, ); - const { flattened, formatted, mapping, indexPattern, renderFields, docJSON } = - props; + const { + flattened, + formatted, + mapping, + indexPattern, + renderFields, + docJSON, + filters, + setFilters, + } = props; return ( <> @@ -121,8 +137,39 @@ const DocViewer = (props: tDocViewerProps) => { const fieldIconProps = { fill: 'none', color: 'gray' }; const scripted = Boolean(fieldMapping?.scripted); + const onFilter = onFilterCellActions( + indexPattern.id, + filters, + setFilters, + ); + return ( + + + onFilter(field, flattened[field], FILTER_OPERATOR.IS) + } + /> + + onFilter( + field, + flattened[field], + FILTER_OPERATOR.IS_NOT, + ) + } + /> + + onFilter(field, null, FILTER_OPERATOR.EXISTS) + } + scripted={fieldMapping && fieldMapping.scripted} + /> + void; + disabled: boolean; +} + +export function DocViewTableRowBtnFilterAdd({ + onClick, + disabled = false, +}: Props) { + const tooltipContent = disabled ? ( + + ) : ( + + ); + + return ( + + + + ); +} diff --git a/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_exists.tsx b/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_exists.tsx new file mode 100644 index 0000000000..53f549ede5 --- /dev/null +++ b/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_exists.tsx @@ -0,0 +1,84 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { FormattedMessage } from '@osd/i18n/react'; +import { EuiToolTip, EuiSmallButtonIcon } from '@elastic/eui'; +import { i18n } from '@osd/i18n'; + +export interface Props { + onClick: () => void; + disabled?: boolean; + scripted?: boolean; +} + +export function DocViewTableRowBtnFilterExists({ + onClick, + disabled = false, + scripted = false, +}: Props) { + const tooltipContent = disabled ? ( + scripted ? ( + + ) : ( + + ) + ) : ( + + ); + + return ( + + + + ); +} diff --git a/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_remove.tsx b/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_remove.tsx new file mode 100644 index 0000000000..d4ad5711d1 --- /dev/null +++ b/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_remove.tsx @@ -0,0 +1,75 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { FormattedMessage } from '@osd/i18n/react'; +import { EuiToolTip, EuiSmallButtonIcon } from '@elastic/eui'; +import { i18n } from '@osd/i18n'; + +export interface Props { + onClick: () => void; + disabled?: boolean; +} + +export function DocViewTableRowBtnFilterRemove({ + onClick, + disabled = false, +}: Props) { + const tooltipContent = disabled ? ( + + ) : ( + + ); + + return ( + + + + ); +} diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index 2592e340b9..98dba51319 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -8,6 +8,8 @@ export const DocumentViewTableAndJson = ({ document, indexPattern, renderFields, + filters, + setFilters, }) => { const docViewerProps = useDocViewer({ doc: document, @@ -22,7 +24,12 @@ export const DocumentViewTableAndJson = ({ id: 'table', name: 'Table', content: ( - + ), }, { diff --git a/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx b/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx index f679f0a142..0406d17c50 100644 --- a/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx +++ b/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx @@ -285,6 +285,8 @@ const WazuhDiscoverComponent = (props: WazuhDiscoverProps) => { defaultTableColumns, wzDiscoverRenderColumns, )} + filters={filters} + setFilters={setFilters} /> From c9f9a32bef9defa41f2af708eadb3b03fa4e2014 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 14:25:45 -0300 Subject: [PATCH 02/54] Add Doc Viewer styles and import to Doc Viewer component --- .../common/doc-viewer/doc-viewer.scss | 68 +++++++++++++++++++ .../common/doc-viewer/doc-viewer.tsx | 1 + 2 files changed, 69 insertions(+) create mode 100644 plugins/main/public/components/common/doc-viewer/doc-viewer.scss diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss new file mode 100644 index 0000000000..ed877e28ff --- /dev/null +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss @@ -0,0 +1,68 @@ +.osdDocViewerTable { + pre, + .osdDocViewer__value { + display: inline-block; + word-break: break-all; + word-wrap: break-word; + white-space: pre-wrap; + color: $euiColorFullShade; + vertical-align: top; + padding-top: 2px; + } + + .osdDocViewer__field { + padding-top: 8px; + } + + .dscFieldName { + color: $euiColorDarkShade; + } + + td, + pre { + font-family: $euiCodeFontFamily; + } + + tr:first-child td { + border-top-color: transparent; + } + + tr:hover { + .osdDocViewer__actionButton { + opacity: 1; + } + } +} + +.osdDocViewer__buttons, +.osdDocViewer__field { + white-space: nowrap; +} + +.osdDocViewer__buttons { + width: 60px; + + // Show all icons if one is focused, + // IE doesn't support, but the fallback is just the focused button becomes visible + &:focus-within { + .osdDocViewer__actionButton { + opacity: 1; + } + } +} + +.osdDocViewer__field { + width: 160px; +} + +.osdDocViewer__actionButton { + opacity: 0; + + &:hover { + opacity: 1; + } +} + +.osdDocViewer__warning { + margin-right: $euiSizeS; +} diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 5b8bf9970c..0be58c0add 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -10,6 +10,7 @@ import { FILTER_OPERATOR } from '../data-source'; import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; +import './doc-viewer.scss'; const COLLAPSE_LINE_LENGTH = 350; const DOT_PREFIX_RE = /(.).+?\./g; From 334b8453e5662a93f77f0d25fe07fbfbb0bc4ac0 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 18:06:57 -0300 Subject: [PATCH 03/54] Refactor cell filter actions to use 'field' instead of 'columnId' --- .../common/data-grid/cell-filter-actions.tsx | 24 +++++++++---------- .../common/data-grid/data-grid-service.ts | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx b/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx index 6f9007dffc..2e9e54c5ff 100644 --- a/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx +++ b/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx @@ -15,14 +15,14 @@ export const filterIsAction = ( rows: any[], pageSize: number, onFilter: ( - columndId: string, - value: any, + field: string, operation: FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, + value?: any, ) => void, ) => { return ({ rowIndex, - columnId, + columnId: field, Component, }: EuiDataGridColumnCellActionProps) => { const filterForValueText = i18n.translate('discover.filterForValue', { @@ -30,7 +30,7 @@ export const filterIsAction = ( }); const filterForValueLabel = i18n.translate('discover.filterForValueLabel', { defaultMessage: 'Filter for value: {value}', - values: { value: columnId }, + values: { value: field }, }); const handleClick = () => { @@ -38,7 +38,7 @@ export const filterIsAction = ( const flattened = indexPattern.flattenHit(row); if (flattened) { - onFilter(columnId, flattened[columnId], FILTER_OPERATOR.IS); + onFilter(field, FILTER_OPERATOR.IS, flattened[field]); } }; @@ -61,18 +61,18 @@ export const filterIsNotAction = rows: any[], pageSize: number, onFilter: ( - columndId: string, - value: any, + field: string, operation: FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, + value?: any, ) => void, ) => - ({ rowIndex, columnId, Component }: EuiDataGridColumnCellActionProps) => { + ({ rowIndex, columnId: field, Component }: EuiDataGridColumnCellActionProps) => { const filterOutValueText = i18n.translate('discover.filterOutValue', { defaultMessage: 'Filter out value', }); const filterOutValueLabel = i18n.translate('discover.filterOutValueLabel', { defaultMessage: 'Filter out value: {value}', - values: { value: columnId }, + values: { value: field }, }); const handleClick = () => { @@ -80,7 +80,7 @@ export const filterIsNotAction = const flattened = indexPattern.flattenHit(row); if (flattened) { - onFilter(columnId, flattened[columnId], FILTER_OPERATOR.IS_NOT); + onFilter(field, FILTER_OPERATOR.IS_NOT, flattened[field]); } }; @@ -103,9 +103,9 @@ export function cellFilterActions( rows: any[], pageSize: number, onFilter: ( - columndId: string, - value: any, + field: string, operation: FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, + value: any, ) => void, ) { if (!field.filterable) return; diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index de3967cef9..a7e39d87e0 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -197,10 +197,10 @@ export const onFilterCellActions = ( filters: Filter[], setFilters: (filters: Filter[]) => void, ) => { - return (columndId: string, value: any, operation: FILTER_OPERATOR) => { + return (field: string, operation: FILTER_OPERATOR, value?: any) => { const newFilter = PatternDataSourceFilterManager.createFilter( operation, - columndId, + field, value, indexPatternId, ); From 3433625e51ef5dbc45e1da5a29ee4a60c8fe97f7 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 18:07:14 -0300 Subject: [PATCH 04/54] Refactor filtering logic in DocViewer component --- .../common/doc-viewer/doc-viewer.tsx | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 0be58c0add..2b6399c957 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -4,8 +4,6 @@ import { escapeRegExp } from 'lodash'; import { i18n } from '@osd/i18n'; import { FieldIcon } from '../../../../../../src/plugins/opensearch_dashboards_react/public'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { onFilterCellActions } from '../data-grid'; -import { Filter } from '../../../../../../src/plugins/data/common'; import { FILTER_OPERATOR } from '../data-source'; import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; @@ -22,8 +20,7 @@ export type tDocViewerProps = { mapping: any; indexPattern: any; docJSON: any; - filters: Filter[]; - setFilters: (filters: Filter[]) => void; + onFilter: (columndId: string, operation: FILTER_OPERATOR, value?: any) => void; }; /** @@ -98,8 +95,7 @@ const DocViewer = (props: tDocViewerProps) => { indexPattern, renderFields, docJSON, - filters, - setFilters, + onFilter, } = props; return ( @@ -138,19 +134,13 @@ const DocViewer = (props: tDocViewerProps) => { const fieldIconProps = { fill: 'none', color: 'gray' }; const scripted = Boolean(fieldMapping?.scripted); - const onFilter = onFilterCellActions( - indexPattern.id, - filters, - setFilters, - ); - return ( - onFilter(field, flattened[field], FILTER_OPERATOR.IS) + onFilter(field, FILTER_OPERATOR.IS, flattened[field]) } /> { onClick={() => onFilter( field, - flattened[field], FILTER_OPERATOR.IS_NOT, + flattened[field], ) } /> - onFilter(field, null, FILTER_OPERATOR.EXISTS) + onFilter(field, FILTER_OPERATOR.EXISTS) } scripted={fieldMapping && fieldMapping.scripted} /> From 71f1ba91a2f0ee82c1e39e4af58a9ef033570683 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 18:07:26 -0300 Subject: [PATCH 05/54] Add onFilterHandler to DocViewer component --- .../wazuh-discover/components/doc-details.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx index da923c4e81..3b8010a90f 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx @@ -1,15 +1,30 @@ import React, { useState } from 'react'; import { useDocViewer } from '../../doc-viewer'; import DocViewer from '../../doc-viewer/doc-viewer'; -import { IndexPattern } from '../../../../../../../src/plugins/data/common'; +import { Filter, IndexPattern } from '../../../../../../../src/plugins/data/common'; import { EuiCodeBlock, EuiFlexGroup, EuiTabbedContent } from '@elastic/eui'; +import { onFilterCellActions } from '../../data-grid'; +import { FILTER_OPERATOR } from '../../data-source'; -const DocDetails = ({ doc, item, indexPattern }) => { +interface DocDetailsProps { + doc: any; + item: any; + indexPattern: IndexPattern; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; +} + +const DocDetails = ({ doc, item, indexPattern, filters, setFilters }: DocDetailsProps) => { const docViewerProps = useDocViewer({ doc, indexPattern: indexPattern as IndexPattern, }); + const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilter = onFilterCellActions(indexPattern.id as string, filters, setFilters); + onFilter(field, operation, value); + }; + return ( { name: 'Table', content: ( <> - + ), }, From 344df6dad0bb0ce521d86249e42005f81e1413df Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 18:09:14 -0300 Subject: [PATCH 06/54] Add onFilter handler to various components --- .../document-view-table-and-json.tsx | 10 +++- .../wazuh-discover/wz-flyout-discover.tsx | 2 +- .../compliance-table/compliance-table.tsx | 2 + .../subrequirements/subrequirements.tsx | 2 + .../technique-row-details.tsx | 39 ++++++++++--- .../threat-hunting/dashboard/dashboard.tsx | 56 ++++++++----------- 6 files changed, 69 insertions(+), 42 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index 98dba51319..362a72fa86 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -3,6 +3,8 @@ import { EuiFlexItem, EuiCodeBlock, EuiTabbedContent } from '@elastic/eui'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; import DocViewer from '../../doc-viewer/doc-viewer'; import { useDocViewer } from '../../doc-viewer'; +import { onFilterCellActions } from "../../data-grid"; +import { FILTER_OPERATOR } from "../../data-source"; export const DocumentViewTableAndJson = ({ document, @@ -16,6 +18,11 @@ export const DocumentViewTableAndJson = ({ indexPattern: indexPattern as IndexPattern, }); + const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); + onFilter(field, operation, value); + }; + return ( ), }, diff --git a/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx b/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx index 93cb855a4f..e3eef162ec 100644 --- a/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx +++ b/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx @@ -254,7 +254,7 @@ const WazuhFlyoutDiscoverComponent = (props: WazuhDiscoverProps) => { indexPattern, }) ) : ( - + ); }; diff --git a/plugins/main/public/components/overview/compliance-table/compliance-table.tsx b/plugins/main/public/components/overview/compliance-table/compliance-table.tsx index d186be87a9..fad80e11b6 100644 --- a/plugins/main/public/components/overview/compliance-table/compliance-table.tsx +++ b/plugins/main/public/components/overview/compliance-table/compliance-table.tsx @@ -352,6 +352,8 @@ export const ComplianceTable = withAgentSupportModule(props => { getRegulatoryComplianceRequirementFilter } {...complianceData} + filters={filters} + setFilters={setFilters} /> diff --git a/plugins/main/public/components/overview/compliance-table/components/subrequirements/subrequirements.tsx b/plugins/main/public/components/overview/compliance-table/components/subrequirements/subrequirements.tsx index 79bb050d2c..5f515b75cc 100644 --- a/plugins/main/public/components/overview/compliance-table/components/subrequirements/subrequirements.tsx +++ b/plugins/main/public/components/overview/compliance-table/components/subrequirements/subrequirements.tsx @@ -361,6 +361,8 @@ export class ComplianceSubrequirements extends Component { ]} openDashboard={(e, itemId) => this.openDashboard(e, itemId)} openDiscover={(e, itemId) => this.openDiscover(e, itemId)} + filters={this.props.filters} + setFilters={this.props.setFilters} /> )} diff --git a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx index b808662c8e..938abb296c 100644 --- a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx +++ b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx @@ -3,17 +3,31 @@ import { EuiCodeBlock, EuiFlexGroup, EuiTabbedContent } from '@elastic/eui'; import { useDocViewer } from '../../../../../../../common/doc-viewer/use-doc-viewer'; import DocViewer from '../../../../../../../common/doc-viewer/doc-viewer'; import RuleDetails from '../rule-details'; -import { IndexPattern } from '../../../../../../../../../../../src/plugins/data/common'; +import { + IndexPattern, + Filter, +} from '../../../../../../../../../../../src/plugins/data/common'; import { WzRequest } from '../../../../../../../../react-services/wz-request'; +import { onFilterCellActions } from "../../../../../../../common/data-grid"; +import { FILTER_OPERATOR } from "../../../../../../../common/data-source"; type Props = { doc: any; item: any; indexPattern: IndexPattern; onRuleItemClick?: (value: any, indexPattern: IndexPattern) => void; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; }; -const TechniqueRowDetails = ({ doc, item, indexPattern, onRuleItemClick }) => { +const TechniqueRowDetails = ({ + doc, + item, + indexPattern, + onRuleItemClick, + filters, + setFilters, +}) => { const docViewerProps = useDocViewer({ doc, indexPattern: indexPattern as IndexPattern, @@ -23,8 +37,11 @@ const TechniqueRowDetails = ({ doc, item, indexPattern, onRuleItemClick }) => { const getRuleData = async () => { const params = { q: `id=${item.rule.id}` }; - const rulesDataResponse = await WzRequest.apiReq('GET', `/rules`, { params }); - const ruleData = ((rulesDataResponse.data || {}).data || {}).affected_items[0] || {}; + const rulesDataResponse = await WzRequest.apiReq('GET', `/rules`, { + params, + }); + const ruleData = + ((rulesDataResponse.data || {}).data || {}).affected_items[0] || {}; setRuleData(ruleData); }; @@ -36,6 +53,11 @@ const TechniqueRowDetails = ({ doc, item, indexPattern, onRuleItemClick }) => { getRuleData(); }, []); + const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); + onFilter(field, operation, value); + }; + return ( { name: 'Table', content: ( <> - + ), }, @@ -56,9 +81,9 @@ const TechniqueRowDetails = ({ doc, item, indexPattern, onRuleItemClick }) => { content: ( {JSON.stringify(item, null, 2)} diff --git a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx index ba380ff059..62193a50c5 100644 --- a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx +++ b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx @@ -17,18 +17,13 @@ import { EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, - EuiTitle, - EuiButtonEmpty, } from '@elastic/eui'; -import { - ErrorFactory, - ErrorHandler, - HttpError, -} from '../../../../react-services/error-management'; +import { ErrorFactory, ErrorHandler, HttpError } from '../../../../react-services/error-management'; import { MAX_ENTRIES_PER_QUERY, exportSearchToCSV, getAllCustomRenders, + onFilterCellActions, } from '../../../common/data-grid/data-grid-service'; import { useDocViewer } from '../../../common/doc-viewer/use-doc-viewer'; import { useDataGrid } from '../../../common/data-grid/use-data-grid'; @@ -47,6 +42,7 @@ import { PatternDataSourceFilterManager, tParsedIndexPattern, useDataSource, + FILTER_OPERATOR, } from '../../../common/data-source'; import { DiscoverNoResults } from '../../../common/no-results/no-results'; import { LoadingSearchbarProgress } from '../../../common/loading-searchbar-progress/loading-searchbar-progress'; @@ -95,18 +91,16 @@ const DashboardTH: React.FC = () => { const rowClicked = results.hits.hits[index]; setInspectedHit(rowClicked); }, - [results], + [results] ); - const DocViewInspectButton = ({ - rowIndex, - }: EuiDataGridCellValueElementProps) => { + const DocViewInspectButton = ({ rowIndex }: EuiDataGridCellValueElementProps) => { const inspectHintMsg = 'Inspect document details'; return ( onClickInspectDoc(rowIndex)} - iconType='inspect' + iconType="inspect" aria-label={inspectHintMsg} /> @@ -132,8 +126,7 @@ const DashboardTH: React.FC = () => { }); const pinnedAgent = - PatternDataSourceFilterManager.getPinnedAgentFilter(dataSource?.id!) - .length > 0; + PatternDataSourceFilterManager.getPinnedAgentFilter(dataSource?.id!).length > 0; useEffect(() => { const currentColumns = !pinnedAgent @@ -161,10 +154,10 @@ const DashboardTH: React.FC = () => { sorting, dateRange: absoluteDateRange, }) - .then(results => { + .then((results) => { setResults(results); }) - .catch(error => { + .catch((error) => { const searchError = ErrorFactory.create(HttpError, { error, message: 'Error fetching data', @@ -205,6 +198,11 @@ const DashboardTH: React.FC = () => { } }; + const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilter = onFilterCellActions(dataSource?.indexPattern?.id, filters, setFilters); + onFilter(field, operation, value); + }; + return ( {isDataSourceLoading && !dataSource ? ( @@ -212,7 +210,7 @@ const DashboardTH: React.FC = () => { ) : ( <> { ) : null}
0 - ? '' - : 'wz-no-display' + !isDataSourceLoading && dataSource && results?.hits?.total > 0 ? '' : 'wz-no-display' }`} > -
+
{ viewMode: ViewMode.VIEW, panels: getDashboardPanels( AlertsRepository.getStoreIndexPatternId(), - pinnedAgent, + pinnedAgent ), isFullScreenMode: false, filters: fetchFilters ?? [], @@ -297,22 +291,20 @@ const DashboardTH: React.FC = () => { ) : null}
{inspectedHit && ( - setInspectedHit(undefined)} size='m'> + setInspectedHit(undefined)} size="m"> - + - + From bc93d2f77c1c48c0fcdc43fb5d219e2953aade91 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 7 Oct 2024 18:09:41 -0300 Subject: [PATCH 07/54] Refactor RequirementFlyout component for readability --- .../requirement-flyout/requirement-flyout.tsx | 129 ++++++++---------- 1 file changed, 56 insertions(+), 73 deletions(-) diff --git a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx index 607adfd9fe..e99e345620 100644 --- a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx +++ b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx @@ -26,20 +26,17 @@ import { import { AppState } from '../../../../../react-services/app-state'; import { requirementGoal } from '../../requirement-goal'; import { getUiSettings } from '../../../../../kibana-services'; -import { - FilterManager, - IndexPattern, -} from '../../../../../../../../src/plugins/data/public/'; +import { FilterManager, IndexPattern } from '../../../../../../../../src/plugins/data/public/'; import { WzFlyout } from '../../../../../components/common/flyouts'; import { WazuhFlyoutDiscover } from '../../../../common/wazuh-discover/wz-flyout-discover'; import { PatternDataSource } from '../../../../common/data-source'; import { formatUIDate } from '../../../../../react-services'; import TechniqueRowDetails from '../../../mitre/framework/components/techniques/components/flyout-technique/technique-row-details'; -import { buildPhraseFilter } from '../../../../../../../../src/plugins/data/common'; +import { buildPhraseFilter, Filter } from '../../../../../../../../src/plugins/data/common'; import { connect } from 'react-redux'; import { wzDiscoverRenderColumns } from '../../../../common/wazuh-discover/render-columns'; -const mapStateToProps = state => ({ +const mapStateToProps = (state) => ({ currentAgentData: state.appStateReducers.currentAgentData, }); @@ -63,9 +60,9 @@ export const RequirementFlyout = connect(mapStateToProps)( } addRenderColumn(columns) { - return columns.map(column => { + return columns.map((column) => { const renderColumn = wzDiscoverRenderColumns.find( - columnRender => columnRender.id === column.id, + (columnRender) => columnRender.id === column.id ); if (renderColumn) { return { ...column, render: renderColumn.render }; @@ -81,7 +78,7 @@ export const RequirementFlyout = connect(mapStateToProps)( isSortable: true, defaultSortDirection: 'desc', displayAsText: 'Time', - render: value => formatUIDate(value), + render: (value) => formatUIDate(value), }, { id: this.props.getRequirementKey(), @@ -101,7 +98,7 @@ export const RequirementFlyout = connect(mapStateToProps)( isSortable: true, defaultSortDirection: 'desc', displayAsText: 'Time', - render: value => formatUIDate(value), + render: (value) => formatUIDate(value), }, { id: 'agent.id', @@ -137,19 +134,15 @@ export const RequirementFlyout = connect(mapStateToProps)(
)) || ( - -

Requirement {currentRequirement}

+ +

Requirement {currentRequirement}

)} ); } - renderDiscoverExpandedRow(props: { - doc: any; - item: any; - indexPattern: any; - }) { + renderDiscoverExpandedRow(props: { doc: any; item: any; indexPattern: any }) { return ( - buildPhraseFilter( - { name: key, type: 'string' }, - item, - indexPattern, - ), - ) + .map((item) => buildPhraseFilter({ name: key, type: 'string' }, item, indexPattern)) .filter(Boolean); this.filterManager.addFilters(newFilter); }} + filters={[]} + setFilters={(filters: Filter[]) => { + const prevFilters = this.filterManager + .getFilters() + .filter( + (prevFilter) => + !filters.find( + (filter) => + filter.meta.key === prevFilter.meta.key && + filter.meta.type === prevFilter.meta.type && + filter.meta.params === prevFilter.meta.params.query && + filter.meta.negate !== prevFilter.meta.negate + ) + ); + const newFilters = [...filters, ...prevFilters]; + this.filterManager.setFilters(newFilters, undefined); + }} /> ); } @@ -185,39 +187,33 @@ export const RequirementFlyout = connect(mapStateToProps)( ? { 'cluster.name': AppState.getClusterInfo().cluster } : { 'manager.name': AppState.getClusterInfo().manager }; this.clusterFilter = clusterFilter; - requirementImplicitFilter[this.props.getRequirementKey()] = - currentRequirement; + requirementImplicitFilter[this.props.getRequirementKey()] = currentRequirement; const implicitFilters = [requirementImplicitFilter, this.clusterFilter]; if (this.props.implicitFilters) { - this.props.implicitFilters.forEach(item => implicitFilters.push(item)); + this.props.implicitFilters.forEach((item) => implicitFilters.push(item)); } //Goal for PCI const currentReq = this.props.currentRequirement.split('.')[0]; return ( - + +

Details

} - paddingSize='xs' + paddingSize="xs" initialIsOpen={true} > -
- +
+ {requirementGoal[currentReq] && ( - + @@ -231,68 +227,57 @@ export const RequirementFlyout = connect(mapStateToProps)( - + -

- Requirement description -

+

Requirement description

{this.props.description}

- +
- + +

Recent events {this.props.view !== 'events' && ( { + onMouseDown={(e) => { this.props.openDashboard(e, currentRequirement); e.stopPropagation(); }} - color='primary' - type='visualizeApp' + color="primary" + type="visualizeApp" style={{ marginRight: '10px' }} > { + onMouseDown={(e) => { this.props.openDiscover(e, currentRequirement); e.stopPropagation(); }} - color='primary' - type='discoverApp' + color="primary" + type="discoverApp" > @@ -301,7 +286,7 @@ export const RequirementFlyout = connect(mapStateToProps)(

} - paddingSize='none' + paddingSize="none" initialIsOpen={true} > - this.renderDiscoverExpandedRow(...args) - } + expandedRowComponent={(...args) => this.renderDiscoverExpandedRow(...args)} />
@@ -346,5 +329,5 @@ export const RequirementFlyout = connect(mapStateToProps)( ); } - }, + } ); From 44db0fce774b58abd795159d64d57a1dbc4632e1 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 14:18:58 -0300 Subject: [PATCH 08/54] Add filter functionality to inventory vulnerabilities dashboard --- .../overview/vulnerabilities/dashboards/inventory/inventory.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx index 4786bf71a1..c764591648 100644 --- a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx @@ -310,6 +310,8 @@ const InventoryVulsComponent = () => { inventoryTableDefaultColumns, wzDiscoverRenderColumns, )} + filters={filters} + setFilters={setFilters} /> From 6b5a363fe2af4eef4321a77ab0af917e7dbb1096 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 14:19:05 -0300 Subject: [PATCH 09/54] Remove unused code related to doc viewer in WazuhDataGrid --- .../components/common/wazuh-data-grid/wz-data-grid.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx index 0da3e2e1c5..03365a4be5 100644 --- a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx +++ b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx @@ -23,7 +23,6 @@ import { IndexPattern, SearchResponse, } from '../../../../../../src/plugins/data/public'; -import { useDocViewer } from '../doc-viewer'; import { ErrorHandler, ErrorFactory, @@ -115,11 +114,6 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { onChangeSorting && onChangeSorting(sorting || []); }, [JSON.stringify(sorting)]); - const docViewerProps = useDocViewer({ - doc: inspectedHit, - indexPattern: indexPattern as IndexPattern, - }); - const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined; From d6eb863cc45421990fb0187dbc106eba114e6e5e Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 14:34:48 -0300 Subject: [PATCH 10/54] Add setFilters function to FileDetails and RequirementFlyout --- .../agents/fim/inventory/fileDetail.tsx | 3 +++ .../common/search-bar/set-filters.ts | 18 ++++++++++++++++++ .../requirement-flyout/requirement-flyout.tsx | 18 ++---------------- 3 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 plugins/main/public/components/common/search-bar/set-filters.ts diff --git a/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx b/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx index 0dff1a4698..9c3071ee4f 100644 --- a/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx +++ b/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx @@ -52,6 +52,7 @@ import { RedirectAppLinks } from '../../../../../../../src/plugins/opensearch_da import TechniqueRowDetails from '../../../overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details'; import { DATA_SOURCE_FILTER_CONTROLLED_CLUSTER_MANAGER } from '../../../../../common/constants'; import NavigationService from '../../../../react-services/navigation-service'; +import { setFilters } from "../../../common/search-bar/set-filters"; export class FileDetails extends Component { props!: { @@ -586,6 +587,8 @@ export class FileDetails extends Component { this.discoverFilterManager.addFilters(newFilter); }} + filters={[]} + setFilters={setFilters(this.discoverFilterManager)} /> ); } diff --git a/plugins/main/public/components/common/search-bar/set-filters.ts b/plugins/main/public/components/common/search-bar/set-filters.ts new file mode 100644 index 0000000000..ffad86e545 --- /dev/null +++ b/plugins/main/public/components/common/search-bar/set-filters.ts @@ -0,0 +1,18 @@ +import { Filter, FilterManager } from '../../../../../../src/plugins/data/public'; + +const isSameNegatedFilter = (filter: Filter, prevFilter: Filter) => { + return ( + filter.meta.key === prevFilter.meta.key && + filter.meta.type === prevFilter.meta.type && + filter.meta.params === prevFilter.meta.params.query && + filter.meta.negate !== prevFilter.meta.negate + ); +}; + +export const setFilters = (filterManager: FilterManager) => (filters: Filter[]) => { + const prevFilters = filterManager + .getFilters() + .filter((prevFilter) => !filters.find((filter) => isSameNegatedFilter(filter, prevFilter))); + const newFilters = [...filters, ...prevFilters]; + filterManager.setFilters(newFilters, undefined); +}; diff --git a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx index e99e345620..f969ca873c 100644 --- a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx +++ b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx @@ -35,6 +35,7 @@ import TechniqueRowDetails from '../../../mitre/framework/components/techniques/ import { buildPhraseFilter, Filter } from '../../../../../../../../src/plugins/data/common'; import { connect } from 'react-redux'; import { wzDiscoverRenderColumns } from '../../../../common/wazuh-discover/render-columns'; +import { setFilters } from "../../../../common/search-bar/set-filters"; const mapStateToProps = (state) => ({ currentAgentData: state.appStateReducers.currentAgentData, @@ -159,22 +160,7 @@ export const RequirementFlyout = connect(mapStateToProps)( this.filterManager.addFilters(newFilter); }} filters={[]} - setFilters={(filters: Filter[]) => { - const prevFilters = this.filterManager - .getFilters() - .filter( - (prevFilter) => - !filters.find( - (filter) => - filter.meta.key === prevFilter.meta.key && - filter.meta.type === prevFilter.meta.type && - filter.meta.params === prevFilter.meta.params.query && - filter.meta.negate !== prevFilter.meta.negate - ) - ); - const newFilters = [...filters, ...prevFilters]; - this.filterManager.setFilters(newFilters, undefined); - }} + setFilters={setFilters(this.filterManager)} /> ); } From 7f3f738af1f20b3866b03509ce985be8d093ccb7 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 16:43:52 -0300 Subject: [PATCH 11/54] Refactor doc-viewer styles for button display --- .../common/doc-viewer/doc-viewer.scss | 29 +++++++---- .../common/doc-viewer/doc-viewer.tsx | 50 +++++++++---------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss index ed877e28ff..b81f4a6611 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss @@ -23,14 +23,29 @@ font-family: $euiCodeFontFamily; } + tr { + position: relative; + } + tr:first-child td { border-top-color: transparent; } tr:hover { - .osdDocViewer__actionButton { - opacity: 1; + .osdDocViewer__buttons { + display: flex; + position: absolute; + background: #fff; + background: linear-gradient(180deg, rgb(255, 255, 255) 0%, rgb(255, 255, 255) 80%, rgba(0, 0, 0, 0) 100%); + right: 0; + top: 0; + transform: translateY(0.5px); + + .osdDocViewer__actionButton { + opacity: 1; + } } + } } @@ -40,15 +55,7 @@ } .osdDocViewer__buttons { - width: 60px; - - // Show all icons if one is focused, - // IE doesn't support, but the fallback is just the focused button becomes visible - &:focus-within { - .osdDocViewer__actionButton { - opacity: 1; - } - } + display: none; } .osdDocViewer__field { diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 2b6399c957..fe08b06f01 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -136,31 +136,6 @@ const DocViewer = (props: tDocViewerProps) => { return ( - - - onFilter(field, FILTER_OPERATOR.IS, flattened[field]) - } - /> - - onFilter( - field, - FILTER_OPERATOR.IS_NOT, - flattened[field], - ) - } - /> - - onFilter(field, FILTER_OPERATOR.EXISTS) - } - scripted={fieldMapping && fieldMapping.scripted} - /> - { +
+ + onFilter(field, FILTER_OPERATOR.IS, flattened[field]) + } + /> + + onFilter( + field, + FILTER_OPERATOR.IS_NOT, + flattened[field], + ) + } + /> + + onFilter(field, FILTER_OPERATOR.EXISTS) + } + scripted={fieldMapping && fieldMapping.scripted} + /> +
{renderFields && renderFields?.find( (field: string) => field?.id === displayName, From a45fb43da13007d50e2df9909bb8f70502e23e75 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 16:44:34 -0300 Subject: [PATCH 12/54] Add filter state management to data grid and drilldown panels --- .../components/common/wazuh-data-grid/wz-data-grid.tsx | 9 ++++++++- .../overview/github/panel/config/drilldown-action.tsx | 4 +++- .../overview/github/panel/config/drilldown-actor.tsx | 4 +++- .../overview/github/panel/config/drilldown-data-grid.tsx | 7 +++++++ .../github/panel/config/drilldown-organization.tsx | 4 +++- .../github/panel/config/drilldown-repository.tsx | 4 +++- .../components/overview/github/panel/github-panel.tsx | 2 ++ .../overview/office/panel/config/drilldown-ip-config.tsx | 4 +++- .../office/panel/config/drilldown-operations-config.tsx | 4 +++- .../office/panel/config/drilldown-rules-config.tsx | 4 +++- .../office/panel/config/drilldown-user-config.tsx | 4 +++- .../components/overview/office/panel/office-panel.tsx | 2 ++ 12 files changed, 43 insertions(+), 9 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx index 03365a4be5..fa79209dc0 100644 --- a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx +++ b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx @@ -20,6 +20,7 @@ import { } from '../data-grid'; import { getWazuhCorePlugin } from '../../../kibana-services'; import { + Filter, IndexPattern, SearchResponse, } from '../../../../../../src/plugins/data/public'; @@ -52,6 +53,8 @@ export type tWazuhDataGridProps = { pageSize: number; }) => void; onChangeSorting: (sorting: { columns: any[]; onSort: any }) => void; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; }; const WazuhDataGrid = (props: tWazuhDataGridProps) => { @@ -66,6 +69,8 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { onChangeSorting, query, dateRange, + filters, + setFilters } = props; const [inspectedHit, setInspectedHit] = useState(undefined); const [isExporting, setIsExporting] = useState(false); @@ -188,9 +193,11 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { document={inspectedHit} indexPattern={indexPattern as IndexPattern} renderFields={getAllCustomRenders( - defaultTableColumns, + defaultColumns, wzDiscoverRenderColumns, )} + filters={filters} + setFilters={setFilters} /> diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx index 37fc626b55..9431ecf9e5 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx @@ -110,7 +110,7 @@ const getDashboardPanels = ( }; export const DrilldownConfigAction = (drilldownProps: ModuleConfigProps) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = drilldownProps; return { @@ -174,6 +174,8 @@ export const DrilldownConfigAction = (drilldownProps: ModuleConfigProps) => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> ); }, diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx index bcc3eb720c..06cc8a0ea7 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx @@ -126,7 +126,7 @@ const getDashboardPanels = ( }; export const DrilldownConfigActor = (drilldownProps: ModuleConfigProps) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = drilldownProps; return { @@ -190,6 +190,8 @@ export const DrilldownConfigActor = (drilldownProps: ModuleConfigProps) => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> ); }, diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx index 0a5c8aa15d..c77036fdca 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx @@ -8,9 +8,12 @@ import { } from '../../../../../react-services/error-management'; import WazuhDataGrid from '../../../../common/wazuh-data-grid/wz-data-grid'; import { tDataGridColumn } from '../../../../common/data-grid'; +import { Filter } from "../../../../../../../../src/plugins/data/common"; type tDrillDownDataGridProps = { defaultTableColumns: tDataGridColumn[]; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; } & ModuleConfigProps; export default function DrillDownDataGrid(props: tDrillDownDataGridProps) { @@ -28,6 +31,8 @@ export default function DrillDownDataGrid(props: tDrillDownDataGridProps) { indexPattern, fetchFilters, defaultTableColumns, + filters, + setFilters, } = props; useEffect(() => { @@ -73,6 +78,8 @@ export default function DrillDownDataGrid(props: tDrillDownDataGridProps) { setSorting(sorting); }} dateRange={searchBarProps?.absoluteDateRange} + filters={filters} + setFilters={setFilters} /> ); diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx index 37b5427ae2..06d295c932 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx @@ -129,7 +129,7 @@ const getDashboardPanels = ( export const DrilldownConfigOrganization = ( drilldownProps: ModuleConfigProps, ) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = drilldownProps; return { @@ -193,6 +193,8 @@ export const DrilldownConfigOrganization = ( fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> ); }, diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx index 83639b34fb..4b20f770cb 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx @@ -119,7 +119,7 @@ const getDashboardPanels = ( export const DrilldownConfigRepository = ( drilldownProps: ModuleConfigProps, ) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = drilldownProps; return { @@ -192,6 +192,8 @@ export const DrilldownConfigRepository = ( fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> ); }, diff --git a/plugins/main/public/components/overview/github/panel/github-panel.tsx b/plugins/main/public/components/overview/github/panel/github-panel.tsx index 200d9310f0..52f745c136 100644 --- a/plugins/main/public/components/overview/github/panel/github-panel.tsx +++ b/plugins/main/public/components/overview/github/panel/github-panel.tsx @@ -104,6 +104,8 @@ export const GitHubPanel = withErrorBoundary(() => { fetchFilters: [...fetchFilters, ...selectedPanelFilter], searchBarProps, indexPattern: dataSource?.indexPattern, + filters, + setFilters, }} isLoading={isDataSourceLoading} /> diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx index c0946559b7..923722b761 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx @@ -99,7 +99,7 @@ const getDashboardPanels = ( }; export const drilldownIPConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = props; + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; return { rows: [ @@ -168,6 +168,8 @@ export const drilldownIPConfig = props => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} />
diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx index 4a700d8b28..bc866a652f 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx @@ -83,7 +83,7 @@ const getDashboardPanels = ( }; export const drilldownOperationsConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = props; + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; return { rows: [ @@ -151,6 +151,8 @@ export const drilldownOperationsConfig = props => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} />
diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx index 04fba33db7..73bd483876 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx @@ -98,7 +98,7 @@ const getDashboardPanels = ( }; export const drilldownRulesConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = props; + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; return { rows: [ @@ -171,6 +171,8 @@ export const drilldownRulesConfig = props => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx index 6e7ec543c8..bb792cbc06 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx @@ -99,7 +99,7 @@ const getDashboardPanels = ( }; export const drilldownUserConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern } = props; + const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; return { rows: [ @@ -171,6 +171,8 @@ export const drilldownUserConfig = props => { fetchFilters={fetchFilters} searchBarProps={searchBarProps} indexPattern={indexPattern} + filters={filters} + setFilters={setFilters} /> diff --git a/plugins/main/public/components/overview/office/panel/office-panel.tsx b/plugins/main/public/components/overview/office/panel/office-panel.tsx index 7d908087d7..3746771ae1 100644 --- a/plugins/main/public/components/overview/office/panel/office-panel.tsx +++ b/plugins/main/public/components/overview/office/panel/office-panel.tsx @@ -105,6 +105,8 @@ export const OfficePanel = withErrorBoundary(() => { fetchFilters: [...fetchFilters, ...selectedPanelFilter], searchBarProps, indexPattern: dataSource?.indexPattern, + filters, + setFilters, }} isLoading={isDataSourceLoading} /> From 64dfcd1ca0bbaf2ced433e24273398c09b720822 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 16:49:07 -0300 Subject: [PATCH 13/54] Fix Prettier issue --- .../agents/fim/inventory/fileDetail.tsx | 2 +- .../common/data-grid/cell-filter-actions.tsx | 6 +- .../common/doc-viewer/doc-viewer.scss | 10 +- .../common/doc-viewer/doc-viewer.tsx | 12 +- .../common/search-bar/set-filters.ts | 23 ++-- .../common/wazuh-data-grid/wz-data-grid.tsx | 2 +- .../wazuh-discover/components/doc-details.tsx | 31 +++-- .../document-view-table-and-json.tsx | 10 +- .../wazuh-discover/wz-flyout-discover.tsx | 8 +- .../requirement-flyout/requirement-flyout.tsx | 117 ++++++++++++------ .../github/panel/config/drilldown-action.tsx | 10 +- .../github/panel/config/drilldown-actor.tsx | 10 +- .../panel/config/drilldown-data-grid.tsx | 2 +- .../panel/config/drilldown-organization.tsx | 10 +- .../panel/config/drilldown-repository.tsx | 10 +- .../technique-row-details.tsx | 15 +-- .../panel/config/drilldown-ip-config.tsx | 9 +- .../config/drilldown-operations-config.tsx | 9 +- .../panel/config/drilldown-rules-config.tsx | 9 +- .../panel/config/drilldown-user-config.tsx | 9 +- .../threat-hunting/dashboard/dashboard.tsx | 58 ++++++--- 21 files changed, 267 insertions(+), 105 deletions(-) diff --git a/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx b/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx index 9c3071ee4f..58fcd5176b 100644 --- a/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx +++ b/plugins/main/public/components/agents/fim/inventory/fileDetail.tsx @@ -52,7 +52,7 @@ import { RedirectAppLinks } from '../../../../../../../src/plugins/opensearch_da import TechniqueRowDetails from '../../../overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details'; import { DATA_SOURCE_FILTER_CONTROLLED_CLUSTER_MANAGER } from '../../../../../common/constants'; import NavigationService from '../../../../react-services/navigation-service'; -import { setFilters } from "../../../common/search-bar/set-filters"; +import { setFilters } from '../../../common/search-bar/set-filters'; export class FileDetails extends Component { props!: { diff --git a/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx b/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx index 2e9e54c5ff..cab188384b 100644 --- a/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx +++ b/plugins/main/public/components/common/data-grid/cell-filter-actions.tsx @@ -66,7 +66,11 @@ export const filterIsNotAction = value?: any, ) => void, ) => - ({ rowIndex, columnId: field, Component }: EuiDataGridColumnCellActionProps) => { + ({ + rowIndex, + columnId: field, + Component, + }: EuiDataGridColumnCellActionProps) => { const filterOutValueText = i18n.translate('discover.filterOutValue', { defaultMessage: 'Filter out value', }); diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss index b81f4a6611..a3a3ef84d4 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss @@ -36,16 +36,20 @@ display: flex; position: absolute; background: #fff; - background: linear-gradient(180deg, rgb(255, 255, 255) 0%, rgb(255, 255, 255) 80%, rgba(0, 0, 0, 0) 100%); + background: linear-gradient( + 180deg, + rgb(255, 255, 255) 0%, + rgb(255, 255, 255) 80%, + rgba(0, 0, 0, 0) 100% + ); right: 0; top: 0; - transform: translateY(0.5px); + transform: translateY(1px); .osdDocViewer__actionButton { opacity: 1; } } - } } diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index fe08b06f01..5d393f0748 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -20,7 +20,11 @@ export type tDocViewerProps = { mapping: any; indexPattern: any; docJSON: any; - onFilter: (columndId: string, operation: FILTER_OPERATOR, value?: any) => void; + onFilter: ( + columndId: string, + operation: FILTER_OPERATOR, + value?: any, + ) => void; }; /** @@ -164,7 +168,11 @@ const DocViewer = (props: tDocViewerProps) => { - onFilter(field, FILTER_OPERATOR.IS, flattened[field]) + onFilter( + field, + FILTER_OPERATOR.IS, + flattened[field], + ) } /> { return ( @@ -9,10 +12,14 @@ const isSameNegatedFilter = (filter: Filter, prevFilter: Filter) => { ); }; -export const setFilters = (filterManager: FilterManager) => (filters: Filter[]) => { - const prevFilters = filterManager - .getFilters() - .filter((prevFilter) => !filters.find((filter) => isSameNegatedFilter(filter, prevFilter))); - const newFilters = [...filters, ...prevFilters]; - filterManager.setFilters(newFilters, undefined); -}; +export const setFilters = + (filterManager: FilterManager) => (filters: Filter[]) => { + const prevFilters = filterManager + .getFilters() + .filter( + prevFilter => + !filters.find(filter => isSameNegatedFilter(filter, prevFilter)), + ); + const newFilters = [...filters, ...prevFilters]; + filterManager.setFilters(newFilters, undefined); + }; diff --git a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx index fa79209dc0..48a190d91f 100644 --- a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx +++ b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx @@ -70,7 +70,7 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { query, dateRange, filters, - setFilters + setFilters, } = props; const [inspectedHit, setInspectedHit] = useState(undefined); const [isExporting, setIsExporting] = useState(false); diff --git a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx index 3b8010a90f..41eccf6970 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx @@ -1,7 +1,10 @@ import React, { useState } from 'react'; import { useDocViewer } from '../../doc-viewer'; import DocViewer from '../../doc-viewer/doc-viewer'; -import { Filter, IndexPattern } from '../../../../../../../src/plugins/data/common'; +import { + Filter, + IndexPattern, +} from '../../../../../../../src/plugins/data/common'; import { EuiCodeBlock, EuiFlexGroup, EuiTabbedContent } from '@elastic/eui'; import { onFilterCellActions } from '../../data-grid'; import { FILTER_OPERATOR } from '../../data-source'; @@ -14,19 +17,33 @@ interface DocDetailsProps { setFilters: (filters: Filter[]) => void; } -const DocDetails = ({ doc, item, indexPattern, filters, setFilters }: DocDetailsProps) => { +const DocDetails = ({ + doc, + item, + indexPattern, + filters, + setFilters, +}: DocDetailsProps) => { const docViewerProps = useDocViewer({ doc, indexPattern: indexPattern as IndexPattern, }); - const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { - const onFilter = onFilterCellActions(indexPattern.id as string, filters, setFilters); + const onFilterHandler = ( + field: string, + operation: FILTER_OPERATOR, + value?: any, + ) => { + const onFilter = onFilterCellActions( + indexPattern.id as string, + filters, + setFilters, + ); onFilter(field, operation, value); }; return ( - + {JSON.stringify(item, null, 2)} diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index 362a72fa86..3833115c0c 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -3,8 +3,8 @@ import { EuiFlexItem, EuiCodeBlock, EuiTabbedContent } from '@elastic/eui'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; import DocViewer from '../../doc-viewer/doc-viewer'; import { useDocViewer } from '../../doc-viewer'; -import { onFilterCellActions } from "../../data-grid"; -import { FILTER_OPERATOR } from "../../data-source"; +import { onFilterCellActions } from '../../data-grid'; +import { FILTER_OPERATOR } from '../../data-source'; export const DocumentViewTableAndJson = ({ document, @@ -18,7 +18,11 @@ export const DocumentViewTableAndJson = ({ indexPattern: indexPattern as IndexPattern, }); - const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilterHandler = ( + field: string, + operation: FILTER_OPERATOR, + value?: any, + ) => { const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); onFilter(field, operation, value); }; diff --git a/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx b/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx index e3eef162ec..3d33a2f351 100644 --- a/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx +++ b/plugins/main/public/components/common/wazuh-discover/wz-flyout-discover.tsx @@ -254,7 +254,13 @@ const WazuhFlyoutDiscoverComponent = (props: WazuhDiscoverProps) => { indexPattern, }) ) : ( - + ); }; diff --git a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx index f969ca873c..0f579e8d29 100644 --- a/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx +++ b/plugins/main/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx @@ -26,18 +26,24 @@ import { import { AppState } from '../../../../../react-services/app-state'; import { requirementGoal } from '../../requirement-goal'; import { getUiSettings } from '../../../../../kibana-services'; -import { FilterManager, IndexPattern } from '../../../../../../../../src/plugins/data/public/'; +import { + FilterManager, + IndexPattern, +} from '../../../../../../../../src/plugins/data/public/'; import { WzFlyout } from '../../../../../components/common/flyouts'; import { WazuhFlyoutDiscover } from '../../../../common/wazuh-discover/wz-flyout-discover'; import { PatternDataSource } from '../../../../common/data-source'; import { formatUIDate } from '../../../../../react-services'; import TechniqueRowDetails from '../../../mitre/framework/components/techniques/components/flyout-technique/technique-row-details'; -import { buildPhraseFilter, Filter } from '../../../../../../../../src/plugins/data/common'; +import { + buildPhraseFilter, + Filter, +} from '../../../../../../../../src/plugins/data/common'; import { connect } from 'react-redux'; import { wzDiscoverRenderColumns } from '../../../../common/wazuh-discover/render-columns'; -import { setFilters } from "../../../../common/search-bar/set-filters"; +import { setFilters } from '../../../../common/search-bar/set-filters'; -const mapStateToProps = (state) => ({ +const mapStateToProps = state => ({ currentAgentData: state.appStateReducers.currentAgentData, }); @@ -61,9 +67,9 @@ export const RequirementFlyout = connect(mapStateToProps)( } addRenderColumn(columns) { - return columns.map((column) => { + return columns.map(column => { const renderColumn = wzDiscoverRenderColumns.find( - (columnRender) => columnRender.id === column.id + columnRender => columnRender.id === column.id, ); if (renderColumn) { return { ...column, render: renderColumn.render }; @@ -79,7 +85,7 @@ export const RequirementFlyout = connect(mapStateToProps)( isSortable: true, defaultSortDirection: 'desc', displayAsText: 'Time', - render: (value) => formatUIDate(value), + render: value => formatUIDate(value), }, { id: this.props.getRequirementKey(), @@ -99,7 +105,7 @@ export const RequirementFlyout = connect(mapStateToProps)( isSortable: true, defaultSortDirection: 'desc', displayAsText: 'Time', - render: (value) => formatUIDate(value), + render: value => formatUIDate(value), }, { id: 'agent.id', @@ -135,15 +141,19 @@ export const RequirementFlyout = connect(mapStateToProps)( )) || ( - -

Requirement {currentRequirement}

+ +

Requirement {currentRequirement}

)} ); } - renderDiscoverExpandedRow(props: { doc: any; item: any; indexPattern: any }) { + renderDiscoverExpandedRow(props: { + doc: any; + item: any; + indexPattern: any; + }) { return ( buildPhraseFilter({ name: key, type: 'string' }, item, indexPattern)) + .map(item => + buildPhraseFilter( + { name: key, type: 'string' }, + item, + indexPattern, + ), + ) .filter(Boolean); this.filterManager.addFilters(newFilter); @@ -173,33 +191,39 @@ export const RequirementFlyout = connect(mapStateToProps)( ? { 'cluster.name': AppState.getClusterInfo().cluster } : { 'manager.name': AppState.getClusterInfo().manager }; this.clusterFilter = clusterFilter; - requirementImplicitFilter[this.props.getRequirementKey()] = currentRequirement; + requirementImplicitFilter[this.props.getRequirementKey()] = + currentRequirement; const implicitFilters = [requirementImplicitFilter, this.clusterFilter]; if (this.props.implicitFilters) { - this.props.implicitFilters.forEach((item) => implicitFilters.push(item)); + this.props.implicitFilters.forEach(item => implicitFilters.push(item)); } //Goal for PCI const currentReq = this.props.currentRequirement.split('.')[0]; return ( - + +

Details

} - paddingSize="xs" + paddingSize='xs' initialIsOpen={true} > -
- +
+ {requirementGoal[currentReq] && ( - + @@ -213,57 +237,68 @@ export const RequirementFlyout = connect(mapStateToProps)( - + -

Requirement description

+

+ Requirement description +

{this.props.description}

- +
- + +

Recent events {this.props.view !== 'events' && ( { + onMouseDown={e => { this.props.openDashboard(e, currentRequirement); e.stopPropagation(); }} - color="primary" - type="visualizeApp" + color='primary' + type='visualizeApp' style={{ marginRight: '10px' }} > { + onMouseDown={e => { this.props.openDiscover(e, currentRequirement); e.stopPropagation(); }} - color="primary" - type="discoverApp" + color='primary' + type='discoverApp' > @@ -272,7 +307,7 @@ export const RequirementFlyout = connect(mapStateToProps)(

} - paddingSize="none" + paddingSize='none' initialIsOpen={true} > this.renderDiscoverExpandedRow(...args)} + expandedRowComponent={(...args) => + this.renderDiscoverExpandedRow(...args) + } />
@@ -315,5 +352,5 @@ export const RequirementFlyout = connect(mapStateToProps)( ); } - } + }, ); diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx index 9431ecf9e5..d0ac77a002 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx @@ -110,8 +110,14 @@ const getDashboardPanels = ( }; export const DrilldownConfigAction = (drilldownProps: ModuleConfigProps) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = - drilldownProps; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx index 06cc8a0ea7..6af6956d07 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx @@ -126,8 +126,14 @@ const getDashboardPanels = ( }; export const DrilldownConfigActor = (drilldownProps: ModuleConfigProps) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = - drilldownProps; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx index c77036fdca..4ff5807b59 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-data-grid.tsx @@ -8,7 +8,7 @@ import { } from '../../../../../react-services/error-management'; import WazuhDataGrid from '../../../../common/wazuh-data-grid/wz-data-grid'; import { tDataGridColumn } from '../../../../common/data-grid'; -import { Filter } from "../../../../../../../../src/plugins/data/common"; +import { Filter } from '../../../../../../../../src/plugins/data/common'; type tDrillDownDataGridProps = { defaultTableColumns: tDataGridColumn[]; diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx index 06d295c932..690bc63269 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx @@ -129,8 +129,14 @@ const getDashboardPanels = ( export const DrilldownConfigOrganization = ( drilldownProps: ModuleConfigProps, ) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = - drilldownProps; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx index 4b20f770cb..2ec53a2fb4 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx @@ -119,8 +119,14 @@ const getDashboardPanels = ( export const DrilldownConfigRepository = ( drilldownProps: ModuleConfigProps, ) => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = - drilldownProps; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx index 938abb296c..d60f010d15 100644 --- a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx +++ b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx @@ -8,8 +8,8 @@ import { Filter, } from '../../../../../../../../../../../src/plugins/data/common'; import { WzRequest } from '../../../../../../../../react-services/wz-request'; -import { onFilterCellActions } from "../../../../../../../common/data-grid"; -import { FILTER_OPERATOR } from "../../../../../../../common/data-source"; +import { onFilterCellActions } from '../../../../../../../common/data-grid'; +import { FILTER_OPERATOR } from '../../../../../../../common/data-source'; type Props = { doc: any; @@ -53,7 +53,11 @@ const TechniqueRowDetails = ({ getRuleData(); }, []); - const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilterHandler = ( + field: string, + operation: FILTER_OPERATOR, + value?: any, + ) => { const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); onFilter(field, operation, value); }; @@ -68,10 +72,7 @@ const TechniqueRowDetails = ({ name: 'Table', content: ( <> - + ), }, diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx index 923722b761..e682a42e9e 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-ip-config.tsx @@ -99,7 +99,14 @@ const getDashboardPanels = ( }; export const drilldownIPConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = props; return { rows: [ diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx index bc866a652f..7ee42ae686 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-operations-config.tsx @@ -83,7 +83,14 @@ const getDashboardPanels = ( }; export const drilldownOperationsConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = props; return { rows: [ diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx index 73bd483876..eff2ba3513 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-rules-config.tsx @@ -98,7 +98,14 @@ const getDashboardPanels = ( }; export const drilldownRulesConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = props; return { rows: [ diff --git a/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx b/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx index bb792cbc06..a8c3514f95 100644 --- a/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx +++ b/plugins/main/public/components/overview/office/panel/config/drilldown-user-config.tsx @@ -99,7 +99,14 @@ const getDashboardPanels = ( }; export const drilldownUserConfig = props => { - const { fetchData, fetchFilters, searchBarProps, indexPattern, filters, setFilters } = props; + const { + fetchData, + fetchFilters, + searchBarProps, + indexPattern, + filters, + setFilters, + } = props; return { rows: [ diff --git a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx index 62193a50c5..8179dd532d 100644 --- a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx +++ b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx @@ -18,7 +18,11 @@ import { EuiFlyoutBody, EuiFlyoutHeader, } from '@elastic/eui'; -import { ErrorFactory, ErrorHandler, HttpError } from '../../../../react-services/error-management'; +import { + ErrorFactory, + ErrorHandler, + HttpError, +} from '../../../../react-services/error-management'; import { MAX_ENTRIES_PER_QUERY, exportSearchToCSV, @@ -91,16 +95,18 @@ const DashboardTH: React.FC = () => { const rowClicked = results.hits.hits[index]; setInspectedHit(rowClicked); }, - [results] + [results], ); - const DocViewInspectButton = ({ rowIndex }: EuiDataGridCellValueElementProps) => { + const DocViewInspectButton = ({ + rowIndex, + }: EuiDataGridCellValueElementProps) => { const inspectHintMsg = 'Inspect document details'; return ( onClickInspectDoc(rowIndex)} - iconType="inspect" + iconType='inspect' aria-label={inspectHintMsg} /> @@ -126,7 +132,8 @@ const DashboardTH: React.FC = () => { }); const pinnedAgent = - PatternDataSourceFilterManager.getPinnedAgentFilter(dataSource?.id!).length > 0; + PatternDataSourceFilterManager.getPinnedAgentFilter(dataSource?.id!) + .length > 0; useEffect(() => { const currentColumns = !pinnedAgent @@ -154,10 +161,10 @@ const DashboardTH: React.FC = () => { sorting, dateRange: absoluteDateRange, }) - .then((results) => { + .then(results => { setResults(results); }) - .catch((error) => { + .catch(error => { const searchError = ErrorFactory.create(HttpError, { error, message: 'Error fetching data', @@ -198,8 +205,16 @@ const DashboardTH: React.FC = () => { } }; - const onFilterHandler = (field: string, operation: FILTER_OPERATOR, value?: any) => { - const onFilter = onFilterCellActions(dataSource?.indexPattern?.id, filters, setFilters); + const onFilterHandler = ( + field: string, + operation: FILTER_OPERATOR, + value?: any, + ) => { + const onFilter = onFilterCellActions( + dataSource?.indexPattern?.id, + filters, + setFilters, + ); onFilter(field, operation, value); }; @@ -210,7 +225,7 @@ const DashboardTH: React.FC = () => { ) : ( <> { ) : null}
0 ? '' : 'wz-no-display' + !isDataSourceLoading && dataSource && results?.hits?.total > 0 + ? '' + : 'wz-no-display' }`} > -
+
{ viewMode: ViewMode.VIEW, panels: getDashboardPanels( AlertsRepository.getStoreIndexPatternId(), - pinnedAgent + pinnedAgent, ), isFullScreenMode: false, filters: fetchFilters ?? [], @@ -291,18 +310,21 @@ const DashboardTH: React.FC = () => { ) : null}
{inspectedHit && ( - setInspectedHit(undefined)} size="m"> + setInspectedHit(undefined)} size='m'> - + - + From 0b92f0b2534ae10eb1f2dbf6af30670495c20e1b Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 16:51:36 -0300 Subject: [PATCH 14/54] Add filter by value to document details fields --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f3be31da..e6822fb9e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Support for Wazuh 4.10.0 - Added sample data for YARA [#6964](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6964) - Added a custom filter and visualization for vulnerability.under_evaluation field [#6968](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6968) [#7044](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7044) [#7046](https://github.com/wazuh/wazuh-dashboard-plugins/issues/7046) +- Added filter by value to document details fields [#7081](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7081) ### Changed From 72cead56a94861415f0934f44710c931103d4757 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 16:53:23 -0300 Subject: [PATCH 15/54] Update defaultColumns to defaultTableColumns in WazuhDataGrid --- .../public/components/common/wazuh-data-grid/wz-data-grid.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx index 48a190d91f..16c4e7432d 100644 --- a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx +++ b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx @@ -193,7 +193,7 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { document={inspectedHit} indexPattern={indexPattern as IndexPattern} renderFields={getAllCustomRenders( - defaultColumns, + defaultTableColumns, wzDiscoverRenderColumns, )} filters={filters} From 92787cea25909aa05498201dc933b57282230a6b Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 17:04:09 -0300 Subject: [PATCH 16/54] Add filter functionality for document viewer --- .../common/doc-viewer/doc-viewer.tsx | 21 ++++++++++++----- .../wazuh-discover/components/doc-details.tsx | 23 +++++-------------- .../document-view-table-and-json.tsx | 14 ++--------- .../technique-row-details.tsx | 17 ++++---------- .../threat-hunting/dashboard/dashboard.tsx | 18 ++------------- 5 files changed, 30 insertions(+), 63 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 5d393f0748..0983ea523f 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -9,6 +9,8 @@ import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; import './doc-viewer.scss'; +import { onFilterCellActions } from '../data-grid'; +import { Filter } from '../../../../../../src/plugins/data/common'; const COLLAPSE_LINE_LENGTH = 350; const DOT_PREFIX_RE = /(.).+?\./g; @@ -20,11 +22,8 @@ export type tDocViewerProps = { mapping: any; indexPattern: any; docJSON: any; - onFilter: ( - columndId: string, - operation: FILTER_OPERATOR, - value?: any, - ) => void; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; }; /** @@ -99,9 +98,19 @@ const DocViewer = (props: tDocViewerProps) => { indexPattern, renderFields, docJSON, - onFilter, + filters, + setFilters, } = props; + const onFilter = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const _onFilter = onFilterCellActions( + indexPattern?.id, + filters, + setFilters, + ); + _onFilter(field, operation, value); + }; + return ( <> {flattened && ( diff --git a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx index 41eccf6970..c52e6c9e44 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/doc-details.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import { useDocViewer } from '../../doc-viewer'; import DocViewer from '../../doc-viewer/doc-viewer'; import { @@ -6,8 +6,6 @@ import { IndexPattern, } from '../../../../../../../src/plugins/data/common'; import { EuiCodeBlock, EuiFlexGroup, EuiTabbedContent } from '@elastic/eui'; -import { onFilterCellActions } from '../../data-grid'; -import { FILTER_OPERATOR } from '../../data-source'; interface DocDetailsProps { doc: any; @@ -29,19 +27,6 @@ const DocDetails = ({ indexPattern: indexPattern as IndexPattern, }); - const onFilterHandler = ( - field: string, - operation: FILTER_OPERATOR, - value?: any, - ) => { - const onFilter = onFilterCellActions( - indexPattern.id as string, - filters, - setFilters, - ); - onFilter(field, operation, value); - }; - return ( - + ), }, diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index 3833115c0c..98dba51319 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -3,8 +3,6 @@ import { EuiFlexItem, EuiCodeBlock, EuiTabbedContent } from '@elastic/eui'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; import DocViewer from '../../doc-viewer/doc-viewer'; import { useDocViewer } from '../../doc-viewer'; -import { onFilterCellActions } from '../../data-grid'; -import { FILTER_OPERATOR } from '../../data-source'; export const DocumentViewTableAndJson = ({ document, @@ -18,15 +16,6 @@ export const DocumentViewTableAndJson = ({ indexPattern: indexPattern as IndexPattern, }); - const onFilterHandler = ( - field: string, - operation: FILTER_OPERATOR, - value?: any, - ) => { - const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); - onFilter(field, operation, value); - }; - return ( ), }, diff --git a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx index d60f010d15..ac8e09b873 100644 --- a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx +++ b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx @@ -8,8 +8,6 @@ import { Filter, } from '../../../../../../../../../../../src/plugins/data/common'; import { WzRequest } from '../../../../../../../../react-services/wz-request'; -import { onFilterCellActions } from '../../../../../../../common/data-grid'; -import { FILTER_OPERATOR } from '../../../../../../../common/data-source'; type Props = { doc: any; @@ -53,15 +51,6 @@ const TechniqueRowDetails = ({ getRuleData(); }, []); - const onFilterHandler = ( - field: string, - operation: FILTER_OPERATOR, - value?: any, - ) => { - const onFilter = onFilterCellActions(indexPattern.id, filters, setFilters); - onFilter(field, operation, value); - }; - return ( - + ), }, diff --git a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx index 8179dd532d..b346d0c501 100644 --- a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx +++ b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx @@ -27,7 +27,6 @@ import { MAX_ENTRIES_PER_QUERY, exportSearchToCSV, getAllCustomRenders, - onFilterCellActions, } from '../../../common/data-grid/data-grid-service'; import { useDocViewer } from '../../../common/doc-viewer/use-doc-viewer'; import { useDataGrid } from '../../../common/data-grid/use-data-grid'; @@ -46,7 +45,6 @@ import { PatternDataSourceFilterManager, tParsedIndexPattern, useDataSource, - FILTER_OPERATOR, } from '../../../common/data-source'; import { DiscoverNoResults } from '../../../common/no-results/no-results'; import { LoadingSearchbarProgress } from '../../../common/loading-searchbar-progress/loading-searchbar-progress'; @@ -205,19 +203,6 @@ const DashboardTH: React.FC = () => { } }; - const onFilterHandler = ( - field: string, - operation: FILTER_OPERATOR, - value?: any, - ) => { - const onFilter = onFilterCellActions( - dataSource?.indexPattern?.id, - filters, - setFilters, - ); - onFilter(field, operation, value); - }; - return ( {isDataSourceLoading && !dataSource ? ( @@ -326,7 +311,8 @@ const DashboardTH: React.FC = () => { threatHuntingTableDefaultColumns, wzDiscoverRenderColumns, )} - onFilter={onFilterHandler} + filters={filters} + setFilters={setFilters} /> From 119332c1238a2d8edc7bd69c3f3936080a3886f1 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 8 Oct 2024 17:16:25 -0300 Subject: [PATCH 17/54] Swap the order of arguments in filter action test --- .../components/common/data-grid/cell-filter-actions.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/cell-filter-actions.test.tsx b/plugins/main/public/components/common/data-grid/cell-filter-actions.test.tsx index 8eb829a886..7eb175314c 100644 --- a/plugins/main/public/components/common/data-grid/cell-filter-actions.test.tsx +++ b/plugins/main/public/components/common/data-grid/cell-filter-actions.test.tsx @@ -61,7 +61,7 @@ describe('cell-filter-actions', () => { fireEvent.click(component); expect(onFilter).toHaveBeenCalledTimes(1); - expect(onFilter).toHaveBeenCalledWith(TEST_COLUMN_ID, TEST_VALUE, 'is'); + expect(onFilter).toHaveBeenCalledWith(TEST_COLUMN_ID, 'is', TEST_VALUE); }); }); @@ -102,8 +102,8 @@ describe('cell-filter-actions', () => { expect(onFilter).toHaveBeenCalledTimes(1); expect(onFilter).toHaveBeenCalledWith( TEST_COLUMN_ID, - TEST_VALUE, 'is not', + TEST_VALUE, ); }); }); From 84cb7084d3fb2f4f1d0ae3325f6dfd1ad8c7c2c3 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 13:54:00 -0300 Subject: [PATCH 18/54] Rename button icons to EuiButtonIcon component --- ...row_btn_filter_add.tsx => table-row-btn-filter-add.tsx} | 7 ++++--- ...n_filter_exists.tsx => table-row-btn-filter-exists.tsx} | 6 +++--- ...n_filter_remove.tsx => table-row-btn-filter-remove.tsx} | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) rename plugins/main/public/components/common/doc-viewer/{table_row_btn_filter_add.tsx => table-row-btn-filter-add.tsx} (92%) rename plugins/main/public/components/common/doc-viewer/{table_row_btn_filter_exists.tsx => table-row-btn-filter-exists.tsx} (94%) rename plugins/main/public/components/common/doc-viewer/{table_row_btn_filter_remove.tsx => table-row-btn-filter-remove.tsx} (94%) diff --git a/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_add.tsx b/plugins/main/public/components/common/doc-viewer/table-row-btn-filter-add.tsx similarity index 92% rename from plugins/main/public/components/common/doc-viewer/table_row_btn_filter_add.tsx rename to plugins/main/public/components/common/doc-viewer/table-row-btn-filter-add.tsx index 265815f819..cf405e126d 100644 --- a/plugins/main/public/components/common/doc-viewer/table_row_btn_filter_add.tsx +++ b/plugins/main/public/components/common/doc-viewer/table-row-btn-filter-add.tsx @@ -30,8 +30,9 @@ import React from 'react'; import { FormattedMessage } from '@osd/i18n/react'; -import { EuiToolTip, EuiSmallButtonIcon } from '@elastic/eui'; +import { EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@osd/i18n'; +import styles from './doc-viewer.scss'; export interface Props { onClick: () => void; @@ -56,14 +57,14 @@ export function DocViewTableRowBtnFilterAdd({ return ( - - - Date: Thu, 17 Oct 2024 13:54:21 -0300 Subject: [PATCH 19/54] Update component import paths and class names --- .../components/common/doc-viewer/doc-viewer.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 0983ea523f..b4377552a8 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -5,9 +5,9 @@ import { i18n } from '@osd/i18n'; import { FieldIcon } from '../../../../../../src/plugins/opensearch_dashboards_react/public'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { FILTER_OPERATOR } from '../data-source'; -import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; -import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; -import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; +import { DocViewTableRowBtnFilterAdd } from './table-row-btn-filter-add'; +import { DocViewTableRowBtnFilterRemove } from './table-row-btn-filter-remove'; +import { DocViewTableRowBtnFilterExists } from './table-row-btn-filter-exists'; import './doc-viewer.scss'; import { onFilterCellActions } from '../data-grid'; import { Filter } from '../../../../../../src/plugins/data/common'; @@ -114,7 +114,7 @@ const DocViewer = (props: tDocViewerProps) => { return ( <> {flattened && ( - +
{Object.keys(flattened) .sort() @@ -125,7 +125,7 @@ const DocViewer = (props: tDocViewerProps) => { const isCollapsed = isCollapsible && !fieldRowOpen[field]; const valueClassName = classNames({ // eslint-disable-next-line @typescript-eslint/naming-convention - osdDocViewer__value: true, + wzDocViewer__value: true, 'truncate-by-height': isCollapsible && isCollapsed, }); const isNestedField = @@ -149,7 +149,7 @@ const DocViewer = (props: tDocViewerProps) => { return ( -
+ { -
+
From 13bd5811f230243f6ee7ba1d68e9239b02d86adb Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 13:54:37 -0300 Subject: [PATCH 20/54] Update doc-viewer styles for wzDocViewer classes --- .../common/doc-viewer/doc-viewer.scss | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss index a3a3ef84d4..bb60bcbb28 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss @@ -1,6 +1,6 @@ -.osdDocViewerTable { +.wzDocViewerTable { pre, - .osdDocViewer__value { + .wzDocViewer__value { display: inline-block; word-break: break-all; word-wrap: break-word; @@ -10,7 +10,7 @@ padding-top: 2px; } - .osdDocViewer__field { + .wzDocViewer__field { padding-top: 8px; } @@ -32,41 +32,52 @@ } tr:hover { - .osdDocViewer__buttons { + .wzDocViewer__buttons { display: flex; + gap: 2px; position: absolute; - background: #fff; - background: linear-gradient( - 180deg, - rgb(255, 255, 255) 0%, - rgb(255, 255, 255) 80%, - rgba(0, 0, 0, 0) 100% - ); right: 0; top: 0; - transform: translateY(1px); + transform: translateY(calc(50% - 8px)); - .osdDocViewer__actionButton { + > span { + z-index: 2; + } + + .wzDocViewer__actionButton { opacity: 1; } + + &::before { + content: ""; + position: absolute; + display: block; + right: 0; + top: 0; + height: 100%; + width: 100%; + background-image: linear-gradient(to right, transparent 0, aliceblue 4px); + z-index: 1; + } } } } -.osdDocViewer__buttons, -.osdDocViewer__field { +.wzDocViewer__buttons, +.wzDocViewer__field { white-space: nowrap; } -.osdDocViewer__buttons { +.wzDocViewer__buttons { display: none; } -.osdDocViewer__field { +.wzDocViewer__field { width: 160px; + white-space: break-spaces; } -.osdDocViewer__actionButton { +.wzDocViewer__actionButton { opacity: 0; &:hover { @@ -74,6 +85,6 @@ } } -.osdDocViewer__warning { +.wzDocViewer__warning { margin-right: $euiSizeS; } From 81862f99995ffd49abe6f82117680d4c72256cbb Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 14:10:23 -0300 Subject: [PATCH 21/54] Refactor adding filters to handle array values efficiently --- .../common/data-grid/data-grid-service.ts | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index a7e39d87e0..a54eb432fe 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -198,13 +198,29 @@ export const onFilterCellActions = ( setFilters: (filters: Filter[]) => void, ) => { return (field: string, operation: FILTER_OPERATOR, value?: any) => { - const newFilter = PatternDataSourceFilterManager.createFilter( - operation, - field, - value, - indexPatternId, - ); - setFilters([...filters, newFilter]); + const newFilters: Filter[] = []; + if (Array.isArray(value)) { + value.forEach(item => { + newFilters.push( + PatternDataSourceFilterManager.createFilter( + operation, + field, + item, + indexPatternId, + ), + ); + }); + } else { + newFilters.push( + PatternDataSourceFilterManager.createFilter( + operation, + field, + value, + indexPatternId, + ), + ); + } + setFilters([...filters, ...newFilters]); }; }; From f7871bef41aba8bb7c39248435db8eebbb0a781d Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:22:06 -0300 Subject: [PATCH 22/54] Add onClose callback to onFilter function in DocViewer --- .../main/public/components/common/doc-viewer/doc-viewer.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index b4377552a8..995c29accd 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -24,6 +24,7 @@ export type tDocViewerProps = { docJSON: any; filters: Filter[]; setFilters: (filters: Filter[]) => void; + onFilter?: () => void; }; /** @@ -100,6 +101,7 @@ const DocViewer = (props: tDocViewerProps) => { docJSON, filters, setFilters, + onFilter: onClose, } = props; const onFilter = (field: string, operation: FILTER_OPERATOR, value?: any) => { @@ -109,6 +111,7 @@ const DocViewer = (props: tDocViewerProps) => { setFilters, ); _onFilter(field, operation, value); + onClose?.(); }; return ( From 8364cc1ffca13216761709cc60e183792dd147c4 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:22:55 -0300 Subject: [PATCH 23/54] Refactor DocumentViewTableAndJson component props --- .../components/document-view-table-and-json.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index 98dba51319..df3602f420 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -1,16 +1,26 @@ import React from 'react'; import { EuiFlexItem, EuiCodeBlock, EuiTabbedContent } from '@elastic/eui'; -import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; +import { IndexPattern, Filter } from '../../../../../../../src/plugins/data/common'; import DocViewer from '../../doc-viewer/doc-viewer'; import { useDocViewer } from '../../doc-viewer'; +interface DocumentViewTableAndJsonProps { + document: any; + indexPattern: IndexPattern; + renderFields?: any; + filters: Filter[]; + setFilters: (filters: Filter[]) => void; + onFilter?: () => void; +} + export const DocumentViewTableAndJson = ({ document, indexPattern, renderFields, filters, setFilters, -}) => { + onFilter, +}: DocumentViewTableAndJsonProps) => { const docViewerProps = useDocViewer({ doc: document, indexPattern: indexPattern as IndexPattern, @@ -29,6 +39,7 @@ export const DocumentViewTableAndJson = ({ renderFields={renderFields} filters={filters} setFilters={setFilters} + onFilter={onFilter} /> ), }, From d09836af80c3ac099f772e84560e2bbe79c1ffdc Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:31:17 -0300 Subject: [PATCH 24/54] Refactor technique row details component props type --- .../components/flyout-technique/technique-row-details.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx index ac8e09b873..c07de35380 100644 --- a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx +++ b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/technique-row-details.tsx @@ -9,7 +9,7 @@ import { } from '../../../../../../../../../../../src/plugins/data/common'; import { WzRequest } from '../../../../../../../../react-services/wz-request'; -type Props = { +type TechniqueRowDetailsProps = { doc: any; item: any; indexPattern: IndexPattern; @@ -25,7 +25,7 @@ const TechniqueRowDetails = ({ onRuleItemClick, filters, setFilters, -}) => { +}: TechniqueRowDetailsProps) => { const docViewerProps = useDocViewer({ doc, indexPattern: indexPattern as IndexPattern, @@ -44,7 +44,7 @@ const TechniqueRowDetails = ({ }; const onAddFilter = (filter: { [key: string]: string }) => { - onRuleItemClick(filter, indexPattern); + onRuleItemClick?.(filter, indexPattern); }; useEffect(() => { From 0ee73ffc3f18ccdc3df126258c2d7d1e47dcd11c Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:33:08 -0300 Subject: [PATCH 25/54] Add setFilters function to TechniqueRowDetails component --- .../components/flyout-technique/flyout-technique.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx index b0eace1ea7..958311c76f 100644 --- a/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx +++ b/plugins/main/public/components/overview/mitre/framework/components/techniques/components/flyout-technique/flyout-technique.tsx @@ -47,6 +47,7 @@ import { buildPhraseFilter } from '../../../../../../../../../../../src/plugins/ import store from '../../../../../../../../redux/store'; import NavigationService from '../../../../../../../../react-services/navigation-service'; import { wzDiscoverRenderColumns } from '../../../../../../../common/wazuh-discover/render-columns'; +import { setFilters } from '../../../../../../../common/search-bar/set-filters'; type tFlyoutTechniqueProps = { currentTechnique: string; @@ -227,7 +228,14 @@ export const FlyoutTechnique = (props: tFlyoutTechniqueProps) => { }; const expandedRow = (props: { doc: any; item: any; indexPattern: any }) => { - return ; + return ( + + ); }; const addRenderColumn = columns => { From ce6badc926e2d94e5b4c9be542cbf7ed537856bd Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:48:08 -0300 Subject: [PATCH 26/54] Refactor closeFlyoutHandler in DashboardTH component --- .../overview/threat-hunting/dashboard/dashboard.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx index b346d0c501..66d7dc9382 100644 --- a/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx +++ b/plugins/main/public/components/overview/threat-hunting/dashboard/dashboard.tsx @@ -203,6 +203,8 @@ const DashboardTH: React.FC = () => { } }; + const closeFlyoutHandler = () => setInspectedHit(undefined); + return ( {isDataSourceLoading && !dataSource ? ( @@ -295,7 +297,7 @@ const DashboardTH: React.FC = () => { ) : null}
{inspectedHit && ( - setInspectedHit(undefined)} size='m'> + { )} filters={filters} setFilters={setFilters} + onFilter={closeFlyoutHandler} /> From cff23c52487011c419f9027a19c8952ce1ee7e96 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 15:52:00 -0300 Subject: [PATCH 27/54] Add closeFlyoutHandler function for flyout onClose event --- .../components/common/wazuh-data-grid/wz-data-grid.tsx | 5 ++++- .../public/components/common/wazuh-discover/wz-discover.tsx | 5 ++++- .../vulnerabilities/dashboards/inventory/inventory.tsx | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx index 16c4e7432d..ff1413aa35 100644 --- a/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx +++ b/plugins/main/public/components/common/wazuh-data-grid/wz-data-grid.tsx @@ -149,6 +149,8 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => { } }; + const closeFlyoutHandler = () => setInspectedHit(undefined); + return ( <> {isLoading ? : null} @@ -177,7 +179,7 @@ const WazuhDataGrid = (props: tWazuhDataGridProps) => {
) : null} {inspectedHit && ( - setInspectedHit(undefined)} size='m'> + { )} filters={filters} setFilters={setFilters} + onFilter={closeFlyoutHandler} /> diff --git a/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx b/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx index 0406d17c50..ab5f93d73a 100644 --- a/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx +++ b/plugins/main/public/components/common/wazuh-discover/wz-discover.tsx @@ -188,6 +188,8 @@ const WazuhDiscoverComponent = (props: WazuhDiscoverProps) => { } }; + const closeFlyoutHandler = () => setInspectedHit(undefined); + return ( {isDataSourceLoading ? ( @@ -268,7 +270,7 @@ const WazuhDiscoverComponent = (props: WazuhDiscoverProps) => { {inspectedHit && ( - setInspectedHit(undefined)} size='m'> + { )} filters={filters} setFilters={setFilters} + onFilter={closeFlyoutHandler} /> diff --git a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx index c764591648..717f3d7645 100644 --- a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx @@ -202,6 +202,8 @@ const InventoryVulsComponent = () => { getUnderEvaluation(filters || []), ); + const closeFlyoutHandler = () => setInspectedHit(undefined); + return ( <> @@ -295,7 +297,7 @@ const InventoryVulsComponent = () => { ) : null} {inspectedHit && ( - setInspectedHit(undefined)} size='m'> +

Vulnerability details

@@ -312,6 +314,7 @@ const InventoryVulsComponent = () => { )} filters={filters} setFilters={setFilters} + onFilter={closeFlyoutHandler} /> From 2ddb2d47112b55b79a30a6bd1bdddccf4607e2de Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Thu, 17 Oct 2024 16:24:54 -0300 Subject: [PATCH 28/54] Fix Prettier issue --- .../public/components/common/doc-viewer/doc-viewer.scss | 8 ++++++-- .../components/document-view-table-and-json.tsx | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss index bb60bcbb28..7f46b8f7c9 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.scss +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.scss @@ -49,14 +49,18 @@ } &::before { - content: ""; + content: ''; position: absolute; display: block; right: 0; top: 0; height: 100%; width: 100%; - background-image: linear-gradient(to right, transparent 0, aliceblue 4px); + background-image: linear-gradient( + to right, + transparent 0, + aliceblue 4px + ); z-index: 1; } } diff --git a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx index df3602f420..04598fa777 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/document-view-table-and-json.tsx @@ -1,6 +1,9 @@ import React from 'react'; import { EuiFlexItem, EuiCodeBlock, EuiTabbedContent } from '@elastic/eui'; -import { IndexPattern, Filter } from '../../../../../../../src/plugins/data/common'; +import { + IndexPattern, + Filter, +} from '../../../../../../../src/plugins/data/common'; import DocViewer from '../../doc-viewer/doc-viewer'; import { useDocViewer } from '../../doc-viewer'; From 9516d551fa1dc262ded2b0540c93b6e4de72b179 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 21 Oct 2024 09:53:24 -0300 Subject: [PATCH 29/54] fix: add guard clause for undefined value in filter cell actions --- .../main/public/components/common/data-grid/data-grid-service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index a54eb432fe..2b29ead160 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -198,6 +198,7 @@ export const onFilterCellActions = ( setFilters: (filters: Filter[]) => void, ) => { return (field: string, operation: FILTER_OPERATOR, value?: any) => { + if (!value) return; const newFilters: Filter[] = []; if (Array.isArray(value)) { value.forEach(item => { From a1f8e72b164e4e5417309739bff76015f74df034 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 14:03:17 -0300 Subject: [PATCH 30/54] feat: add FilterStateStore enum and update state management in PatternDataSourceFilterManager to use it --- plugins/main/common/constants.ts | 5 +++++ .../pattern-data-source-filter-manager.ts | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/main/common/constants.ts b/plugins/main/common/constants.ts index 7b25a1d98c..fec2adeb12 100644 --- a/plugins/main/common/constants.ts +++ b/plugins/main/common/constants.ts @@ -530,3 +530,8 @@ export const OSD_URL_STATE_STORAGE_ID = 'state:storeInSessionStorage'; export const APP_STATE_URL_KEY = '_a'; export const GLOBAL_STATE_URL_KEY = '_g'; + +export enum FilterStateStore { + APP_STATE = 'appState', + GLOBAL_STATE = 'globalState', +} \ No newline at end of file diff --git a/plugins/main/public/components/common/data-source/pattern/pattern-data-source-filter-manager.ts b/plugins/main/public/components/common/data-source/pattern/pattern-data-source-filter-manager.ts index 8e4781c360..40bd4c2cd6 100644 --- a/plugins/main/public/components/common/data-source/pattern/pattern-data-source-filter-manager.ts +++ b/plugins/main/public/components/common/data-source/pattern/pattern-data-source-filter-manager.ts @@ -10,11 +10,10 @@ import { tDataSource, tFilterManager, } from '../index'; -import { - DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER, - AUTHORIZED_AGENTS, -} from '../../../../../common/constants'; +import { DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER } from '../../../../../common/constants'; import { PinnedAgentManager } from '../../../wz-agent-selector/wz-agent-selector-service'; +import { FilterStateStore } from '../../../../../common/constants'; + const MANAGER_AGENT_ID = '000'; const AGENT_ID_KEY = 'agent.id'; @@ -36,7 +35,7 @@ export function getFilterExcludeManager(indexPatternId: string) { controlledBy: DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER, }, query: { match_phrase: { [AGENT_ID_KEY]: MANAGER_AGENT_ID } }, - $state: { store: 'appState' }, + $state: { store: FilterStateStore.APP_STATE }, }; } @@ -278,7 +277,7 @@ export class PatternDataSourceFilterManager }; //@ts-ignore managerFilter.$state = { - store: 'appState', + store: FilterStateStore.APP_STATE, }; //@ts-ignore return [managerFilter] as tFilter[]; @@ -382,7 +381,7 @@ export class PatternDataSourceFilterManager controlledBy, }, exists: { field: key }, - $state: { store: 'appState' }, + $state: { store: FilterStateStore.APP_STATE }, }; case FILTER_OPERATOR.IS_ONE_OF: case FILTER_OPERATOR.IS_NOT_ONE_OF: @@ -429,7 +428,7 @@ export class PatternDataSourceFilterManager lte: value[1] || NaN, }, }, - $state: { store: 'appState' }, + $state: { store: FilterStateStore.APP_STATE }, }; default: throw new Error('Invalid filter type'); @@ -484,7 +483,7 @@ export class PatternDataSourceFilterManager controlledBy, }, ...query, - $state: { store: 'appState' }, + $state: { store: FilterStateStore.APP_STATE }, }; } From bfad495454e4c2ca043ddb8f710252cda35e5945 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 15:08:33 -0300 Subject: [PATCH 31/54] fix: update onFilter function to accept more specific FILTER_OPERATOR types and value types in DocViewer component --- .../public/components/common/doc-viewer/doc-viewer.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 995c29accd..3c1d8caba4 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -104,7 +104,14 @@ const DocViewer = (props: tDocViewerProps) => { onFilter: onClose, } = props; - const onFilter = (field: string, operation: FILTER_OPERATOR, value?: any) => { + const onFilter = ( + field: string, + operation: + | FILTER_OPERATOR.IS + | FILTER_OPERATOR.IS_NOT + | FILTER_OPERATOR.EXISTS, + value?: string | string[], + ) => { const _onFilter = onFilterCellActions( indexPattern?.id, filters, From ec96ca7dd30b4046dc4d7067d0433eae3e48af43 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 15:30:03 -0300 Subject: [PATCH 32/54] feat: add isNullish utility function and update exports in util index for better nullish checks --- plugins/main/public/components/common/util/index.ts | 1 + plugins/main/public/components/common/util/is-nullish.ts | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 plugins/main/public/components/common/util/is-nullish.ts diff --git a/plugins/main/public/components/common/util/index.ts b/plugins/main/public/components/common/util/index.ts index 906515e7ec..2971d4bbad 100644 --- a/plugins/main/public/components/common/util/index.ts +++ b/plugins/main/public/components/common/util/index.ts @@ -16,3 +16,4 @@ export { TruncateHorizontalComponents } from './truncate-horizontal-components/t export { GroupingComponents } from './grouping-components'; export * from './markdown/markdown'; export * from './wz-overlay-mask-interface'; +export * from './is-nullish'; diff --git a/plugins/main/public/components/common/util/is-nullish.ts b/plugins/main/public/components/common/util/is-nullish.ts new file mode 100644 index 0000000000..94666d7bef --- /dev/null +++ b/plugins/main/public/components/common/util/is-nullish.ts @@ -0,0 +1,3 @@ +export const isNullish = ( + value: T | null | undefined, +): value is null | undefined => value === null || value === undefined; From 6d3307f79a6998fffafb5c060b17df32d59be020 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 15:30:15 -0300 Subject: [PATCH 33/54] fix: refactor onFilterCellActions to use isNullish for improved handling of FILTER_OPERATOR and value inputs in data grid service --- .../common/data-grid/data-grid-service.ts | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index 2b29ead160..1410e398b4 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -14,6 +14,7 @@ import { FILTER_OPERATOR, PatternDataSourceFilterManager, } from '../data-source/pattern/pattern-data-source-filter-manager'; +import { isNullish } from '../util'; type ParseData = | { @@ -197,29 +198,47 @@ export const onFilterCellActions = ( filters: Filter[], setFilters: (filters: Filter[]) => void, ) => { - return (field: string, operation: FILTER_OPERATOR, value?: any) => { - if (!value) return; + return ( + field: string, + operation: + | FILTER_OPERATOR.EXISTS + | FILTER_OPERATOR.IS + | FILTER_OPERATOR.IS_NOT, + values?: string | string[], + ) => { + // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 + const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); + let _operation: FILTER_OPERATOR = operation; + if (isNullish(values) && ![FILTER_OPERATOR.EXISTS].includes(operation)) { + if (negated) { + _operation = FILTER_OPERATOR.EXISTS; + } else { + _operation = FILTER_OPERATOR.DOES_NOT_EXISTS; + } + } + const newFilters: Filter[] = []; - if (Array.isArray(value)) { - value.forEach(item => { + if (isNullish(values)) { + newFilters.push( + PatternDataSourceFilterManager.createFilter( + _operation, + field, + values, + indexPatternId, + ), + ); + } else { + values = Array.isArray(values) ? values : [values]; + values.forEach(item => { newFilters.push( PatternDataSourceFilterManager.createFilter( - operation, + _operation, field, item, indexPatternId, ), ); }); - } else { - newFilters.push( - PatternDataSourceFilterManager.createFilter( - operation, - field, - value, - indexPatternId, - ), - ); } setFilters([...filters, ...newFilters]); }; From 21e1038eea3105dbe6edd31884464692e465d756 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 15:37:25 -0300 Subject: [PATCH 34/54] fix: refactor onFilterCellActions import path for improved structure and maintainability in data-grid and doc-viewer components --- .../common/data-grid/data-grid-service.ts | 57 +------------------ .../common/data-grid/filter-cell-actions.ts | 57 +++++++++++++++++++ .../common/doc-viewer/doc-viewer.tsx | 2 +- 3 files changed, 59 insertions(+), 57 deletions(-) create mode 100644 plugins/main/public/components/common/data-grid/filter-cell-actions.ts diff --git a/plugins/main/public/components/common/data-grid/data-grid-service.ts b/plugins/main/public/components/common/data-grid/data-grid-service.ts index 1410e398b4..b209d05bdf 100644 --- a/plugins/main/public/components/common/data-grid/data-grid-service.ts +++ b/plugins/main/public/components/common/data-grid/data-grid-service.ts @@ -10,11 +10,7 @@ import { export const MAX_ENTRIES_PER_QUERY = 10000; import { tDataGridColumn } from './use-data-grid'; import { cellFilterActions } from './cell-filter-actions'; -import { - FILTER_OPERATOR, - PatternDataSourceFilterManager, -} from '../data-source/pattern/pattern-data-source-filter-manager'; -import { isNullish } from '../util'; +import { onFilterCellActions } from './filter-cell-actions'; type ParseData = | { @@ -193,57 +189,6 @@ export const exportSearchToCSV = async ( } }; -export const onFilterCellActions = ( - indexPatternId: string, - filters: Filter[], - setFilters: (filters: Filter[]) => void, -) => { - return ( - field: string, - operation: - | FILTER_OPERATOR.EXISTS - | FILTER_OPERATOR.IS - | FILTER_OPERATOR.IS_NOT, - values?: string | string[], - ) => { - // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 - const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); - let _operation: FILTER_OPERATOR = operation; - if (isNullish(values) && ![FILTER_OPERATOR.EXISTS].includes(operation)) { - if (negated) { - _operation = FILTER_OPERATOR.EXISTS; - } else { - _operation = FILTER_OPERATOR.DOES_NOT_EXISTS; - } - } - - const newFilters: Filter[] = []; - if (isNullish(values)) { - newFilters.push( - PatternDataSourceFilterManager.createFilter( - _operation, - field, - values, - indexPatternId, - ), - ); - } else { - values = Array.isArray(values) ? values : [values]; - values.forEach(item => { - newFilters.push( - PatternDataSourceFilterManager.createFilter( - _operation, - field, - item, - indexPatternId, - ), - ); - }); - } - setFilters([...filters, ...newFilters]); - }; -}; - const mapToDataGridColumn = ( field: IFieldType, indexPattern: IndexPattern, diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts new file mode 100644 index 0000000000..98588a0755 --- /dev/null +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts @@ -0,0 +1,57 @@ +import { + FILTER_OPERATOR, + PatternDataSourceFilterManager, +} from '../data-source/pattern/pattern-data-source-filter-manager'; +import { Filter } from '../../../../../../src/plugins/data/common'; +import { isNullish } from '../util'; + +export const onFilterCellActions = ( + indexPatternId: string, + filters: Filter[], + setFilters: (filters: Filter[]) => void, +) => { + return ( + field: string, + operation: + | FILTER_OPERATOR.EXISTS + | FILTER_OPERATOR.IS + | FILTER_OPERATOR.IS_NOT, + values?: string | string[], + ) => { + // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 + const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); + let _operation: FILTER_OPERATOR = operation; + if (isNullish(values) && ![FILTER_OPERATOR.EXISTS].includes(operation)) { + if (negated) { + _operation = FILTER_OPERATOR.EXISTS; + } else { + _operation = FILTER_OPERATOR.DOES_NOT_EXISTS; + } + } + + const newFilters: Filter[] = []; + if (isNullish(values)) { + newFilters.push( + PatternDataSourceFilterManager.createFilter( + _operation, + field, + values, + indexPatternId, + ), + ); + } else { + values = Array.isArray(values) ? values : [values]; + values.forEach(item => { + newFilters.push( + PatternDataSourceFilterManager.createFilter( + _operation, + field, + item, + indexPatternId, + ), + ); + }); + } + setFilters([...filters, ...newFilters]); + }; +}; diff --git a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx index 3c1d8caba4..9ebc58e339 100644 --- a/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx +++ b/plugins/main/public/components/common/doc-viewer/doc-viewer.tsx @@ -9,7 +9,7 @@ import { DocViewTableRowBtnFilterAdd } from './table-row-btn-filter-add'; import { DocViewTableRowBtnFilterRemove } from './table-row-btn-filter-remove'; import { DocViewTableRowBtnFilterExists } from './table-row-btn-filter-exists'; import './doc-viewer.scss'; -import { onFilterCellActions } from '../data-grid'; +import { onFilterCellActions } from '../data-grid/filter-cell-actions'; import { Filter } from '../../../../../../src/plugins/data/common'; const COLLAPSE_LINE_LENGTH = 350; From 38224118c68b825626e325b085ed001b363df50e Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:07:02 -0300 Subject: [PATCH 35/54] fix: update onFilterCellActions to accept number type in values for enhanced filtering capabilities in data grid component --- .../public/components/common/data-grid/filter-cell-actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts index 98588a0755..2d8d757b21 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts @@ -16,7 +16,7 @@ export const onFilterCellActions = ( | FILTER_OPERATOR.EXISTS | FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, - values?: string | string[], + values?: number | string | string[], ) => { // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); From 2c2de2206ef272b67818986b8e8db70f41cb6cef Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:07:30 -0300 Subject: [PATCH 36/54] test: add unit tests for onFilterCellActions to verify filtering with number values in data grid component --- .../data-grid/filter-cell-actions.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts new file mode 100644 index 0000000000..393ddee8c4 --- /dev/null +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -0,0 +1,69 @@ +import { FilterStateStore } from '../../../../common/constants'; +import { Filter } from '../../../../../../src/plugins/data/common'; +import { onFilterCellActions } from './filter-cell-actions'; +import { FILTER_OPERATOR } from '../data-source'; + +const INDEX_PATTERN_ID = 'index-pattern-test'; + +const buildFilter = ( + type: string, + key: string, + value: string | string[] | any, +) => { + return { + meta: { + alias: null, + controlledBy: undefined, + disabled: false, + key: key, + value: Array.isArray(value) ? value.join(', ') : value, + params: value, + negate: type === 'is not', + type: Array.isArray(value) ? 'phrases' : 'phrase', + index: INDEX_PATTERN_ID, + }, + query: { match_phrase: { [key]: { query: value } } }, + $state: { store: FilterStateStore.APP_STATE }, + }; +}; + +describe('onFilterCellActions', () => { + let filters: Filter[]; + let setFilters: jest.Mock; + + beforeEach(() => { + filters = []; + setFilters = jest.fn(); + }); + + it('should add filter with given key (rule.level) and number value (3)', () => { + const key = 'rule.level'; + const value = 3; + onFilterCellActions(INDEX_PATTERN_ID, filters, setFilters)( + key, + FILTER_OPERATOR.IS, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + ...filters, + buildFilter(FILTER_OPERATOR.IS, key, value), + ]); + }); + + it('should add filter with is not operator for key and number value (3)', () => { + const key = 'rule.level'; + const value = 3; + + onFilterCellActions(INDEX_PATTERN_ID, filters, setFilters)( + key, + FILTER_OPERATOR.IS_NOT, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + ...filters, + buildFilter(FILTER_OPERATOR.IS_NOT, key, value), + ]); + }); +}); From 70ad2e724bb5bef58924eea3680e2e659edffcd6 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:08:54 -0300 Subject: [PATCH 37/54] test: simplify onFilterCellActions tests by removing unused filters array for clearer unit tests in data grid component --- .../common/data-grid/filter-cell-actions.test.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index 393ddee8c4..b18d60724d 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -1,5 +1,4 @@ import { FilterStateStore } from '../../../../common/constants'; -import { Filter } from '../../../../../../src/plugins/data/common'; import { onFilterCellActions } from './filter-cell-actions'; import { FILTER_OPERATOR } from '../data-source'; @@ -28,25 +27,22 @@ const buildFilter = ( }; describe('onFilterCellActions', () => { - let filters: Filter[]; let setFilters: jest.Mock; beforeEach(() => { - filters = []; setFilters = jest.fn(); }); it('should add filter with given key (rule.level) and number value (3)', () => { const key = 'rule.level'; const value = 3; - onFilterCellActions(INDEX_PATTERN_ID, filters, setFilters)( + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( key, FILTER_OPERATOR.IS, value, ); expect(setFilters).toHaveBeenCalledWith([ - ...filters, buildFilter(FILTER_OPERATOR.IS, key, value), ]); }); @@ -55,14 +51,13 @@ describe('onFilterCellActions', () => { const key = 'rule.level'; const value = 3; - onFilterCellActions(INDEX_PATTERN_ID, filters, setFilters)( + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( key, FILTER_OPERATOR.IS_NOT, value, ); expect(setFilters).toHaveBeenCalledWith([ - ...filters, buildFilter(FILTER_OPERATOR.IS_NOT, key, value), ]); }); From 6f00f9334240f5b2884c2e61a224c874bc6c46f2 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:15:16 -0300 Subject: [PATCH 38/54] test: enhance onFilterCellActions tests by clarifying filter addition with improved descriptions for number and string values in data grid --- .../data-grid/filter-cell-actions.test.ts | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index b18d60724d..58de24ce2a 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -33,32 +33,67 @@ describe('onFilterCellActions', () => { setFilters = jest.fn(); }); - it('should add filter with given key (rule.level) and number value (3)', () => { + it('should add single filter with given key (rule.level) and number value (3)', () => { const key = 'rule.level'; const value = 3; + const operation = FILTER_OPERATOR.IS; + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( key, - FILTER_OPERATOR.IS, + operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(FILTER_OPERATOR.IS, key, value), + buildFilter(operation, key, value), ]); }); - it('should add filter with is not operator for key and number value (3)', () => { + it('should add single filter with is not operator for key and number value (3)', () => { const key = 'rule.level'; const value = 3; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(operation, key, value), + ]); + }); + + it('should add single filter with key (rule.id) and string value (19003)', () => { + const key = 'rule.id'; + const value = '19003'; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(operation, key, value), + ]); + }); + + it('should add single filter with key (rule.id) and string value (19003)', () => { + const key = 'rule.id'; + const value = '19003'; + const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( key, - FILTER_OPERATOR.IS_NOT, + operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(FILTER_OPERATOR.IS_NOT, key, value), + buildFilter(operation, key, value), ]); }); }); From 30ed18a2dfa8d7d801a3461a3b8e202ab7837724 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:16:46 -0300 Subject: [PATCH 39/54] test: refactor buildFilter usage in onFilterCellActions tests for improved clarity on filter creation in data grid component --- .../common/data-grid/filter-cell-actions.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index 58de24ce2a..6a2a97bc05 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -5,8 +5,8 @@ import { FILTER_OPERATOR } from '../data-source'; const INDEX_PATTERN_ID = 'index-pattern-test'; const buildFilter = ( - type: string, key: string, + operation: string, value: string | string[] | any, ) => { return { @@ -17,7 +17,7 @@ const buildFilter = ( key: key, value: Array.isArray(value) ? value.join(', ') : value, params: value, - negate: type === 'is not', + negate: operation === 'is not', type: Array.isArray(value) ? 'phrases' : 'phrase', index: INDEX_PATTERN_ID, }, @@ -45,7 +45,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(operation, key, value), + buildFilter(key, operation, value), ]); }); @@ -61,7 +61,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(operation, key, value), + buildFilter(key, operation, value), ]); }); @@ -77,7 +77,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(operation, key, value), + buildFilter(key, operation, value), ]); }); @@ -93,7 +93,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(operation, key, value), + buildFilter(key, operation, value), ]); }); }); From 5e639aba06db861214c776862369086506837f93 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:27:49 -0300 Subject: [PATCH 40/54] test: improve onFilterCellActions tests with clearer descriptions for filters and added date filter cases in data grid component --- .../data-grid/filter-cell-actions.test.ts | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index 6a2a97bc05..4261fb9d7e 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -49,7 +49,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with is not operator for key and number value (3)', () => { + it('should add single filter with is not operator for given key (rule.level) and number value (3)', () => { const key = 'rule.level'; const value = 3; const operation = FILTER_OPERATOR.IS_NOT; @@ -65,7 +65,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with key (rule.id) and string value (19003)', () => { + it('should add single filter with given key (rule.id) and string value (19003)', () => { const key = 'rule.id'; const value = '19003'; const operation = FILTER_OPERATOR.IS; @@ -81,7 +81,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with key (rule.id) and string value (19003)', () => { + it('should add single filter with is not operator for given key (rule.id) and string value (19003)', () => { const key = 'rule.id'; const value = '19003'; const operation = FILTER_OPERATOR.IS_NOT; @@ -96,4 +96,36 @@ describe('onFilterCellActions', () => { buildFilter(key, operation, value), ]); }); + + it('should add single filter with given key (timestamp) and date value (2024-10-19T18:44:40.487Z)', () => { + const key = 'timestamp'; + const value = '2024-10-19T18:44:40.487Z'; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, value), + ]); + }); + + it('should add single filter is not operator for given key (timestamp) and date value (2024-10-19T18:44:40.487Z)', () => { + const key = 'timestamp'; + const value = '2024-10-19T18:44:40.487Z'; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, value), + ]); + }); }); From fe069739cf4baf31660b89604404f6724e990d9c Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:36:37 -0300 Subject: [PATCH 41/54] test: add tests for single filter actions with string values and 'is'/'is not' operators in onFilterCellActions for data grid --- .../data-grid/filter-cell-actions.test.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index 4261fb9d7e..cf3469b6f8 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -128,4 +128,38 @@ describe('onFilterCellActions', () => { buildFilter(key, operation, value), ]); }); + + it('should add single filter with given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and string value (10.0.2.2)', () => { + const key = + 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + const value = '10.0.2.2'; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, value), + ]); + }); + + it('should add single filter with is not operator for given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and string value (10.0.2.2)', () => { + const key = + 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + const value = '10.0.2.2'; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, value), + ]); + }); }); From 3e7555d67c8553590fef047c3e7f95044476a43b Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:36:44 -0300 Subject: [PATCH 42/54] test: add tests for multiple filters with 'is' and 'is not' operators for rule.groups in onFilterCellActions for data grid --- .../data-grid/filter-cell-actions.test.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index cf3469b6f8..ac9d60b1ba 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -162,4 +162,38 @@ describe('onFilterCellActions', () => { buildFilter(key, operation, value), ]); }); + + it('should add two filters with given key (rule.groups) and value (group1, group2) respectively', () => { + const key = 'rule.groups'; + const values = ['group1', 'group2']; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + values, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, values[0]), + buildFilter(key, operation, values[1]), + ]); + }); + + it('should add two filters with is not operator for given key (rule.groups) and value (group1, group2) respectively', () => { + const key = 'rule.groups'; + const values = ['group1', 'group2']; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + values, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, operation, values[0]), + buildFilter(key, operation, values[1]), + ]); + }); }); From 17c0db55399c1aa348023d0768adb74662ccb05a Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 16:56:25 -0300 Subject: [PATCH 43/54] test: add test for onFilterCellActions with undefined value to ensure appropriate filter behavior in data grid component --- .../data-grid/filter-cell-actions.test.ts | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index ac9d60b1ba..fa2c1834d8 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -9,19 +9,33 @@ const buildFilter = ( operation: string, value: string | string[] | any, ) => { + const hasExists = operation.includes('exists'); + const hasPhrase = !hasExists && value; + return { + ...(hasExists && { exists: { field: key } }), meta: { alias: null, controlledBy: undefined, disabled: false, key: key, - value: Array.isArray(value) ? value.join(', ') : value, - params: value, - negate: operation === 'is not', - type: Array.isArray(value) ? 'phrases' : 'phrase', + ...(hasPhrase && { params: value }), + value: hasPhrase + ? Array.isArray(value) + ? value.join(', ') + : value + : 'exists', + negate: operation === 'is not' || !value, + type: hasPhrase + ? Array.isArray(value) + ? 'phrases' + : 'phrase' + : 'exists', index: INDEX_PATTERN_ID, }, - query: { match_phrase: { [key]: { query: value } } }, + ...(hasPhrase && { + query: { match_phrase: { [key]: { query: value } } }, + }), $state: { store: FilterStateStore.APP_STATE }, }; }; @@ -196,4 +210,21 @@ describe('onFilterCellActions', () => { buildFilter(key, operation, values[1]), ]); }); + + it('should add single filter with given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and undefined value', () => { + const key = + 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + const values = undefined; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + values, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, FILTER_OPERATOR.DOES_NOT_EXISTS, values), + ]); + }); }); From 5c0ea1c25a3895ac651daf682833029da67d47d5 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:13:59 -0300 Subject: [PATCH 44/54] test: update filter negate logic and add test for 'is not' operator with undefined value in onFilterCellActions for data grid --- .../data-grid/filter-cell-actions.test.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index fa2c1834d8..e677bcfb1c 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -25,7 +25,7 @@ const buildFilter = ( ? value.join(', ') : value : 'exists', - negate: operation === 'is not' || !value, + negate: operation.includes('not'), type: hasPhrase ? Array.isArray(value) ? 'phrases' @@ -227,4 +227,21 @@ describe('onFilterCellActions', () => { buildFilter(key, FILTER_OPERATOR.DOES_NOT_EXISTS, values), ]); }); + + it('should add single filter with is not operator for given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and undefined value', () => { + const key = + 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + const values = undefined; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + key, + operation, + values, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildFilter(key, FILTER_OPERATOR.EXISTS, values), + ]); + }); }); From d1757f28a70b94e6318de76019fefd676b200dd3 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:15:09 -0300 Subject: [PATCH 45/54] Fix Prettier issue --- plugins/main/common/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/common/constants.ts b/plugins/main/common/constants.ts index fec2adeb12..4da147db02 100644 --- a/plugins/main/common/constants.ts +++ b/plugins/main/common/constants.ts @@ -534,4 +534,4 @@ export const GLOBAL_STATE_URL_KEY = '_g'; export enum FilterStateStore { APP_STATE = 'appState', GLOBAL_STATE = 'globalState', -} \ No newline at end of file +} From 741029b10f2cb35492c6428f4a61ffcb978f8e84 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:19:22 -0300 Subject: [PATCH 46/54] test: refactor filter creation logic in onFilterCellActions tests for improved clarity and consistency in data grid component --- .../data-grid/filter-cell-actions.test.ts | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index e677bcfb1c..e712f21015 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -4,38 +4,41 @@ import { FILTER_OPERATOR } from '../data-source'; const INDEX_PATTERN_ID = 'index-pattern-test'; -const buildFilter = ( +const buildMatchFilter = ( key: string, operation: string, value: string | string[] | any, ) => { - const hasExists = operation.includes('exists'); - const hasPhrase = !hasExists && value; + return { + meta: { + alias: null, + controlledBy: undefined, + disabled: false, + key: key, + params: value, + value: Array.isArray(value) ? value.join(', ') : value, + negate: operation.includes('not'), + type: Array.isArray(value) ? 'phrases' : 'phrase', + index: INDEX_PATTERN_ID, + }, + query: { match_phrase: { [key]: { query: value } } }, + $state: { store: FilterStateStore.APP_STATE }, + }; +}; +const buildExistsFilter = (key: string, operation: string) => { return { - ...(hasExists && { exists: { field: key } }), + exists: { field: key }, meta: { alias: null, controlledBy: undefined, disabled: false, key: key, - ...(hasPhrase && { params: value }), - value: hasPhrase - ? Array.isArray(value) - ? value.join(', ') - : value - : 'exists', + value: 'exists', negate: operation.includes('not'), - type: hasPhrase - ? Array.isArray(value) - ? 'phrases' - : 'phrase' - : 'exists', + type: 'exists', index: INDEX_PATTERN_ID, }, - ...(hasPhrase && { - query: { match_phrase: { [key]: { query: value } } }, - }), $state: { store: FilterStateStore.APP_STATE }, }; }; @@ -59,7 +62,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -75,7 +78,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -91,7 +94,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -107,7 +110,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -123,7 +126,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -139,7 +142,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -156,7 +159,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -173,7 +176,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, value), + buildMatchFilter(key, operation, value), ]); }); @@ -189,8 +192,8 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, values[0]), - buildFilter(key, operation, values[1]), + buildMatchFilter(key, operation, values[0]), + buildMatchFilter(key, operation, values[1]), ]); }); @@ -206,8 +209,8 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, operation, values[0]), - buildFilter(key, operation, values[1]), + buildMatchFilter(key, operation, values[0]), + buildMatchFilter(key, operation, values[1]), ]); }); @@ -224,7 +227,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, FILTER_OPERATOR.DOES_NOT_EXISTS, values), + buildExistsFilter(key, FILTER_OPERATOR.DOES_NOT_EXISTS), ]); }); @@ -241,7 +244,7 @@ describe('onFilterCellActions', () => { ); expect(setFilters).toHaveBeenCalledWith([ - buildFilter(key, FILTER_OPERATOR.EXISTS, values), + buildExistsFilter(key, FILTER_OPERATOR.EXISTS), ]); }); }); From 638da8df823c838d99f922693220120115c668d7 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:26:08 -0300 Subject: [PATCH 47/54] test: unify key usage in filter tests in onFilterCellActions for clearer and more maintainable assertions in data grid component --- .../data-grid/filter-cell-actions.test.ts | 93 ++++++++----------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index e712f21015..f3546b4893 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -2,6 +2,7 @@ import { FilterStateStore } from '../../../../common/constants'; import { onFilterCellActions } from './filter-cell-actions'; import { FILTER_OPERATOR } from '../data-source'; +const KEY = 'test-key'; const INDEX_PATTERN_ID = 'index-pattern-test'; const buildMatchFilter = ( @@ -50,201 +51,185 @@ describe('onFilterCellActions', () => { setFilters = jest.fn(); }); - it('should add single filter with given key (rule.level) and number value (3)', () => { - const key = 'rule.level'; + it('should add single filter with given key and number value (3)', () => { const value = 3; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with is not operator for given key (rule.level) and number value (3)', () => { - const key = 'rule.level'; + it('should add single filter with is not operator for given key and number value (3)', () => { const value = 3; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with given key (rule.id) and string value (19003)', () => { - const key = 'rule.id'; + it('should add single filter with given key and string value (19003)', () => { const value = '19003'; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with is not operator for given key (rule.id) and string value (19003)', () => { - const key = 'rule.id'; + it('should add single filter with is not operator for given key and string value (19003)', () => { const value = '19003'; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with given key (timestamp) and date value (2024-10-19T18:44:40.487Z)', () => { - const key = 'timestamp'; + it('should add single filter with given key and date value (2024-10-19T18:44:40.487Z)', () => { const value = '2024-10-19T18:44:40.487Z'; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter is not operator for given key (timestamp) and date value (2024-10-19T18:44:40.487Z)', () => { - const key = 'timestamp'; + it('should add single filter is not operator for given key and date value (2024-10-19T18:44:40.487Z)', () => { const value = '2024-10-19T18:44:40.487Z'; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and string value (10.0.2.2)', () => { - const key = - 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + it('should add single filter with given key and string value (10.0.2.2)', () => { const value = '10.0.2.2'; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add single filter with is not operator for given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and string value (10.0.2.2)', () => { - const key = - 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + it('should add single filter with is not operator for given key and string value (10.0.2.2)', () => { const value = '10.0.2.2'; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, value, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, value), + buildMatchFilter(KEY, operation, value), ]); }); - it('should add two filters with given key (rule.groups) and value (group1, group2) respectively', () => { - const key = 'rule.groups'; + it('should add two filters with given key and value (group1, group2) respectively', () => { const values = ['group1', 'group2']; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, values, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, values[0]), - buildMatchFilter(key, operation, values[1]), + buildMatchFilter(KEY, operation, values[0]), + buildMatchFilter(KEY, operation, values[1]), ]); }); - it('should add two filters with is not operator for given key (rule.groups) and value (group1, group2) respectively', () => { - const key = 'rule.groups'; + it('should add two filters with is not operator for given key and value (group1, group2) respectively', () => { const values = ['group1', 'group2']; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, values, ); expect(setFilters).toHaveBeenCalledWith([ - buildMatchFilter(key, operation, values[0]), - buildMatchFilter(key, operation, values[1]), + buildMatchFilter(KEY, operation, values[0]), + buildMatchFilter(KEY, operation, values[1]), ]); }); - it('should add single filter with given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and undefined value', () => { - const key = - 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + it('should add single filter with given key and undefined value', () => { const values = undefined; const operation = FILTER_OPERATOR.IS; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, values, ); expect(setFilters).toHaveBeenCalledWith([ - buildExistsFilter(key, FILTER_OPERATOR.DOES_NOT_EXISTS), + buildExistsFilter(KEY, FILTER_OPERATOR.DOES_NOT_EXISTS), ]); }); - it('should add single filter with is not operator for given key (data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress) and undefined value', () => { - const key = - 'data.aws.resource.instanceDetails.networkInterfaces.privateIpAddress'; + it('should add single filter with is not operator for given key and undefined value', () => { const values = undefined; const operation = FILTER_OPERATOR.IS_NOT; onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( - key, + KEY, operation, values, ); expect(setFilters).toHaveBeenCalledWith([ - buildExistsFilter(key, FILTER_OPERATOR.EXISTS), + buildExistsFilter(KEY, FILTER_OPERATOR.EXISTS), ]); }); }); From 48205ed45bba0446e3beb332639788da17b95cff Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:28:56 -0300 Subject: [PATCH 48/54] test: add filter logic tests for boolean values in onFilterCellActions for better coverage in data grid component --- .../data-grid/filter-cell-actions.test.ts | 30 +++++++++++++++++++ .../common/data-grid/filter-cell-actions.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index f3546b4893..bb0b1849af 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -111,6 +111,36 @@ describe('onFilterCellActions', () => { ]); }); + it('should add single filter with given key and string value (true)', () => { + const value = true; + const operation = FILTER_OPERATOR.IS; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + KEY, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildMatchFilter(KEY, operation, value), + ]); + }); + + it('should add single filter with is not operator for given key and string value (true)', () => { + const value = true; + const operation = FILTER_OPERATOR.IS_NOT; + + onFilterCellActions(INDEX_PATTERN_ID, [], setFilters)( + KEY, + operation, + value, + ); + + expect(setFilters).toHaveBeenCalledWith([ + buildMatchFilter(KEY, operation, value), + ]); + }); + it('should add single filter with given key and date value (2024-10-19T18:44:40.487Z)', () => { const value = '2024-10-19T18:44:40.487Z'; const operation = FILTER_OPERATOR.IS; diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts index 2d8d757b21..4827ee00ab 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts @@ -16,7 +16,7 @@ export const onFilterCellActions = ( | FILTER_OPERATOR.EXISTS | FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, - values?: number | string | string[], + values?: boolean | number | string | string[], ) => { // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); From 4233592a188cde6cc9a4d363214476ee735dec4e Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:29:18 -0300 Subject: [PATCH 49/54] test: update filter tests in onFilterCellActions to clarify handling of boolean values in data grid component --- .../components/common/data-grid/filter-cell-actions.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index bb0b1849af..623ac5db09 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -111,7 +111,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with given key and string value (true)', () => { + it('should add single filter with given key and boolean value (true)', () => { const value = true; const operation = FILTER_OPERATOR.IS; @@ -126,7 +126,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with is not operator for given key and string value (true)', () => { + it('should add single filter with is not operator for given key and boolean value (true)', () => { const value = true; const operation = FILTER_OPERATOR.IS_NOT; From e88e502183247752eca00386de719ffc9e13d637 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:29:54 -0300 Subject: [PATCH 50/54] test: improve clarity in filter cell action tests by specifying value types in data grid component assertions --- .../common/data-grid/filter-cell-actions.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts index 623ac5db09..a6dae0615f 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.test.ts @@ -171,7 +171,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with given key and string value (10.0.2.2)', () => { + it('should add single filter with given key and ip value (10.0.2.2)', () => { const value = '10.0.2.2'; const operation = FILTER_OPERATOR.IS; @@ -186,7 +186,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add single filter with is not operator for given key and string value (10.0.2.2)', () => { + it('should add single filter with is not operator for given key and ip value (10.0.2.2)', () => { const value = '10.0.2.2'; const operation = FILTER_OPERATOR.IS_NOT; @@ -201,7 +201,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add two filters with given key and value (group1, group2) respectively', () => { + it('should add two filters with given key and values (group1, group2) respectively', () => { const values = ['group1', 'group2']; const operation = FILTER_OPERATOR.IS; @@ -217,7 +217,7 @@ describe('onFilterCellActions', () => { ]); }); - it('should add two filters with is not operator for given key and value (group1, group2) respectively', () => { + it('should add two filters with is not operator for given key and values (group1, group2) respectively', () => { const values = ['group1', 'group2']; const operation = FILTER_OPERATOR.IS_NOT; From fd9a9e883918d26a52804fe13aa787e049016710 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Tue, 22 Oct 2024 17:40:09 -0300 Subject: [PATCH 51/54] test: refine value type definition in onFilterCellActions to enhance clarity for boolean and numeric filters in data grid component --- .../public/components/common/data-grid/filter-cell-actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts index 4827ee00ab..8b108e67a7 100644 --- a/plugins/main/public/components/common/data-grid/filter-cell-actions.ts +++ b/plugins/main/public/components/common/data-grid/filter-cell-actions.ts @@ -16,7 +16,7 @@ export const onFilterCellActions = ( | FILTER_OPERATOR.EXISTS | FILTER_OPERATOR.IS | FILTER_OPERATOR.IS_NOT, - values?: boolean | number | string | string[], + values?: boolean | number | string | (boolean | number | string)[], ) => { // https://github.com/opensearch-project/OpenSearch-Dashboards/blob/4e34a7a5141d089f6c341a535be5a7ba2737d965/src/plugins/data/public/query/filter_manager/lib/generate_filters.ts#L89 const negated = [FILTER_OPERATOR.IS_NOT].includes(operation); From 9954031d5339157e00f051d6a4ead5ef1a4a6238 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Fri, 25 Oct 2024 08:11:00 -0300 Subject: [PATCH 52/54] Refactor drilldown components to simplify destructuring of props, removing unused variables for cleaner code --- .../overview/github/panel/config/drilldown-action.tsx | 10 ++-------- .../overview/github/panel/config/drilldown-actor.tsx | 10 ++-------- .../github/panel/config/drilldown-organization.tsx | 10 ++-------- .../github/panel/config/drilldown-repository.tsx | 10 ++-------- .../components/overview/github/panel/github-panel.tsx | 2 -- 5 files changed, 8 insertions(+), 34 deletions(-) diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx index c0c375db88..d5e571faa5 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-action.tsx @@ -109,14 +109,8 @@ const getDashboardPanels = ( }; export const DrilldownConfigAction = (drilldownProps: ModuleConfigProps) => { - const { - fetchData, - fetchFilters, - searchBarProps, - indexPattern, - filters, - setFilters, - } = drilldownProps; + const { fetchData, fetchFilters, searchBarProps, indexPattern } = + drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx index c6b002f0ac..42cb7381b8 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-actor.tsx @@ -109,14 +109,8 @@ const getDashboardPanels = ( }; export const DrilldownConfigActor = (drilldownProps: ModuleConfigProps) => { - const { - fetchData, - fetchFilters, - searchBarProps, - indexPattern, - filters, - setFilters, - } = drilldownProps; + const { fetchData, fetchFilters, searchBarProps, indexPattern } = + drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx index efc3bd766a..ece1caad00 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-organization.tsx @@ -111,14 +111,8 @@ const getDashboardPanels = ( export const DrilldownConfigOrganization = ( drilldownProps: ModuleConfigProps, ) => { - const { - fetchData, - fetchFilters, - searchBarProps, - indexPattern, - filters, - setFilters, - } = drilldownProps; + const { fetchData, fetchFilters, searchBarProps, indexPattern } = + drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx index dae0b261f8..28bf58517e 100644 --- a/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx +++ b/plugins/main/public/components/overview/github/panel/config/drilldown-repository.tsx @@ -111,14 +111,8 @@ const getDashboardPanels = ( export const DrilldownConfigRepository = ( drilldownProps: ModuleConfigProps, ) => { - const { - fetchData, - fetchFilters, - searchBarProps, - indexPattern, - filters, - setFilters, - } = drilldownProps; + const { fetchData, fetchFilters, searchBarProps, indexPattern } = + drilldownProps; return { rows: [ diff --git a/plugins/main/public/components/overview/github/panel/github-panel.tsx b/plugins/main/public/components/overview/github/panel/github-panel.tsx index 52f745c136..200d9310f0 100644 --- a/plugins/main/public/components/overview/github/panel/github-panel.tsx +++ b/plugins/main/public/components/overview/github/panel/github-panel.tsx @@ -104,8 +104,6 @@ export const GitHubPanel = withErrorBoundary(() => { fetchFilters: [...fetchFilters, ...selectedPanelFilter], searchBarProps, indexPattern: dataSource?.indexPattern, - filters, - setFilters, }} isLoading={isDataSourceLoading} /> From ad190babcef1ee064e3a14b7f776bc634df5d01b Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Fri, 25 Oct 2024 08:21:44 -0300 Subject: [PATCH 53/54] Remove unused `filters` and `setFilters` props from OfficePanel for cleaner code and improved readability --- .../public/components/overview/office/panel/office-panel.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/main/public/components/overview/office/panel/office-panel.tsx b/plugins/main/public/components/overview/office/panel/office-panel.tsx index 3746771ae1..7d908087d7 100644 --- a/plugins/main/public/components/overview/office/panel/office-panel.tsx +++ b/plugins/main/public/components/overview/office/panel/office-panel.tsx @@ -105,8 +105,6 @@ export const OfficePanel = withErrorBoundary(() => { fetchFilters: [...fetchFilters, ...selectedPanelFilter], searchBarProps, indexPattern: dataSource?.indexPattern, - filters, - setFilters, }} isLoading={isDataSourceLoading} /> From b28fd9d2ab8f3e3e5c340d20aa68246299da9162 Mon Sep 17 00:00:00 2001 From: Guido Modarelli Date: Mon, 28 Oct 2024 11:48:28 -0300 Subject: [PATCH 54/54] Fix typos in export button label across data grid components --- .../wazuh-discover/components/data-grid-additional-controls.tsx | 2 +- .../overview/vulnerabilities/dashboards/inventory/inventory.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/components/common/wazuh-discover/components/data-grid-additional-controls.tsx b/plugins/main/public/components/common/wazuh-discover/components/data-grid-additional-controls.tsx index 2494628f72..1826e15a2a 100644 --- a/plugins/main/public/components/common/wazuh-discover/components/data-grid-additional-controls.tsx +++ b/plugins/main/public/components/common/wazuh-discover/components/data-grid-additional-controls.tsx @@ -74,7 +74,7 @@ const DiscoverDataGridAdditionalControls = ( className='euiDataGrid__controlBtn' onClick={onHandleExportResults} > - Export Formated + Export Formatted ); diff --git a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx index 54d9bcbae3..2497b0af16 100644 --- a/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/dashboards/inventory/inventory.tsx @@ -288,7 +288,7 @@ const InventoryVulsComponent = () => { className='euiDataGrid__controlBtn' onClick={onClickExportResults} > - Export Formated + Export Formatted ),