Repository navigation
feat(tags): let people suggest a tag, and admins review suggestions #648
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
93553e6
feat(tags): let people suggest a tag, and admins review suggestions
alukach 4248928
feat(tags): show tags pending review only in the product's settings
alukach 083a6d0
fix(tags): show products as they are when the tag table can't be read
alukach e5859dd
refactor(tags): send the form only the product's own pending tags
alukach 108722a
feat(tags): show admins a dot when suggested tags await review
alukach 5a3581b
docs(storybook): file TagPicker under Settings/Products
alukach da21de6
feat(api): list, suggest, approve, merge and reject tags under /api/v…
alukach 42581ab
feat(tags): review suggestions with likely matches and a staged merge
alukach 45fd962
feat(tags): record who approved a tag, and list every tag for admins
alukach 7141045
fix(tags): suggest tags with hyphens between words
alukach d432f8e
fix(tags): take #719's stricter tag spelling
alukach 056f11f
fix(tags): call seeded tags' origin "Initial import"
alukach 51f2c5e
feat(tags): link each tag in the admin list to its filtered products
alukach 3c8a18c
feat(tags): suggest new tags when the product is saved, not when picked
alukach 067414f
feat(forms): ask before leaving any form with unsaved changes
alukach f40bfa0
feat(forms): show unsaved changes by Save, and enable Save only when …
alukach bbb4602
test(tags): mock the tag table's rows in #719's spelling tests
alukach cdd90b1
feat(tags): make the merge-target picker read as a button
alukach 87f98d4
fix(tags): match a suggestion to the plural of an approved tag
alukach b1a2409
feat(tags): merge a suggestion into several tags, and reset a staged …
alukach efa0c47
feat(tags): keep reviewed suggestions on record, with undo
alukach 675e56e
feat(tags): show an account's card on hover wherever a tag page names…
alukach 8055f6f
feat(tags): keyboard-driven tag menus, and the products a reviewed ta…
alukach 8106e78
fix(tags): use Radix's TextField for TagMenu's search field
alukach 4514f42
fix(tags): keep pending tags out of tag filters, and review cleanups
alukach 9d61a6f
feat(ui): show the account card wherever an account is named (#724)
alukach 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
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
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,113 @@ | ||
| import { Metadata } from "next"; | ||
| import { Flex, Heading } from "@radix-ui/themes"; | ||
| import { FormTitle } from "@/components/core"; | ||
| import { AdminReviewedTags } from "@/components/features/admin/AdminReviewedTags"; | ||
| import { AdminTagList } from "@/components/features/admin/AdminTagList"; | ||
| import { AdminTagSuggestions } from "@/components/features/admin/AdminTagSuggestions"; | ||
| import { accountsTable, productsTable } from "@/lib/clients/database"; | ||
| import { publicView } from "@/lib/operations/accounts"; | ||
| import { getPageSession } from "@/lib/api/utils"; | ||
| import { reviewTag } from "@/lib/actions/tags"; | ||
| import { listTags } from "@/lib/operations/tags"; | ||
| import { similarTags, splitTag } from "@/lib/tags/similar"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "Admin — Tags", | ||
| }; | ||
|
|
||
| // Access is gated by the /admin layout. | ||
| export default async function AdminTagsPage() { | ||
| const session = await getPageSession(); | ||
| const [pending, approved, reviewed, tagged] = await Promise.all([ | ||
| listTags(session, { pending: "true" }), | ||
| listTags(session, {}), | ||
| listTags(session, { reviewed: "true" }), | ||
| productsTable.listTagged(), | ||
| ]); | ||
| if (!pending.ok) throw new Error(pending.message); | ||
| if (!approved.ok) throw new Error(approved.message); | ||
| if (!reviewed.ok) throw new Error(reviewed.message); | ||
|
|
||
| // ponytail: one scan of every tagged product, grouped here; a per-tag count | ||
| // on the tags table if the products table outgrows a page render. | ||
| const byTag = new Map<string, typeof tagged>(); | ||
| for (const p of tagged) { | ||
| for (const t of p.metadata.tags!) { | ||
| if (!byTag.has(t)) byTag.set(t, []); | ||
| byTag.get(t)!.push(p); | ||
| } | ||
| } | ||
| const carrying = (tag: string) => byTag.get(tag) ?? []; | ||
| // Everyone named on the page, for their account cards on hover; public | ||
| // views only, since they go to the browser. | ||
| const named = [...pending.value.items, ...approved.value.items, ...reviewed.value.items] | ||
| .flatMap((t) => [t.suggested_by, t.reviewed_by]) | ||
| .filter((id): id is string => !!id); | ||
| const accounts = Object.fromEntries( | ||
| (await accountsTable.fetchManyByIds([...new Set(named)])).map((a) => [ | ||
| a.account_id, | ||
| publicView(a), | ||
| ]) | ||
| ); | ||
| const approvedTags = approved.value.items.map((t) => t.tag_id); | ||
| const counted = approved.value.items.map((t) => ({ | ||
| tag: t.tag_id, | ||
| products: carrying(t.tag_id).length, | ||
| suggested_by: t.suggested_by, | ||
| reviewed_by: t.reviewed_by, | ||
| reviewed_at: t.reviewed_at, | ||
| })); | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap="6"> | ||
| <FormTitle | ||
| title="Tags" | ||
| description="Review tags people have suggested. Approving adds a tag to the list everyone picks from; merging replaces it with an approved tag on every product that carries it; rejecting takes it off them." | ||
| /> | ||
| <Flex direction="column" gap="3"> | ||
| <Heading size="4"> | ||
| Awaiting review ({pending.value.items.length}) | ||
| </Heading> | ||
| <AdminTagSuggestions | ||
| suggestions={pending.value.items.map((t) => ({ | ||
| tag: t.tag_id, | ||
| suggested_by: t.suggested_by, | ||
| suggested_at: t.suggested_at, | ||
| products: carrying(t.tag_id).map(({ account_id, product_id }) => ({ | ||
| account_id, | ||
| product_id, | ||
| })), | ||
| matches: similarTags(t.tag_id, approvedTags), | ||
| split: splitTag(t.tag_id, approvedTags), | ||
| }))} | ||
| approved={counted} | ||
| action={reviewTag} | ||
| accounts={accounts} | ||
| /> | ||
| </Flex> | ||
| <Flex direction="column" gap="3"> | ||
| <Heading size="4">Reviewed ({reviewed.value.items.length})</Heading> | ||
| <AdminReviewedTags | ||
| reviewed={reviewed.value.items.map((t) => ({ | ||
| tag: t.tag_id, | ||
| outcome: t.outcome!, | ||
| reviewed_by: t.reviewed_by, | ||
| reviewed_at: t.reviewed_at, | ||
| suggested_by: t.suggested_by, | ||
| merged_into: t.merged_into, | ||
| products: (t.changed ?? carrying(t.tag_id)).map(({ account_id, product_id }) => ({ | ||
| account_id, | ||
| product_id, | ||
| })), | ||
| }))} | ||
| action={reviewTag} | ||
| accounts={accounts} | ||
| /> | ||
| </Flex> | ||
| <Flex direction="column" gap="3"> | ||
| <Heading size="4">All tags</Heading> | ||
| <AdminTagList tags={counted} accounts={accounts} /> | ||
| </Flex> | ||
| </Flex> | ||
| ); | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.