Import the remade decks on stable ids and recommend one card per job, so a saved draft still loads after a chip is renamed.

The real-group profiles stay as a test, so a change that moves a pick fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
adilalloandCursor committed 2026-11-04 14:22:54 -07:00
1 parent 96ca15d8e3
commit bcbc6f30d9
89 files changed
+36555 -2828

No files matched your search

+39 -5
View File
@@ -3,8 +3,10 @@ import type {
CreateFlowState,
} from "../../app/(app)/create/types";
import coreValuesMessages from "../../messages/en/create/customRule/coreValues.json";
import templateChipsFile from "../../data/templates/templateChips.json";
import { assignTemplateMethodSlugsToPrefill } from "./customRuleFacets";
import { methodSlugFromTitle } from "./methodSlugFromTitle";
import type { DeckId } from "./deckTypes";
type TemplateEntry = { title: unknown };
type TemplateSection = { categoryName: unknown; entries: unknown };
@@ -33,15 +35,19 @@ function normaliseCategoryKey(name: string): string {
return name.toLowerCase().replace(/[^a-z]+/g, "");
}
/** Preset core-value labels with the chip id (1-based preset index as string) the select screen expects. */
/** Preset core values keyed by the stable id in `coreValues.json`. */
type CorePresetRow = { id: string; label: string };
const CORE_VALUE_PRESETS: readonly CorePresetRow[] = (() => {
const raw = (coreValuesMessages as { values: unknown }).values;
if (!Array.isArray(raw)) return [];
return raw.map((v, i) => ({
id: String(i + 1),
label: typeof v === "string" ? v : (v as { label: string }).label,
}));
const out: CorePresetRow[] = [];
for (const value of raw) {
if (!value || typeof value !== "object") continue;
const row = value as { id?: unknown; label?: unknown };
if (typeof row.id !== "string" || typeof row.label !== "string") continue;
out.push({ id: row.id, label: row.label });
}
return out;
})();
function buildCoreValuePrefill(
@@ -95,9 +101,37 @@ function buildCoreValuePrefill(
*
* Returns an empty object for malformed bodies (no sections array).
*/
type TemplateChipSet = Record<DeckId | "coreValues", string[]>;
function prefillFromTemplateChips(slug: string): Partial<CreateFlowState> | null {
const templates = (
templateChipsFile as { templates: Record<string, TemplateChipSet> }
).templates;
const chips = templates[slug];
if (!chips) return null;
const selected = new Set(chips.coreValues);
return {
selectedCoreValueIds: [...chips.coreValues],
coreValuesChipsSnapshot: CORE_VALUE_PRESETS.map((preset) => ({
id: preset.id,
label: preset.label,
state: selected.has(preset.id) ? "selected" : "unselected",
})),
selectedDecisionApproachIds: [...chips.decisionApproaches],
selectedMembershipMethodIds: [...chips.membership],
selectedConflictManagementIds: [...chips.conflictManagement],
selectedCommunicationMethodIds: [...chips.communication],
};
}
export function buildTemplateCustomizePrefill(
body: unknown,
templateSlug?: string,
): Partial<CreateFlowState> {
if (templateSlug) {
const fromIds = prefillFromTemplateChips(templateSlug);
if (fromIds) return fromIds;
}
if (!body || typeof body !== "object") return {};
const sections = (body as { sections?: unknown }).sections;
if (!Array.isArray(sections)) return {};