Skip to content

Commit

Permalink
Merge pull request #1482 from Wr4th100/wrath100/subtable-refresh-bug
Browse files Browse the repository at this point in the history
fix: subtable filters refresh bug
  • Loading branch information
il3ven authored Nov 28, 2023
2 parents 80b2f0f + a12fb3e commit c6e64f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/components/TableToolbar/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { analytics, logEvent } from "@src/analytics";
import type { TableFilter } from "@src/types/table";
import { generateId } from "@src/utils/table";
import { useFilterUrl } from "./useFilterUrl";
import { isEqual } from "lodash-es";

const shouldDisableApplyButton = (queries: any) => {
for (let query of queries) {
Expand Down Expand Up @@ -255,10 +256,7 @@ export default function Filters() {
// If the filter in URL is not the same as currently applied local filter
// then update the user filter.
useEffect(() => {
if (
filtersUrl &&
JSON.stringify(filtersUrl) !== JSON.stringify(appliedFilters)
) {
if (filtersUrl && !isEqual(filtersUrl, appliedFilters)) {
setUserFilters(filtersUrl);
setOverrideTableFilters(true);
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/TableToolbar/Filters/useFilterUrl.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { tableFiltersAtom, tableScope } from "@src/atoms/tableScope";
import { TableFilter } from "@src/types/table";
import { useAtom } from "jotai";
import { isEqual } from "lodash-es";
import { useSnackbar } from "notistack";
import { useEffect, useState } from "react";
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";

function isTableFilter(filter: any): filter is TableFilter {
Expand All @@ -16,7 +19,7 @@ function isTableFilter(filter: any): filter is TableFilter {
export function useFilterUrl() {
const [searchParams, setSearchParams] = useSearchParams();
const { enqueueSnackbar } = useSnackbar();
const [filters, setFilters] = useState<TableFilter[] | null>(null);
const [filters, setFilters] = useAtom(tableFiltersAtom, tableScope);

// Fetch filter from URL and update user filter
useEffect(() => {
Expand All @@ -32,8 +35,7 @@ export function useFilterUrl() {
for (const _filter of _filters) {
if (!isTableFilter(_filter)) throw new Error("Invalid Filter");
}

setFilters(_filters);
if (!isEqual(_filters, filters)) setFilters(_filters);
} catch (err) {
enqueueSnackbar("Oops, filter in URL is incorrect!!!", {
variant: "error",
Expand Down

0 comments on commit c6e64f8

Please sign in to comment.