Skip to content

Commit

Permalink
filter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
armintalaie committed Sep 3, 2024
1 parent 9701735 commit 3c928a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/app/portal/admin/forms/[id]/submissions/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,30 @@ export function createColumns<TData>(
}

if (field.type === "select") {
console.log(filterValue);
if (!field.options) {
return row.original[key]
.toString()
.toLowerCase()
.includes(filterValue.toLowerCase());
}

const matchCriteria = field.options?.filter(
(op) =>
filterValue.includes(op.label) || filterValue.includes(op.id),
const matchCriteria = field.options?.filter((op) =>
filterValue.includes(op.id),
);
return (
matchCriteria?.filter((op) =>
row.original[key]
matchCriteria?.filter((op) => {
if (
row.original[key] === null ||
row.original[key] === undefined
) {
return false;
}
return row.original[key]
.toString()
.toLowerCase()
.includes(op.label.toLowerCase()),
).length > 0
.includes(op.id.toLowerCase());
}).length > 0
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/app/portal/admin/forms/[id]/submissions/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function TableFilter({
left-0 top-0
"
>
<div className="flex flex-col items-center p-4 w-full justify-between gap-2 pb-2 px-4 max-w-2xl rounded border border-background-600 bg-background-700 pointer-events-auto shadow-lg">
<div className="flex flex-col max-h-screen overflow-y-scroll items-center p-4 w-full justify-between gap-2 pb-2 px-4 max-w-2xl rounded border border-background-600 bg-background-700 pointer-events-auto shadow-lg">
<h3 className="text-lg w-full text-left pb-4 font-semibold">
Filters
</h3>
Expand Down Expand Up @@ -365,8 +365,10 @@ function ColumnFilterInput<TData>({
<MultiSelect
allowMultiple={false}
options={options}
value={value}
onChange={(e) => setValue(e ? e[0] : "")}
value={[value]}
onChange={(e) => {
setValue(e ? e[0] : "");
}}
onBlur={() => {
updateColumnFilter([{ id: column.id, value }]);
}}
Expand Down
4 changes: 3 additions & 1 deletion src/components/general/multiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ export default function MultiSelect({
type="button"
>
<span className="text-white justify-center flex z-1 items-center gap-2 ">
{/*{JSON.stringify(selectedOptions)}*/}
{/*{JSON.stringify(value)}*/}
{selectedOptions !== [null] &&
selectedOptions.map((option) => (
<span
key={option.label}
key={option.value}
className="p-0.5 px-2 z-1! rounded bg-lp-500"
>
{option.label}
Expand Down

0 comments on commit 3c928a2

Please sign in to comment.