Skip to content

Commit

Permalink
fix: update isFiltered calculation and fix toast not showing in updat…
Browse files Browse the repository at this point in the history
…e view form
  • Loading branch information
nainglinnkhant committed Jul 8, 2024
1 parent fdb3ae6 commit c0ab48d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,11 @@ export function DataTableAdvancedToolbar<TData>({
<CreateViewPopover selectedOptions={selectedOptions} />
)}

{isUpdated && currentView && (
<UpdateViewForm
currentView={currentView}
filterParams={filterParams}
/>
)}
<UpdateViewForm
isUpdated={isUpdated}
currentView={currentView}
filterParams={filterParams}
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import type { FilterParams } from "@/app/_lib/validations"
import type { ViewItem } from "./data-table-views-dropdown"

interface UpdateViewFormProps {
currentView: ViewItem
isUpdated: boolean
currentView: ViewItem | undefined
filterParams: FilterParams
}

export default function UpdateViewForm({
isUpdated,
currentView,
filterParams,
}: UpdateViewFormProps) {
Expand All @@ -39,6 +41,8 @@ export default function UpdateViewForm({
}
}, [state])

if (!isUpdated || !currentView) return

return (
<form action={formAction}>
<input type="hidden" name="id" value={currentView.id} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/data-table/advanced/views/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export function calcFilterParams<T = unknown>(
const filterParams: FilterParams = {
filters: filterItems,
}
if (searchParams.get("operator")) {
filterParams.operator = searchParams.get("operator") as Operator
}
filterParams.operator = (searchParams.get("operator") as Operator) || "and"
if (searchParams.get("sort")) {
filterParams.sort = searchParams.get("sort") as Sort
}
Expand Down Expand Up @@ -79,6 +77,10 @@ export function getIsFiltered(searchParams: ReadonlyURLSearchParams) {
continue
}

if (key === "operator" && value === "and") {
continue
}

if (FILTERABLE_FIELDS.includes(key)) {
filters.push(key)
}
Expand Down

0 comments on commit c0ab48d

Please sign in to comment.