@mohasinac/appkit 4.57.0 → 4.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.build-stamp.json +4 -4
- package/dist/_internal/server/features/beys/data.d.ts +44 -0
- package/dist/_internal/server/features/beys/data.js +107 -0
- package/dist/_internal/server/features/beys/og.d.ts +42 -0
- package/dist/_internal/server/features/beys/og.js +89 -0
- package/dist/_internal/server/features/parts/data.js +3 -2
- package/dist/_internal/shared/actions/action-registry.d.ts +1 -1
- package/dist/_internal/shared/actions/action-registry.js +86 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +1 -0
- package/dist/constants/api-endpoints.d.ts +12 -0
- package/dist/constants/api-endpoints.js +10 -0
- package/dist/constants/field-names.d.ts +46 -0
- package/dist/constants/field-names.js +46 -0
- package/dist/features/admin/components/AdminBeysView.d.ts +27 -0
- package/dist/features/admin/components/AdminBeysView.js +178 -0
- package/dist/features/admin/components/AdminPartsView.d.ts +27 -0
- package/dist/features/admin/components/AdminPartsView.js +160 -0
- package/dist/features/admin/components/OwnerQuickActions.d.ts +19 -2
- package/dist/features/admin/components/OwnerQuickActions.js +31 -3
- package/dist/features/admin/components/RecordOwnerQuickActions.d.ts +31 -0
- package/dist/features/admin/components/RecordOwnerQuickActions.js +128 -0
- package/dist/features/admin/components/ReferenceRecordEditor.d.ts +45 -0
- package/dist/features/admin/components/ReferenceRecordEditor.js +153 -0
- package/dist/features/admin/schemas/firestore.d.ts +1 -1
- package/dist/features/auctions/components/MarketplaceAuctionCard.js +15 -2
- package/dist/features/auth/permissions/constants.d.ts +1 -1
- package/dist/features/auth/permissions/constants.js +12 -1
- package/dist/features/beys/components/BeyDetailPageView.d.ts +50 -0
- package/dist/features/beys/components/BeyDetailPageView.js +98 -0
- package/dist/features/beys/schemas/firestore.d.ts +417 -0
- package/dist/features/beys/schemas/firestore.js +65 -0
- package/dist/features/blog/components/BlogFeaturedCard.js +15 -2
- package/dist/features/blog/components/BlogPostView.js +2 -2
- package/dist/features/categories/components/BrandDetailPageView.js +4 -2
- package/dist/features/categories/components/BundleDetailView.js +2 -2
- package/dist/features/categories/components/CategoryDetailPageView.js +36 -3
- package/dist/features/categories/components/CategoryGrid.js +24 -2
- package/dist/features/categories/components/FranchiseDetailPageView.js +2 -3
- package/dist/features/events/components/EventCard.js +15 -2
- package/dist/features/grouped/components/GroupedListingDetailView.js +2 -3
- package/dist/features/homepage/components/CustomCardsSection.js +67 -50
- package/dist/features/homepage/components/ShopByCategorySection.js +23 -10
- package/dist/features/homepage/schemas/index.d.ts +10 -10
- package/dist/features/parts/components/PartDetailPageView.js +5 -3
- package/dist/features/parts/components/PartsSearchBox.js +79 -4
- package/dist/features/parts/schemas/admin-edit.d.ts +81 -0
- package/dist/features/parts/schemas/admin-edit.js +89 -0
- package/dist/features/parts/schemas/firestore.d.ts +2 -1
- package/dist/features/pre-orders/components/MarketplacePreorderCard.js +15 -2
- package/dist/features/products/components/MarketplaceBundleCard.js +15 -2
- package/dist/features/products/components/MarketplacePrizeDrawCard.js +15 -2
- package/dist/features/products/components/ProductGrid.js +18 -2
- package/dist/features/products/schemas/firestore.d.ts +18 -0
- package/dist/features/seller/components/CategoryInlineSelect.d.ts +10 -1
- package/dist/features/seller/components/CategoryInlineSelect.js +53 -5
- package/dist/features/seller/components/SellerProductShell.d.ts +39 -0
- package/dist/features/seller/components/SellerProductShell.js +31 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.js +13 -0
- package/dist/next/routing/route-map.d.ts +13 -1
- package/dist/next/routing/route-map.js +37 -0
- package/dist/schemas/registry.d.ts +6 -6
- package/dist/seed/_helpers/category-parts-glossary-map.js +38 -38
- package/dist/seed/_helpers/category-parts.js +39 -39
- package/dist/seed/bey-products-seed-data.d.ts +18 -0
- package/dist/seed/bey-products-seed-data.js +18011 -0
- package/dist/seed/beys/chunk0.d.ts +17 -0
- package/dist/seed/beys/chunk0.js +36733 -0
- package/dist/seed/beys/chunk1.d.ts +17 -0
- package/dist/seed/beys/chunk1.js +35728 -0
- package/dist/seed/beys/chunk2.d.ts +17 -0
- package/dist/seed/beys/chunk2.js +35857 -0
- package/dist/seed/beys/chunk3.d.ts +17 -0
- package/dist/seed/beys/chunk3.js +34476 -0
- package/dist/seed/beys-seed-data.d.ts +18 -0
- package/dist/seed/beys-seed-data.js +11 -0
- package/dist/seed/homepage-sections-seed-data.js +16 -0
- package/dist/seed/index.d.ts +2 -0
- package/dist/seed/index.js +3 -0
- package/dist/seed/media-assets-seed-data.js +4 -4
- package/dist/seed/products-catalogue/chunk0.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk0.js +7262 -0
- package/dist/seed/products-catalogue/chunk1.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk1.js +7290 -0
- package/dist/seed/products-catalogue/chunk10.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk10.js +7290 -0
- package/dist/seed/products-catalogue/chunk11.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk11.js +7005 -0
- package/dist/seed/products-catalogue/chunk12.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk12.js +7002 -0
- package/dist/seed/products-catalogue/chunk13.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk13.js +7002 -0
- package/dist/seed/products-catalogue/chunk14.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk14.js +7002 -0
- package/dist/seed/products-catalogue/chunk15.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk15.js +7002 -0
- package/dist/seed/products-catalogue/chunk16.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk16.js +7002 -0
- package/dist/seed/products-catalogue/chunk17.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk17.js +7002 -0
- package/dist/seed/products-catalogue/chunk18.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk18.js +4398 -0
- package/dist/seed/products-catalogue/chunk2.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk2.js +7268 -0
- package/dist/seed/products-catalogue/chunk3.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk3.js +7264 -0
- package/dist/seed/products-catalogue/chunk4.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk4.js +7268 -0
- package/dist/seed/products-catalogue/chunk5.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk5.js +7258 -0
- package/dist/seed/products-catalogue/chunk6.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk6.js +7268 -0
- package/dist/seed/products-catalogue/chunk7.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk7.js +7311 -0
- package/dist/seed/products-catalogue/chunk8.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk8.js +7304 -0
- package/dist/seed/products-catalogue/chunk9.d.ts +12 -0
- package/dist/seed/products-catalogue/chunk9.js +7309 -0
- package/dist/seed/products-catalogue-seed-data.d.ts +2 -22
- package/dist/seed/products-catalogue-seed-data.js +58 -86382
- package/dist/seed/seed-purpose.js +9 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +8 -0
- package/dist/styles.css +468 -1
- package/dist/tailwind-utilities.css +1 -1
- package/dist/ui/components/PosterCard.d.ts +99 -0
- package/dist/ui/components/PosterCard.js +109 -0
- package/dist/ui/components/PosterCard.style.css +466 -0
- package/dist/ui/components/index.style.css +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +1 -1
- package/scripts/seed-cli.mjs +108 -1
|
@@ -35,13 +35,88 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
35
35
|
import React from "react";
|
|
36
36
|
import { Div, Input, Stack, Text, TextLink } from "../../../ui/index.js";
|
|
37
37
|
import { useSiteSearch } from "../../search/hooks/useSiteSearch.js";
|
|
38
|
+
import { useUrlTable } from "../../../react/hooks/useUrlTable.js";
|
|
39
|
+
import { TABLE_KEYS } from "../../../constants/table-keys.js";
|
|
38
40
|
/** Only this slice of the index. See `resolveEntity`'s `types` parameter. */
|
|
39
41
|
const PART_TYPES = ["part"];
|
|
40
42
|
/** Stable identity — a `useMemo` dependency inside the hook. */
|
|
41
43
|
const partLabel = () => "Parts";
|
|
42
44
|
export function PartsSearchBox({ indexEnabled, placeholder = "Search parts by name or code — RF, 105, Rubber Flat…", limit = 10, }) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
/*
|
|
46
|
+
* ── 🛑 THE QUERY LIVES IN THE URL, SO A SEARCH IS SHAREABLE ──────────────
|
|
47
|
+
*
|
|
48
|
+
* This was `React.useState("")`, which meant typing filtered the list and
|
|
49
|
+
* left the address bar on `/parts`. Every detail page here is a real slug
|
|
50
|
+
* (`/parts/{classification}/{code}`, `/beys/{slug}`) and every other listing
|
|
51
|
+
* surface puts its state in the URL — `/search?q=…` reads `searchParams`
|
|
52
|
+
* server-side, and the category pages go as far as path segments
|
|
53
|
+
* (`/categories/{slug}/{tab}/sort/{sortKey}/page/{page}`). A client-local
|
|
54
|
+
* box was the one surface where you could not send someone what you were
|
|
55
|
+
* looking at.
|
|
56
|
+
*
|
|
57
|
+
* `useUrlTable` is the mechanism, not a second one invented here: it owns
|
|
58
|
+
* `router.replace()`, uses replace rather than push so typing does not fill
|
|
59
|
+
* the back button, and `TABLE_KEYS.QUERY` is the same `q` the rest of the
|
|
60
|
+
* app reads.
|
|
61
|
+
*
|
|
62
|
+
* 🛑 TWO pieces of state, deliberately, and they are not redundant. `draft`
|
|
63
|
+
* drives the input so a keystroke is never waiting on a navigation; the URL
|
|
64
|
+
* is the shareable record, written on a debounce. Driving the input straight
|
|
65
|
+
* from `searchParams` makes every character a round trip through the router
|
|
66
|
+
* and the field feels broken on a slow render.
|
|
67
|
+
*
|
|
68
|
+
* 🛑 `useSearchParams` requires a `<Suspense>` ancestor or the build fails
|
|
69
|
+
* on prerender (Root Cause #17b). The root locale layout has one, which is
|
|
70
|
+
* what the ~246 comments citing that pattern are about.
|
|
71
|
+
*/
|
|
72
|
+
/*
|
|
73
|
+
* 🛑 DESTRUCTURED, because `useUrlTable` returns a fresh object literal every
|
|
74
|
+
* render while the callbacks inside it are `useCallback`-memoised. Depending
|
|
75
|
+
* on `table` would make the effect below re-run on every render; depending on
|
|
76
|
+
* `set`/`clear` is stable. Same trap as the `loadOptions` identity bug in
|
|
77
|
+
* `PaginatedSelect`, where an unstable function re-triggered a fetch effect.
|
|
78
|
+
*/
|
|
79
|
+
const { get, set, clear } = useUrlTable();
|
|
80
|
+
const urlQuery = get(TABLE_KEYS.QUERY) ?? "";
|
|
81
|
+
const [draft, setDraft] = React.useState(urlQuery);
|
|
82
|
+
/*
|
|
83
|
+
* 🛑 SEEDED FROM THE URL, not `false`.
|
|
84
|
+
*
|
|
85
|
+
* `useSiteSearch` only fetches the index when `active`, which previously
|
|
86
|
+
* meant "the user has focused the box". Arriving on `/parts?q=rubber-flat`
|
|
87
|
+
* from a shared link, `active` would be false — so the query would sit in
|
|
88
|
+
* the field and in the address bar having searched NOTHING until the visitor
|
|
89
|
+
* clicked into the input. That defeats the entire reason for putting the
|
|
90
|
+
* query in the URL, and it is the kind of gap that looks like the link
|
|
91
|
+
* "didn't work" rather than like a missing fetch.
|
|
92
|
+
*/
|
|
93
|
+
const [active, setActive] = React.useState(urlQuery.length > 0);
|
|
94
|
+
/*
|
|
95
|
+
* Back/forward and a shared link both change the URL without touching the
|
|
96
|
+
* input, so the draft follows the URL when the URL moves on its own.
|
|
97
|
+
* Guarded on inequality — without that this fights the user's typing.
|
|
98
|
+
*/
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
setDraft((prev) => (prev === urlQuery ? prev : urlQuery));
|
|
101
|
+
}, [urlQuery]);
|
|
102
|
+
/*
|
|
103
|
+
* 🛑 Debounced, because `router.replace` on every keystroke is a navigation
|
|
104
|
+
* per character. 300ms is the same order the rest of the app uses for a
|
|
105
|
+
* search field, and the cleanup makes the last keystroke the one that wins.
|
|
106
|
+
*/
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (draft === urlQuery)
|
|
109
|
+
return;
|
|
110
|
+
const t = setTimeout(() => {
|
|
111
|
+
if (draft)
|
|
112
|
+
set(TABLE_KEYS.QUERY, draft);
|
|
113
|
+
else
|
|
114
|
+
clear([TABLE_KEYS.QUERY]);
|
|
115
|
+
}, 300);
|
|
116
|
+
return () => clearTimeout(t);
|
|
117
|
+
}, [draft, urlQuery, set, clear]);
|
|
118
|
+
/* The index is searched on the URL's value — the thing that is shareable. */
|
|
119
|
+
const query = urlQuery;
|
|
45
120
|
const { status, result } = useSiteSearch(query, {
|
|
46
121
|
active,
|
|
47
122
|
indexEnabled,
|
|
@@ -50,8 +125,8 @@ export function PartsSearchBox({ indexEnabled, placeholder = "Search parts by na
|
|
|
50
125
|
});
|
|
51
126
|
const hits = result?.groups[0]?.hits ?? [];
|
|
52
127
|
const typed = query.trim().length > 0;
|
|
53
|
-
return (_jsxs(Stack, { gap: "sm", className: "min-w-0", children: [_jsx(Input, { type: "search", value:
|
|
128
|
+
return (_jsxs(Stack, { gap: "sm", className: "min-w-0", children: [_jsx(Input, { type: "search", value: draft, placeholder: placeholder, "aria-label": "Search parts", onFocus: () => setActive(true), onChange: (event) => {
|
|
54
129
|
setActive(true);
|
|
55
|
-
|
|
130
|
+
setDraft(event.target.value);
|
|
56
131
|
} }), typed && status === "loading" && _jsx(Text, { color: "muted", children: "Searching\u2026" }), typed && (status === "failed" || status === "disabled") && (_jsx(Text, { size: "sm", color: "muted", children: "Part search is unavailable right now \u2014 browse by classification below." })), typed && status === "ready" && hits.length === 0 && (_jsx(Text, { color: "muted", children: "No part matches that name or code." })), hits.length > 0 && (_jsx(Stack, { gap: "xs", className: "min-w-0", children: hits.slice(0, limit).map((hit) => (_jsxs(Div, { surface: "card", padding: "sm", rounded: "md", border: "subtle", children: [_jsx(TextLink, { href: hit.href, children: hit.title }), hit.detail && (_jsx(Text, { size: "xs", color: "muted", children: hit.detail }))] }, hit.id))) }))] }));
|
|
57
132
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field-level protection for hand-corrections to GENERATED reference data.
|
|
3
|
+
*
|
|
4
|
+
* ── 🛑 THE PROBLEM THIS SOLVES ────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* `partGlossary` (2,488 rows) and `beys` (1,988) are produced by committed
|
|
7
|
+
* generators from a crawled corpus, and `appkit-seed load` writes them with
|
|
8
|
+
* `set(doc, { merge: true })`. A merge-write overwrites every key present in
|
|
9
|
+
* the payload — so an admin who corrects a wrong extracted weight loses that
|
|
10
|
+
* correction on the next reseed, silently, and the row goes back to being
|
|
11
|
+
* wrong while `appkit-seed status` reports the collection perfectly in sync
|
|
12
|
+
* (it counts ids, and the id did not change).
|
|
13
|
+
*
|
|
14
|
+
* That is not hypothetical for this dataset. This session alone found five
|
|
15
|
+
* wrong claims in the source corpus — an inverted tip transition, a mode that
|
|
16
|
+
* was actually launch spin direction, a mechanism on the wrong part, a part
|
|
17
|
+
* with no modes at all, and a part named "Duo:Dual" that is Delta Drive. A
|
|
18
|
+
* hand-correction is the fast path for exactly those, and it has to survive.
|
|
19
|
+
*
|
|
20
|
+
* ── 🛑 FIELD-LEVEL, NOT ROW-LEVEL ────────────────────────────────────────
|
|
21
|
+
*
|
|
22
|
+
* The obvious shape is one boolean meaning "do not touch this row". It is
|
|
23
|
+
* wrong: freezing a whole row because somebody fixed one weight means the row
|
|
24
|
+
* stops receiving every genuine improvement the generator makes afterwards —
|
|
25
|
+
* a better description, a newly resolved part id, a corrected release date.
|
|
26
|
+
* The row quietly falls out of the dataset's own maintenance.
|
|
27
|
+
*
|
|
28
|
+
* So `adminEditedFields` names the keys a human owns. The loader strips
|
|
29
|
+
* exactly those from its payload and writes everything else, which means a
|
|
30
|
+
* corrected weight and an improved description can both be true at once.
|
|
31
|
+
*
|
|
32
|
+
* `adminEdited` is a plain boolean beside it purely so the loader can find
|
|
33
|
+
* these rows with ONE equality query per collection instead of reading all
|
|
34
|
+
* 4,476 documents to discover the handful that matter. `array-contains` on
|
|
35
|
+
* `adminEditedFields` cannot answer "has any value", and an `orderBy` or `!=`
|
|
36
|
+
* on it would silently exclude every row that lacks the field — which is all
|
|
37
|
+
* of them (Root Cause #100).
|
|
38
|
+
*
|
|
39
|
+
* 🛑 KEEP THE TWO IN SYNC. `adminEdited` is `adminEditedFields.length > 0`.
|
|
40
|
+
* Writing one without the other either hides a protected row from the loader
|
|
41
|
+
* (so the edit is lost anyway) or makes the loader fetch a row with nothing to
|
|
42
|
+
* protect. `applyAdminEdit` is the only function that should set either.
|
|
43
|
+
*/
|
|
44
|
+
/** The fields a human has taken ownership of on one generated row. */
|
|
45
|
+
export interface AdminEditableRecord {
|
|
46
|
+
/**
|
|
47
|
+
* `true` iff `adminEditedFields` is non-empty. Exists ONLY so the seed
|
|
48
|
+
* loader can find protected rows with one indexed equality.
|
|
49
|
+
*/
|
|
50
|
+
adminEdited?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Keys the generator must not overwrite. Dot paths are NOT supported — a
|
|
53
|
+
* nested object is owned whole, because a merge-write replaces a map wholesale
|
|
54
|
+
* and protecting one leaf of it is not something `{ merge: true }` can express.
|
|
55
|
+
*/
|
|
56
|
+
adminEditedFields?: string[];
|
|
57
|
+
/** When the most recent hand-edit landed. Audit trail, never read by logic. */
|
|
58
|
+
adminEditedAt?: Date;
|
|
59
|
+
/** Who. The Auth UID, never a name — this travels into no public projection. */
|
|
60
|
+
adminEditedBy?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Merge a hand-edit into a record, keeping the two protection fields honest.
|
|
64
|
+
*
|
|
65
|
+
* Returns the patch to write — the caller's changed fields plus the updated
|
|
66
|
+
* ownership set. 🛑 Ownership is CUMULATIVE: editing the weight today and the
|
|
67
|
+
* description tomorrow must leave both protected, so the existing set is
|
|
68
|
+
* unioned rather than replaced.
|
|
69
|
+
*/
|
|
70
|
+
export declare function applyAdminEdit<TChanges extends object>(existing: Pick<AdminEditableRecord, "adminEditedFields"> | null | undefined, changes: TChanges, actorUid: string): TChanges & Required<Pick<AdminEditableRecord, "adminEdited" | "adminEditedFields">> & {
|
|
71
|
+
adminEditedAt: Date;
|
|
72
|
+
adminEditedBy: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Strip the fields a human owns out of a generator payload.
|
|
76
|
+
*
|
|
77
|
+
* Used by `appkit/scripts/seed-cli.mjs`. Exported from here rather than
|
|
78
|
+
* duplicated there so the rule has one definition — the CLI is `.mjs` and
|
|
79
|
+
* reads this through the built package, the same way it reads the seed data.
|
|
80
|
+
*/
|
|
81
|
+
export declare function stripAdminOwnedFields<T extends object>(payload: T, ownedFields: readonly string[] | undefined): Partial<T>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field-level protection for hand-corrections to GENERATED reference data.
|
|
3
|
+
*
|
|
4
|
+
* ── 🛑 THE PROBLEM THIS SOLVES ────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* `partGlossary` (2,488 rows) and `beys` (1,988) are produced by committed
|
|
7
|
+
* generators from a crawled corpus, and `appkit-seed load` writes them with
|
|
8
|
+
* `set(doc, { merge: true })`. A merge-write overwrites every key present in
|
|
9
|
+
* the payload — so an admin who corrects a wrong extracted weight loses that
|
|
10
|
+
* correction on the next reseed, silently, and the row goes back to being
|
|
11
|
+
* wrong while `appkit-seed status` reports the collection perfectly in sync
|
|
12
|
+
* (it counts ids, and the id did not change).
|
|
13
|
+
*
|
|
14
|
+
* That is not hypothetical for this dataset. This session alone found five
|
|
15
|
+
* wrong claims in the source corpus — an inverted tip transition, a mode that
|
|
16
|
+
* was actually launch spin direction, a mechanism on the wrong part, a part
|
|
17
|
+
* with no modes at all, and a part named "Duo:Dual" that is Delta Drive. A
|
|
18
|
+
* hand-correction is the fast path for exactly those, and it has to survive.
|
|
19
|
+
*
|
|
20
|
+
* ── 🛑 FIELD-LEVEL, NOT ROW-LEVEL ────────────────────────────────────────
|
|
21
|
+
*
|
|
22
|
+
* The obvious shape is one boolean meaning "do not touch this row". It is
|
|
23
|
+
* wrong: freezing a whole row because somebody fixed one weight means the row
|
|
24
|
+
* stops receiving every genuine improvement the generator makes afterwards —
|
|
25
|
+
* a better description, a newly resolved part id, a corrected release date.
|
|
26
|
+
* The row quietly falls out of the dataset's own maintenance.
|
|
27
|
+
*
|
|
28
|
+
* So `adminEditedFields` names the keys a human owns. The loader strips
|
|
29
|
+
* exactly those from its payload and writes everything else, which means a
|
|
30
|
+
* corrected weight and an improved description can both be true at once.
|
|
31
|
+
*
|
|
32
|
+
* `adminEdited` is a plain boolean beside it purely so the loader can find
|
|
33
|
+
* these rows with ONE equality query per collection instead of reading all
|
|
34
|
+
* 4,476 documents to discover the handful that matter. `array-contains` on
|
|
35
|
+
* `adminEditedFields` cannot answer "has any value", and an `orderBy` or `!=`
|
|
36
|
+
* on it would silently exclude every row that lacks the field — which is all
|
|
37
|
+
* of them (Root Cause #100).
|
|
38
|
+
*
|
|
39
|
+
* 🛑 KEEP THE TWO IN SYNC. `adminEdited` is `adminEditedFields.length > 0`.
|
|
40
|
+
* Writing one without the other either hides a protected row from the loader
|
|
41
|
+
* (so the edit is lost anyway) or makes the loader fetch a row with nothing to
|
|
42
|
+
* protect. `applyAdminEdit` is the only function that should set either.
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Merge a hand-edit into a record, keeping the two protection fields honest.
|
|
46
|
+
*
|
|
47
|
+
* Returns the patch to write — the caller's changed fields plus the updated
|
|
48
|
+
* ownership set. 🛑 Ownership is CUMULATIVE: editing the weight today and the
|
|
49
|
+
* description tomorrow must leave both protected, so the existing set is
|
|
50
|
+
* unioned rather than replaced.
|
|
51
|
+
*/
|
|
52
|
+
export function applyAdminEdit(existing, changes, actorUid) {
|
|
53
|
+
const owned = new Set(existing?.adminEditedFields ?? []);
|
|
54
|
+
for (const key of Object.keys(changes)) {
|
|
55
|
+
/*
|
|
56
|
+
* The protection fields themselves are never protected — that would make
|
|
57
|
+
* the set unmodifiable by the next edit.
|
|
58
|
+
*/
|
|
59
|
+
if (key.startsWith("adminEdited"))
|
|
60
|
+
continue;
|
|
61
|
+
owned.add(key);
|
|
62
|
+
}
|
|
63
|
+
const fields = [...owned].sort();
|
|
64
|
+
return {
|
|
65
|
+
...changes,
|
|
66
|
+
adminEditedFields: fields,
|
|
67
|
+
adminEdited: fields.length > 0,
|
|
68
|
+
adminEditedAt: new Date(),
|
|
69
|
+
adminEditedBy: actorUid,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Strip the fields a human owns out of a generator payload.
|
|
74
|
+
*
|
|
75
|
+
* Used by `appkit/scripts/seed-cli.mjs`. Exported from here rather than
|
|
76
|
+
* duplicated there so the rule has one definition — the CLI is `.mjs` and
|
|
77
|
+
* reads this through the built package, the same way it reads the seed data.
|
|
78
|
+
*/
|
|
79
|
+
export function stripAdminOwnedFields(payload, ownedFields) {
|
|
80
|
+
if (!ownedFields?.length)
|
|
81
|
+
return payload;
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
84
|
+
if (ownedFields.includes(k))
|
|
85
|
+
continue;
|
|
86
|
+
out[k] = v;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* `Record<Generation, Slot[]>` would be the hand-written enumeration of Root
|
|
30
30
|
* Cause #61 with a merge case it structurally cannot hold.
|
|
31
31
|
*/
|
|
32
|
+
import type { AdminEditableRecord } from "./admin-edit";
|
|
32
33
|
import type { BaseDocument } from "../../../_internal/shared/types/base-document";
|
|
33
34
|
export declare const PART_GLOSSARY_COLLECTION: "partGlossary";
|
|
34
35
|
export declare const MODEL_COMPOSITION_COLLECTION: "modelComposition";
|
|
@@ -271,7 +272,7 @@ export interface PartWboLegality {
|
|
|
271
272
|
* source. A slot missing from that map yields no `role` rather than a guess.
|
|
272
273
|
*/
|
|
273
274
|
export type PartRole = "chip" | "ring" | "wheel" | "weight" | "base" | "blade" | "track" | "tip" | "gear" | "support";
|
|
274
|
-
export interface PartGlossaryDocument extends BaseDocument {
|
|
275
|
+
export interface PartGlossaryDocument extends BaseDocument, AdminEditableRecord {
|
|
275
276
|
/** `${slot}--${codeOrSlug}` — both halves, because a code is not unique. */
|
|
276
277
|
id: string;
|
|
277
278
|
/** Buyer-facing label: "Performance Tip", "Fusion Wheel". */
|
|
@@ -19,6 +19,7 @@ import { normalizeRichTextHtml } from "../../../utils/string.formatter.js";
|
|
|
19
19
|
import { PreorderBadge } from "./PreorderCard.js";
|
|
20
20
|
import { WishlistHeartButton } from "../../wishlist/components/WishlistHeartButton.js";
|
|
21
21
|
import { CardStoreLine } from "../../products/components/CardStoreLine.js";
|
|
22
|
+
import { ProductOwnerQuickActions } from "../../products/components/ProductOwnerQuickActions.js";
|
|
22
23
|
const DEFAULT_LABELS = {
|
|
23
24
|
preOrderBadge: "Pre-order",
|
|
24
25
|
featuredBadge: "Featured",
|
|
@@ -69,11 +70,23 @@ export function MarketplacePreorderCard({ product, className = "", variant = "gr
|
|
|
69
70
|
_jsxs(_Fragment, { children: [_jsxs(Row, { className: "min-w-0", align: "start", justify: "between", gap: "sm", children: [_jsx(TextLink, { href: detailHref, className: "min-w-0 flex-1", children: _jsx(Text, { size: "sm", weight: "medium", color: "primary", truncate: 2, children: product.title }) }), wishlistActions && (_jsx(WishlistHeartButton, { size: "inline", inWishlist: inWishlist, addLabel: mergedLabels.addToWishlist, removeLabel: mergedLabels.removeFromWishlist, onToggle: handleWishlist }))] }), _jsx(CardStoreLine, { storeName: product.storeName, storeId: product.storeId }), _jsxs(Row, { align: "center", gap: "sm", wrap: true, children: [_jsx(Text, { className: "text-primary", size: "sm", weight: "bold", children: _jsx(GatedPrice, { children: formatCurrency(product.price, getDefaultCurrency()) }) }), shipDate && _jsx(PreorderBadge, { shipDate: shipDate })] }), _jsx(Button, { type: "button", variant: "primary", size: "sm", textSize: "xs", className: "self-start mt-0.5", onClick: handleNavigate, children: mergedLabels.reserveNow })] })) : (
|
|
70
71
|
/* ── Full grid layout ── */
|
|
71
72
|
_jsxs(_Fragment, { children: [_jsx(TextLink, { href: detailHref, children: _jsx(Text, { size: "sm", weight: "medium", color: "primary", truncate: 2, children: product.title }) }), _jsx(CardStoreLine, { storeName: product.storeName, storeId: product.storeId }), product.description ? (_jsx(RichText, { html: normalizeRichTextHtml(product.description), proseClass: "prose prose-sm max-w-none dark:prose-invert prose-p:my-0", className: "line-clamp-2 text-[length:var(--appkit-text-xs)] text-[var(--appkit-color-text-muted)]" })) : null, _jsxs(Row, { justify: "between", className: "mt-1", gap: "sm", children: [_jsx(Text, { size: "sm", weight: "semibold", color: "primary", children: _jsx(GatedPrice, { children: formatCurrency(product.price, getDefaultCurrency()) }) }), shipDate && _jsx(PreorderBadge, { shipDate: shipDate })] }), _jsxs(Row, { justify: "between", className: "mt-auto pt-[var(--appkit-space-2)]", gap: "sm", children: [_jsx(Button, { type: "button", variant: "primary", size: "sm", textSize: "xs", className: "flex-1", onClick: handleNavigate, children: mergedLabels.reserveNow }), onAddToCart ? (_jsx(Button, { type: "button", variant: "outline", size: "sm", textSize: "xs", className: "flex-1", onClick: (e) => { e.stopPropagation(); onAddToCart(product); }, children: mergedLabels.addToCart })) : null, wishlistActions ? (_jsx(WishlistHeartButton, { size: "inline", inWishlist: inWishlist, addLabel: mergedLabels.addToWishlist, removeLabel: mergedLabels.removeFromWishlist, onToggle: handleWishlist })) : null] })] })) })] }));
|
|
72
|
-
|
|
73
|
+
/*
|
|
74
|
+
* 🛑 Default, not opt-in. Nothing in either repo ever passed
|
|
75
|
+
* `renderOwnerActions`, so this toolbar was unreachable on every grid that
|
|
76
|
+
* mounts this card (Root Cause #8 — a slot shell rendered with zero render
|
|
77
|
+
* props). A card is resource-specific by construction, so it names its own
|
|
78
|
+
* resource rather than being threaded one; the prop stays as an override.
|
|
79
|
+
*/
|
|
80
|
+
const ownerActions = renderOwnerActions
|
|
81
|
+
? renderOwnerActions()
|
|
82
|
+
: product.id
|
|
83
|
+
? (_jsx(ProductOwnerQuickActions, { productId: String(product.id), storeId: product.storeId ? String(product.storeId) : undefined, recordLabel: product.title, placement: "card" }))
|
|
84
|
+
: null;
|
|
85
|
+
if (!ownerActions)
|
|
73
86
|
return card;
|
|
74
87
|
/*
|
|
75
88
|
* Sibling of the card, never a child — see the prop's docstring. `z-20`
|
|
76
89
|
* clears this card's own overlays, which all sit at `z-10`.
|
|
77
90
|
*/
|
|
78
|
-
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 bottom-2 z-20", children:
|
|
91
|
+
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 bottom-2 z-20", children: ownerActions })] }));
|
|
79
92
|
}
|
|
@@ -14,6 +14,7 @@ import { BaseListingCard, Div, GatedPrice, PricesOnly, Row, Span, Stack, Text, T
|
|
|
14
14
|
import { MediaImage } from "../../media/MediaImage.js";
|
|
15
15
|
import { computeBundleDiscount } from "../../../_internal/shared/features/categories/bundle-pricing.js";
|
|
16
16
|
import { BUNDLE_COPY } from "../../../_internal/shared/features/categories/bundle-copy.js";
|
|
17
|
+
import { RecordOwnerQuickActions } from "../../admin/components/RecordOwnerQuickActions.js";
|
|
17
18
|
const DEFAULT_LABELS = {
|
|
18
19
|
bundleBadge: "Bundle",
|
|
19
20
|
inStockBadge: "In stock",
|
|
@@ -58,11 +59,23 @@ export function MarketplaceBundleCard({ bundle, className = "", variant = "grid"
|
|
|
58
59
|
? formatCurrency(price, getDefaultCurrency())
|
|
59
60
|
: "—" }), discount && (_jsx(Text, { size: "xs", color: "muted", className: "line-through", children: formatCurrency(discount.originalTotal, getDefaultCurrency()) }))] }) }) }), _jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", children: mergedLabels.itemsLabel(memberCount) })] }), _jsx(Div, { className: CLS_VIEW_BTN, role: "button", tabIndex: 0, onClick: handleNavigate, onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ")
|
|
60
61
|
handleNavigate(); }, children: "View Bundle" })] })] }));
|
|
61
|
-
|
|
62
|
+
/*
|
|
63
|
+
* 🛑 Default, not opt-in. Nothing in either repo ever passed
|
|
64
|
+
* `renderOwnerActions`, so this toolbar was unreachable on every grid that
|
|
65
|
+
* mounts this card (Root Cause #8 — a slot shell rendered with zero render
|
|
66
|
+
* props). A card is resource-specific by construction, so it names its own
|
|
67
|
+
* resource rather than being threaded one; the prop stays as an override.
|
|
68
|
+
*/
|
|
69
|
+
const ownerActions = renderOwnerActions
|
|
70
|
+
? renderOwnerActions()
|
|
71
|
+
: bundle.id
|
|
72
|
+
? (_jsx(RecordOwnerQuickActions, { resource: "BUNDLE", recordId: String(bundle.id), recordLabel: String(bundle.name), placement: "card" }))
|
|
73
|
+
: null;
|
|
74
|
+
if (!ownerActions)
|
|
62
75
|
return card;
|
|
63
76
|
/*
|
|
64
77
|
* Sibling of the card, never a child — see the prop's docstring. `z-20`
|
|
65
78
|
* clears this card's own overlays, which all sit at `z-10`.
|
|
66
79
|
*/
|
|
67
|
-
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 top-2 z-20", children:
|
|
80
|
+
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 top-2 z-20", children: ownerActions })] }));
|
|
68
81
|
}
|
|
@@ -11,6 +11,7 @@ const CLS_PRIZE_PILL = "inline-flex items-center rounded-full bg-fuchsia-600 px-
|
|
|
11
11
|
import { BaseListingCard, Button, Div, GatedPrice, Row, Span, Stack, Text, TextLink } from "../../../ui/index.js";
|
|
12
12
|
import { MediaImage } from "../../media/MediaImage.js";
|
|
13
13
|
import { CardStoreLine } from "./CardStoreLine.js";
|
|
14
|
+
import { ProductOwnerQuickActions } from "./ProductOwnerQuickActions.js";
|
|
14
15
|
const DEFAULT_LABELS = {
|
|
15
16
|
prizeDrawBadge: "Prize draw",
|
|
16
17
|
pendingBadge: "Reveal pending",
|
|
@@ -100,11 +101,23 @@ export function MarketplacePrizeDrawCard({ product, className = "", variant = "g
|
|
|
100
101
|
}, className: selectable || isSelected
|
|
101
102
|
? "opacity-100"
|
|
102
103
|
: "opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition-opacity" }))] }), _jsxs(BaseListingCard.Info, { variant: variant, children: [_jsx(TextLink, { href: String(detailHref), children: _jsx(Text, { size: "sm", weight: "medium", color: "primary", truncate: 2, children: product.title }) }), _jsx(CardStoreLine, { storeName: product.storeName, storeId: product.storeId }), _jsxs(Row, { justify: "between", className: "mt-1", gap: "sm", children: [_jsx(Text, { size: "sm", weight: "semibold", color: "primary", children: _jsxs(GatedPrice, { label: "Sign in to see the entry price", children: [formatCurrency(pricePerEntry, getDefaultCurrency()), " ", _jsx(Span, { size: "xs", weight: "normal", className: "text-[var(--appkit-color-text-muted)]", children: mergedLabels.pricePerEntryLabel })] }) }), max > 0 ? (_jsx(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", children: mergedLabels.entriesRemainingLabel(remaining, max) })) : null] }), countdown ? (_jsxs(Text, { className: "text-[var(--appkit-color-text-muted)]", size: "xs", children: [status === "pending" ? "Opens in" : "Closes in", " ", countdown] })) : null, _jsx(Button, { type: "button", variant: "primary", size: "sm", textSize: "xs", className: "mt-2 w-full", onClick: handleNavigate, disabled: status === "closed" || remaining === 0, children: mergedLabels.enterDraw })] })] }));
|
|
103
|
-
|
|
104
|
+
/*
|
|
105
|
+
* 🛑 Default, not opt-in. Nothing in either repo ever passed
|
|
106
|
+
* `renderOwnerActions`, so this toolbar was unreachable on every grid that
|
|
107
|
+
* mounts this card (Root Cause #8 — a slot shell rendered with zero render
|
|
108
|
+
* props). A card is resource-specific by construction, so it names its own
|
|
109
|
+
* resource rather than being threaded one; the prop stays as an override.
|
|
110
|
+
*/
|
|
111
|
+
const ownerActions = renderOwnerActions
|
|
112
|
+
? renderOwnerActions()
|
|
113
|
+
: product.id
|
|
114
|
+
? (_jsx(ProductOwnerQuickActions, { productId: String(product.id), storeId: product.storeId ? String(product.storeId) : undefined, recordLabel: product.title, placement: "card" }))
|
|
115
|
+
: null;
|
|
116
|
+
if (!ownerActions)
|
|
104
117
|
return card;
|
|
105
118
|
/*
|
|
106
119
|
* Sibling of the card, never a child — see the prop's docstring. `z-20`
|
|
107
120
|
* clears this card's own overlays, which all sit at `z-10`.
|
|
108
121
|
*/
|
|
109
|
-
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 top-2 z-20", children:
|
|
122
|
+
return (_jsxs(Div, { className: "relative h-full", children: [card, _jsx(Div, { className: "absolute right-2 top-2 z-20", children: ownerActions })] }));
|
|
110
123
|
}
|
|
@@ -17,6 +17,7 @@ import { PRODUCT_FEATURE_CARD_MAX_VISIBLE } from "../constants/product-features.
|
|
|
17
17
|
import { normalizeListingType } from "../utils/listing-type.js";
|
|
18
18
|
import { pluginFor } from "../../../_internal/shared/listing-types/_registry.js";
|
|
19
19
|
import { WishlistHeartButton } from "../../wishlist/components/WishlistHeartButton.js";
|
|
20
|
+
import { ProductOwnerQuickActions } from "./ProductOwnerQuickActions.js";
|
|
20
21
|
const __P = {
|
|
21
22
|
p3: "p-[var(--appkit-space-3)]",
|
|
22
23
|
};
|
|
@@ -125,7 +126,22 @@ export function ProductCard({ product, href, onClick, onAddToWishlist, isWishlis
|
|
|
125
126
|
onAddToCart(product);
|
|
126
127
|
}, className: "justify-center text-[length:var(--appkit-text-xs)]", children: [_jsx("svg", { className: "h-3.5 w-3.5 flex-shrink-0", fill: "none", stroke: "currentColor", strokeWidth: 2, viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 3h2l.4 2M7 13h10l4-8H5.4m1.6 8L5 3H3m4 10v7a1 1 0 001 1h8a1 1 0 001-1v-7M9 21h6" }) }), "Cart"] }))] }))] })] })] }));
|
|
127
128
|
const wrapped = href && !selectionMode ? (_jsx(Link, { href: href, className: "block h-full", children: cardBody })) : (cardBody);
|
|
128
|
-
|
|
129
|
+
/*
|
|
130
|
+
* 🛑 Default, not opt-in — nothing in either repo ever passed
|
|
131
|
+
* `renderOwnerActions`, so this toolbar was unreachable on every product
|
|
132
|
+
* grid in the app despite the prop, the docstring and the positioning all
|
|
133
|
+
* being present (Root Cause #8).
|
|
134
|
+
*
|
|
135
|
+
* `ProductOwnerQuickActions`, not the generic wrapper: a product is the one
|
|
136
|
+
* collection a SELLER can also own, so its endpoints live under
|
|
137
|
+
* `SELLER_ENDPOINTS` and its clone has a bespoke redirect to the copy's
|
|
138
|
+
* editor. `storeId` is the store SLUG, which is what `SessionUser.storeId`
|
|
139
|
+
* holds — the component renders nothing for anyone who owns neither.
|
|
140
|
+
*/
|
|
141
|
+
const ownerActions = renderOwnerActions ? (renderOwnerActions()) : product.id ? (_jsx(ProductOwnerQuickActions, { productId: String(product.id), storeId: product.storeId ? String(product.storeId) : undefined, recordLabel: product.title, placement: "card" })) : null;
|
|
142
|
+
// Selection is still suppressed: a bulk-select gesture and a per-record edit
|
|
143
|
+
// are different intents, and offering both at once invites the wrong one.
|
|
144
|
+
if (!ownerActions || selectionMode || isSelected)
|
|
129
145
|
return wrapped;
|
|
130
146
|
/*
|
|
131
147
|
* 🛑 OUTSIDE the anchor, as a sibling — never inside `cardBody`.
|
|
@@ -144,7 +160,7 @@ export function ProductCard({ product, href, onClick, onAddToWishlist, isWishlis
|
|
|
144
160
|
*
|
|
145
161
|
* `z-20` beats the in-card overlays, which all sit at `z-10`.
|
|
146
162
|
*/
|
|
147
|
-
return (_jsxs(Div, { className: "relative h-full", children: [wrapped, _jsx(Div, { className: "absolute right-2 top-14 z-20", children:
|
|
163
|
+
return (_jsxs(Div, { className: "relative h-full", children: [wrapped, _jsx(Div, { className: "absolute right-2 top-14 z-20", children: ownerActions })] }));
|
|
148
164
|
}
|
|
149
165
|
function ProductListRow({ product, onClick, onAddToWishlist, isWishlisted, }) {
|
|
150
166
|
const discount = product.originalPrice && product.originalPrice > product.price
|
|
@@ -379,6 +379,24 @@ export interface ProductDocument extends BaseDocument {
|
|
|
379
379
|
* defects welded into the TITLE.
|
|
380
380
|
*/
|
|
381
381
|
unitLabel?: string;
|
|
382
|
+
/**
|
|
383
|
+
* This listing is a complete BEY, and this is which one.
|
|
384
|
+
*
|
|
385
|
+
* The `beys` document id, which is also its slug and also the URL
|
|
386
|
+
* (`/beys/{beyId}`) with no re-derivation — the same property that made
|
|
387
|
+
* `partGlossaryId` a single id rather than a pair.
|
|
388
|
+
*
|
|
389
|
+
* 🛑 THE EXACT COUNTERPART OF `partGlossaryId`, and the pair is what makes
|
|
390
|
+
* the seller's "single" choice meaningful: a single item is either one named
|
|
391
|
+
* bey or one named part, and those are the only two things in the catalogue
|
|
392
|
+
* that have an identity to point at. A lot has neither, which is why it
|
|
393
|
+
* files under a non-leaf CATEGORY instead (see `isLot`).
|
|
394
|
+
*
|
|
395
|
+
* 🛑 Never set together with `partGlossaryId`. A listing is a whole bey or a
|
|
396
|
+
* component, not both — and the two link to different reference pages, so a
|
|
397
|
+
* row carrying both would render two contradictory "what is this" sections.
|
|
398
|
+
*/
|
|
399
|
+
beyId?: string;
|
|
382
400
|
/**
|
|
383
401
|
* This listing is a COMPONENT, and this is which one.
|
|
384
402
|
*
|
|
@@ -22,5 +22,14 @@ export interface CategoryInlineSelectProps {
|
|
|
22
22
|
* `MAX_CATEGORY_ASSIGNMENTS`, which is what the repository refuses above.
|
|
23
23
|
*/
|
|
24
24
|
maxAssignments?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Scope the rows to LEAVES (a single item) or to COLLECTIONS (a lot).
|
|
27
|
+
*
|
|
28
|
+
* 🛑 `undefined` means UNSCOPED, which is what every existing call site
|
|
29
|
+
* gets — this cannot default, because a caller that does not know whether it
|
|
30
|
+
* is a lot must not be silently told it is a single. See `leafFilterFor`
|
|
31
|
+
* for why the server makes this load-bearing rather than cosmetic.
|
|
32
|
+
*/
|
|
33
|
+
leavesOnly?: boolean;
|
|
25
34
|
}
|
|
26
|
-
export declare function CategoryInlineSelect({ value, onChange, placeholder, disabled, allowCreate, extraValues, onExtraValuesChange, maxAssignments, }: CategoryInlineSelectProps): React.JSX.Element;
|
|
35
|
+
export declare function CategoryInlineSelect({ value, onChange, placeholder, disabled, allowCreate, extraValues, onExtraValuesChange, maxAssignments, leavesOnly, }: CategoryInlineSelectProps): React.JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React from "react";
|
|
3
4
|
import { PaginatedSelect } from "../../../ui/components/PaginatedSelect.js";
|
|
4
5
|
import { CategoryQuickCreateForm } from "../../admin/components/CategoryQuickCreateForm.js";
|
|
5
6
|
import { apiClient } from "../../../http/index.js";
|
|
@@ -7,14 +8,48 @@ import { ADMIN_ENDPOINTS, CATEGORY_ENDPOINTS } from "../../../constants/api-endp
|
|
|
7
8
|
import { Stack } from "../../../ui/components/Layout.js";
|
|
8
9
|
import { Text } from "../../../ui/components/Typography.js";
|
|
9
10
|
import { MAX_CATEGORY_ASSIGNMENTS } from "../../products/repository/category-assignment.js";
|
|
11
|
+
/**
|
|
12
|
+
* ── 🛑 LOT vs SINGLE SCOPES THE ROWS, AND THE SERVER ALREADY REFUSES THE
|
|
13
|
+
* WRONG ONE ───────────────────────────────────────────────────────────────
|
|
14
|
+
*
|
|
15
|
+
* `assertAssignmentShape` has enforced both directions since 2026-10-14
|
|
16
|
+
* (`ENFORCE_LEAF_FILING = true`):
|
|
17
|
+
*
|
|
18
|
+
* a LOT at a LEAF -> "A lot holds several different items, so it cannot
|
|
19
|
+
* be filed under X, which is a single-item category."
|
|
20
|
+
* a SINGLE at a BRANCH -> "X has subcategories, so it describes a group
|
|
21
|
+
* rather than one item."
|
|
22
|
+
*
|
|
23
|
+
* Until now the picker offered EVERY category to both, so roughly half of all
|
|
24
|
+
* choices walked the seller into a 400 they could not act on. Scoping the rows
|
|
25
|
+
* is therefore not a convenience — it is the client half of a rule the server
|
|
26
|
+
* already holds.
|
|
27
|
+
*
|
|
28
|
+
* 🛑 `isLeaf` NEEDS NO ROUTE CHANGE. `/api/admin/categories` forwards its
|
|
29
|
+
* `filters` string straight into `categoriesRepository.list`, and the public
|
|
30
|
+
* `/api/categories` whitelists `isLeaf` in `SAFE_CATEGORY_FILTER_FIELDS`. So
|
|
31
|
+
* this is a query-string addition, not new endpoint surface — which is also
|
|
32
|
+
* why it can ship without a build to verify it.
|
|
33
|
+
*
|
|
34
|
+
* `undefined` means UNSCOPED, which is what every existing caller gets. A
|
|
35
|
+
* caller that does not know whether it is a lot must not be silently told it
|
|
36
|
+
* is a single.
|
|
37
|
+
*/
|
|
38
|
+
function leafFilterFor(leavesOnly) {
|
|
39
|
+
if (leavesOnly === undefined)
|
|
40
|
+
return null;
|
|
41
|
+
return leavesOnly ? "isLeaf==true" : "isLeaf==false";
|
|
42
|
+
}
|
|
10
43
|
// Admin: paginated + server-side search via /api/admin/categories (admin/mod only).
|
|
11
44
|
// Response via successResponse({ data: items, total }) → apiClient unwraps to { data, total, ... }.
|
|
12
|
-
async function loadAdminCategoryOptions(query, page) {
|
|
45
|
+
async function loadAdminCategoryOptions(query, page, leavesOnly) {
|
|
46
|
+
const leafFilter = leafFilterFor(leavesOnly);
|
|
13
47
|
const params = new URLSearchParams({
|
|
14
48
|
q: query,
|
|
15
49
|
page: String(page),
|
|
16
50
|
pageSize: "20",
|
|
17
51
|
flat: "true",
|
|
52
|
+
...(leafFilter ? { filters: leafFilter } : {}),
|
|
18
53
|
});
|
|
19
54
|
const res = await apiClient.get(`${ADMIN_ENDPOINTS.CATEGORIES}?${params}`);
|
|
20
55
|
const items = (res.data ?? []).map((c) => ({
|
|
@@ -26,8 +61,13 @@ async function loadAdminCategoryOptions(query, page) {
|
|
|
26
61
|
}
|
|
27
62
|
// Seller: fetch all flat categories from the public unauthenticated endpoint,
|
|
28
63
|
// filter client-side by query. Public endpoint returns { success, data: CategoryItem[] }.
|
|
29
|
-
async function loadPublicCategoryOptions(query, _page) {
|
|
30
|
-
const
|
|
64
|
+
async function loadPublicCategoryOptions(query, _page, leavesOnly) {
|
|
65
|
+
const leafFilter = leafFilterFor(leavesOnly);
|
|
66
|
+
const params = new URLSearchParams({
|
|
67
|
+
flat: "true",
|
|
68
|
+
pageSize: "200",
|
|
69
|
+
...(leafFilter ? { filters: leafFilter } : {}),
|
|
70
|
+
});
|
|
31
71
|
const res = await fetch(CATEGORY_ENDPOINTS.FILTERED(params.toString()), { credentials: "include" });
|
|
32
72
|
const json = await res.json().catch(() => ({}));
|
|
33
73
|
const all = (json.data ?? []).map((c) => ({
|
|
@@ -38,8 +78,16 @@ async function loadPublicCategoryOptions(query, _page) {
|
|
|
38
78
|
const items = q ? all.filter((c) => c.label.toLowerCase().includes(q)) : all;
|
|
39
79
|
return { items, hasMore: false, nextPage: 2 };
|
|
40
80
|
}
|
|
41
|
-
export function CategoryInlineSelect({ value, onChange, placeholder = "Search categories…", disabled, allowCreate = true, extraValues, onExtraValuesChange, maxAssignments = MAX_CATEGORY_ASSIGNMENTS, }) {
|
|
42
|
-
|
|
81
|
+
export function CategoryInlineSelect({ value, onChange, placeholder = "Search categories…", disabled, allowCreate = true, extraValues, onExtraValuesChange, maxAssignments = MAX_CATEGORY_ASSIGNMENTS, leavesOnly, }) {
|
|
82
|
+
/*
|
|
83
|
+
* 🛑 MEMOISED, because `PaginatedSelect` consumes `loadOptions` inside an
|
|
84
|
+
* effect keyed on query/page. A fresh function identity every render
|
|
85
|
+
* re-triggers that effect, and the existing loaders are module-scope
|
|
86
|
+
* functions precisely to avoid it — binding the scope here would reintroduce
|
|
87
|
+
* the loop if it were done inline.
|
|
88
|
+
*/
|
|
89
|
+
const base = allowCreate ? loadAdminCategoryOptions : loadPublicCategoryOptions;
|
|
90
|
+
const loadOptions = React.useCallback((query, page) => base(query, page, leavesOnly), [base, leavesOnly]);
|
|
43
91
|
const primary = (_jsx(PaginatedSelect, { value: value || null, onChange: (v) => onChange(v ?? ""), loadOptions: loadOptions, placeholder: placeholder, disabled: disabled, createLabel: "category", drawerTitle: "Create Category", renderCreateForm: allowCreate
|
|
44
92
|
? ({ onCreated, onCancel }) => (_jsx(CategoryQuickCreateForm, { onSaved: (id, name) => onCreated({ value: id, label: name }), onCancel: onCancel }))
|
|
45
93
|
: undefined }));
|
|
@@ -19,6 +19,28 @@ import type { ListingType } from "../../products/types/index";
|
|
|
19
19
|
export type ProductListingMode = ListingType | "bundle";
|
|
20
20
|
export interface SellerProductDraft {
|
|
21
21
|
title?: string;
|
|
22
|
+
/**
|
|
23
|
+
* LOT or SINGLE — and this had a field and a server rule but no control.
|
|
24
|
+
*
|
|
25
|
+
* 🛑 `ProductDocument.isLot` has existed since G3a and
|
|
26
|
+
* `ProductRepository.deriveTaxonomy` ENFORCES it at line 488
|
|
27
|
+
* (`assertAssignmentShape(resolved, input.isLot === true, …)`): a lot must
|
|
28
|
+
* file under a non-leaf category, a single may file anywhere. The form never
|
|
29
|
+
* set it, so every listing reached that check as a single — and a seller
|
|
30
|
+
* with a mixed pile had no way to say otherwise.
|
|
31
|
+
*
|
|
32
|
+
* The reason the rule exists is a claim about the ITEMS, not about counting:
|
|
33
|
+
* filing "12 assorted Burst beys" under `category-dragoon-g` asserts all
|
|
34
|
+
* twelve are Dragoon G.
|
|
35
|
+
*/
|
|
36
|
+
isLot?: boolean;
|
|
37
|
+
/** How many items the lot holds. Optional even when `isLot` — a seller who
|
|
38
|
+
* has not counted the pile yet must still be able to save a draft. */
|
|
39
|
+
lotSize?: number;
|
|
40
|
+
/** The named bey this single IS, when the seller picked one. */
|
|
41
|
+
beyId?: string;
|
|
42
|
+
/** The named PART this single is, when it is a component rather than a bey. */
|
|
43
|
+
partGlossaryId?: string;
|
|
22
44
|
slug?: string;
|
|
23
45
|
description?: string;
|
|
24
46
|
category?: string;
|
|
@@ -170,6 +192,23 @@ export interface SellerProductShellProps {
|
|
|
170
192
|
renderCategorySelector?: (props: {
|
|
171
193
|
value: string;
|
|
172
194
|
onChange: (v: string) => void;
|
|
195
|
+
/**
|
|
196
|
+
* Whether the listing is a LOT, so the selector can offer the right rows.
|
|
197
|
+
*
|
|
198
|
+
* 🛑 OPTIONAL, like `extraValues` beside it and for the same measured
|
|
199
|
+
* reason: `QuickProductForm` is a second consumer of this slot and making
|
|
200
|
+
* a new prop required broke it immediately last time (Root Cause #20, a
|
|
201
|
+
* public prop change without its consumers — which the comment below
|
|
202
|
+
* already warns about). A selector that ignores this keeps today's
|
|
203
|
+
* behaviour exactly.
|
|
204
|
+
*
|
|
205
|
+
* 🛑 The server has enforced the split since 2026-10-14
|
|
206
|
+
* (`ENFORCE_LEAF_FILING = true`): a lot at a leaf and a single at a branch
|
|
207
|
+
* are both refused. So a selector that offers the wrong rows is not a
|
|
208
|
+
* cosmetic issue — it walks the seller into a 400 they cannot act on,
|
|
209
|
+
* which is what every seller hit before this prop existed.
|
|
210
|
+
*/
|
|
211
|
+
isLot?: boolean;
|
|
173
212
|
/**
|
|
174
213
|
* 🛑 OPTIONAL, and that is the whole point. `QuickProductForm` is a second
|
|
175
214
|
* consumer of this slot and making these required broke it immediately —
|