Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds an admin-only tool section to the Feed Detail page (served via the authed feed route rewrite) that allows MobilityData staff to trigger ISR cache revalidation for a specific feed, and refactors existing revalidation logic into a shared utility.
Changes:
- Add an admin check (
@mobilitydata.org) and plumb anisMobilityDatabaseAdminflag into the authed feed page →FeedView. - Introduce a server action + client button to trigger revalidation for a specific feed.
- Extract revalidation helpers into
src/app/utils/revalidate-feeds.tsand reuse them from/api/revalidate.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app/utils/revalidate-feeds.ts | New shared helpers for revalidating feed-related paths/tags. |
| src/app/utils/auth-server.ts | Adds isMobilityDatabaseAdmin helper used by page + server action. |
| src/app/screens/Feed/actions.ts | New server action to revalidate a specific feed’s cache with admin gating. |
| src/app/screens/Feed/components/RevalidateCacheButton.tsx | New client UI to call the server action and show result. |
| src/app/screens/Feed/FeedView.tsx | Renders admin tools section when isMobilityDatabaseAdmin is true. |
| src/app/components/ContentBox.tsx | Adds a new prop to support a subtitle-like section in ContentBox. |
| src/app/api/revalidate/route.ts | Refactors to use the shared revalidation utilities. |
| src/app/[locale]/feeds/[feedDataType]/[feedId]/authed/page.tsx | Computes admin status from cookie user and passes it to FeedView. |
Applied skill: vercel-react-best-practices (server/client boundaries and server action usage).
| <ContentBox | ||
| title={'MobilityDatabase Admin Tools'} | ||
| subtile={ | ||
| <> | ||
| This section is only visible to Mobility Data employees with an{' '} | ||
| <code>@mobilitydata.org</code> email address. It contains tools | ||
| for debugging and managing feed data | ||
| </> |
There was a problem hiding this comment.
The new admin section strings are hardcoded English, but this page already uses next-intl translations (getTranslations(...)). To keep localization consistent (especially for /fr), move these new strings into the message catalogs and render them via t(...).
| revalidateSpecificFeeds([feedId]); | ||
| return { ok: true, message: `Cache revalidated for feed ${feedId}` }; |
There was a problem hiding this comment.
This server action assumes feedId is always a meaningful non-empty string. Given the UI currently passes feed.id ?? '', consider validating feedId (e.g., trim().length > 0) and returning an error instead of calling revalidateSpecificFeeds with an empty id.
| revalidateSpecificFeeds([feedId]); | |
| return { ok: true, message: `Cache revalidated for feed ${feedId}` }; | |
| const normalizedFeedId = feedId.trim(); | |
| if (normalizedFeedId.length === 0) { | |
| return { ok: false, message: 'Invalid feed id: value is empty or whitespace' }; | |
| } | |
| revalidateSpecificFeeds([normalizedFeedId]); | |
| return { ok: true, message: `Cache revalidated for feed ${normalizedFeedId}` }; |
| <Button variant='contained' onClick={handleClick} disabled={isPending}> | ||
| {isPending ? 'Revalidating…' : 'Revalidate The Cache of This Page'} | ||
| </Button> |
There was a problem hiding this comment.
The button label / status text is hardcoded. Since the app is localized with next-intl, consider moving these strings into the message files and using translations so admin users on /fr don't see mixed-language UI.
| {isMobilityDatabaseAdmin && ( | ||
| <ContentBox | ||
| title={'MobilityDatabase Admin Tools'} | ||
| subtile={ | ||
| <> | ||
| This section is only visible to Mobility Data employees with an{' '} | ||
| <code>@mobilitydata.org</code> email address. It contains tools | ||
| for debugging and managing feed data | ||
| </> | ||
| } | ||
| outlineColor='background.paper' | ||
| sx={{ mt: 4, backgroundColor: 'background.paper' }} | ||
| > | ||
| <RevalidateCacheButton feedId={feed.id ?? ''} /> | ||
| </ContentBox> |
There was a problem hiding this comment.
There are existing unit tests for the Feed screen (Feed.spec.tsx), but the new admin-only section and revalidation flow are currently untested. Consider adding tests that verify the admin tools render only when isMobilityDatabaseAdmin is true and that unauthorized users don’t see/can’t trigger revalidation.
|
*Lighthouse ran on https://mobilitydatabase-ijl5r8khy-mobility-data.vercel.app/ * (Desktop)
*Lighthouse ran on https://mobilitydatabase-ijl5r8khy-mobility-data.vercel.app/feeds * (Desktop)
*Lighthouse ran on https://mobilitydatabase-ijl5r8khy-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-ijl5r8khy-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-ijl5r8khy-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
|
Summary:
closes #36
Added an admin view in the feed detail page only accessible to users with
@mobilitydata.orgemail addressesExpected behavior:
When you are logged in with a mobilitydata email address you will see an admin section at the bottom of each feed detail page
Testing tips:
Open 2 different browser
Browser 1: Do not log in, go to a feed detail page (mark down the 'generated at' value)
Browser 2: Log into your mobility data account, go to the same feed detail page, you should see the admin section at the bottom
In browser 2, revalidate the cache, then refresh browser 1, you should see the 'generated at' value update
Please make sure these boxes are checked before submitting your pull request - thanks!
yarn testto make sure you didn't break anything