Quellcode durchsuchen

fix(admin-ui): Correctly handle localeText custom fields

Fixes #2181
Michael Bromley vor 2 Jahren
Ursprung
Commit
96082c37c9

+ 1 - 1
packages/admin-ui/src/lib/core/src/common/base-detail.component.ts

@@ -138,7 +138,7 @@ export abstract class BaseDetailComponent<Entity extends { id: string; updatedAt
         for (const fieldDef of customFields) {
             const key = fieldDef.name;
             const value =
-                fieldDef.type === 'localeString'
+                fieldDef.type === 'localeString' || fieldDef.type === 'localeText'
                     ? (currentTranslation as any)?.customFields?.[key]
                     : (entity as any).customFields?.[key];
             const control = formGroup?.get(key);

+ 39 - 31
packages/admin-ui/src/lib/core/src/data/utils/add-custom-fields.ts

@@ -38,38 +38,43 @@ export function addCustomFields(documentNode: DocumentNode, customFields: Custom
                 kind: Kind.FIELD,
                 selectionSet: {
                     kind: Kind.SELECTION_SET,
-                    selections: customFieldsForType.map(customField => ({
-                            kind: Kind.FIELD,
-                            name: {
-                                kind: Kind.NAME,
-                                value: customField.name,
-                            },
-                            // For "relation" custom fields, we need to also select
-                            // all the scalar fields of the related type
-                            ...(customField.type === 'relation'
-                                ? {
-                                      selectionSet: {
-                                          kind: Kind.SELECTION_SET,
-                                          selections: (
-                                              customField as RelationCustomFieldFragment
-                                          ).scalarFields.map(f => ({
-                                              kind: Kind.FIELD,
-                                              name: { kind: Kind.NAME, value: f },
-                                          })),
-                                      },
-                                  }
-                                : {}),
-                        } as FieldNode)),
+                    selections: customFieldsForType.map(
+                        customField =>
+                            ({
+                                kind: Kind.FIELD,
+                                name: {
+                                    kind: Kind.NAME,
+                                    value: customField.name,
+                                },
+                                // For "relation" custom fields, we need to also select
+                                // all the scalar fields of the related type
+                                ...(customField.type === 'relation'
+                                    ? {
+                                          selectionSet: {
+                                              kind: Kind.SELECTION_SET,
+                                              selections: (
+                                                  customField as RelationCustomFieldFragment
+                                              ).scalarFields.map(f => ({
+                                                  kind: Kind.FIELD,
+                                                  name: { kind: Kind.NAME, value: f },
+                                              })),
+                                          },
+                                      }
+                                    : {}),
+                            } as FieldNode),
+                    ),
                 },
             });
 
-            const localeStrings = customFieldsForType.filter(field => field.type === 'localeString');
+            const localizedFields = customFieldsForType.filter(
+                field => field.type === 'localeString' || field.type === 'localeText',
+            );
 
             const translationsField = fragmentDef.selectionSet.selections
                 .filter(isFieldNode)
                 .find(field => field.name.value === 'translations');
 
-            if (localeStrings.length && translationsField && translationsField.selectionSet) {
+            if (localizedFields.length && translationsField && translationsField.selectionSet) {
                 (translationsField.selectionSet.selections as SelectionNode[]).push({
                     name: {
                         kind: Kind.NAME,
@@ -78,13 +83,16 @@ export function addCustomFields(documentNode: DocumentNode, customFields: Custom
                     kind: Kind.FIELD,
                     selectionSet: {
                         kind: Kind.SELECTION_SET,
-                        selections: localeStrings.map(customField => ({
-                                kind: Kind.FIELD,
-                                name: {
-                                    kind: Kind.NAME,
-                                    value: customField.name,
-                                },
-                            } as FieldNode)),
+                        selections: localizedFields.map(
+                            customField =>
+                                ({
+                                    kind: Kind.FIELD,
+                                    name: {
+                                        kind: Kind.NAME,
+                                        value: customField.name,
+                                    },
+                                } as FieldNode),
+                        ),
                     },
                 });
             }