Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter by value to document details fields #7081

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
48b25d7
Refactor filter button actions in DocViewer
guidomodarelli Oct 7, 2024
c9f9a32
Add Doc Viewer styles and import to Doc Viewer component
guidomodarelli Oct 7, 2024
334b845
Refactor cell filter actions to use 'field' instead of 'columnId'
guidomodarelli Oct 7, 2024
3433625
Refactor filtering logic in DocViewer component
guidomodarelli Oct 7, 2024
71f1ba9
Add onFilterHandler to DocViewer component
guidomodarelli Oct 7, 2024
344df6d
Add onFilter handler to various components
guidomodarelli Oct 7, 2024
bc93d2f
Refactor RequirementFlyout component for readability
guidomodarelli Oct 7, 2024
44db0fc
Add filter functionality to inventory vulnerabilities dashboard
guidomodarelli Oct 8, 2024
6b5a363
Remove unused code related to doc viewer in WazuhDataGrid
guidomodarelli Oct 8, 2024
d6eb863
Add setFilters function to FileDetails and RequirementFlyout
guidomodarelli Oct 8, 2024
7f3f738
Refactor doc-viewer styles for button display
guidomodarelli Oct 8, 2024
a45fb43
Add filter state management to data grid and drilldown panels
guidomodarelli Oct 8, 2024
64dfcd1
Fix Prettier issue
guidomodarelli Oct 8, 2024
0b92f0b
Add filter by value to document details fields
guidomodarelli Oct 8, 2024
72cead5
Update defaultColumns to defaultTableColumns in WazuhDataGrid
guidomodarelli Oct 8, 2024
92787ce
Add filter functionality for document viewer
guidomodarelli Oct 8, 2024
119332c
Swap the order of arguments in filter action test
guidomodarelli Oct 8, 2024
9612879
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 10, 2024
c20b626
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 14, 2024
daf4529
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 14, 2024
3d563be
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 17, 2024
84cb708
Rename button icons to EuiButtonIcon component
guidomodarelli Oct 17, 2024
8b2bffc
Update component import paths and class names
guidomodarelli Oct 17, 2024
13bd581
Update doc-viewer styles for wzDocViewer classes
guidomodarelli Oct 17, 2024
81862f9
Refactor adding filters to handle array values efficiently
guidomodarelli Oct 17, 2024
f7871be
Add onClose callback to onFilter function in DocViewer
guidomodarelli Oct 17, 2024
8364cc1
Refactor DocumentViewTableAndJson component props
guidomodarelli Oct 17, 2024
d09836a
Refactor technique row details component props type
guidomodarelli Oct 17, 2024
0ee73ff
Add setFilters function to TechniqueRowDetails component
guidomodarelli Oct 17, 2024
ce6badc
Refactor closeFlyoutHandler in DashboardTH component
guidomodarelli Oct 17, 2024
cff23c5
Add closeFlyoutHandler function for flyout onClose event
guidomodarelli Oct 17, 2024
da5411a
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 17, 2024
2ddb2d4
Fix Prettier issue
guidomodarelli Oct 17, 2024
2ab5e94
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 18, 2024
9516d55
fix: add guard clause for undefined value in filter cell actions
guidomodarelli Oct 21, 2024
24eedda
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
asteriscos Oct 22, 2024
a1f8e72
feat: add FilterStateStore enum and update state management in Patter…
guidomodarelli Oct 22, 2024
bfad495
fix: update onFilter function to accept more specific FILTER_OPERATOR…
guidomodarelli Oct 22, 2024
ec96ca7
feat: add isNullish utility function and update exports in util index…
guidomodarelli Oct 22, 2024
6d3307f
fix: refactor onFilterCellActions to use isNullish for improved handl…
guidomodarelli Oct 22, 2024
21e1038
fix: refactor onFilterCellActions import path for improved structure …
guidomodarelli Oct 22, 2024
3822411
fix: update onFilterCellActions to accept number type in values for e…
guidomodarelli Oct 22, 2024
2c2de22
test: add unit tests for onFilterCellActions to verify filtering with…
guidomodarelli Oct 22, 2024
70ad2e7
test: simplify onFilterCellActions tests by removing unused filters a…
guidomodarelli Oct 22, 2024
6f00f93
test: enhance onFilterCellActions tests by clarifying filter addition…
guidomodarelli Oct 22, 2024
30ed18a
test: refactor buildFilter usage in onFilterCellActions tests for imp…
guidomodarelli Oct 22, 2024
5e639ab
test: improve onFilterCellActions tests with clearer descriptions for…
guidomodarelli Oct 22, 2024
fe06973
test: add tests for single filter actions with string values and 'is'…
guidomodarelli Oct 22, 2024
3e7555d
test: add tests for multiple filters with 'is' and 'is not' operators…
guidomodarelli Oct 22, 2024
17c0db5
test: add test for onFilterCellActions with undefined value to ensure…
guidomodarelli Oct 22, 2024
5c0ea1c
test: update filter negate logic and add test for 'is not' operator w…
guidomodarelli Oct 22, 2024
d1757f2
Fix Prettier issue
guidomodarelli Oct 22, 2024
741029b
test: refactor filter creation logic in onFilterCellActions tests for…
guidomodarelli Oct 22, 2024
638da8d
test: unify key usage in filter tests in onFilterCellActions for clea…
guidomodarelli Oct 22, 2024
48205ed
test: add filter logic tests for boolean values in onFilterCellAction…
guidomodarelli Oct 22, 2024
4233592
test: update filter tests in onFilterCellActions to clarify handling …
guidomodarelli Oct 22, 2024
e88e502
test: improve clarity in filter cell action tests by specifying value…
guidomodarelli Oct 22, 2024
fd9a9e8
test: refine value type definition in onFilterCellActions to enhance …
guidomodarelli Oct 22, 2024
1e54b41
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 24, 2024
d4fe110
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
asteriscos Oct 24, 2024
9954031
Refactor drilldown components to simplify destructuring of props, rem…
guidomodarelli Oct 25, 2024
ad190ba
Remove unused `filters` and `setFilters` props from OfficePanel for c…
guidomodarelli Oct 25, 2024
53a2ca5
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 25, 2024
4d96145
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
guidomodarelli Oct 28, 2024
b28fd9d
Fix typos in export button label across data grid components
guidomodarelli Oct 28, 2024
c6fb420
Merge branch '4.10.0' into enhancement/7080-add-filter-by-value-to-do…
asteriscos Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!: {
Expand Down Expand Up @@ -586,6 +587,8 @@ export class FileDetails extends Component {

this.discoverFilterManager.addFilters(newFilter);
}}
filters={[]}
setFilters={setFilters(this.discoverFilterManager)}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -102,8 +102,8 @@ describe('cell-filter-actions', () => {
expect(onFilter).toHaveBeenCalledTimes(1);
expect(onFilter).toHaveBeenCalledWith(
TEST_COLUMN_ID,
TEST_VALUE,
'is not',
TEST_VALUE,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ 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', {
defaultMessage: 'Filter for value',
});
const filterForValueLabel = i18n.translate('discover.filterForValueLabel', {
defaultMessage: 'Filter for value: {value}',
values: { value: columnId },
values: { value: field },
});

const handleClick = () => {
const row = rows[rowIndex % pageSize];
const flattened = indexPattern.flattenHit(row);

if (flattened) {
onFilter(columnId, flattened[columnId], FILTER_OPERATOR.IS);
onFilter(field, FILTER_OPERATOR.IS, flattened[field]);
}
};

Expand All @@ -61,26 +61,30 @@ 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 = () => {
const row = rows[rowIndex % pageSize];
const flattened = indexPattern.flattenHit(row);

if (flattened) {
onFilter(columnId, flattened[columnId], FILTER_OPERATOR.IS_NOT);
onFilter(field, FILTER_OPERATOR.IS_NOT, flattened[field]);
}
};

Expand All @@ -103,9 +107,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,15 @@ 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 (field: string, operation: FILTER_OPERATOR, value?: any) => {
const newFilter = PatternDataSourceFilterManager.createFilter(
operation,
columndId,
field,
value,
indexPatternId,
);
Expand Down
79 changes: 79 additions & 0 deletions plugins/main/public/components/common/doc-viewer/doc-viewer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
.osdDocViewerTable {
guidomodarelli marked this conversation as resolved.
Show resolved Hide resolved
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 {
position: relative;
}

tr:first-child td {
border-top-color: transparent;
}

tr:hover {
.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(1px);

.osdDocViewer__actionButton {
opacity: 1;
}
}
}
}

.osdDocViewer__buttons,
.osdDocViewer__field {
white-space: nowrap;
}

.osdDocViewer__buttons {
display: none;
}

.osdDocViewer__field {
width: 160px;
}

.osdDocViewer__actionButton {
opacity: 0;

&:hover {
opacity: 1;
}
}

.osdDocViewer__warning {
margin-right: $euiSizeS;
}
59 changes: 57 additions & 2 deletions plugins/main/public/components/common/doc-viewer/doc-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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 { 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';
import { onFilterCellActions } from '../data-grid';
import { Filter } from '../../../../../../src/plugins/data/common';

const COLLAPSE_LINE_LENGTH = 350;
const DOT_PREFIX_RE = /(.).+?\./g;
Expand All @@ -15,6 +22,8 @@ export type tDocViewerProps = {
mapping: any;
indexPattern: any;
docJSON: any;
filters: Filter[];
setFilters: (filters: Filter[]) => void;
};

/**
Expand Down Expand Up @@ -82,8 +91,25 @@ const DocViewer = (props: tDocViewerProps) => {
const [fieldRowOpen, setFieldRowOpen] = useState(
{} as Record<string, boolean>,
);
const { flattened, formatted, mapping, indexPattern, renderFields, docJSON } =
props;
const {
flattened,
formatted,
mapping,
indexPattern,
renderFields,
docJSON,
filters,
setFilters,
} = props;

const onFilter = (field: string, operation: FILTER_OPERATOR, value?: any) => {
const _onFilter = onFilterCellActions(
indexPattern?.id,
filters,
setFilters,
);
_onFilter(field, operation, value);
};

return (
<>
Expand Down Expand Up @@ -147,6 +173,35 @@ const DocViewer = (props: tDocViewerProps) => {
</EuiFlexGroup>
</td>
<td>
<div className='osdDocViewer__buttons'>
<DocViewTableRowBtnFilterAdd
disabled={!fieldMapping || !fieldMapping.filterable}
onClick={() =>
onFilter(
field,
FILTER_OPERATOR.IS,
flattened[field],
)
}
/>
<DocViewTableRowBtnFilterRemove
disabled={!fieldMapping || !fieldMapping.filterable}
onClick={() =>
onFilter(
field,
FILTER_OPERATOR.IS_NOT,
flattened[field],
)
}
/>
<DocViewTableRowBtnFilterExists
disabled={!fieldMapping || !fieldMapping.filterable}
onClick={() =>
onFilter(field, FILTER_OPERATOR.EXISTS)
}
scripted={fieldMapping && fieldMapping.scripted}
/>
</div>
{renderFields &&
renderFields?.find(
(field: string) => field?.id === displayName,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 DocViewTableRowBtnFilterAdd({
onClick,
disabled = false,
}: Props) {
const tooltipContent = disabled ? (
<FormattedMessage
id='discover.docViews.table.unindexedFieldsCanNotBeSearchedTooltip'
defaultMessage='Unindexed fields can not be searched'
/>
) : (
<FormattedMessage
id='discover.docViews.table.filterForValueButtonTooltip'
defaultMessage='Filter for value'
/>
);

return (
<EuiToolTip content={tooltipContent}>
<EuiSmallButtonIcon
aria-label={i18n.translate(
'discover.docViews.table.filterForValueButtonAriaLabel',
{
defaultMessage: 'Filter for value',
},
)}
className='osdDocViewer__actionButton'
data-test-subj='addInclusiveFilterButton'
disabled={disabled}
onClick={onClick}
iconType={'magnifyWithPlus'}
iconSize={'s'}
/>
</EuiToolTip>
);
}
Loading
Loading