Fix the failing auto-creation of default languages in translation field setup (#22409)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Hannes Küttner
2024-05-08 12:00:09 +02:00
committed by GitHub
parent bd49cf0057
commit fd4821d890
2 changed files with 22 additions and 8 deletions

View File

@@ -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.

View File

@@ -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() {