Skip to content

Commit 5542eba

Browse files
renemadsenclaude
andcommitted
fix(visual-editor): initialize field types synchronously before async DB load
The field type dropdown was empty until getFieldTypes() API resolved, causing Playwright tests to timeout waiting for options. Now initialize with hardcoded enum IDs immediately (synchronous), then update with correct DB IDs when the API responds. This ensures the dropdown is always usable even if the API is slow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c009bdd commit 5542eba

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

eform-client/src/app/modules/eforms/eform-visual-editor/components/eform-visual-editor-elements/field/visual-editor-field-modal/visual-editor-field-modal.component.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,45 @@ export class VisualEditorFieldModalComponent implements OnInit {
5151
}
5252

5353
setFieldTypes() {
54+
this.buildFieldTypeList(null);
55+
5456
this.eformService.getFieldTypes().subscribe(res => {
55-
const dbFieldTypes = res?.success && res.model ? res.model : [];
56-
const allTypes = getTranslatedTypes(this.translateService, dbFieldTypes);
57+
if (res?.success && res.model?.length > 0) {
58+
this.buildFieldTypeList(res.model);
59+
}
60+
});
61+
}
5762

58-
const adminOnlyNames = ['Audio', 'Movie', 'NumberStepper'];
59-
const fieldGroupName = 'FieldGroup';
63+
private buildFieldTypeList(dbFieldTypes: {id: number; type: string}[] | null) {
64+
const allTypes = getTranslatedTypes(this.translateService, dbFieldTypes ?? undefined);
6065

61-
const dbFieldGroupId = dbFieldTypes.find(ft => ft.type === fieldGroupName)?.id;
62-
const dbAdminIds = dbFieldTypes
63-
.filter(ft => adminOnlyNames.includes(ft.type))
64-
.map(ft => ft.id);
66+
const adminOnlyNames = ['Audio', 'Movie', 'NumberStepper'];
67+
const fieldGroupName = 'FieldGroup';
6568

66-
if (this.recursionModel.fieldIsNested) {
67-
this.fieldTypes = allTypes.filter(x => x.id !== dbFieldGroupId);
68-
} else {
69-
this.fieldTypes = [...allTypes];
70-
}
69+
let fieldGroupId: number | undefined;
70+
let adminIds: number[] = [];
7171

72-
this.selectCurrentUserIsAdmin$.subscribe((isAdmin) => {
73-
if (isAdmin) {
74-
this.fieldTypes = [
75-
...this.fieldTypes,
76-
...allTypes.filter(x => dbAdminIds.includes(x.id))
77-
];
78-
}
79-
});
72+
if (dbFieldTypes) {
73+
fieldGroupId = dbFieldTypes.find(ft => ft.type === fieldGroupName)?.id;
74+
adminIds = dbFieldTypes.filter(ft => adminOnlyNames.includes(ft.type)).map(ft => ft.id);
75+
} else {
76+
fieldGroupId = EformFieldTypesEnum.FieldGroup;
77+
adminIds = [EformFieldTypesEnum.Audio, EformFieldTypesEnum.Movie, EformFieldTypesEnum.NumberStepper];
78+
}
79+
80+
if (this.recursionModel.fieldIsNested) {
81+
this.fieldTypes = allTypes.filter(x => x.id !== fieldGroupId);
82+
} else {
83+
this.fieldTypes = [...allTypes];
84+
}
85+
86+
this.selectCurrentUserIsAdmin$.subscribe((isAdmin) => {
87+
if (isAdmin) {
88+
this.fieldTypes = [
89+
...this.fieldTypes,
90+
...allTypes.filter(x => adminIds.includes(x.id))
91+
];
92+
}
8093
});
8194
}
8295

0 commit comments

Comments
 (0)