Skip to content

Commit 77fdc3b

Browse files
committed
admin section in feed view
1 parent 5a41671 commit 77fdc3b

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/app/[locale]/feeds/[feedDataType]/[feedId]/authed/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import type { Metadata, ResolvingMetadata } from 'next';
55
import { getTranslations } from 'next-intl/server';
66
import { fetchCompleteFeedData } from '../lib/feed-data';
77
import { generateFeedMetadata } from '../lib/generate-feed-metadata';
8+
import {
9+
getCurrentUserFromCookie,
10+
isMobilityDatabaseAdmin,
11+
} from '../../../../../utils/auth-server';
812

913
interface Props {
1014
params: Promise<{ locale: string; feedDataType: string; feedId: string }>;
@@ -40,7 +44,11 @@ export default async function AuthedFeedPage({
4044
}: Props): Promise<ReactElement> {
4145
const { feedId, feedDataType } = await params;
4246

43-
const feedData = await fetchCompleteFeedData(feedDataType, feedId);
47+
const [userData, feedData] = await Promise.all([
48+
getCurrentUserFromCookie(),
49+
fetchCompleteFeedData(feedDataType, feedId),
50+
]);
51+
const isAdmin = isMobilityDatabaseAdmin(userData?.email);
4452

4553
if (feedData == null) {
4654
return <div>Feed not found</div>;
@@ -69,6 +77,7 @@ export default async function AuthedFeedPage({
6977
relatedGtfsRtFeeds={relatedGtfsRtFeeds}
7078
totalRoutes={totalRoutes}
7179
routeTypes={routeTypes}
80+
isMobilityDatabaseAdmin={isAdmin}
7281
/>
7382
</>
7483
);

src/app/components/ContentBox.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Box, Typography, type SxProps } from '@mui/material';
33

44
export interface ContentBoxProps {
55
title: string;
6+
subtile?: React.ReactNode;
67
width?: Record<string, string>;
78
outlineColor: string;
89
padding?: Partial<SxProps>;
@@ -45,6 +46,11 @@ export const ContentBox = (
4546
{props.action != null && props.action}
4647
</Typography>
4748
)}
49+
{props.subtile != null && (
50+
<Typography variant='subtitle1' sx={{ mb: 2 }}>
51+
{props.subtile}
52+
</Typography>
53+
)}
4854
{props.children}
4955
</Box>
5056
);

src/app/screens/Feed/FeedView.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ import {
2424
type GTFSRTFeedType,
2525
} from '../../services/feeds/utils';
2626
import ClientDownloadButton from './components/ClientDownloadButton';
27+
import RevalidateCacheButton from './components/RevalidateCacheButton';
2728
import { type components } from '../../services/feeds/types';
2829
import ClientQualityReportButton from './components/ClientQualityReportButton';
2930
import { getBoundingBox } from './Feed.functions';
3031
import dynamic from 'next/dynamic';
32+
import { ContentBox } from '../../components/ContentBox';
3133

3234
const CoveredAreaMap = dynamic(
3335
async () =>
@@ -68,6 +70,7 @@ interface Props {
6870
relatedGtfsRtFeeds?: GTFSRTFeedType[];
6971
totalRoutes?: number;
7072
routeTypes?: string[];
73+
isMobilityDatabaseAdmin?: boolean;
7174
}
7275

7376
type LatestDatasetFull = components['schemas']['GtfsDataset'] | undefined;
@@ -79,6 +82,7 @@ export default async function FeedView({
7982
relatedGtfsRtFeeds = [],
8083
totalRoutes,
8184
routeTypes,
85+
isMobilityDatabaseAdmin = false,
8286
}: Props): Promise<React.ReactElement> {
8387
if (feed == undefined) notFound();
8488

@@ -418,6 +422,22 @@ export default async function FeedView({
418422
</Box>
419423
</Box>
420424
</Box>
425+
{isMobilityDatabaseAdmin && (
426+
<ContentBox
427+
title={'MobilityDatabase Admin Tools'}
428+
subtile={
429+
<>
430+
This section is only visible to Mobility Data employees with an{' '}
431+
<code>@mobilitydata.org</code> email address. It contains tools
432+
for debugging and managing feed data
433+
</>
434+
}
435+
outlineColor='background.paper'
436+
sx={{ mt: 4, backgroundColor: 'background.paper' }}
437+
>
438+
<RevalidateCacheButton feedId={feed.id ?? ''} />
439+
</ContentBox>
440+
)}
421441
</Container>
422442
);
423443
}

src/app/utils/auth-server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,7 @@ export async function getUserContextJwtFromCookie(): Promise<
225225
return undefined;
226226
}
227227
}
228+
229+
export function isMobilityDatabaseAdmin(email: string | undefined): boolean {
230+
return email?.endsWith('@mobilitydata.org') === true;
231+
}

0 commit comments

Comments
 (0)