From 1fb049c62e80925153088ed2d00dcb433c31206b Mon Sep 17 00:00:00 2001 From: Mike Turley Date: Thu, 12 Oct 2023 15:36:33 -0400 Subject: [PATCH] Revert "Attempting to improve disallowing irrelevant args, not working out" This reverts commit 9b0f43efee689ee127bd21f2e3c927510deb8983. --- .../filtering/getFilterProps.ts | 40 +++++++------------ .../filtering/getLocalFilterDerivedState.ts | 36 +++++------------ .../getLocalTableControlDerivedState.ts | 4 +- .../applications-table-analyze.tsx | 4 +- 4 files changed, 28 insertions(+), 56 deletions(-) diff --git a/client/src/app/hooks/table-controls/filtering/getFilterProps.ts b/client/src/app/hooks/table-controls/filtering/getFilterProps.ts index 21e6acf928..6eb3d65f58 100644 --- a/client/src/app/hooks/table-controls/filtering/getFilterProps.ts +++ b/client/src/app/hooks/table-controls/filtering/getFilterProps.ts @@ -4,31 +4,19 @@ import { } from "@app/components/FilterToolbar"; import { IFilterState } from "./useFilterState"; -export type IFilterPropsEnabledArgs< - TItem, - TFilterCategoryKey extends string, -> = { - filterCategories: FilterCategory[]; -}; - -export type IFilterPropsArgs = { +export interface IFilterPropsArgs { filterState: IFilterState; -} & ( - | ({ isFilterEnabled: true } & IFilterPropsEnabledArgs< - TItem, - TFilterCategoryKey - >) - | { isFilterEnabled?: false } -); + filterCategories?: FilterCategory[]; +} -export const getFilterProps = ( - args: IFilterPropsArgs -): IFilterToolbarProps => { - const { isFilterEnabled } = args; - return { - filterCategories: (isFilterEnabled && args.filterCategories) || [], - filterValues: (isFilterEnabled && args.filterState.filterValues) || {}, - setFilterValues: - (isFilterEnabled && args.filterState.setFilterValues) || (() => {}), - }; -}; +export const getFilterProps = ({ + filterState: { filterValues, setFilterValues }, + filterCategories = [], +}: IFilterPropsArgs): IFilterToolbarProps< + TItem, + TFilterCategoryKey +> => ({ + filterCategories, + filterValues, + setFilterValues, +}); diff --git a/client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts b/client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts index aa98aef5ca..cb5a7e9e09 100644 --- a/client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts +++ b/client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts @@ -5,38 +5,24 @@ import { import { objectKeys } from "@app/utils/utils"; import { IFilterState } from "./useFilterState"; -export type ILocalFilterDerivedStateEnabledArgs< +export interface ILocalFilterDerivedStateArgs< TItem, TFilterCategoryKey extends string, -> = { +> { items: TItem[]; - filterCategories: FilterCategory[]; -}; - -export type ILocalFilterDerivedStateArgs< - TItem, - TFilterCategoryKey extends string, -> = - | ({ isFilterEnabled: true } & ILocalFilterDerivedStateEnabledArgs< - TItem, - TFilterCategoryKey - >) - | { isFilterEnabled?: false }; + filterCategories?: FilterCategory[]; +} export const getLocalFilterDerivedState = < TItem, TFilterCategoryKey extends string, ->( - args: ILocalFilterDerivedStateArgs & { - filterState: IFilterState; - } -) => { - const { - isFilterEnabled, - filterState: { filterValues }, - } = args; - const items = (isFilterEnabled && args.items) || []; - const filterCategories = (isFilterEnabled && args.filterCategories) || []; +>({ + items, + filterCategories = [], + filterState: { filterValues }, +}: ILocalFilterDerivedStateArgs & { + filterState: IFilterState; +}) => { const filteredItems = items.filter((item) => objectKeys(filterValues).every((categoryKey) => { const values = filterValues[categoryKey]; diff --git a/client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts b/client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts index 4e196effc8..b7a4d256fa 100644 --- a/client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts +++ b/client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts @@ -28,10 +28,10 @@ export const getLocalTableControlDerivedState = < TFilterCategoryKey > ): ITableControlDerivedState => { - const { items, isPaginationEnabled, isFilterEnabled } = args; + const { items, isPaginationEnabled = true } = args; const { filteredItems } = getLocalFilterDerivedState({ ...args, - ...(isFilterEnabled ? { items } : {}), + items, }); const { sortedItems } = getLocalSortDerivedState({ ...args, diff --git a/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx b/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx index bf30575227..9db1edbe8c 100644 --- a/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx +++ b/client/src/app/pages/applications/applications-table-analyze/applications-table-analyze.tsx @@ -196,8 +196,6 @@ export const ApplicationsTableAnalyze: React.FC = () => { analysis: "Analysis", tags: "Tags", }, - isSortEnabled: true, - isSelectionEnabled: true, sortableColumns: ["name", "description", "businessService", "tags"], initialSort: { columnKey: "name", direction: "asc" }, getSortValues: (app) => ({ @@ -206,7 +204,6 @@ export const ApplicationsTableAnalyze: React.FC = () => { businessService: app.businessService?.name || "", tags: app.tags?.length || 0, }), - // TODO why is there no error for including filterCategories when isFilterEnabled isn't true? filterCategories: [ { key: "name", @@ -327,6 +324,7 @@ export const ApplicationsTableAnalyze: React.FC = () => { ], initialItemsPerPage: 10, hasActionsColumn: true, + isSelectionEnabled: true, }); const {