From ff6e4f6684117eabad4cc9a4156b2c7c49cc5634 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 12 Apr 2025 18:55:00 -0500 Subject: [PATCH] Centralize insights data --- src/admin/insights/AdminAppInsights.tsx | 54 ++++--------------------- src/admin/insights/index.ts | 39 ++++++++++++++++++ 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/admin/insights/AdminAppInsights.tsx b/src/admin/insights/AdminAppInsights.tsx index 8595a9d0..de07d2e9 100644 --- a/src/admin/insights/AdminAppInsights.tsx +++ b/src/admin/insights/AdminAppInsights.tsx @@ -8,21 +8,9 @@ import { getUniqueTags, } from '@/photo/db/query'; import AdminAppInsightsClient from './AdminAppInsightsClient'; -import { - APP_CONFIGURATION, - CATEGORY_VISIBILITY, - GRID_HOMEPAGE_ENABLED, - HAS_STATIC_OPTIMIZATION, - IS_META_TITLE_CONFIGURED, - IS_META_DESCRIPTION_CONFIGURED, - MATTE_PHOTOS, -} from '@/app/config'; -import { getGitHubMetaForCurrentApp, getSignificantInsights } from '.'; +import { getAllInsights, getGitHubMetaForCurrentApp } from '.'; import { getOutdatedPhotosCount } from '@/photo/db/query'; -const BASIC_PHOTO_INSTALLATION_COUNT = 32; -const TAG_COUNT_THRESHOLD = 12; - export default async function AdminAppInsights() { const [ { count: photosCount, dateRange }, @@ -49,43 +37,17 @@ export default async function AdminAppInsights() { getUniqueFilms(), getUniqueFocalLengths(), ]); - - const { isAiTextGenerationEnabled } = APP_CONFIGURATION; - - const { - forkBehind, - noAiRateLimiting, - noConfiguredDomain, - outdatedPhotos, - } = getSignificantInsights({ - codeMeta, - photosCountOutdated, - }); return ( 0 && !MATTE_PHOTOS, - camerasFirst: ( - tags.length > TAG_COUNT_THRESHOLD && - CATEGORY_VISIBILITY[0] !== 'cameras' - ), - gridFirst: ( - photosCount >= BASIC_PHOTO_INSTALLATION_COUNT && - !GRID_HOMEPAGE_ENABLED - ), - noStaticOptimization: !HAS_STATIC_OPTIMIZATION, - }} + insights={getAllInsights({ + codeMeta, + photosCount, + photosCountOutdated, + photosCountPortrait, + tagsCount: tags.length, + })} photoStats={{ photosCount, photosCountHidden, diff --git a/src/admin/insights/index.ts b/src/admin/insights/index.ts index e6716a10..65b22eb3 100644 --- a/src/admin/insights/index.ts +++ b/src/admin/insights/index.ts @@ -6,10 +6,20 @@ import { IS_VERCEL_GIT_PROVIDER_GITHUB, IS_DEVELOPMENT, APP_CONFIGURATION, + MATTE_PHOTOS, + IS_META_DESCRIPTION_CONFIGURED, + IS_META_TITLE_CONFIGURED, + CATEGORY_VISIBILITY, + HAS_STATIC_OPTIMIZATION, + GRID_HOMEPAGE_ENABLED, + AI_TEXT_GENERATION_ENABLED, } from '@/app/config'; import { PhotoDateRange } from '@/photo'; import { getGitHubMeta } from '@/platforms/github'; +const BASIC_PHOTO_INSTALLATION_COUNT = 32; +const TAG_COUNT_THRESHOLD = 12; + const AdminAppInsightCode = [ 'noFork', 'forkBehind', @@ -105,3 +115,32 @@ export const indicatorStatusForSignificantInsights = ( return 'blue'; } }; + +export const getAllInsights = ({ + codeMeta, + photosCountOutdated, + photosCount, + photosCountPortrait, + tagsCount, +}: Parameters[0] & { + photosCount: number + photosCountPortrait: number + tagsCount: number +}) => ({ + ...getSignificantInsights({ codeMeta, photosCountOutdated }), + noFork: !codeMeta?.isForkedFromBase && !codeMeta?.isBaseRepo, + noAi: !AI_TEXT_GENERATION_ENABLED, + noConfiguredMeta: + !IS_META_TITLE_CONFIGURED || + !IS_META_DESCRIPTION_CONFIGURED, + photoMatting: photosCountPortrait > 0 && !MATTE_PHOTOS, + camerasFirst: ( + tagsCount > TAG_COUNT_THRESHOLD && + CATEGORY_VISIBILITY[0] !== 'cameras' + ), + gridFirst: ( + photosCount >= BASIC_PHOTO_INSTALLATION_COUNT && + !GRID_HOMEPAGE_ENABLED + ), + noStaticOptimization: !HAS_STATIC_OPTIMIZATION, +});