Skip to content

Commit e517fae

Browse files
committed
fix(templates): restore full category enum, gate share UI via explicit list
Uncomment the remaining templateResourceCategories now that their adapters are implemented, and move the share-flow restriction from the enum itself to an explicit AVAILABLE_CATEGORIES list (flows, tags, customFields) in template-contents-card.tsx so narrowing what's shareable no longer requires touching the enum backing the pgEnum and adapter registry. Also fixes message-item-avatar.test.tsx, which was pulling in a live pg Pool via MediaLibraryTrigger's server-query imports under vitest.
1 parent 1a3a776 commit e517fae

3 files changed

Lines changed: 53 additions & 30 deletions

File tree

apps/builder/__tests__/message-item-avatar.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ vi.mock("next-intl", () => ({
99
useTranslations: () => (key: string) => key,
1010
}))
1111

12+
// MessageItem -> MessageActions -> MediaLibraryTrigger, which imports its
13+
// `"use server"` query modules at module scope. Next.js rewrites those to RPC
14+
// stubs, but vitest evaluates them for real, dragging in the
15+
// `@chatbotx.io/business` barrel and a live pg Pool — which throws on
16+
// `env.DATABASE_URL` under the browser-conditions preset. Stubbing the
17+
// trigger cuts that chain and keeps this test about avatar gating.
18+
vi.mock("@/features/media-library/components/media-library-trigger", () => ({
19+
MediaLibraryTrigger: () => null,
20+
}))
21+
1222
// Base UI's Avatar.Image only mounts once the underlying <img> actually
1323
// fires a load/error event (see useImageLoadingStatus), which jsdom never
1424
// dispatches for a src that isn't really fetched. Mock it down to plain

apps/builder/src/features/templates/components/template-contents-card.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
"use client"
22

33
import type { TemplateCategory } from "@chatbotx.io/database/partials"
4-
import {
5-
templateCategories,
6-
templateResourceCategories,
7-
} from "@chatbotx.io/database/partials"
4+
import { templateCategories } from "@chatbotx.io/database/partials"
85
import {
96
Accordion,
107
AccordionContent,
@@ -28,27 +25,43 @@ import { EMPTY_SELECTION, selectionCount } from "../lib/selection"
2825
import { CategoryResourceList } from "./category-resource-list"
2926

3027
/**
31-
* Categories with a working `listSelectableResources` picker query +
32-
* `ResourceCollector.resolveIds`/`collect` — derived from
33-
* `templateResourceCategories` (`packages/database/src/partials/template.ts`)
34-
* so this list cannot drift from the adapter registry it mirrors: every
35-
* resource category has an adapter (`registry.ts`'s
36-
* `satisfies Record<TemplateResourceCategory, ResourceAdapter>` with no
37-
* `Partial` guarantees that at compile time), so every resource category is
38-
* available here too. `tags`/`customFields` are added on top since those two
39-
* manifest-only categories also have their own picker + ownership check
40-
* (`snapshot.service.ts`'s inline `assertIdsBelongToWorkspace` path).
41-
* `productCategories` stays excluded — it is never independently selectable;
42-
* a product's category comes along automatically via `productsAdapter`'s
43-
* collector.
28+
* Categories currently exposed for sharing. This is a deliberate **product**
29+
* restriction, not a technical one: every category in `ALL_CATEGORIES` still
30+
* has a working adapter and picker query (`registry.ts` enforces adapter
31+
* completeness at compile time via
32+
* `satisfies Record<TemplateResourceCategory, ResourceAdapter>`), so the rest
33+
* are fully implemented — they are just held back from the share flow for now
34+
* and render disabled with a "Coming soon" badge.
35+
*
36+
* Kept as an explicit list rather than derived from
37+
* `templateResourceCategories` so that narrowing what users can share never
38+
* requires touching the enum: that enum feeds a `pgEnum`
39+
* (`schema/template-installed-resource.ts`) and the adapter registry, so
40+
* editing it to gate the UI breaks the build and drifts from the database.
41+
* To release a category, add it back to this array — nothing else.
42+
*
43+
* `productCategories` is excluded for a different, permanent reason: it is
44+
* never independently selectable — a product's category comes along
45+
* automatically via `productsAdapter`'s collector.
4446
*/
4547
const AVAILABLE_CATEGORIES: readonly TemplateCategory[] = [
46-
...templateResourceCategories.options,
48+
"flows",
4749
"tags",
4850
"customFields",
4951
]
5052

51-
const ALL_CATEGORIES: readonly TemplateCategory[] = templateCategories.options
53+
/**
54+
* Display order: the available categories first, in the order above, then
55+
* every remaining category. The tail is derived from `templateCategories`
56+
* rather than hand-listed so a newly added category still shows up here (as
57+
* "Coming soon") instead of silently vanishing from the form.
58+
*/
59+
const ALL_CATEGORIES: readonly TemplateCategory[] = [
60+
...AVAILABLE_CATEGORIES,
61+
...templateCategories.options.filter(
62+
(category) => !AVAILABLE_CATEGORIES.includes(category),
63+
),
64+
]
5265

5366
type TemplateContentsCardProps = {
5467
workspaceId: string

packages/database/src/partials/template.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ import { z } from "zod"
1818
export const templateManifestOnlyCategories = z.enum([
1919
"customFields",
2020
"tags",
21-
// "productCategories",
21+
"productCategories",
2222
])
2323
export type TemplateManifestOnlyCategory = z.infer<
2424
typeof templateManifestOnlyCategories
2525
>
2626

2727
export const templateResourceCategories = z.enum([
2828
"flows",
29-
// "products",
30-
// "aiFunctions",
31-
// "aiAgents",
32-
// "calendars",
33-
// "webchats",
34-
// "keywords",
35-
// "entryPointLinks",
36-
// "triggers",
37-
// "fbCommentAutomations",
38-
// "settings",
29+
"products",
30+
"aiFunctions",
31+
"aiAgents",
32+
"calendars",
33+
"webchats",
34+
"keywords",
35+
"entryPointLinks",
36+
"triggers",
37+
"fbCommentAutomations",
38+
"settings",
3939
])
4040
export type TemplateResourceCategory = z.infer<
4141
typeof templateResourceCategories

0 commit comments

Comments
 (0)