Skip to content

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

dashboard: remove unnecessary org/project exists check

Carl-Gerhard Lindesvärd7ba60cdaf382
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/[dashboardId]/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/[dashboardId]/page.tsx
index a26d773ad..53eb8f4f2 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/[dashboardId]/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/[dashboardId]/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { notFound } from 'next/navigation';
import { getDashboardById, getReportsByDashboardId } from '@openpanel/db';
@@ -20,7 +19,6 @@ export default async function Page({
const [dashboard, reports] = await Promise.all([
getDashboardById(dashboardId, projectId),
getReportsByDashboardId(dashboardId),
- getExists(organizationId),
]);
if (!dashboard) {
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/page.tsx
index 398ab32fe..49cbea01b 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/dashboards/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { getDashboardsByProjectId } from '@openpanel/db';
@@ -16,10 +15,7 @@ interface PageProps {
export default async function Page({
params: { projectId, organizationId },
}: PageProps) {
- const [dashboards] = await Promise.all([
- getDashboardsByProjectId(projectId),
- await getExists(organizationId, projectId),
- ]);
+ const dashboards = await getDashboardsByProjectId(projectId);
return (
<PageLayout title="Dashboards" organizationSlug={organizationId}>
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/events/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/events/page.tsx
index 032d85e12..264da7a2c 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/events/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/events/page.tsx
@@ -5,7 +5,6 @@ import {
eventQueryFiltersParser,
eventQueryNamesFilter,
} from '@/hooks/useEventQueryFilters';
-import { getExists } from '@/server/pageExists';
import { parseAsInteger } from 'nuqs';
import { getEventList, getEventsCount } from '@openpanel/db';
@@ -54,7 +53,6 @@ export default async function Page({
events: eventsFilter,
filters,
}),
- getExists(organizationId, projectId),
]);
return (
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/page.tsx
index 737aa546f..62c984f80 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/page.tsx
@@ -9,7 +9,6 @@ import OverviewTopEvents from '@/components/overview/overview-top-events';
import OverviewTopGeo from '@/components/overview/overview-top-geo';
import OverviewTopPages from '@/components/overview/overview-top-pages';
import OverviewTopSources from '@/components/overview/overview-top-sources';
-import { getExists } from '@/server/pageExists';
import { db } from '@openpanel/db';
@@ -27,14 +26,11 @@ interface PageProps {
export default async function Page({
params: { organizationId, projectId },
}: PageProps) {
- const [share] = await Promise.all([
- db.shareOverview.findUnique({
- where: {
- project_id: projectId,
- },
- }),
- getExists(organizationId, projectId),
- ]);
+ const share = await db.shareOverview.findUnique({
+ where: {
+ project_id: projectId,
+ },
+ });
return (
<PageLayout title="Overview" organizationSlug={organizationId}>
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/[profileId]/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/[profileId]/page.tsx
index fe8b6f3d4..793a6e1a5 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/[profileId]/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/[profileId]/page.tsx
@@ -9,7 +9,6 @@ import {
eventQueryFiltersParser,
eventQueryNamesFilter,
} from '@/hooks/useEventQueryFilters';
-import { getExists } from '@/server/pageExists';
import { getProfileName } from '@/utils/getters';
import { notFound } from 'next/navigation';
import { parseAsInteger, parseAsString } from 'nuqs';
@@ -63,7 +62,6 @@ export default async function Page({
getEventList(eventListOptions),
getEventsCount(eventListOptions),
getConversionEventNames(projectId),
- getExists(organizationId, projectId),
]);
const chartSelectedEvents: IChartEvent[] = [
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/page.tsx
index 278ed9421..aa69df260 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/profiles/page.tsx
@@ -2,7 +2,6 @@ import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
import { OverviewFiltersButtons } from '@/components/overview/filters/overview-filters-buttons';
import { OverviewFiltersDrawer } from '@/components/overview/filters/overview-filters-drawer';
import { eventQueryFiltersParser } from '@/hooks/useEventQueryFilters';
-import { getExists } from '@/server/pageExists';
import { parseAsInteger } from 'nuqs';
import { StickyBelowHeader } from '../layout-sticky-below-header';
@@ -25,12 +24,10 @@ const nuqsOptions = {
shallow: false,
};
-export default async function Page({
+export default function Page({
params: { organizationId, projectId },
searchParams: { cursor, f },
}: PageProps) {
- await getExists(organizationId, projectId);
-
return (
<PageLayout title="Profiles" organizationSlug={organizationId}>
<StickyBelowHeader className="p-4 flex justify-between">
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/[reportId]/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/[reportId]/page.tsx
index 88c4ad592..1051caf92 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/[reportId]/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/[reportId]/page.tsx
@@ -1,9 +1,8 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { Pencil } from 'lucide-react';
import { notFound } from 'next/navigation';
-import { getOrganizationBySlug, getReportById } from '@openpanel/db';
+import { getReportById } from '@openpanel/db';
import ReportEditor from '../report-editor';
@@ -16,12 +15,9 @@ interface PageProps {
}
export default async function Page({
- params: { reportId, organizationId, projectId },
+ params: { reportId, organizationId },
}: PageProps) {
- const [report] = await Promise.all([
- getReportById(reportId),
- getExists(organizationId, projectId),
- ]);
+ const report = await getReportById(reportId);
if (!report) {
return notFound();
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/page.tsx
index 636f0555d..c2d2ee609 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/reports/page.tsx
@@ -1,9 +1,5 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { Pencil } from 'lucide-react';
-import { notFound } from 'next/navigation';
-
-import { getOrganizationBySlug } from '@openpanel/db';
import ReportEditor from './report-editor';
@@ -14,11 +10,7 @@ interface PageProps {
};
}
-export default async function Page({
- params: { organizationId, projectId },
-}: PageProps) {
- await getExists(organizationId, projectId);
-
+export default function Page({ params: { organizationId } }: PageProps) {
return (
<PageLayout
organizationSlug={organizationId}
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/clients/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/clients/page.tsx
index 694d9adfd..685c94c6b 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/clients/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/clients/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { getClientsByOrganizationId } from '@openpanel/db';
@@ -12,7 +11,6 @@ interface PageProps {
}
export default async function Page({ params: { organizationId } }: PageProps) {
- await getExists(organizationId);
const clients = await getClientsByOrganizationId(organizationId);
return (
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/profile/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/profile/page.tsx
index 1c7a02f22..bbe12f3b0 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/profile/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/profile/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { auth } from '@clerk/nextjs';
import { getUserById } from '@openpanel/db';
@@ -14,7 +13,6 @@ interface PageProps {
}
export default async function Page({ params: { organizationId } }: PageProps) {
const { userId } = auth();
- await getExists(organizationId);
const profile = await getUserById(userId!);
return (
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/projects/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/projects/page.tsx
index 700431ab2..86b2c09a9 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/projects/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/projects/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { getProjectsByOrganizationSlug } from '@openpanel/db';
@@ -12,7 +11,6 @@ interface PageProps {
}
export default async function Page({ params: { organizationId } }: PageProps) {
- await getExists(organizationId);
const projects = await getProjectsByOrganizationSlug(organizationId);
return (
diff --git a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/references/page.tsx b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/references/page.tsx
index 8a082f16a..643510755 100644
--- a/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/references/page.tsx
+++ b/apps/dashboard/src/app/(app)/[organizationId]/[projectId]/settings/references/page.tsx
@@ -1,5 +1,4 @@
import PageLayout from '@/app/(app)/[organizationId]/[projectId]/page-layout';
-import { getExists } from '@/server/pageExists';
import { getReferences } from '@openpanel/db';
@@ -15,7 +14,6 @@ interface PageProps {
export default async function Page({
params: { organizationId, projectId },
}: PageProps) {
- await getExists(organizationId, projectId);
const references = await getReferences({
where: {
project_id: projectId,
diff --git a/apps/dashboard/src/server/pageExists.tsx b/apps/dashboard/src/server/pageExists.tsx
deleted file mode 100644
index b93e25e89..000000000
--- a/apps/dashboard/src/server/pageExists.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { notFound } from 'next/navigation';
-
-import { getOrganizationBySlug, getProjectById } from '@openpanel/db';
-
-export async function getExists(organizationSlug: string, projectId?: string) {
- const promises: Promise<any>[] = [getOrganizationBySlug(organizationSlug)];
-
- if (projectId) {
- promises.push(getProjectById(projectId));
- }
-
- const results = await Promise.all(promises);
-
- if (results.some((res) => !res)) {
- return notFound();
- }
-
- return {
- organization: results[0] as Awaited<
- ReturnType<typeof getOrganizationBySlug>
- >,
- project: results[1] as Awaited<ReturnType<typeof getProjectById>>,
- };
-}