Repository navigation
feat(associations): display reviewed links and link the representative portal #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
viganogabriele
wants to merge
3
commits into
main
Choose a base branch
from
feat/association-portal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
6d673fe
feat(associations): render reviewed registry links and portal entry
viganogabriele 7989572
feat(associations): label repeated links and support reviewed externa…
viganogabriele 5a9c168
fix(associations): harden extraLinks parsing, label only repeated lin…
viganogabriele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Published association registry | ||
|
|
||
| The association listing accepts the optional `extraLinks` field from the reviewed backend registry. It validates the additive payload and keeps the existing `links` fallback for older backend deployments. Visible labels are shown only for repeated platforms and for Twitch/other links (single links keep the icon-only look); an invalid `extraLinks` payload falls back to the legacy `links` for that association instead of emptying the list. Multiple entries for the same platform have their own visible labels, including unsupported platforms with a generic web icon. Public email remains a mail link. | ||
|
|
||
| The public page links representatives to `/dashboard/associations` on `ADMIN_URL` (default `https://admin.polinetwork.org`). Registration, representative approvals, private evidence and draft content belong to the backend/admin portal; this website receives only the approved public version. | ||
|
|
||
| Reviewed external logo URLs are rendered without Next's server-side image optimization, avoiding arbitrary remote fetches through the image optimizer. Bundled static images retain optimization. | ||
|
|
||
| This PR can deploy before the coordinated backend/admin release. Run `pnpm check`, `pnpm build`, and `pnpm typecheck`. The backend tests cover publication gating, preservation of existing associations and numeric IDs. In staging, confirm existing associations, repeated platform links and labels, and logo display after content approval. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { z } from "zod" | ||
|
|
||
| const httpUrl = z.url().refine((url) => /^https?:\/\//i.test(url)) | ||
|
|
||
| const extraLinksSchema = z.array( | ||
| z.object({ | ||
| platform: z.string(), | ||
| label: z.string().trim().min(1), | ||
| url: httpUrl, | ||
| }) | ||
| ) | ||
|
|
||
| export type ExtraLink = z.infer<typeof extraLinksSchema>[number] | ||
|
|
||
| /** Platforms without a default name in the legacy link list: the label is the only meaningful text. */ | ||
| const PLATFORM_NAMES: Record<string, string> = { | ||
| website: "Web", | ||
| facebook: "Facebook", | ||
| instagram: "Instagram", | ||
| tiktok: "TikTok", | ||
| x: "X", | ||
| youtube: "Youtube", | ||
| telegram: "Telegram", | ||
| linkedin: "LinkedIn", | ||
| spotify: "Spotify", | ||
| twitch: "Twitch", | ||
| other: "Link", | ||
| } | ||
|
|
||
| export function platformName(platform: string) { | ||
| return PLATFORM_NAMES[platform] ?? "Link" | ||
| } | ||
|
|
||
| /** | ||
| * Validates the additive `extraLinks` field of an association. Returns `undefined` when it is absent | ||
| * (older backend) or when any entry is malformed, so the caller falls back to the legacy `links` | ||
| * instead of failing the whole listing. | ||
| */ | ||
| export function parseExtraLinks(value: unknown): ExtraLink[] | undefined { | ||
| if (value === undefined || value === null) return undefined | ||
| const result = extraLinksSchema.safeParse(value) | ||
| if (!result.success) { | ||
| console.error("Ignoring invalid association extraLinks", result.error.message) | ||
| return undefined | ||
| } | ||
| return result.data | ||
| } | ||
|
|
||
| /** | ||
| * A visible label is only needed to tell links apart (repeated platform) or when the platform has no | ||
| * recognizable icon (twitch/other). Single links keep the icon-only rendering. | ||
| */ | ||
| export function withVisibleLabels(links: ExtraLink[]) { | ||
| const counts = new Map<string, number>() | ||
| for (const { platform } of links) counts.set(platform, (counts.get(platform) ?? 0) + 1) | ||
| return links.map((link) => ({ | ||
| ...link, | ||
| visibleLabel: (counts.get(link.platform) ?? 0) > 1 || link.platform === "twitch" || link.platform === "other", | ||
| })) | ||
| } | ||
|
|
||
| /** True when the URL belongs to the hosts configured in next.config.js `images.remotePatterns` for the optimizer. */ | ||
| export function isOptimizableImageHost(url: string) { | ||
| try { | ||
| const { protocol, hostname } = new URL(url) | ||
| return protocol === "https:" && hostname.endsWith(".blob.core.windows.net") | ||
| } catch { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| export function isHttpUrl(value: string) { | ||
| return /^https?:\/\//i.test(value) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import assert from "node:assert/strict" | ||
| import test from "node:test" | ||
| import { | ||
| isHttpUrl, | ||
| isOptimizableImageHost, | ||
| parseExtraLinks, | ||
| platformName, | ||
| withVisibleLabels, | ||
| } from "../src/lib/association-links.ts" | ||
|
|
||
| const link = (platform, label, url = "https://example.com/x") => ({ platform, label, url }) | ||
|
|
||
| test("missing extraLinks (older backend) yields undefined", () => { | ||
| assert.equal(parseExtraLinks(undefined), undefined) | ||
| }) | ||
|
|
||
| test("a malformed entry falls back instead of throwing", () => { | ||
| const quiet = console.error | ||
| console.error = () => {} | ||
| try { | ||
| assert.equal(parseExtraLinks([link("website", "Web"), link("x", "", "https://x.com")]), undefined) | ||
| assert.equal(parseExtraLinks([link("website", "Web", "javascript:alert(1)")]), undefined) | ||
| } finally { | ||
| console.error = quiet | ||
| } | ||
| }) | ||
|
|
||
| test("valid links pass through", () => { | ||
| assert.equal(parseExtraLinks([link("twitch", "Live")])?.length, 1) | ||
| }) | ||
|
|
||
| test("labels are visible only for repeated platforms and twitch/other", () => { | ||
| const out = withVisibleLabels([ | ||
| link("website", "website"), | ||
| link("telegram", "Canale"), | ||
| link("telegram", "Gruppo"), | ||
| link("twitch", "Live"), | ||
| ]) | ||
| assert.deepEqual( | ||
| out.map((l) => l.visibleLabel), | ||
| [false, true, true, true] | ||
| ) | ||
| }) | ||
|
|
||
| test("platform names and image helpers", () => { | ||
| assert.equal(platformName("twitch"), "Twitch") | ||
| assert.equal(platformName("unknown"), "Link") | ||
| assert.equal(isHttpUrl("javascript:alert(1)"), false) | ||
| assert.equal(isOptimizableImageHost("https://acct.blob.core.windows.net/a.png"), true) | ||
| assert.equal(isOptimizableImageHost("https://evil.example/a.png"), false) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep legacy website and social links when
extraLinksis present.The
extraLinksbranch replaces every legacy non-email link. An emptyextraLinksarray is truthy, so it also suppresseslinks.websiteand the social links. The documentation describesextraLinksas additive, so a supplemental array can also drop these links. The fallback applies only when the field is absent, so a backend response that includesextraLinksfor an association with a published website can hide that website.Build the legacy links from
LINK_CONFIGin every case, then append the mappedextraLinks. Keep the email entry as it is now, and check that theLINK_CONFIGemail entry does not duplicate it.