From c915c167da2e8c07cee678b86212de50e2fd7987 Mon Sep 17 00:00:00 2001 From: Julian Gernun <17549662+jcger@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:17:04 +0100 Subject: [PATCH] added onDelete prop on filters --- .../all_cases/table_filter_config/types.ts | 1 + .../use_custom_fields_filter_config.tsx | 7 +++ .../table_filter_config/use_filter_config.tsx | 14 +++++- .../use_system_filter_config.tsx | 22 ++++++++- .../components/all_cases/table_filters.tsx | 48 +++++++++---------- 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/types.ts b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/types.ts index 67895dc133c8..b814eb64e4f3 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/types.ts +++ b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/types.ts @@ -29,5 +29,6 @@ export interface FilterConfig { label: string; isActive: boolean; isAvailable: boolean; + onDeactivate: (params: { onChange: FilterChangeHandler }) => void; render: (params: FilterConfigRenderParams) => React.ReactNode; } diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_custom_fields_filter_config.tsx b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_custom_fields_filter_config.tsx index 465d7250a3d4..59a294d56750 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_custom_fields_filter_config.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_custom_fields_filter_config.tsx @@ -32,6 +32,13 @@ export const useCustomFieldsFilterConfig = () => { isActive: false, isAvailable: type === CustomFieldTypes.TOGGLE, label: buttonLabel, + onDeactivate: ({ onChange }) => { + onChange({ + filterId: fieldKey, + selectedOptionKeys: [], + customFieldType: type, + }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => { const onCustomFieldChange = ({ filterId, diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_filter_config.tsx b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_filter_config.tsx index f6ea9abed77b..a2a46d55e469 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_filter_config.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_filter_config.tsx @@ -8,7 +8,7 @@ import { useState, useEffect } from 'react'; import useLocalStorage from 'react-use/lib/useLocalStorage'; import { LOCAL_STORAGE_KEYS } from '../../../../common/constants'; -import type { FilterConfig, FilterConfigState } from './types'; +import type { FilterChangeHandler, FilterConfig, FilterConfigState } from './types'; import { useCustomFieldsFilterConfig } from './use_custom_fields_filter_config'; import { MoreFiltersSelectable } from './more_filters_selectable'; import { useCasesContext } from '../../cases_context/use_cases_context'; @@ -31,7 +31,13 @@ const deserializeFilterVisibilityMap = (value: string): Map { +export const useFilterConfig = ({ + systemFilterConfig, + onFilterOptionChange, +}: { + systemFilterConfig: FilterConfig[]; + onFilterOptionChange: FilterChangeHandler; +}) => { const { appId } = useCasesContext(); const { customFieldsFilterConfig } = useCustomFieldsFilterConfig(); const [filters, setFilters] = useState>( @@ -64,6 +70,10 @@ export const useFilterConfig = ({ systemFilterConfig }: { systemFilterConfig: Fi newFilterVisibilityMap.set(key, { key, isActive: true }); } } else { + const filter = filters.get(key); + if (filter) { + filter.onDeactivate({ onChange: onFilterOptionChange }); + } newFilterVisibilityMap.set(key, { key, isActive: false }); } }); diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_system_filter_config.tsx b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_system_filter_config.tsx index 050dc087a95c..a9e0b2760237 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_system_filter_config.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table_filter_config/use_system_filter_config.tsx @@ -17,7 +17,7 @@ import { SeverityFilter } from '../severity_filter'; import { AssigneesFilterPopover } from '../assignees_filter'; import type { CurrentUserProfile } from '../../types'; import type { AssigneesFilteringSelection } from '../../user_profiles/types'; -import type { FilterConfig, FilterConfigRenderParams } from './types'; +import type { FilterChangeHandler, FilterConfig, FilterConfigRenderParams } from './types'; interface UseFilterConfigProps { availableSolutions: string[]; @@ -56,6 +56,9 @@ export const getSystemFilterConfig = ({ label: i18n.SEVERITY, isActive: true, isAvailable: true, + onDeactivate: ({ onChange }: { onChange: FilterChangeHandler }) => { + onChange({ filterId: 'severity', selectedOptionKeys: [] }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => ( ), @@ -65,6 +68,9 @@ export const getSystemFilterConfig = ({ label: i18n.STATUS, isActive: true, isAvailable: true, + onDeactivate: ({ onChange }: { onChange: FilterChangeHandler }) => { + onChange({ filterId: 'status', selectedOptionKeys: [] }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => ( { + onChange({ filterId: 'assignee', selectedOptionKeys: [] }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => { return ( { + onChange({ filterId: 'tags', selectedOptionKeys: [] }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => ( { + onChange({ filterId: 'category', selectedOptionKeys: [] }); + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => ( 1, + onDeactivate: ({ onChange }: { onChange: FilterChangeHandler }) => { + if (availableSolutions.length > 1) { + onChange({ filterId: 'owner', selectedOptionKeys: [] }); + } + }, render: ({ filterOptions, onChange }: FilterConfigRenderParams) => ( { const trimSearch = newSearch.trim();