From db9faa2f4bf964226824344f20ef6f9b77caffa4 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Mon, 30 Sep 2024 09:43:23 +0200 Subject: [PATCH] chore: WIP --- components/filters/FilterControls.tsx | 44 +++++++++++-------- components/filters/filters.ts | 13 ++++++ components/filters/index.ts | 1 + .../providers/table/data-table-provider.tsx | 13 ------ .../ui/custom/custom-dropdown-filter.tsx | 17 ++++--- 5 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 components/filters/filters.ts diff --git a/components/filters/FilterControls.tsx b/components/filters/FilterControls.tsx index fca3669405..b2aabdb337 100644 --- a/components/filters/FilterControls.tsx +++ b/components/filters/FilterControls.tsx @@ -4,6 +4,7 @@ import { useRouter, useSearchParams } from "next/navigation"; import React, { useCallback, useEffect, useState } from "react"; import { CrossIcon } from "../icons"; +import { DataTableFilterCustom } from "../providers/table"; import { CustomButton } from "../ui/custom"; import { CustomAccountSelection } from "./CustomAccountSelection"; import { CustomCheckboxMutedFindings } from "./CustomCheckboxMutedFindings"; @@ -19,6 +20,7 @@ interface FilterControlsProps { regions?: boolean; accounts?: boolean; mutedFindings?: boolean; + customFilters?: { key: string; values: string[] }[]; } export const FilterControls: React.FC = ({ @@ -28,6 +30,7 @@ export const FilterControls: React.FC = ({ regions = false, accounts = false, mutedFindings = false, + customFilters = [], }) => { const router = useRouter(); const searchParams = useSearchParams(); @@ -51,26 +54,29 @@ export const FilterControls: React.FC = ({ }, [router, searchParams]); return ( -
- {search && } - {providers && } - {date && } - {regions && } - {accounts && } - {mutedFindings && } +
+
+ {search && } + {providers && } + {date && } + {regions && } + {accounts && } + {mutedFindings && } - {showClearButton && ( - } - radius="sm" - > - Reset - - )} + {showClearButton && ( + } + radius="sm" + > + Reset + + )} +
+
); }; diff --git a/components/filters/filters.ts b/components/filters/filters.ts new file mode 100644 index 0000000000..22dddaf082 --- /dev/null +++ b/components/filters/filters.ts @@ -0,0 +1,13 @@ +export const filtersProviders = [ + { + key: "provider", + labelCheckboxGroup: "Provider", + values: ["aws", "gcp", "azure"], + }, + { + key: "connected", + labelCheckboxGroup: "Status provider", + values: ["false", "true"], + }, + // Add more filter categories as needed +]; diff --git a/components/filters/index.ts b/components/filters/index.ts index 7b437a7a63..f78eee1f34 100644 --- a/components/filters/index.ts +++ b/components/filters/index.ts @@ -5,3 +5,4 @@ export * from "../filters/CustomProviderInputs"; export * from "../filters/CustomRegionSelection"; export * from "../filters/CustomSelectProvider"; export * from "../filters/FilterControls"; +export * from "../filters/filters"; diff --git a/components/providers/table/data-table-provider.tsx b/components/providers/table/data-table-provider.tsx index 9b59765ee8..b2a0655779 100644 --- a/components/providers/table/data-table-provider.tsx +++ b/components/providers/table/data-table-provider.tsx @@ -23,7 +23,6 @@ import { } from "@/components/ui/table"; import { MetaDataProps } from "@/types"; -import { DataTableFilterCustom } from "./data-table-filter-custom"; import { DataTablePagination } from "./data-table-pagination"; interface DataTableProviderProps { @@ -55,20 +54,8 @@ export function DataTableProvider({ }, }); - // This will be used to have "custom" filters in the table and will be - // passed to the DataTableFilterCustom component. This needs to be dynamic - // based on the columns that are available in the table. - - const filters = [ - { key: "provider", values: ["aws", "gcp", "azure"] }, - { key: "connected", values: ["false", "true"] }, - // Add more filter categories as needed - ]; - return ( <> - -
diff --git a/components/ui/custom/custom-dropdown-filter.tsx b/components/ui/custom/custom-dropdown-filter.tsx index e901bd2725..972ed5b4b6 100644 --- a/components/ui/custom/custom-dropdown-filter.tsx +++ b/components/ui/custom/custom-dropdown-filter.tsx @@ -20,10 +20,12 @@ interface FilterOption { interface CustomDropdownFilterProps { filter?: FilterOption; + onFilterChange?: (key: string, values: string[]) => void; } export const CustomDropdownFilter: React.FC = ({ filter, + onFilterChange, }) => { // Early return if filter is undefined if (!filter) { @@ -52,8 +54,15 @@ export const CustomDropdownFilter: React.FC = ({ } else { setGroupSelected(newSelection); } + + if (onFilterChange && filter) { + const selectedValues = Array.from(newSelection).filter( + (key) => key !== "all", + ); + onFilterChange(filter.key, selectedValues); + } }, - [allFilterKeys, groupSelected], + [allFilterKeys, groupSelected, onFilterChange, filter], ); const handleSelectAllClick = useCallback(() => { @@ -85,11 +94,7 @@ export const CustomDropdownFilter: React.FC = ({ value={Array.from(groupSelected)} onValueChange={onSelectionChange} > - + Select All {allFilterKeys.map((value) => (