Improve website events query performance and fix activity search persistence
This commit is contained in:
1 parent
b6b500ea4f
commit
079cfdde84
7 files changed
+95
-54
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
type ReactElement,
|
||||
type ReactNode,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
@@ -73,7 +74,6 @@ export function DataGrid({
|
||||
const handleSearch = (value: string) => {
|
||||
if (value !== search) {
|
||||
setSearch(value);
|
||||
router.push(updateParams({ search: value, page: 1 }));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -84,6 +84,24 @@ export function DataGrid({
|
||||
[router, updateParams, search],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setSearch(queryParams?.search || '');
|
||||
}, [queryParams?.search]);
|
||||
|
||||
useEffect(() => {
|
||||
const currentSearch = queryParams?.search || '';
|
||||
|
||||
if (search === currentSearch) {
|
||||
return;
|
||||
}
|
||||
|
||||
const timer = window.setTimeout(() => {
|
||||
router.push(updateParams({ search: search || undefined, page: 1 }));
|
||||
}, searchDelay || DEFAULT_SEARCH_DELAY);
|
||||
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [queryParams?.search, router, search, searchDelay, updateParams]);
|
||||
|
||||
const child = data ? (typeof children === 'function' ? children(data) : children) : null;
|
||||
|
||||
const viewToggleButton = (
|
||||
@@ -106,7 +124,7 @@ export function DataGrid({
|
||||
<SearchField
|
||||
value={search}
|
||||
onSearch={handleSearch}
|
||||
delay={searchDelay || DEFAULT_SEARCH_DELAY}
|
||||
delay={0}
|
||||
autoFocus={autoFocus}
|
||||
placeholder={t(labels.search)}
|
||||
className="w-full max-w-md"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { buildPath } from '@/lib/url';
|
||||
|
||||
export function useNavigation() {
|
||||
@@ -11,7 +11,8 @@ export function useNavigation() {
|
||||
const [, linkId] = pathname.match(/\/links\/([a-f0-9-]+)/) || [];
|
||||
const [, pixelId] = pathname.match(/\/pixels\/([a-f0-9-]+)/) || [];
|
||||
const [, boardId] = pathname.match(/\/boards\/([a-f0-9-]+)/) || [];
|
||||
const [queryParams, setQueryParams] = useState(Object.fromEntries(searchParams));
|
||||
const searchParamsString = searchParams.toString();
|
||||
const queryParams = useMemo(() => Object.fromEntries(searchParams), [searchParamsString]);
|
||||
|
||||
const updateParams = useCallback(
|
||||
(params?: Record<string, string | number>) => {
|
||||
@@ -37,10 +38,6 @@ export function useNavigation() {
|
||||
[teamId, queryParams],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setQueryParams(Object.fromEntries(searchParams));
|
||||
}, [searchParams.toString()]);
|
||||
|
||||
return {
|
||||
router,
|
||||
pathname,
|
||||
|
||||
@@ -17,9 +17,14 @@ import { useNavigation } from './useNavigation';
|
||||
export function useWebsiteNavItems(websiteId: string) {
|
||||
const { t, labels } = useMessages();
|
||||
const { pathname, renderUrl } = useNavigation();
|
||||
const resetParams = {
|
||||
search: undefined,
|
||||
page: undefined,
|
||||
};
|
||||
|
||||
const renderPath = (path: string) =>
|
||||
renderUrl(`/websites/${websiteId}${path}`, {
|
||||
...resetParams,
|
||||
event: undefined,
|
||||
compare: undefined,
|
||||
view: undefined,
|
||||
|
||||
Reference in new issue
Block a user