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:
1 parent
96ca15d8e3
commit
bcbc6f30d9
89 files changed
+36555
-2828
No files matched your search
@@ -1,24 +1,89 @@
|
||||
import type { CreateFlowState } from "../../app/(app)/create/types";
|
||||
import type {
|
||||
CommunityStructureChipSnapshotRow,
|
||||
CreateFlowState,
|
||||
} from "../../app/(app)/create/types";
|
||||
import communityStructure from "../../messages/en/create/community/communityStructure.json";
|
||||
import {
|
||||
migrateChipSnapshot,
|
||||
resolveChipIdList,
|
||||
resolveMaturityChipId,
|
||||
resolveOrgChipId,
|
||||
resolveScaleChipId,
|
||||
resolveSizeChipId,
|
||||
} from "./communityChipIds";
|
||||
import { migrateSavedDeckIds } from "./idAliases";
|
||||
|
||||
/** Legacy `currentStep` values mapped to the current `CreateFlowStep` id. */
|
||||
const LEGACY_CREATE_FLOW_STEP_RENAMES: Readonly<Record<string, string>> = {
|
||||
"right-rail": "decision-approaches",
|
||||
};
|
||||
|
||||
function chipPresets(
|
||||
rows: readonly { id: string; label: string }[],
|
||||
): { id: string; label: string }[] {
|
||||
return rows.map((row) => ({ id: row.id, label: row.label }));
|
||||
}
|
||||
|
||||
function migrateCommunityChips(state: CreateFlowState): CreateFlowState {
|
||||
const snapshots = state.communityStructureChipSnapshots;
|
||||
const maturity = migrateChipSnapshot(
|
||||
snapshots?.maturity as CommunityStructureChipSnapshotRow[] | undefined,
|
||||
chipPresets(communityStructure.maturityOptions),
|
||||
resolveMaturityChipId,
|
||||
);
|
||||
const organizationTypes = migrateChipSnapshot(
|
||||
snapshots?.organizationTypes,
|
||||
chipPresets(communityStructure.organizationTypes),
|
||||
resolveOrgChipId,
|
||||
);
|
||||
const scale = migrateChipSnapshot(
|
||||
snapshots?.scale,
|
||||
chipPresets(communityStructure.scaleOptions),
|
||||
resolveScaleChipId,
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
selectedCommunitySizeIds: resolveChipIdList(
|
||||
state.selectedCommunitySizeIds,
|
||||
resolveSizeChipId,
|
||||
),
|
||||
selectedOrganizationTypeIds: resolveChipIdList(
|
||||
state.selectedOrganizationTypeIds,
|
||||
resolveOrgChipId,
|
||||
),
|
||||
selectedScaleIds: resolveChipIdList(state.selectedScaleIds, resolveScaleChipId),
|
||||
selectedMaturityIds: resolveChipIdList(
|
||||
state.selectedMaturityIds,
|
||||
resolveMaturityChipId,
|
||||
),
|
||||
...(snapshots || maturity || organizationTypes || scale
|
||||
? {
|
||||
communityStructureChipSnapshots: {
|
||||
...snapshots,
|
||||
...(organizationTypes ? { organizationTypes } : {}),
|
||||
...(scale ? { scale } : {}),
|
||||
...(maturity ? { maturity } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes parsed draft JSON before merging into create-flow context.
|
||||
* Renames deprecated step ids so old drafts and bookmarks stay valid.
|
||||
* Renames deprecated step ids and remaps deck and chip ids from before the remake.
|
||||
*/
|
||||
export function migrateLegacyCreateFlowState(
|
||||
raw: Record<string, unknown> | null | undefined,
|
||||
): CreateFlowState {
|
||||
if (!raw || typeof raw !== "object") return {};
|
||||
const step = raw.currentStep;
|
||||
let state = raw as CreateFlowState;
|
||||
if (typeof step === "string") {
|
||||
const next = LEGACY_CREATE_FLOW_STEP_RENAMES[step];
|
||||
if (next !== undefined) {
|
||||
return { ...raw, currentStep: next } as CreateFlowState;
|
||||
state = { ...state, currentStep: next } as CreateFlowState;
|
||||
}
|
||||
}
|
||||
return raw as CreateFlowState;
|
||||
return migrateCommunityChips(migrateSavedDeckIds(state));
|
||||
}
|
||||
Reference in new issue
Block a user