From e085aff3cc6b1cac5fb7ef7dc466d663200f255d Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Wed, 18 Nov 2026 18:45:31 +0530 Subject: [PATCH 1/5] feat(icons): let boards, statuses and help-center topics pick an icon Boards gain a nullable icon column (with migration) and the create/rename sheets use the icon picker; the dashboard sidebar and the public board nav render it. Post statuses use their existing icon column, with per-type client defaults and the mark shown in status settings, status fields, board lanes/cards, roadmaps and the activity timeline. Help-center topics move from the closed Hugeicons set to the same picker, with a new client default. The picker is composed into a popover-backed IconPickerField, and null icon names resolve through @feeblo/web-shared/icons/defaults so the default lives on the client and needs no backfill. The versioned Public API DTOs are deliberately unchanged; exposing the icon there is a separate contract change. --- .../components/feedback/board-list-card.tsx | 29 +++++-- .../roadmap/public-roadmap-page.tsx | 1 + .../src/pages/board-page.tsx | 21 ++++- .../components/common/app-sidebar.tsx | 8 +- .../board-surface/board-grid-lane-column.tsx | 10 ++- .../board-surface/board-grid-post-card.tsx | 1 + .../board-surface/board-grid-view.tsx | 1 + .../board-surface/board-lane-icon.tsx | 4 +- .../board-surface/board-list-view.tsx | 6 +- .../board-surface/board-post-row-item.tsx | 2 +- .../components/board-surface/status-icon.tsx | 14 +-- .../board/components/board-surface/types.ts | 2 + .../board-surface/use-board-posts-data.ts | 2 + .../board/components/board-surface/utils.ts | 6 ++ .../board/components/create-board-dialog.tsx | 13 +++ .../board/components/rename-board-dialog.tsx | 29 ++++++- .../dashboard/features/board/shared-form.ts | 3 + .../components/help-center-article-editor.tsx | 2 +- .../components/help-center-index.tsx | 2 +- .../components/help-center-topic-dialog.tsx | 35 ++------ .../components/help-center-topic-icon.tsx | 22 +++++ .../components/help-center-topic-icons.tsx | 85 ------------------- .../features/help-center/help-center-forms.ts | 27 +++--- .../components/post-status-create-dialog.tsx | 18 ++++ .../components/post-status-edit-dialog.tsx | 20 +++++ .../components/post-status-settings.tsx | 6 +- .../post/components/post-activity-list.tsx | 57 +++++++++---- .../roadmap/components/roadmap-board.tsx | 3 + apps/web/src/dashboard/lib/collections.ts | 4 + apps/web/src/lib/board-llms.test.ts | 1 + .../portal/help-center/help-center-page.tsx | 10 ++- ...0-the-icon-picker-is-a-generated-sprite.md | 2 +- .../migration.sql | 1 + .../snapshot.json | 47 ++++++++++ packages/db/src/schema/feedback.ts | 10 ++- packages/db/src/schema/help-center.ts | 2 +- packages/domain/src/board/handlers.ts | 14 ++- packages/domain/src/board/repository.ts | 3 + packages/domain/src/board/schema.ts | 7 ++ packages/domain/src/data-transfer/worker.ts | 1 + packages/domain/src/post-status/repository.ts | 3 + packages/domain/src/post-status/schema.ts | 8 ++ packages/post-ui/package.json | 4 + packages/post-ui/src/post-field.tsx | 49 ++++++----- packages/post-ui/src/post-status-icon.tsx | 26 ++++++ packages/post-ui/src/roadmap/roadmap-grid.tsx | 1 + .../src/roadmap/roadmap-issue-card.tsx | 4 +- .../src/roadmap/roadmap-lane-column.tsx | 7 +- .../src/roadmap/roadmap-status-icon.tsx | 18 ++-- packages/post-ui/src/roadmap/types.ts | 3 + .../post-ui/src/roadmap/use-roadmap-data.ts | 10 ++- packages/post-ui/src/roadmap/utils.ts | 1 + packages/ui/src/icon-picker/index.tsx | 63 ++++++++++++++ packages/ui/src/icon-picker/sprite.ts | 14 ++- packages/ui/src/icon-picker/types.ts | 19 +++++ packages/web-shared/package.json | 4 + packages/web-shared/src/board/constants.ts | 25 ++---- .../web-shared/src/icons/defaults.test.ts | 27 ++++++ packages/web-shared/src/icons/defaults.ts | 47 ++++++++++ 59 files changed, 640 insertions(+), 224 deletions(-) create mode 100644 apps/web/src/dashboard/features/help-center/components/help-center-topic-icon.tsx delete mode 100644 apps/web/src/dashboard/features/help-center/components/help-center-topic-icons.tsx create mode 100644 packages/db/src/migrations/20261118124737_wooden_exiles/migration.sql create mode 100644 packages/db/src/migrations/20261118124737_wooden_exiles/snapshot.json create mode 100644 packages/post-ui/src/post-status-icon.tsx create mode 100644 packages/web-shared/src/icons/defaults.test.ts create mode 100644 packages/web-shared/src/icons/defaults.ts diff --git a/apps/public-feature-board/src/components/feedback/board-list-card.tsx b/apps/public-feature-board/src/components/feedback/board-list-card.tsx index 6c81e77ef..7d03e1748 100644 --- a/apps/public-feature-board/src/components/feedback/board-list-card.tsx +++ b/apps/public-feature-board/src/components/feedback/board-list-card.tsx @@ -1,4 +1,6 @@ +import { TablerIcon } from "@feeblo/ui/icon-picker"; import { cn } from "@feeblo/ui/utils"; +import { boardIconName } from "@feeblo/web-shared/icons/defaults"; import { eq, useLiveQuery } from "@tanstack/react-db"; import { Link, useLocation } from "@tanstack/react-router"; @@ -33,6 +35,7 @@ export function BoardListCard() { {data?.map((board) => ( @@ -44,10 +47,12 @@ export function BoardListCard() { export function BoardNavLink({ href, + icon, label, showActiveIndicator = false, }: { href: string; + icon?: string | null; label: string; showActiveIndicator?: boolean; }) { @@ -64,13 +69,23 @@ export function BoardNavLink({ )} to={href} > - + {icon === undefined ? ( + + ) : ( + + )} {label} ); diff --git a/apps/public-feature-board/src/components/roadmap/public-roadmap-page.tsx b/apps/public-feature-board/src/components/roadmap/public-roadmap-page.tsx index 4217fc849..c281ceaec 100644 --- a/apps/public-feature-board/src/components/roadmap/public-roadmap-page.tsx +++ b/apps/public-feature-board/src/components/roadmap/public-roadmap-page.tsx @@ -198,6 +198,7 @@ function PublicRoadmapBoardContent() { key={post.id} onClick={() => openPost(post.slug)} status={post.status} + statusIcon={post.statusIcon} title={post.title} updatedAt={post.updatedAt} /> diff --git a/apps/public-feature-board/src/pages/board-page.tsx b/apps/public-feature-board/src/pages/board-page.tsx index c8667b653..3d67cc221 100644 --- a/apps/public-feature-board/src/pages/board-page.tsx +++ b/apps/public-feature-board/src/pages/board-page.tsx @@ -6,10 +6,12 @@ import { EmptyHeader, EmptyTitle, } from "@feeblo/ui/empty"; +import { TablerIcon } from "@feeblo/ui/icon-picker"; import { isLiveQueryFailed, isLiveQueryPending, } from "@feeblo/web-shared/collections"; +import { boardIconName } from "@feeblo/web-shared/icons/defaults"; import { and, eq, useLiveQuery } from "@tanstack/react-db"; import type { ReactNode } from "react"; @@ -41,10 +43,21 @@ function MainContent({ children }: { children: ReactNode }) { ); } -function ListHeader({ count, title }: { count?: number; title: string }) { +function ListHeader({ + count, + icon, + title, +}: { + count?: number; + icon?: string | null; + title: string; +}) { return (
-

+

+ {icon === undefined ? null : ( + + )} {title}

{count !== undefined && ( @@ -192,7 +205,7 @@ export function BoardPage({ boardSlug }: { readonly boardSlug: string }) { return (
- + {m.plane_strong_crow()} @@ -207,7 +220,7 @@ export function BoardPage({ boardSlug }: { readonly boardSlug: string }) { return (
- +
{posts.map(({ post, postStatus }) => ( @@ -297,6 +300,7 @@ function BoardList() { @@ -308,10 +312,11 @@ function BoardList() { interface BoardItemProp { boardPublicId: string; boardSlug: string; + icon: string | null; name: string; } -function BoardItem({ boardPublicId, name, boardSlug }: BoardItemProp) { +function BoardItem({ boardPublicId, icon, name, boardSlug }: BoardItemProp) { const organizationId = useOrganizationId(); const pathname = useRouterState({ @@ -331,6 +336,7 @@ function BoardItem({ boardPublicId, name, boardSlug }: BoardItemProp) { to="/$organizationId/board/$boardSlug" {...props} > + {name} )} diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-lane-column.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-lane-column.tsx index 7e1a79513..bbfcba23c 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-lane-column.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-lane-column.tsx @@ -22,6 +22,7 @@ interface BoardGridLaneColumnProps { label: string; /** Present only for a status lane. */ status?: BoardPostStatus; + statusIcon?: string | null; statusId?: string; totalPosts: number; } @@ -32,6 +33,7 @@ const BoardGridLaneColumn = memo(function BoardGridLaneColumn({ children, totalPosts, status, + statusIcon, statusId, boardId, groupBy, @@ -74,7 +76,13 @@ const BoardGridLaneColumn = memo(function BoardGridLaneColumn({ ) : undefined } contentRef={ref} - icon={} + icon={ + + } isHighlighted={isDropTarget} label={effectiveLabel} status={status} diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-post-card.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-post-card.tsx index 350b8b10b..a67d37c41 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-post-card.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-post-card.tsx @@ -52,6 +52,7 @@ export const BoardGridPostCard = memo(function BoardGridPostCard({ } rootRef={ref} status={post.status} + statusIcon={post.statusIcon} title={post.title} updatedAt={post.updatedAt} /> diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx index f519dd27c..305bfe9e3 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx @@ -310,6 +310,7 @@ export function BoardGridView({ key={lane.id} label={lane.label} status={lane.status} + statusIcon={lane.statusIcon} statusId={lane.statusId} totalPosts={rows.length} > diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-lane-icon.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-lane-icon.tsx index 3f2ab2fd7..cad189eec 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-lane-icon.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-lane-icon.tsx @@ -34,12 +34,14 @@ const LANE_ICON_BY_GROUPING: Record = { export function BoardLaneIcon({ groupBy, status, + statusIcon, }: { groupBy: TBoardGroupBy; status?: BoardPostStatus; + statusIcon?: string | null; }) { if (groupBy === "status" && status) { - return ; + return ; } const icon = LANE_ICON_BY_GROUPING[groupBy]; diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-list-view.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-list-view.tsx index bb597b2e6..b932c466d 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-list-view.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-list-view.tsx @@ -161,7 +161,11 @@ function BoardListLaneHeader({ icon={ArrowUp01Icon} strokeWidth={2} /> - +

{laneLabel}

{lane.posts.length} diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-post-row-item.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-post-row-item.tsx index c3eb092f9..fc94cda64 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-post-row-item.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-post-row-item.tsx @@ -69,7 +69,7 @@ export function BoardPostRowItem({ /> {post.upvoteCount} - +

{post.title}

diff --git a/apps/web/src/dashboard/features/board/components/board-surface/status-icon.tsx b/apps/web/src/dashboard/features/board/components/board-surface/status-icon.tsx index b45165d52..c45bb6cb1 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/status-icon.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/status-icon.tsx @@ -1,18 +1,22 @@ +import { PostStatusIcon } from "@feeblo/post-ui/post-status-icon"; import { cn } from "@feeblo/ui/utils"; import { BOARD_LANE_COLOR_MAP, - BoardIconMap, type BoardPostStatus, } from "@feeblo/web-shared/board/constants"; -import { HugeiconsIcon } from "@hugeicons/react"; -export function StatusIcon({ status }: { status: BoardPostStatus }) { - const Icon = BoardIconMap[status] ?? BoardIconMap.PLANNED; +export function StatusIcon({ + icon, + status, +}: { + icon?: string | null; + status: BoardPostStatus; +}) { const color = BOARD_LANE_COLOR_MAP[status]; return ( - + ); } diff --git a/apps/web/src/dashboard/features/board/components/board-surface/types.ts b/apps/web/src/dashboard/features/board/components/board-surface/types.ts index 950346500..68ccc9a0c 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/types.ts +++ b/apps/web/src/dashboard/features/board/components/board-surface/types.ts @@ -13,6 +13,7 @@ export type BoardPostRow = { slug: string; statusId: string; status: BoardPostStatus; + statusIcon?: string | null; title: string; summary: string; updatedAt: Date | string; @@ -31,6 +32,7 @@ export type BoardPostLane = { * status to write. */ status?: BoardPostStatus; + statusIcon?: string | null; statusId?: string; }; diff --git a/apps/web/src/dashboard/features/board/components/board-surface/use-board-posts-data.ts b/apps/web/src/dashboard/features/board/components/board-surface/use-board-posts-data.ts index b5915bd6a..94a07db79 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/use-board-posts-data.ts +++ b/apps/web/src/dashboard/features/board/components/board-surface/use-board-posts-data.ts @@ -59,6 +59,7 @@ type UseBoardPostsDataOptions = { */ function visiblePostStatuses( postStatuses: ReadonlyArray<{ + icon: string | null; id: string; type: BoardPostStatus; label: string; @@ -330,6 +331,7 @@ export function useBoardPostsData({ slug: post.slug, statusId: post.statusId, status: postStatus.type, + statusIcon: postStatus.icon, summary: post.excerpt, title: post.title, updatedAt: post.updatedAt, diff --git a/apps/web/src/dashboard/features/board/components/board-surface/utils.ts b/apps/web/src/dashboard/features/board/components/board-surface/utils.ts index 12dbaa784..a9f714cdf 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/utils.ts +++ b/apps/web/src/dashboard/features/board/components/board-surface/utils.ts @@ -9,6 +9,8 @@ import type { } from "./types"; type BoardGroupingStatus = { + /** Optional so a test fixture or a partial status row still groups. */ + icon?: string | null; id: string; label: string; type: BoardPostStatus; @@ -81,6 +83,7 @@ function groupByStatus( label: string; posts: BoardPostRow[]; status: BoardPostStatus; + statusIcon?: string | null; statusId: string; } >( @@ -90,6 +93,7 @@ function groupByStatus( label: status.label, posts: [], status: status.type, + statusIcon: status.icon, statusId: status.id, }, ]) @@ -107,6 +111,7 @@ function groupByStatus( label: "", posts: [post], status: post.status, + statusIcon: post.statusIcon, statusId: post.statusId, }); } @@ -123,6 +128,7 @@ function groupByStatus( label: lane.label, posts: lane.posts, status: lane.status, + statusIcon: lane.statusIcon, statusId: lane.statusId, }); } diff --git a/apps/web/src/dashboard/features/board/components/create-board-dialog.tsx b/apps/web/src/dashboard/features/board/components/create-board-dialog.tsx index 5a5eac3be..d0a3964dc 100644 --- a/apps/web/src/dashboard/features/board/components/create-board-dialog.tsx +++ b/apps/web/src/dashboard/features/board/components/create-board-dialog.tsx @@ -9,6 +9,7 @@ import { EmptyTitle, } from "@feeblo/ui/empty"; import { useAppForm } from "@feeblo/ui/hooks/form"; +import { IconPickerField } from "@feeblo/ui/icon-picker"; import { Sheet, SheetClose, @@ -21,6 +22,7 @@ import { } from "@feeblo/ui/sheet"; import { toastManager } from "@feeblo/ui/toast"; import { slugify } from "@feeblo/utils/url"; +import { DEFAULT_BOARD_ICON } from "@feeblo/web-shared/icons/defaults"; import { SparklesIcon } from "@hugeicons/core-free-icons"; import { HugeiconsIcon } from "@hugeicons/react"; import { useSelector } from "@xstate/store-react"; @@ -77,6 +79,7 @@ function CreateBoardForm() { createdAt: new Date(), updatedAt: new Date(), name: data.value.name, + icon: data.value.icon, visibility: data.value.visibility, slug: slugify(data.value.name), organizationId, @@ -140,6 +143,16 @@ function CreateBoardForm() { {(field) => } + + {(field) => ( + field.handleChange(icon)} + value={field.state.value} + /> + )} + diff --git a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx index 2a4b7d0ee..a7eb40571 100644 --- a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx +++ b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx @@ -1,5 +1,6 @@ import { Button } from "@feeblo/ui/button"; import { useAppForm } from "@feeblo/ui/hooks/form"; +import { IconPickerField } from "@feeblo/ui/icon-picker"; import { Sheet, SheetClose, @@ -12,6 +13,7 @@ import { } from "@feeblo/ui/sheet"; import { toastManager } from "@feeblo/ui/toast"; import { slugify } from "@feeblo/utils/url"; +import { DEFAULT_BOARD_ICON } from "@feeblo/web-shared/icons/defaults"; import { and, eq, useLiveQuery } from "@tanstack/react-db"; import { useNavigate } from "@tanstack/react-router"; import { useSelector } from "@xstate/store-react"; @@ -70,7 +72,20 @@ function RenameBoardForm() { return ; } -function RenameBoardFormFields({ board }: { board: BoardFormValues }) { +/** + * The row the edit sheet seeds from. + * + * `icon` is the stored nullable value, not the form's string: the form defaults + * it to the client's default, and the row itself is allowed to have never + * picked one. + */ +type RenameBoardRow = { + icon: string | null; + name: string; + visibility: BoardFormValues["visibility"]; +}; + +function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { const organizationId = useOrganizationId(); const { boardCollection } = useDashboardCollections(); const store = useRenameBoardDialogContext(); @@ -81,6 +96,7 @@ function RenameBoardFormFields({ board }: { board: BoardFormValues }) { ...boardFormOpts, defaultValues: { name: board.name, + icon: board.icon ?? DEFAULT_BOARD_ICON, visibility: board.visibility, }, onSubmit: async (data) => { @@ -89,6 +105,7 @@ function RenameBoardFormFields({ board }: { board: BoardFormValues }) { const tx = boardCollection.update(boardId, (draft) => { draft.name = data.value.name; + draft.icon = data.value.icon; draft.visibility = data.value.visibility; draft.slug = boardSlug; }); @@ -129,6 +146,16 @@ function RenameBoardFormFields({ board }: { board: BoardFormValues }) { {(field) => } + + {(field) => ( + field.handleChange(icon)} + value={field.state.value} + /> + )} + diff --git a/apps/web/src/dashboard/features/board/shared-form.ts b/apps/web/src/dashboard/features/board/shared-form.ts index e77909abc..3a94420de 100644 --- a/apps/web/src/dashboard/features/board/shared-form.ts +++ b/apps/web/src/dashboard/features/board/shared-form.ts @@ -1,8 +1,10 @@ +import { DEFAULT_BOARD_ICON } from "@feeblo/web-shared/icons/defaults"; import { formOptions } from "@tanstack/react-form"; import { z } from "zod"; export const boardFormSchema = z.object({ name: z.string().trim().min(1, "Board name is required"), + icon: z.string().trim().min(1).max(64), visibility: z.enum(["PUBLIC", "PRIVATE"]), }); @@ -11,6 +13,7 @@ export type BoardFormValues = z.infer; export const boardFormOpts = formOptions({ defaultValues: { name: "", + icon: DEFAULT_BOARD_ICON, // SAFETY: The upstream source guarantees one of these values; the cast bridges an untyped API. visibility: "PUBLIC" as "PUBLIC" | "PRIVATE", }, diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-article-editor.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-article-editor.tsx index 44a9787a4..b94c3e617 100644 --- a/apps/web/src/dashboard/features/help-center/components/help-center-article-editor.tsx +++ b/apps/web/src/dashboard/features/help-center/components/help-center-article-editor.tsx @@ -28,7 +28,7 @@ import { helpCenterArticleFormValues, type HelpCenterArticleFormValues, } from "../help-center-forms"; -import { HelpCenterTopicIcon } from "./help-center-topic-icons"; +import { HelpCenterTopicIcon } from "./help-center-topic-icon"; /** * What the editor is editing, as a discriminated union rather than an optional diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-index.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-index.tsx index fc2230dcc..42ccfbad9 100644 --- a/apps/web/src/dashboard/features/help-center/components/help-center-index.tsx +++ b/apps/web/src/dashboard/features/help-center/components/help-center-index.tsx @@ -42,7 +42,7 @@ import { CreateHelpCenterTopicDialog, EditHelpCenterTopicDialog, } from "./help-center-topic-dialog"; -import { HelpCenterTopicIcon } from "./help-center-topic-icons"; +import { HelpCenterTopicIcon } from "./help-center-topic-icon"; /** The collection's own row: `description` and `icon` are nullable columns. */ type THelpCenterTopicRow = { diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx index 0c4dc2c7c..2af02133d 100644 --- a/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx +++ b/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx @@ -11,7 +11,8 @@ import { DialogTitle, } from "@feeblo/ui/dialog"; import { useAppForm } from "@feeblo/ui/hooks/form"; -import { cn } from "@feeblo/ui/utils"; +import { IconPickerField } from "@feeblo/ui/icon-picker"; +import { DEFAULT_HELP_CENTER_TOPIC_ICON } from "@feeblo/web-shared/icons/defaults"; import { parseRpcError } from "@feeblo/web-shared/rpc-error"; import { useState } from "react"; @@ -22,10 +23,6 @@ import { helpCenterTopicFormValues, type HelpCenterTopicFormValues, } from "../help-center-forms"; -import { - HELP_CENTER_TOPIC_ICON_KEYS, - HelpCenterTopicIcon, -} from "./help-center-topic-icons"; /** * The section dialog, as two variants rather than one component with a mode. @@ -225,28 +222,12 @@ function TopicFields({ {(field) => ( -
- Icon -
- {HELP_CENTER_TOPIC_ICON_KEYS.map((key) => ( - - ))} -
-
+ field.handleChange(icon)} + value={field.state.value} + /> )}
diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-topic-icon.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-topic-icon.tsx new file mode 100644 index 000000000..caf348e4b --- /dev/null +++ b/apps/web/src/dashboard/features/help-center/components/help-center-topic-icon.tsx @@ -0,0 +1,22 @@ +import { TablerIcon } from "@feeblo/ui/icon-picker"; +import { helpCenterTopicIconName } from "@feeblo/web-shared/icons/defaults"; + +/** + * A section's icon. + * + * The column stores a Tabler name; a null or unknown value falls back to the + * client's default, so a section created before the picker existed still has + * a mark. The sprite is fetched by the first icon that renders, not by the + * dialog, so a list of sections draws without opening the picker. + */ +export function HelpCenterTopicIcon({ + className, + icon, +}: { + className?: string; + icon: string | null | undefined; +}) { + return ( + + ); +} diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-topic-icons.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-topic-icons.tsx deleted file mode 100644 index e0adee588..000000000 --- a/apps/web/src/dashboard/features/help-center/components/help-center-topic-icons.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { - BookOpen01Icon, - Briefcase01Icon, - Bug01Icon, - CreditCardIcon, - PuzzleIcon, - RocketIcon, - Settings01Icon, - UserIcon, -} from "@hugeicons/core-free-icons"; -import type { IconSvgElement } from "@hugeicons/react"; -import { HugeiconsIcon } from "@hugeicons/react"; - -/** - * The topic icons the dashboard offers. - * - * A closed set rather than a free-text field, and stored as the key: the column - * is a *name* the UI resolves, so changing the artwork later is a code change - * and not a data migration, and an unknown stored value degrades to the - * fallback instead of rendering nothing. - */ -export const HELP_CENTER_TOPIC_ICON_KEYS = [ - "book", - "rocket", - "settings", - "card", - "bug", - "puzzle", - "briefcase", - "user", -] as const; - -export type THelpCenterTopicIcon = (typeof HELP_CENTER_TOPIC_ICON_KEYS)[number]; - -// The `satisfies` is what makes adding a key to the list above a compile error -// until it has artwork, and what makes an artwork key that is not in the list a -// compile error too. -export const HELP_CENTER_TOPIC_ICONS = { - book: BookOpen01Icon, - rocket: RocketIcon, - settings: Settings01Icon, - card: CreditCardIcon, - bug: Bug01Icon, - puzzle: PuzzleIcon, - briefcase: Briefcase01Icon, - user: UserIcon, -} satisfies Record; - -export const DEFAULT_HELP_CENTER_TOPIC_ICON: THelpCenterTopicIcon = "book"; - -/** True when `value` names an icon this build knows. */ -export const isHelpCenterTopicIcon = ( - value: string | null | undefined -): value is THelpCenterTopicIcon => - value !== null && value !== undefined && isTopicIconKey(value); - -/** - * The membership test, widened once. - * - * `includes` on the readonly tuple wants a member of the union, and the whole - * point of the guard is to accept a value that is not one yet — so the search - * runs over the same keys as plain strings. - */ -const isTopicIconKey = (value: string): boolean => - HELP_CENTER_TOPIC_ICON_KEYS.some((key) => key === value); - -export function HelpCenterTopicIcon({ - className, - icon, -}: { - className?: string; - icon: string | null | undefined; -}) { - const resolved = isHelpCenterTopicIcon(icon) - ? icon - : DEFAULT_HELP_CENTER_TOPIC_ICON; - - return ( - - ); -} diff --git a/apps/web/src/dashboard/features/help-center/help-center-forms.ts b/apps/web/src/dashboard/features/help-center/help-center-forms.ts index cf18669cd..c08dd799a 100644 --- a/apps/web/src/dashboard/features/help-center/help-center-forms.ts +++ b/apps/web/src/dashboard/features/help-center/help-center-forms.ts @@ -1,22 +1,21 @@ import { HELP_CENTER_ARTICLE_WRITE_STATES } from "@feeblo/domain-contracts/help-center-article"; import type { THelpCenterArticle } from "@feeblo/domain/help-center-article/schema"; import type { THelpCenterTopic } from "@feeblo/domain/help-center-topic/schema"; -import { formOptions } from "@tanstack/react-form"; -import { z } from "zod"; - import { DEFAULT_HELP_CENTER_TOPIC_ICON, - HELP_CENTER_TOPIC_ICON_KEYS, - type THelpCenterTopicIcon, -} from "./components/help-center-topic-icons"; + helpCenterTopicIconName, +} from "@feeblo/web-shared/icons/defaults"; +import { formOptions } from "@tanstack/react-form"; +import { z } from "zod"; /** * The topic form's shape, and the labels its controls render. * * The schema mirrors the server's bounds rather than defining them: a courtesy * check that turns a round trip into an inline message, with the RPC as the - * enforcement point. `icon` is an enum over the catalogue, so a stored value - * the picker cannot render is a validation failure instead of an empty tile. + * enforcement point. `icon` is a Tabler name from the picker; an unknown name + * renders the client's default rather than an empty tile, so the form only + * enforces the column's length. */ export const helpCenterTopicFormSchema = z.object({ name: z @@ -25,7 +24,7 @@ export const helpCenterTopicFormSchema = z.object({ .min(1, "A section needs a name.") .max(100, "Use 100 characters or fewer."), description: z.string().trim().max(500, "Use 500 characters or fewer."), - icon: z.enum(HELP_CENTER_TOPIC_ICON_KEYS), + icon: z.string().trim().min(1).max(64), }); export type HelpCenterTopicFormValues = z.infer< @@ -48,14 +47,12 @@ export type HelpCenterTopicFormSeed = Pick< export const helpCenterTopicFormValues = ( topic?: HelpCenterTopicFormSeed, - fallbackIcon: THelpCenterTopicIcon = DEFAULT_HELP_CENTER_TOPIC_ICON + fallbackIcon: string = DEFAULT_HELP_CENTER_TOPIC_ICON ): HelpCenterTopicFormValues => ({ description: topic?.description ?? "", - // `find` over the tuple already narrows to the icon union, so the fallback is - // the only `undefined` it can return. - icon: - HELP_CENTER_TOPIC_ICON_KEYS.find((key) => key === topic?.icon) ?? - fallbackIcon, + // Resolved here rather than on submit: the picker renders the value it is + // given, so a legacy key has to become a Tabler name before the form opens. + icon: helpCenterTopicIconName(topic?.icon ?? fallbackIcon), name: topic?.name ?? "", }); diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx index f64221efb..d016cc9ee 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx @@ -14,7 +14,9 @@ import { } from "@feeblo/ui/dialog"; import { Field, FieldLabel } from "@feeblo/ui/field"; import { useAppForm } from "@feeblo/ui/hooks/form"; +import { IconPickerField } from "@feeblo/ui/icon-picker"; import { toastManager } from "@feeblo/ui/toast"; +import { DEFAULT_POST_STATUS_ICONS } from "@feeblo/web-shared/icons/defaults"; import { useSelector } from "@xstate/store-react"; import { z } from "zod"; @@ -58,11 +60,13 @@ function PostStatusCreateForm({ type }: { type: TPostStatusType }) { const form = useAppForm({ defaultValues: { color: DEFAULT_POST_STATUS_COLORS[type], + icon: DEFAULT_POST_STATUS_ICONS[type], label: "", }, validators: { onSubmit: z.object({ color: z.string(), + icon: z.string().trim().min(1).max(64), label: z.string().min(1).max(60), }), }, @@ -84,6 +88,7 @@ function PostStatusCreateForm({ type }: { type: TPostStatusType }) { id, color: data.value.color, createdAt: new Date(), + icon: data.value.icon, isDefault: false, label: data.value.label, orderIndex, @@ -133,6 +138,19 @@ function PostStatusCreateForm({ type }: { type: TPostStatusType }) { )} + + {(field) => ( + + Icon + field.handleChange(icon)} + value={field.state.value} + /> + + )} + }>Cancel diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx index 053d4dc79..85f6686f9 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx @@ -12,6 +12,7 @@ import { } from "@feeblo/ui/dialog"; import { Field, FieldLabel } from "@feeblo/ui/field"; import { useAppForm } from "@feeblo/ui/hooks/form"; +import { IconPickerField } from "@feeblo/ui/icon-picker"; import { Select, SelectItem, @@ -20,6 +21,7 @@ import { SelectValue, } from "@feeblo/ui/select"; import { toastManager } from "@feeblo/ui/toast"; +import { DEFAULT_POST_STATUS_ICONS } from "@feeblo/web-shared/icons/defaults"; import { eq, useLiveQuery } from "@tanstack/react-db"; import { useSelector } from "@xstate/store-react"; import { z } from "zod"; @@ -59,6 +61,7 @@ export function PostStatusEditDialog() { key={status.id} status={{ color: status.color ?? null, + icon: status.icon ?? null, id: status.id, label: status.label, type: status.type, @@ -72,6 +75,7 @@ export function PostStatusEditDialog() { type EditableStatus = { color: string | null; + icon: string | null; id: string; label: string; type: TPostStatusType; @@ -84,12 +88,14 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { const form = useAppForm({ defaultValues: { color: status.color, + icon: status.icon ?? DEFAULT_POST_STATUS_ICONS[status.type], label: status.label, type: status.type, }, validators: { onSubmit: z.object({ color: z.string().nullable(), + icon: z.string().trim().min(1).max(64), label: z.string().min(1).max(60), type: z.enum([ "PENDING", @@ -116,6 +122,7 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { const tx = postStatusCollection.update(status.id, (draft) => { draft.color = data.value.color; + draft.icon = data.value.icon; draft.label = data.value.label; draft.type = data.value.type; @@ -164,6 +171,19 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { )} + + {(field) => ( + + Icon + field.handleChange(icon)} + value={field.state.value} + /> + + )} + {(field) => ( diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-settings.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-settings.tsx index f210cbc52..97451590d 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-settings.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-settings.tsx @@ -3,13 +3,13 @@ import { DragDropProvider } from "@dnd-kit/react"; import { useSortable } from "@dnd-kit/react/sortable"; import type { TPostStatusType } from "@feeblo/domain/post-status/schema"; import { formatPostStatus } from "@feeblo/post-ui/post-status"; +import { PostStatusIcon } from "@feeblo/post-ui/post-status-icon"; import { Badge } from "@feeblo/ui/badge"; import { Button } from "@feeblo/ui/button"; import { Menu, MenuItem, MenuPopup, MenuTrigger } from "@feeblo/ui/menu"; import { SkeletonLoader, SkeletonWrapper } from "@feeblo/ui/skeleton-loader"; import { toastManager } from "@feeblo/ui/toast"; import { cn } from "@feeblo/ui/utils"; -import { BoardIconMap } from "@feeblo/web-shared/board/constants"; import { hasPermission, PolicyGuard } from "@feeblo/web-shared/use-policy"; import { CheckmarkBadge01Icon, @@ -36,6 +36,7 @@ import { postStatusSections } from "../sections"; type StatusRow = { color?: string | null; + icon?: string | null; id: string; isDefault: boolean; label: string; @@ -261,7 +262,6 @@ function PostStatusRow({ data: { type: status.type }, }); - const Icon = BoardIconMap[status.type]; const label = status.label || formatPostStatus(status.type); /** @@ -318,7 +318,7 @@ function PostStatusRow({ className="inline-flex items-center justify-center" style={status.color ? { color: status.color } : undefined} > - +
diff --git a/apps/web/src/dashboard/features/post/components/post-activity-list.tsx b/apps/web/src/dashboard/features/post/components/post-activity-list.tsx index 94b5e79f9..e98ace640 100644 --- a/apps/web/src/dashboard/features/post/components/post-activity-list.tsx +++ b/apps/web/src/dashboard/features/post/components/post-activity-list.tsx @@ -2,6 +2,7 @@ import type { TContact } from "@feeblo/domain/contact/schema"; import type { TPostActivityKind } from "@feeblo/domain/post-activity/schema"; import type { TPostActivity } from "@feeblo/domain/post-activity/schema"; import { formatPostStatus } from "@feeblo/post-ui/post-status"; +import { PostStatusIcon } from "@feeblo/post-ui/post-status-icon"; import { ActivityTimeline, ActivityTimelineItem, @@ -10,7 +11,6 @@ import { cn } from "@feeblo/ui/utils"; import * as dayjs from "@feeblo/utils/dayjs"; import { BOARD_LANE_COLOR_MAP, - BoardIconMap, type BoardPostStatus, } from "@feeblo/web-shared/board/constants"; import { @@ -158,26 +158,32 @@ function getActivityDescription({ return descriptions[activity.kind]; } -type ActivityIcon = { icon: typeof FileAddIcon; color: string }; +type ActivityIcon = { + color: string; + icon?: typeof FileAddIcon; + statusIcon?: string | null; + statusType?: BoardPostStatus; +}; function getActivityIcon( activity: TPostActivity, - statusTypes: ReadonlyMap + statuses: ReadonlyMap ): ActivityIcon { if (activity.kind === "STATUS_CHANGED" && activity.nextValue) { - const statusType = statusTypes.get(activity.nextValue); + const status = statuses.get(activity.nextValue); - if (statusType) { + if (status) { return { - icon: BoardIconMap[statusType] ?? StatusIcon, - color: BOARD_LANE_COLOR_MAP[statusType] ?? "text-muted-foreground", + color: BOARD_LANE_COLOR_MAP[status.type] ?? "text-muted-foreground", + statusIcon: status.icon, + statusType: status.type, }; } } return { - icon: activityIconMap[activity.kind], color: "text-muted-foreground", + icon: activityIconMap[activity.kind], }; } @@ -240,8 +246,14 @@ export function PostActivityList({ [statuses] ); - const statusTypes = useMemo( - () => new Map(statuses.map((status) => [status.id, status.type])), + const statusMarks = useMemo( + () => + new Map( + statuses.map((status) => [ + status.id, + { icon: status.icon, type: status.type }, + ]) + ), [statuses] ); @@ -311,7 +323,8 @@ export function PostActivityList({ {activities.map((activity) => { const actorName = activity.actor.name ?? "Someone"; - const { icon, color } = getActivityIcon(activity, statusTypes); + const activityIcon = getActivityIcon(activity, statusMarks); + const { color } = activityIcon; const onBehalfMetadata = getOnBehalfMetadata(activity); const onBehalfSubject = onBehalfMetadata @@ -326,12 +339,22 @@ export function PostActivityList({ return (
diff --git a/packages/post-ui/src/roadmap/roadmap-lane-column.tsx b/packages/post-ui/src/roadmap/roadmap-lane-column.tsx index 65a1a02c1..fdfd9e14e 100644 --- a/packages/post-ui/src/roadmap/roadmap-lane-column.tsx +++ b/packages/post-ui/src/roadmap/roadmap-lane-column.tsx @@ -16,6 +16,7 @@ interface RoadmapLaneColumnProps { label?: string; name?: string; status?: RoadmapStatus; + statusIcon?: string | null; totalPosts?: number; } @@ -28,6 +29,7 @@ export function RoadmapLaneColumn({ label, name, status, + statusIcon, totalPosts, }: RoadmapLaneColumnProps) { const readableStatus = @@ -46,7 +48,10 @@ export function RoadmapLaneColumn({
- {icon ?? (status ? : null)} + {icon ?? + (status ? ( + + ) : null)}

{readableStatus}

{resolvedAction} diff --git a/packages/post-ui/src/roadmap/roadmap-status-icon.tsx b/packages/post-ui/src/roadmap/roadmap-status-icon.tsx index cbb0e2185..335e31f00 100644 --- a/packages/post-ui/src/roadmap/roadmap-status-icon.tsx +++ b/packages/post-ui/src/roadmap/roadmap-status-icon.tsx @@ -1,19 +1,21 @@ import { cn } from "@feeblo/ui/utils"; -import { - BOARD_LANE_COLOR_MAP, - BoardIconMap, -} from "@feeblo/web-shared/board/constants"; -import { HugeiconsIcon } from "@hugeicons/react"; +import { BOARD_LANE_COLOR_MAP } from "@feeblo/web-shared/board/constants"; +import { PostStatusIcon } from "../post-status-icon"; import type { RoadmapStatus } from "./types"; -export function RoadmapStatusIcon({ status }: { status: RoadmapStatus }) { - const Icon = BoardIconMap[status] ?? BoardIconMap.PLANNED; +export function RoadmapStatusIcon({ + icon, + status, +}: { + icon?: string | null; + status: RoadmapStatus; +}) { const color = BOARD_LANE_COLOR_MAP[status]; return ( - + ); } diff --git a/packages/post-ui/src/roadmap/types.ts b/packages/post-ui/src/roadmap/types.ts index f7b1bc387..6d59a8263 100644 --- a/packages/post-ui/src/roadmap/types.ts +++ b/packages/post-ui/src/roadmap/types.ts @@ -7,6 +7,7 @@ export type RoadmapColumnDefinition = { name: string; roadmapId: string; statusId: string; + statusIcon?: string | null; type: RoadmapStatus; label: string; }; @@ -17,6 +18,7 @@ export type RoadmapPost = { id: string; slug: string; status: RoadmapStatus; + statusIcon?: string | null; statusId: string; summary: string; title: string; @@ -33,5 +35,6 @@ export type RoadmapLane = { name?: string; posts: TPost[]; status: RoadmapStatus; + statusIcon?: string | null; statusId: string; }; diff --git a/packages/post-ui/src/roadmap/use-roadmap-data.ts b/packages/post-ui/src/roadmap/use-roadmap-data.ts index ec199b7b1..f3cb6390e 100644 --- a/packages/post-ui/src/roadmap/use-roadmap-data.ts +++ b/packages/post-ui/src/roadmap/use-roadmap-data.ts @@ -43,7 +43,13 @@ type PostRowLike = Pick< type PostStatusRowLike = Pick< TPostStatus, "id" | "label" | "organizationId" | "type" ->; +> & { + /** + * Optional so a collection fixture that predates the picker still satisfies + * the constraint; the production collection always carries it. + */ + icon?: string | null; +}; type RoadmapRowLike = Pick< TRoadmap, @@ -245,6 +251,7 @@ export function useRoadmapData< name: column.name, roadmapId: column.roadmapId, statusId: postStatus.id, + statusIcon: postStatus.icon ?? null, type: postStatus.type, label: postStatus.label, })) @@ -294,6 +301,7 @@ export function useRoadmapData< id: post.id, slug: post.slug, status: postStatus.type, + statusIcon: postStatus.icon ?? null, statusId: post.statusId, summary: post.excerpt, title: post.title, diff --git a/packages/post-ui/src/roadmap/utils.ts b/packages/post-ui/src/roadmap/utils.ts index cc3ce3b8a..84cea0a72 100644 --- a/packages/post-ui/src/roadmap/utils.ts +++ b/packages/post-ui/src/roadmap/utils.ts @@ -31,6 +31,7 @@ export function groupRoadmapPostsByStatus( name: column.name, posts: [], status: column.type, + statusIcon: column.statusIcon, statusId: column.statusId, }, ]) diff --git a/packages/ui/src/icon-picker/index.tsx b/packages/ui/src/icon-picker/index.tsx index e0d1380b1..7ec3734dd 100644 --- a/packages/ui/src/icon-picker/index.tsx +++ b/packages/ui/src/icon-picker/index.tsx @@ -22,7 +22,9 @@ import { type UIEvent as ReactUIEvent, } from "react"; +import { Button } from "../button"; import { Input } from "../input"; +import { Popover, PopoverPopup, PopoverTrigger } from "../popover"; import { cn } from "../utils"; import { loadIconPickerCatalogue, preloadIconPickerCatalogue } from "./data"; import { TABLER_FILLED_SYMBOL_PREFIX } from "./generated/tabler-filled-symbol-prefix"; @@ -49,6 +51,7 @@ import type { IconPickerDataCategory, IconPickerEmptyProps, IconPickerEmptyRenderProps, + IconPickerFieldProps, IconPickerIcon, IconPickerListCategoryHeaderProps, IconPickerListComponents, @@ -1544,9 +1547,67 @@ function TablerIcon({ ); } +function IconPickerField({ + className, + disabled, + fallbackIcon, + label = "Choose icon", + onChange, + value, +}: IconPickerFieldProps): ReactElement { + const [open, setOpen] = useState(false); + + const selected = + isString(value) && value.trim().length > 0 ? value : fallbackIcon; + + return ( + + preloadIconPickerCatalogue()} + onPointerEnter={() => preloadIconPickerCatalogue()} + type="button" + variant="outline" + /> + } + > + + {label} + + + { + onChange(icon.name); + setOpen(false); + }} + value={selected} + /> +
+ +
+
+
+ ); +} + const IconPicker = { ActiveIcon: IconPickerActiveIcon, Content: IconPickerContent, + Field: IconPickerField, Empty: IconPickerEmpty, Icon: TablerIcon, List: IconPickerList, @@ -1564,6 +1625,7 @@ const IconPicker = { export { IconPicker, IconPickerActiveIcon, + IconPickerField, IconPickerContent, IconPickerEmpty, IconPickerList, @@ -1586,6 +1648,7 @@ export type { IconPickerDataCategory, IconPickerDataRow, IconPickerEmptyProps, + IconPickerFieldProps, IconPickerIcon, IconPickerInteraction, IconPickerListCategoryHeaderProps, diff --git a/packages/ui/src/icon-picker/sprite.ts b/packages/ui/src/icon-picker/sprite.ts index cdd2c54fe..84aa0523e 100644 --- a/packages/ui/src/icon-picker/sprite.ts +++ b/packages/ui/src/icon-picker/sprite.ts @@ -1,8 +1,20 @@ import { useEffect, useSyncExternalStore } from "react"; -import spriteUrl from "./generated/tabler-filled-sprite.svg?url"; import type { IconPickerSpriteStatus } from "./types"; +/** + * The generated sprite as a Vite asset. + * + * `new URL(..., import.meta.url)` is resolved at build time into one emitted + * file, the same as a `?url` import, and it keeps the asset's type out of the + * package's ambient declarations: a consumer that imports the picker would + * otherwise need the `*.svg?url` declaration in its own program. + */ +const spriteUrl = new URL( + "./generated/tabler-filled-sprite.svg", + import.meta.url +).href; + const SPRITE_ATTRIBUTE = "data-icon-picker-sprite"; type Listener = () => void; diff --git a/packages/ui/src/icon-picker/types.ts b/packages/ui/src/icon-picker/types.ts index 87bdec131..974c02749 100644 --- a/packages/ui/src/icon-picker/types.ts +++ b/packages/ui/src/icon-picker/types.ts @@ -166,6 +166,25 @@ export type IconPickerActiveIconProps = { children: (props: IconPickerActiveIconRenderProps) => ReactNode; }; +/** + * The picker behind a trigger button, in a popover. + * + * A convenience composition rather than a fifth part: the picker itself does + * not own a popover, and the settings dialogs that select an entity icon would + * otherwise each repeat the same trigger, popup and preload wiring. `onChange` + * reports the Tabler name the caller stores. + */ +export type IconPickerFieldProps = { + className?: string; + disabled?: boolean; + /** The icon a null value renders and "Use default" restores. */ + fallbackIcon: string; + /** The trigger's visible text and accessible name. */ + label?: string; + onChange: (name: string) => void; + value: string | null | undefined; +}; + export type IconPickerContentProps = Omit & { /** * The message shown when a search has no matches. diff --git a/packages/web-shared/package.json b/packages/web-shared/package.json index 77bb39887..7cd071fbe 100644 --- a/packages/web-shared/package.json +++ b/packages/web-shared/package.json @@ -102,6 +102,10 @@ "types": "./src/board/constants.ts", "default": "./src/board/constants.ts" }, + "./icons/defaults": { + "types": "./src/icons/defaults.ts", + "default": "./src/icons/defaults.ts" + }, "./analytics-provider": { "types": "./src/lib/analytics-provider.tsx", "default": "./src/lib/analytics-provider.tsx" diff --git a/packages/web-shared/src/board/constants.ts b/packages/web-shared/src/board/constants.ts index 83837c416..153bacb3f 100644 --- a/packages/web-shared/src/board/constants.ts +++ b/packages/web-shared/src/board/constants.ts @@ -1,24 +1,15 @@ import type { TPostStatusType } from "@feeblo/domain/post-status/schema"; -import { - CancelCircleIcon, - CheckmarkCircle02Icon, - CircleIcon, - Clock01Icon, - DashedLineCircleIcon, - PauseCircleIcon, -} from "@hugeicons/core-free-icons"; export type BoardPostStatus = TPostStatusType; -export const BoardIconMap = { - CLOSED: CancelCircleIcon, - PENDING: PauseCircleIcon, - COMPLETED: CheckmarkCircle02Icon, - REVIEW: DashedLineCircleIcon, - PLANNED: Clock01Icon, - IN_PROGRESS: CircleIcon, -} satisfies Record; - +/** + * The colour a status lane paints its mark with. + * + * The mark itself is a Tabler name stored on the status; this map is only the + * lane's colour, which a workspace does not customise on the board surface. + * A status with no colour still reads as a status because the mark is the + * picker's, not this map's. + */ export const BOARD_LANE_COLOR_MAP = { // Muted, dark-safe hues model the low-saturation status language of Linear. PENDING: "text-neutral-500 dark:text-neutral-400", diff --git a/packages/web-shared/src/icons/defaults.test.ts b/packages/web-shared/src/icons/defaults.test.ts new file mode 100644 index 000000000..7127fc53b --- /dev/null +++ b/packages/web-shared/src/icons/defaults.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from "vitest"; + +import { + boardIconName, + DEFAULT_BOARD_ICON, + DEFAULT_HELP_CENTER_TOPIC_ICON, + helpCenterTopicIconName, + postStatusIconName, +} from "./defaults"; + +describe("entity icon defaults", () => { + it("uses the board default when no icon is stored", () => { + expect(boardIconName(null)).toBe(DEFAULT_BOARD_ICON); + expect(boardIconName("")).toBe(DEFAULT_BOARD_ICON); + expect(boardIconName("bolt")).toBe("bolt"); + }); + + it("uses the status type's default when the row has no icon", () => { + expect(postStatusIconName(null, "COMPLETED")).toBe("circle-check"); + expect(postStatusIconName("sparkles", "PENDING")).toBe("sparkles"); + }); + + it("uses the help-center default when no icon is stored", () => { + expect(helpCenterTopicIconName(null)).toBe(DEFAULT_HELP_CENTER_TOPIC_ICON); + expect(helpCenterTopicIconName("bug")).toBe("bug"); + }); +}); diff --git a/packages/web-shared/src/icons/defaults.ts b/packages/web-shared/src/icons/defaults.ts new file mode 100644 index 000000000..a36f02803 --- /dev/null +++ b/packages/web-shared/src/icons/defaults.ts @@ -0,0 +1,47 @@ +import type { TPostStatusType } from "@feeblo/domain/post-status/schema"; +import { isString } from "@feeblo/utils/runtime-kind"; + +/** + * The icon a board, status or help-center topic renders when it has none. + * + * The default lives on the client rather than in the database so an existing + * row can stay null and still draw something. The resolver only fills in a + * null or empty value; it does not validate a name against the catalogue, + * because the catalogue is code-split and not available synchronously. + */ +export const DEFAULT_BOARD_ICON = "layout-grid"; + +export const DEFAULT_HELP_CENTER_TOPIC_ICON = "lifebuoy"; + +/** + * One default per built-in status type. + * + * A workspace may replace any of these with a picked icon; this map is what a + * status created before the picker existed still shows, and what the status + * form pre-selects for a new status in that section. + */ +export const DEFAULT_POST_STATUS_ICONS = { + PENDING: "clock", + REVIEW: "eye", + PLANNED: "calendar-event", + IN_PROGRESS: "circle-dot", + COMPLETED: "circle-check", + CLOSED: "circle-x", +} satisfies Record; + +const resolveIconName = ( + icon: string | null | undefined, + fallback: string +): string => (isString(icon) && icon.trim().length > 0 ? icon : fallback); + +export const boardIconName = (icon: string | null | undefined): string => + resolveIconName(icon, DEFAULT_BOARD_ICON); + +export const helpCenterTopicIconName = ( + icon: string | null | undefined +): string => resolveIconName(icon, DEFAULT_HELP_CENTER_TOPIC_ICON); + +export const postStatusIconName = ( + icon: string | null | undefined, + type: TPostStatusType +): string => resolveIconName(icon, DEFAULT_POST_STATUS_ICONS[type]); From 2265245796dc215b0848a2a69f0aeb70b6527a2e Mon Sep 17 00:00:00 2001 From: nafees nazik Date: Wed, 18 Nov 2026 19:37:54 +0530 Subject: [PATCH 2/5] fix(icons): address review feedback on icon persistence and previews The picker now emits null for "Use default" so boards and statuses store no override until the user picks one; the client default is only a display fallback. Board updates accept partial payloads and the rename sheet writes the icon only when its field is dirty, so a concurrent change to another field is not overwritten. Status edit keeps a nullable stored icon, derives its fallback from the current section, and does not block unrelated edits. Drag previews take the target lane's icon and the roadmap preview is rebuilt from the latest lanes. Status fields resolve the icon from the current status list, names are trimmed, and the activity icon shape is a discriminated union. --- .../board-surface/board-grid-view.tsx | 1 + .../board/components/rename-board-dialog.tsx | 35 ++++++------ .../dashboard/features/board/shared-form.ts | 7 +-- .../components/help-center-topic-dialog.tsx | 4 +- .../components/post-status-create-dialog.tsx | 5 +- .../components/post-status-edit-dialog.tsx | 48 +++++++++------- .../post/components/post-activity-list.tsx | 26 ++++++--- .../roadmap/components/roadmap-board.tsx | 34 +++++++----- apps/web/src/dashboard/lib/collections.ts | 17 ++++-- packages/domain/src/board/handlers.ts | 13 +++-- packages/domain/src/board/policies.ts | 3 +- packages/domain/src/board/repository.ts | 4 +- packages/domain/src/board/schema.ts | 4 +- packages/post-ui/src/post-field.tsx | 55 +++++++++++-------- .../post-ui/src/roadmap/use-roadmap-data.ts | 5 +- packages/ui/src/icon-picker/index.tsx | 7 ++- packages/ui/src/icon-picker/types.ts | 5 +- packages/web-shared/src/icons/defaults.ts | 10 +++- 18 files changed, 164 insertions(+), 119 deletions(-) diff --git a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx index 305bfe9e3..5a7170700 100644 --- a/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx +++ b/apps/web/src/dashboard/features/board/components/board-surface/board-grid-view.tsx @@ -75,6 +75,7 @@ function movePostToColumn( { ...movedPost, status: targetStatus, + statusIcon: lane.statusIcon, statusId: targetLaneStatusId, }, ...lane.posts, diff --git a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx index a7eb40571..eb444779e 100644 --- a/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx +++ b/apps/web/src/dashboard/features/board/components/rename-board-dialog.tsx @@ -1,3 +1,4 @@ +import type { TBoard } from "@feeblo/domain/board/schema"; import { Button } from "@feeblo/ui/button"; import { useAppForm } from "@feeblo/ui/hooks/form"; import { IconPickerField } from "@feeblo/ui/icon-picker"; @@ -22,7 +23,7 @@ import { useOrganizationId } from "~/hooks/use-organization-id"; import { useDashboardCollections } from "~/providers/dashboard-collections-provider"; import { useRenameBoardDialogContext } from "../dialog-stores"; -import { type BoardFormValues, boardFormOpts } from "../shared-form"; +import { boardFormOpts } from "../shared-form"; import { BoardVisibilityField } from "./board-visibility-field"; export function RenameBoardDialog() { @@ -72,18 +73,8 @@ function RenameBoardForm() { return ; } -/** - * The row the edit sheet seeds from. - * - * `icon` is the stored nullable value, not the form's string: the form defaults - * it to the client's default, and the row itself is allowed to have never - * picked one. - */ -type RenameBoardRow = { - icon: string | null; - name: string; - visibility: BoardFormValues["visibility"]; -}; +/** The row the edit sheet seeds from. */ +type RenameBoardRow = Pick; function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { const organizationId = useOrganizationId(); @@ -96,18 +87,24 @@ function RenameBoardFormFields({ board }: { board: RenameBoardRow }) { ...boardFormOpts, defaultValues: { name: board.name, - icon: board.icon ?? DEFAULT_BOARD_ICON, + icon: board.icon, visibility: board.visibility, }, - onSubmit: async (data) => { + onSubmit: async ({ formApi, value }) => { try { - const boardSlug = slugify(data.value.name); + const boardSlug = slugify(value.name); + // A save that only renamed the board must not repoint the icon at the + // value this form opened with; a concurrent icon change would lose. + const iconIsDirty = formApi.getFieldMeta("icon")?.isDirty ?? false; const tx = boardCollection.update(boardId, (draft) => { - draft.name = data.value.name; - draft.icon = data.value.icon; - draft.visibility = data.value.visibility; + draft.name = value.name; + draft.visibility = value.visibility; draft.slug = boardSlug; + + if (iconIsDirty) { + draft.icon = value.icon; + } }); await tx.when("settled"); diff --git a/apps/web/src/dashboard/features/board/shared-form.ts b/apps/web/src/dashboard/features/board/shared-form.ts index 3a94420de..8003ba111 100644 --- a/apps/web/src/dashboard/features/board/shared-form.ts +++ b/apps/web/src/dashboard/features/board/shared-form.ts @@ -4,16 +4,15 @@ import { z } from "zod"; export const boardFormSchema = z.object({ name: z.string().trim().min(1, "Board name is required"), - icon: z.string().trim().min(1).max(64), + icon: z.string().trim().max(64).nullable(), visibility: z.enum(["PUBLIC", "PRIVATE"]), }); -export type BoardFormValues = z.infer; - export const boardFormOpts = formOptions({ defaultValues: { name: "", - icon: DEFAULT_BOARD_ICON, + // SAFETY: The form's icon is nullable; null means "use the client default". + icon: null as string | null, // SAFETY: The upstream source guarantees one of these values; the cast bridges an untyped API. visibility: "PUBLIC" as "PUBLIC" | "PRIVATE", }, diff --git a/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx b/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx index 2af02133d..26aab764a 100644 --- a/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx +++ b/apps/web/src/dashboard/features/help-center/components/help-center-topic-dialog.tsx @@ -225,7 +225,9 @@ function TopicFields({ field.handleChange(icon)} + onChange={(icon) => + field.handleChange(icon ?? DEFAULT_HELP_CENTER_TOPIC_ICON) + } value={field.state.value} /> )} diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx index d016cc9ee..02ba4634f 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-create-dialog.tsx @@ -60,13 +60,14 @@ function PostStatusCreateForm({ type }: { type: TPostStatusType }) { const form = useAppForm({ defaultValues: { color: DEFAULT_POST_STATUS_COLORS[type], - icon: DEFAULT_POST_STATUS_ICONS[type], + // SAFETY: The form's icon is nullable; null means "use the type default". + icon: null as string | null, label: "", }, validators: { onSubmit: z.object({ color: z.string(), - icon: z.string().trim().min(1).max(64), + icon: z.string().trim().max(64).nullable(), label: z.string().min(1).max(60), }), }, diff --git a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx index 85f6686f9..3556381c1 100644 --- a/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx +++ b/apps/web/src/dashboard/features/post-status/components/post-status-edit-dialog.tsx @@ -1,4 +1,7 @@ -import type { TPostStatusType } from "@feeblo/domain/post-status/schema"; +import type { + TPostStatus, + TPostStatusType, +} from "@feeblo/domain/post-status/schema"; import { Button } from "@feeblo/ui/button"; import { Dialog, @@ -73,12 +76,9 @@ export function PostStatusEditDialog() { ); } -type EditableStatus = { - color: string | null; - icon: string | null; - id: string; - label: string; - type: TPostStatusType; +type EditableStatus = Pick & { + /** The projection normalizes the optional column to an explicit null. */ + color: Exclude; }; function PostStatusEditForm({ status }: { status: EditableStatus }) { @@ -88,14 +88,16 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { const form = useAppForm({ defaultValues: { color: status.color, - icon: status.icon ?? DEFAULT_POST_STATUS_ICONS[status.type], + icon: status.icon, label: status.label, type: status.type, }, validators: { onSubmit: z.object({ color: z.string().nullable(), - icon: z.string().trim().min(1).max(64), + // No length rule here: an untouched stored icon must not block an + // unrelated edit. The picker can only emit catalogue names. + icon: z.string().trim().nullable(), label: z.string().min(1).max(60), type: z.enum([ "PENDING", @@ -171,19 +173,23 @@ function PostStatusEditForm({ status }: { status: EditableStatus }) { )} - - {(field) => ( - - Icon - field.handleChange(icon)} - value={field.state.value} - /> - + state.values.type}> + {(type) => ( + + {(field) => ( + + Icon + field.handleChange(icon)} + value={field.state.value} + /> + + )} + )} - + {(field) => ( diff --git a/apps/web/src/dashboard/features/post/components/post-activity-list.tsx b/apps/web/src/dashboard/features/post/components/post-activity-list.tsx index e98ace640..a5cabe6f4 100644 --- a/apps/web/src/dashboard/features/post/components/post-activity-list.tsx +++ b/apps/web/src/dashboard/features/post/components/post-activity-list.tsx @@ -158,12 +158,18 @@ function getActivityDescription({ return descriptions[activity.kind]; } -type ActivityIcon = { - color: string; - icon?: typeof FileAddIcon; - statusIcon?: string | null; - statusType?: BoardPostStatus; -}; +type ActivityIcon = + | { + color: string; + kind: "status"; + statusIcon: string | null; + statusType: BoardPostStatus; + } + | { + color: string; + icon: typeof FileAddIcon; + kind: "generic"; + }; function getActivityIcon( activity: TPostActivity, @@ -175,6 +181,7 @@ function getActivityIcon( if (status) { return { color: BOARD_LANE_COLOR_MAP[status.type] ?? "text-muted-foreground", + kind: "status", statusIcon: status.icon, statusType: status.type, }; @@ -183,7 +190,8 @@ function getActivityIcon( return { color: "text-muted-foreground", - icon: activityIconMap[activity.kind], + icon: activityIconMap[activity.kind] ?? FileAddIcon, + kind: "generic", }; } @@ -339,7 +347,7 @@ export function PostActivityList({ return (