-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(filters): implement multi select filters
- Loading branch information
1 parent
fadaaf0
commit 2726e33
Showing
17 changed files
with
200 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,85 @@ | ||
import { IColumnFilterBag } from "shared/types/data"; | ||
import { msg } from "@lingui/macro"; | ||
import { useDebounce, useSessionStorage } from "react-use"; | ||
import { useState } from "react"; | ||
import { IFilterProps } from "./types"; | ||
// import { AsyncFormMultiSelect } from "@/frontend/design-system/components/Form/Select/Async"; | ||
import { MultiFilterValues } from "./_MultiFilterValues"; | ||
import { Select } from "@/components/ui/select"; | ||
import { ILabelValue } from "@/shared/types/options"; | ||
import { useApi } from "@/frontend/lib/data/useApi"; | ||
import { sluggify } from "@/shared/lib/strings"; | ||
import { transformLabelValueToSelectData } from "@/translations/fake"; | ||
|
||
export function FilterTableByListSelection({ | ||
column: { filterValue, setFilter }, | ||
bag, | ||
bag: url, | ||
}: IFilterProps<IColumnFilterBag<string[]>, string>) { | ||
const values = filterValue?.value || []; | ||
|
||
const [cosmeticValues, setCosmeticValues] = useSessionStorage<ILabelValue[]>( | ||
`cosmetic-multi-select-values-${sluggify(url)}`, | ||
[] | ||
); | ||
|
||
const [search, setSearch] = useState(""); | ||
|
||
const [debounceSearch, setDebounceSearch] = useState(""); | ||
|
||
const selectOptions = useApi<ILabelValue[]>( | ||
debounceSearch ? `${url}?search=${debounceSearch}` : url, | ||
{ | ||
defaultData: [], | ||
} | ||
); | ||
|
||
const appendCosmeticValues = (value: string) => { | ||
setCosmeticValues([ | ||
...cosmeticValues, | ||
{ | ||
value, | ||
label: | ||
selectOptions.data.find( | ||
(option) => String(option.value) === String(value) | ||
)?.label || value, | ||
}, | ||
]); | ||
}; | ||
|
||
useDebounce( | ||
() => { | ||
setDebounceSearch(search); | ||
}, | ||
700, | ||
[search] | ||
); | ||
|
||
return ( | ||
<div className="min-w-64"> | ||
<div>TODO</div> | ||
{/* <AsyncFormMultiSelect | ||
url={bag} | ||
values={filterValue?.value || []} | ||
<div> | ||
<MultiFilterValues | ||
filterValue={filterValue} | ||
setFilter={setFilter} | ||
values={values} | ||
options={cosmeticValues} | ||
/> | ||
<Select | ||
onChange={(value) => { | ||
appendCosmeticValues(value); | ||
setFilter({ | ||
...filterValue, | ||
value, | ||
value: [...new Set([...values, value])], | ||
}); | ||
}} | ||
/> */} | ||
name="select-filter" | ||
value="" | ||
options={transformLabelValueToSelectData(selectOptions.data)} | ||
onSearch={{ | ||
isLoading: selectOptions.isLoading, | ||
onChange: setSearch, | ||
value: search, | ||
}} | ||
disabledOptions={values} | ||
placeholder={msg`Select Option`} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
import { IColumnFilterBag } from "shared/types/data"; | ||
import { ISelectData } from "shared/types/options"; | ||
import { msg } from "@lingui/macro"; | ||
import { useLingui } from "@lingui/react"; | ||
import { IFilterProps } from "./types"; | ||
// import { FormMultiSelect } from "@/frontend/design-system/components/Form/Select"; | ||
import { Select } from "@/components/ui/select"; | ||
import { MultiFilterValues } from "./_MultiFilterValues"; | ||
|
||
export function FilterTableByStatus({ | ||
column: { filterValue, setFilter }, | ||
bag, | ||
}: IFilterProps<IColumnFilterBag<string[]>, ISelectData[]>) { | ||
const values = filterValue?.value || []; | ||
const { _ } = useLingui(); | ||
return ( | ||
<div className="min-w-64"> | ||
<div>TODO</div> | ||
{/* <FormMultiSelect | ||
selectData={bag} | ||
values={filterValue?.value || []} | ||
ariaLabel="Select Status" | ||
<div> | ||
<MultiFilterValues | ||
filterValue={filterValue} | ||
setFilter={setFilter} | ||
values={values} | ||
options={bag.map(({ label, value }) => ({ | ||
value: String(value), | ||
label: _(label), | ||
}))} | ||
/> | ||
<Select | ||
onChange={(value) => { | ||
setFilter({ | ||
...filterValue, | ||
value, | ||
value: [...new Set([...values, value])], | ||
}); | ||
}} | ||
/> */} | ||
name="select-filter" | ||
value="" | ||
options={bag} | ||
disabledOptions={values} | ||
placeholder={msg`Select Option`} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { X } from "react-feather"; | ||
import { Button, buttonVariants } from "@/components/ui/button"; | ||
import { cn } from "@/lib/utils"; | ||
import { IColumnFilterBag } from "@/shared/types/data"; | ||
|
||
interface IProps { | ||
values: string[]; | ||
filterValue: IColumnFilterBag<string[]>; | ||
setFilter: (value: IColumnFilterBag<string[]>) => void; | ||
options: { value: string; label: string }[]; | ||
} | ||
|
||
export function MultiFilterValues({ | ||
values, | ||
filterValue, | ||
setFilter, | ||
options, | ||
}: IProps) { | ||
return ( | ||
<> | ||
{values.map((value) => { | ||
const label = options.find( | ||
(option) => String(option.value) === String(value) | ||
)?.label; | ||
return ( | ||
<div key={value} className="inline-flex mb-1 mr-1"> | ||
<div | ||
className={cn( | ||
buttonVariants({ variant: "soft", size: "sm" }), | ||
"rounded-r-none hover:bg-primary-alpha hover:text-primary-alpha-text" | ||
)} | ||
> | ||
{label || value} | ||
</div> | ||
<Button | ||
className="rounded-l-none px-1" | ||
size="sm" | ||
variant="destructive" | ||
onClick={() => { | ||
setFilter({ | ||
...filterValue, | ||
value: values.filter((option) => option !== value), | ||
}); | ||
}} | ||
> | ||
<X size={14} /> | ||
</Button> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.