Skip setup questions on the template path and collect name, photo, and description without recommendations.
Customize opens a dialog then walks the template decks; Use without changes lands on final review with Has Name Field. Template cards stay first, the engine is not called, and the catalog no longer shows a recommended tag.
This commit is contained in:
1 parent
53d236d0d5
commit
6498d52541
37 files changed
+1450
-733
No files matched your search
@@ -14,8 +14,8 @@ export type GovernanceTemplateCatalogEntry = {
|
||||
/** Path under public/ for getAssetPath() — Figma Asset / Template Mark */
|
||||
iconPath: string;
|
||||
/**
|
||||
* When true, static catalog rows show the “RECOMMENDED” tag. Facet-ranked
|
||||
* `/templates` sets this in `gridEntriesWithFacetScores` instead.
|
||||
* Templates carry no recommendation. Kept so grid card rows stay a
|
||||
* stable shape; always treat as false.
|
||||
*/
|
||||
recommended?: boolean;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { RuleTemplateDto, TemplateFacetScoreDto } from "../create/fetchTemplates";
|
||||
import type { RuleTemplateDto } from "../create/fetchTemplates";
|
||||
import { templateSummaryFromBody } from "../create/templateReviewMapping";
|
||||
import type { GovernanceTemplateCatalogEntry } from "./governanceTemplateCatalog";
|
||||
import {
|
||||
@@ -25,7 +25,7 @@ function presentationForSlug(slug: string): Pick<
|
||||
return {
|
||||
iconPath: catalog.iconPath,
|
||||
backgroundColor: catalog.backgroundColor,
|
||||
recommended: catalog.recommended === true,
|
||||
recommended: false,
|
||||
};
|
||||
}
|
||||
return TEMPLATE_GRID_FALLBACK_PRESENTATION;
|
||||
@@ -43,74 +43,10 @@ export function ruleTemplateToGridEntry(template: RuleTemplateDto): TemplateGrid
|
||||
description,
|
||||
iconPath: pres.iconPath,
|
||||
backgroundColor: pres.backgroundColor,
|
||||
recommended: pres.recommended,
|
||||
recommended: false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Max templates that show the “RECOMMENDED” tag when facet-ranked. Within the
|
||||
* **top score tier** only: we do not pad with lower-scoring templates (e.g. two
|
||||
* at score 4 and three at 3 → recommend the two 4s only), but if the top tier
|
||||
* exceeds this cap we still take the first `limit` in API order.
|
||||
*/
|
||||
export const TEMPLATE_GRID_COMPACT_RECOMMENDED_LIMIT = 5;
|
||||
|
||||
/**
|
||||
* Among templates in **API rank order** (score desc) with `score > 0`, mark
|
||||
* only those in the **maximum-score tier** (no lower tiers), at most `limit`
|
||||
* (API order is the tie-break when many tie for first place).
|
||||
*/
|
||||
export function deriveRecommendedTemplateSlugs(
|
||||
templatesInRankOrder: ReadonlyArray<{ slug: string }>,
|
||||
scores: Record<string, { score?: number } | undefined>,
|
||||
limit: number,
|
||||
): Set<string> {
|
||||
if (limit <= 0) return new Set();
|
||||
const matched = templatesInRankOrder.filter(
|
||||
(t) => (scores[t.slug]?.score ?? 0) > 0,
|
||||
);
|
||||
if (matched.length === 0) return new Set();
|
||||
let maxScore = 0;
|
||||
for (const t of matched) {
|
||||
const s = scores[t.slug]?.score ?? 0;
|
||||
if (s > maxScore) maxScore = s;
|
||||
}
|
||||
const topTier = matched.filter(
|
||||
(t) => (scores[t.slug]?.score ?? 0) === maxScore,
|
||||
);
|
||||
return new Set(topTier.slice(0, limit).map((t) => t.slug));
|
||||
}
|
||||
|
||||
export type GridEntriesWithFacetScoresOptions = {
|
||||
/** Default {@link TEMPLATE_GRID_COMPACT_RECOMMENDED_LIMIT}. */
|
||||
compactRecommendedLimit?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* After `GET /api/templates?facet.*` with `scores`, mark `recommended` only
|
||||
* for the top facet matches (see {@link deriveRecommendedTemplateSlugs}).
|
||||
*/
|
||||
export function gridEntriesWithFacetScores(
|
||||
templates: RuleTemplateDto[],
|
||||
scores: Record<string, TemplateFacetScoreDto>,
|
||||
options?: GridEntriesWithFacetScoresOptions,
|
||||
): TemplateGridCardEntry[] {
|
||||
const cap =
|
||||
options?.compactRecommendedLimit ?? TEMPLATE_GRID_COMPACT_RECOMMENDED_LIMIT;
|
||||
const recommendedSlugs = deriveRecommendedTemplateSlugs(
|
||||
templates,
|
||||
scores,
|
||||
cap,
|
||||
);
|
||||
return templates.map((t) => {
|
||||
const base = ruleTemplateToGridEntry(t);
|
||||
return {
|
||||
...base,
|
||||
recommended: recommendedSlugs.has(t.slug),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const bySlug = (templates: RuleTemplateDto[]) =>
|
||||
new Map(templates.map((t) => [t.slug, t] as const));
|
||||
|
||||
|
||||
Reference in new issue
Block a user