Skip to content

Commit

Permalink
Remove tags filter
Browse files Browse the repository at this point in the history
  • Loading branch information
e40pud committed Nov 22, 2024
1 parent 04ea3d0 commit c68b368
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* 2.0.
*/

import { EuiFilterGroup, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { isEqual } from 'lodash/fp';
import { EuiFlexGroup } from '@elastic/eui';
import type { Dispatch, SetStateAction } from 'react';
import React, { useCallback } from 'react';
import styled from 'styled-components';
import * as i18n from './translations';
import { TagsFilterPopover } from '../../../../detection_engine/rule_management_ui/components/rules_table/rules_table_filters/tags_filter_popover';
import { RuleSearchField } from '../../../../detection_engine/rule_management_ui/components/rules_table/rules_table_filters/rule_search_field';
import type { TableFilterOptions } from '../../hooks/use_filter_rules_to_install';

Expand All @@ -25,11 +23,6 @@ export interface FiltersComponentProps {
*/
filterOptions: TableFilterOptions;

/**
* All unique tags for all rule translations
*/
tags: string[];

/**
* Handles filter options changes
*/
Expand All @@ -40,13 +33,7 @@ export interface FiltersComponentProps {
* Collection of filters for filtering data within the SIEM Rules Migrations table.
* Contains search bar and tag selection
*/
const FiltersComponent: React.FC<FiltersComponentProps> = ({
filterOptions,
tags,
setFilterOptions,
}) => {
const { tags: selectedTags } = filterOptions;

const FiltersComponent: React.FC<FiltersComponentProps> = ({ filterOptions, setFilterOptions }) => {
const handleOnSearch = useCallback(
(filterString: string) => {
setFilterOptions((filters) => ({
Expand All @@ -57,35 +44,13 @@ const FiltersComponent: React.FC<FiltersComponentProps> = ({
[setFilterOptions]
);

const handleSelectedTags = useCallback(
(newTags: string[]) => {
if (!isEqual(newTags, selectedTags)) {
setFilterOptions((filters) => ({
...filters,
tags: newTags,
}));
}
},
[selectedTags, setFilterOptions]
);

return (
<FilterWrapper gutterSize="m" justifyContent="flexEnd" wrap>
<RuleSearchField
initialValue={filterOptions.filter}
onSearch={handleOnSearch}
placeholder={i18n.SEARCH_PLACEHOLDER}
/>
<EuiFlexItem grow={false}>
<EuiFilterGroup>
<TagsFilterPopover
onSelectedTagsChanged={handleSelectedTags}
selectedTags={selectedTags}
tags={tags}
data-test-subj="allRulesTagPopover"
/>
</EuiFilterGroup>
</EuiFlexItem>
</FilterWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import React, { useMemo, useState } from 'react';
import React, { useState } from 'react';

import type { RuleMigration } from '../../../../../common/siem_migrations/model/rule_migration.gen';
import {
Expand Down Expand Up @@ -55,16 +55,13 @@ const RulesTableComponent: React.FC<RulesTableComponentProps> = ({

const [filterOptions, setFilterOptions] = useState<TableFilterOptions>({
filter: '',
tags: [],
});

const filteredRuleMigrations = useFilterRulesToInstall({
filterOptions,
ruleMigrations: ruleMigrations ?? [],
});

const tags = useMemo<string[]>(() => [], []);

const shouldShowProgress = isLoading;

const rulesColumns = useRulesTableColumns({
Expand Down Expand Up @@ -96,11 +93,7 @@ const RulesTableComponent: React.FC<RulesTableComponentProps> = ({
<>
<EuiFlexGroup direction="column">
<EuiFlexItem grow={false}>
<Filters
filterOptions={filterOptions}
tags={tags}
setFilterOptions={setFilterOptions}
/>
<Filters filterOptions={filterOptions} setFilterOptions={setFilterOptions} />
</EuiFlexItem>
</EuiFlexGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useMemo } from 'react';
import type { RuleMigration } from '../../../../common/siem_migrations/model/rule_migration.gen';
import type { FilterOptions } from '../../../detection_engine/rule_management/logic/types';

export type TableFilterOptions = Pick<FilterOptions, 'filter' | 'tags'>;
export type TableFilterOptions = Pick<FilterOptions, 'filter'>;

export const useFilterRulesToInstall = ({
ruleMigrations,
Expand All @@ -19,18 +19,12 @@ export const useFilterRulesToInstall = ({
filterOptions: TableFilterOptions;
}) => {
const filteredRules = useMemo(() => {
const { filter, tags } = filterOptions;
const { filter } = filterOptions;
return ruleMigrations.filter((migration) => {
const name = migration.elastic_rule?.title ?? migration.original_rule.title;
if (filter && !name.toLowerCase().includes(filter.toLowerCase())) {
return false;
}

if (tags && tags.length > 0) {
// TODO: Uncomment this once tags are available for rule migrations
// return tags.every((tag) => migration.tags.includes(tag));
}

return true;
});
}, [filterOptions, ruleMigrations]);
Expand Down

0 comments on commit c68b368

Please sign in to comment.