Mock server workflow - first draft
This commit is contained in:
@@ -86,7 +86,11 @@ export default function CampaignFieldsPage({ settings, campaignId }: { settings:
|
||||
|
||||
setDraft((current) => {
|
||||
const nextDraft = updateNested(current ?? {}, ["fields"], nextFields);
|
||||
return updateNested(nextDraft, ["global_values"], nextGlobalValues);
|
||||
const nextWithGlobalValues = updateNested(nextDraft, ["global_values"], nextGlobalValues);
|
||||
if (duplicate || !cleanedName || !valueKey || valueKey === cleanedName) {
|
||||
return nextWithGlobalValues;
|
||||
}
|
||||
return migrateEntryFieldValues(nextWithGlobalValues, valueKey, cleanedName);
|
||||
});
|
||||
markDirty();
|
||||
}
|
||||
@@ -219,6 +223,28 @@ function normalizeFields(value: unknown): CampaignFieldDefinition[] {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
function migrateEntryFieldValues(draft: Record<string, unknown>, oldName: string, newName: string): Record<string, unknown> {
|
||||
const entries = asRecord(draft.entries);
|
||||
const inlineEntries = Array.isArray(entries.inline) ? entries.inline : [];
|
||||
if (inlineEntries.length === 0) return draft;
|
||||
|
||||
const nextInlineEntries = inlineEntries.map((entry) => {
|
||||
if (!isRecord(entry)) return entry;
|
||||
const fields = asRecord(entry.fields);
|
||||
if (!Object.prototype.hasOwnProperty.call(fields, oldName)) return entry;
|
||||
|
||||
const nextFields = { ...fields };
|
||||
if (!Object.prototype.hasOwnProperty.call(nextFields, newName)) {
|
||||
nextFields[newName] = nextFields[oldName];
|
||||
}
|
||||
delete nextFields[oldName];
|
||||
return { ...entry, fields: nextFields };
|
||||
});
|
||||
|
||||
return updateNested(draft, ["entries", "inline"], nextInlineEntries);
|
||||
}
|
||||
|
||||
function migrateFieldOverridePolicy(draft: Record<string, unknown>, editorState: Record<string, unknown>): Record<string, unknown> {
|
||||
const overridePolicy = asRecord(editorState.field_overrides);
|
||||
if (Object.keys(overridePolicy).length === 0) return draft;
|
||||
|
||||
Reference in New Issue
Block a user