dashboard: remove unnecessary org/project exists check

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-21 09:43:43 +01:00
parent d2db0ab2ff
commit 7ba60cdaf3
13 changed files with 11 additions and 72 deletions

View File

@@ -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) {

View File

@@ -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}>

View File

@@ -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 (

View File

@@ -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}>

View File

@@ -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[] = [

View File

@@ -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">

View File

@@ -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();

View File

@@ -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}

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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,

View File

@@ -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>>,
};
}