Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: invalidate queries better

Carl-Gerhard Lindesvärd8b18b86deb75
diff --git a/apps/start/src/modals/add-dashboard.tsx b/apps/start/src/modals/add-dashboard.tsx
index 0e2fe0081..bf8b6c108 100644
--- a/apps/start/src/modals/add-dashboard.tsx
+++ b/apps/start/src/modals/add-dashboard.tsx
@@ -47,7 +47,7 @@ export default function AddDashboard() {
toast('Success', {
description: 'Dashboard created.',
});
- queryClient.invalidateQueries(trpc.dashboard.pathFilter());
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
popModal();
},
onError: handleError,
diff --git a/apps/start/src/modals/save-report.tsx b/apps/start/src/modals/save-report.tsx
index c59fdb0e4..b478ddb29 100644
--- a/apps/start/src/modals/save-report.tsx
+++ b/apps/start/src/modals/save-report.tsx
@@ -56,6 +56,7 @@ export default function SaveReport({
projectId,
}),
);
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
const goToReport = () => {
router.navigate({
@@ -157,6 +158,7 @@ function SelectDashboard({
projectId: string;
}) {
const trpc = useTRPC();
+ const queryClient = useQueryClient();
const [isCreatingNew, setIsCreatingNew] = useState(false);
const [newDashboardName, setNewDashboardName] = useState('');
@@ -177,6 +179,7 @@ function SelectDashboard({
trpc.dashboard.create.mutationOptions({
onError: handleError,
async onSuccess(res) {
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
await dashboardQuery.refetch();
onChange(res.id);
setIsCreatingNew(false);
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
index 7660d690e..ec217388e 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx
@@ -29,7 +29,7 @@ import FullPageLoadingState from '@/components/full-page-loading-state';
import { PageContainer } from '@/components/page-container';
import { PageHeader } from '@/components/page-header';
import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react';
-import { useMutation, useQuery } from '@tanstack/react-query';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { Link, createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute(
@@ -58,6 +58,7 @@ export const Route = createFileRoute(
function Component() {
const { projectId } = Route.useParams();
const trpc = useTRPC();
+ const queryClient = useQueryClient();
const query = useQuery(
trpc.dashboard.list.queryOptions({
projectId,
@@ -80,6 +81,7 @@ function Component() {
})(error);
},
onSuccess() {
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
query.refetch();
toast('Success', {
description: 'Dashboard deleted.',
diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
index 31e52d3c3..db92f35a9 100644
--- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
+++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx
@@ -35,7 +35,7 @@ import {
} from '@/components/report/report-item';
import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react';
import { pushModal, showConfirm } from '@/modals';
-import { useMutation, useQuery } from '@tanstack/react-query';
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { createFileRoute, useRouter } from '@tanstack/react-router';
import { useCallback, useEffect, useState } from 'react';
@@ -85,6 +85,7 @@ function Component() {
const router = useRouter();
const { organizationId, dashboardId, projectId } = Route.useParams();
const trpc = useTRPC();
+ const queryClient = useQueryClient();
const { range, startDate, endDate, interval } = useOverviewOptions();
const dashboardQuery = useQuery(
@@ -105,6 +106,7 @@ function Component() {
trpc.dashboard.delete.mutationOptions({
onError: handleErrorToastOptions({}),
onSuccess() {
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
toast('Dashboard deleted');
router.navigate({
to: '/$organizationId/$projectId/dashboards',
@@ -139,6 +141,7 @@ function Component() {
trpc.report.delete.mutationOptions({
onError: handleErrorToastOptions({}),
onSuccess() {
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
reportsQuery.refetch();
toast('Report deleted');
},
@@ -149,6 +152,7 @@ function Component() {
trpc.report.duplicate.mutationOptions({
onError: handleErrorToastOptions({}),
onSuccess() {
+ queryClient.invalidateQueries(trpc.dashboard.list.pathFilter());
reportsQuery.refetch();
toast('Report duplicated');
},