Fix duplicate Fields widget (#19696)

## Context
Tab duplication was broken after the view creation logic was deferred
and moved to the FE.

- Duplicating a tab or a FIELDS widget now produces a fully independent
copy: new view, new view field groups, new view fields — all with fresh
IDs — while preserving any unsaved edits
  from the source widget.
- Removed the backend auto-seed of default view fields / view field
groups in ViewService.createOne for FIELDS_WIDGET views. The frontend
always sends the complete layout via
upsertFieldsWidget, so the auto-seed was both redundant and the source
of potential bugs.
- Extracted a shared useDuplicateFieldsWidgetForPageLayout hook used by
both tab and widget duplication paths, plus a small
useCloneViewInMetadataStore helper that clones the FlatView
in the metadata store and returns the copied flat view fields/groups for
the caller.
This commit is contained in:
Weiko
2026-04-15 14:29:44 +02:00
committed by GitHub
parent 2df32f7003
commit e12b55a951
9 changed files with 402 additions and 607 deletions
@@ -174,6 +174,7 @@ export class PageLayoutUpdateService {
});
const orphanedViewIds = this.collectOrphanedViewIdsFromRemovedWidgets({
widgetsToCreate,
widgetsToUpdate,
widgetsToDelete,
tabsToUpdate,
@@ -868,12 +869,14 @@ export class PageLayoutUpdateService {
}
private collectOrphanedViewIdsFromRemovedWidgets({
widgetsToCreate,
widgetsToUpdate,
widgetsToDelete,
tabsToUpdate,
tabsToDelete,
flatPageLayoutWidgetMaps,
}: {
widgetsToCreate: FlatPageLayoutWidget[];
widgetsToUpdate: FlatPageLayoutWidget[];
widgetsToDelete: FlatPageLayoutWidget[];
tabsToUpdate: FlatPageLayoutTab[];
@@ -934,6 +937,14 @@ export class PageLayoutUpdateService {
}
}
for (const widget of widgetsToCreate) {
const viewId = this.getViewIdFromFieldsWidget(widget);
if (isDefined(viewId)) {
viewIdsToDelete.delete(viewId);
}
}
return [...viewIdsToDelete];
}