diff --git a/.changeset/curvy-houses-grin.md b/.changeset/curvy-houses-grin.md new file mode 100644 index 0000000000..a78ef5bf17 --- /dev/null +++ b/.changeset/curvy-houses-grin.md @@ -0,0 +1,5 @@ +--- +'@directus/app': patch +--- + +Fixed the failing auto-creating of default languages for translation fields when using an existing, custom language collection. diff --git a/app/src/modules/settings/routes/data-model/field-detail/store/index.ts b/app/src/modules/settings/routes/data-model/field-detail/store/index.ts index dafa0eacfb..4e0b0355dc 100644 --- a/app/src/modules/settings/routes/data-model/field-detail/store/index.ts +++ b/app/src/modules/settings/routes/data-model/field-detail/store/index.ts @@ -38,7 +38,7 @@ export const useFieldDetailStore = defineStore({ /** What field we're currently editing ("+"" for new) */ editing: '+' as string, - /** Full field data with edits */ + /** Full field data with edits */ field: { field: undefined, type: undefined, @@ -165,14 +165,9 @@ export const useFieldDetailStore = defineStore({ alterations[localType].applyChanges(updates, state, { hasChanged, getCurrent }); } - const { field: fieldUpdates, ...restUpdates } = updates; - - mergeWith(state, restUpdates, (_, srcValue, key, object) => { - if (Array.isArray(srcValue)) return srcValue; - if (srcValue === undefined) object[key] = undefined; - return; - }); + const { field: fieldUpdates, items: itemUpdates, ...restUpdates } = updates; + // Handle `field` updates, shallow merge and mirror to `fieldUpdates` if (fieldUpdates) { const { schema: schemaUpdates, meta: metaUpdates, ...restFieldUpdates } = fieldUpdates; @@ -189,6 +184,20 @@ export const useFieldDetailStore = defineStore({ Object.assign((state.fieldUpdates.meta ??= {}), metaUpdates); } } + + // Handle `item` updates, allowing full replacements + if (itemUpdates) { + state.items = itemUpdates as (typeof this.$state)['items']; + } + + // Handle remaining updates, deep merge + mergeWith(state, restUpdates, (_, srcValue, key, object) => { + // Override arrays instead of merging + if (Array.isArray(srcValue)) return srcValue; + // Allow properties to be resettable + if (srcValue === undefined) object[key] = undefined; + return; + }); }); }, async save() {