Skip to content

Commit

Permalink
Revert "Attempting to discriminate args for feature prop helpers"
Browse files Browse the repository at this point in the history
This reverts commit 8f4f4a5.
  • Loading branch information
mturley committed Oct 16, 2023
1 parent 8f4f4a5 commit 9722644
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,24 @@ import {
} from "@app/components/FilterToolbar";
import { objectKeys } from "@app/utils/utils";
import { IFilterState } from "./useFilterState";
import { DiscriminatedArgs } from "@app/utils/type-utils";

export type ILocalFilterDerivedStateArgs<
export interface ILocalFilterDerivedStateArgs<
TItem,
TFilterCategoryKey extends string,
> = DiscriminatedArgs<
"isFilterEnabled",
{
items: TItem[];
filterCategories: FilterCategory<TItem, TFilterCategoryKey>[];
filterState: IFilterState<TFilterCategoryKey>;
}
>;

export type ILocalFilterDerivedState<TItem> = {
filteredItems: TItem[];
};
> {
items: TItem[];
filterCategories?: FilterCategory<TItem, TFilterCategoryKey>[];
filterState: IFilterState<TFilterCategoryKey>;
}

export const getLocalFilterDerivedState = <
TItem,
TFilterCategoryKey extends string,
>(
args: ILocalFilterDerivedStateArgs<TItem, TFilterCategoryKey>
) => {
if (!args.isFilterEnabled) {
return { filteredItems: [] };
}

const {
items,
filterCategories,
filterState: { filterValues },
} = args;

>({
items,
filterCategories = [],
filterState: { filterValues },
}: ILocalFilterDerivedStateArgs<TItem, TFilterCategoryKey>) => {

Check warning on line 24 in client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/getLocalFilterDerivedState.ts#L24

Added line #L24 was not covered by tests
const filteredItems = items.filter((item) =>
objectKeys(filterValues).every((categoryKey) => {
const values = filterValues[categoryKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,39 @@ import {
import { IFilterState } from "./useFilterState";
import { ToolbarProps } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { DiscriminatedArgs } from "@app/utils/type-utils";

// Args that should be passed into useTableControlProps
export type IFilterPropHelpersExternalArgs<
export interface IFilterPropHelpersExternalArgs<
TItem,
TFilterCategoryKey extends string,
> = DiscriminatedArgs<
"isFilterEnabled",
{
filterState: IFilterState<TFilterCategoryKey>;
filterCategories: FilterCategory<TItem, TFilterCategoryKey>[];
}
>;

// TODO fix the confusing naming here... we have FilterToolbar and Toolbar which both have filter-related props
export type IFilterPropHelpers<TItem, TFilterCategoryKey extends string> = {
filterPropsForToolbar: ToolbarProps;
propsForFilterToolbar: IFilterToolbarProps<TItem, TFilterCategoryKey>;
};
> {
filterState: IFilterState<TFilterCategoryKey>;
filterCategories?: FilterCategory<TItem, TFilterCategoryKey>[];
}

export const useFilterPropHelpers = <TItem, TFilterCategoryKey extends string>(
args: IFilterPropHelpersExternalArgs<TItem, TFilterCategoryKey>
): IFilterPropHelpers<TItem, TFilterCategoryKey> => {
) => {
const { t } = useTranslation();

Check warning on line 21 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L20-L21

Added lines #L20 - L21 were not covered by tests

if (!args.isFilterEnabled) {
return {
filterPropsForToolbar: {},
propsForFilterToolbar: {
filterCategories: [],
filterValues: {},
setFilterValues: () => {},
},
};
}

const {
filterState: { filterValues, setFilterValues },
filterCategories = [],
} = args;

Check warning on line 26 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L26

Added line #L26 was not covered by tests

return {
filterPropsForToolbar: {
collapseListedFiltersBreakpoint: "xl",
clearAllFilters: () => setFilterValues({}),
clearFiltersButtonText: t("actions.clearAllFilters"),
},
propsForFilterToolbar: {
const filterPropsForToolbar: ToolbarProps = {

Check warning on line 28 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L28

Added line #L28 was not covered by tests
collapseListedFiltersBreakpoint: "xl",
clearAllFilters: () => setFilterValues({}),

Check warning on line 30 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L30

Added line #L30 was not covered by tests
clearFiltersButtonText: t("actions.clearAllFilters"),
};

const propsForFilterToolbar: IFilterToolbarProps<TItem, TFilterCategoryKey> =
{

Check warning on line 35 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L35

Added line #L35 was not covered by tests
filterCategories,
filterValues,
setFilterValues,
},
};
};

// TODO fix the confusing naming here... we have FilterToolbar and Toolbar which both have filter-related props
return { filterPropsForToolbar, propsForFilterToolbar };

Check warning on line 42 in client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/filtering/useFilterPropHelpers.ts#L42

Added line #L42 was not covered by tests
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getLocalTableControlDerivedState = <
const { items, isPaginationEnabled = true } = args;
const { filteredItems } = getLocalFilterDerivedState({

Check warning on line 32 in client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts#L32

Added line #L32 was not covered by tests
...args,
...(args.isFilterEnabled && { items }),
items,
});
const { sortedItems } = getLocalSortDerivedState({

Check warning on line 36 in client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/hooks/table-controls/getLocalTableControlDerivedState.ts#L36

Added line #L36 was not covered by tests
...args,
Expand Down
1 change: 0 additions & 1 deletion client/src/app/hooks/useLegacyFilterState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const useLegacyFilterState = <TItem, TFilterCategoryKey extends string>(
filterCategories,
});
const { filteredItems } = getLocalFilterDerivedState({
isFilterEnabled: true,
items,
filterCategories,
filterState: { filterValues, setFilterValues },
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/migration-waves/migration-waves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const MigrationWaves: React.FC = () => {
stakeholders: "Stakeholders",
status: "Status",
},
// isFilterEnabled: true,
isFilterEnabled: true,
isSortEnabled: true,
isPaginationEnabled: true,
isExpansionEnabled: true,
Expand Down

0 comments on commit 9722644

Please sign in to comment.