Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc #1497

Merged
merged 8 commits into from
Nov 30, 2023
Merged

Rc #1497

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
7 changes: 5 additions & 2 deletions src/sources/ProjectSourceFirebase/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { getAuth, connectAuthEmulator } from "firebase/auth";
import {
initializeFirestore,
connectFirestoreEmulator,
enableMultiTabIndexedDbPersistence,
persistentLocalCache,
persistentMultipleTabManager,
} from "firebase/firestore";
import { getStorage, connectStorageEmulator } from "firebase/storage";
import { getFunctions } from "firebase/functions";
Expand Down Expand Up @@ -59,10 +60,12 @@ export const firebaseAuthAtom = atom((get) => {
export const firebaseDbAtom = atom((get) => {
const db = initializeFirestore(get(firebaseAppAtom), {
ignoreUndefinedProperties: true,
localCache: persistentLocalCache({
tabManager: persistentMultipleTabManager(),
}),
});
if (!(window as any).firebaseDbStarted) {
if (envConnectEmulators) connectFirestoreEmulator(db, "localhost", 9299);
else enableMultiTabIndexedDbPersistence(db);
(window as any).firebaseDbStarted = true;
}
return db;
Expand Down