Skip to content

Commit

Permalink
Fix the failing auto-creation of default languages in translation fie…
Browse files Browse the repository at this point in the history
…ld setup (#22409)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
  • Loading branch information
hanneskuettner and paescuj committed May 8, 2024
1 parent bd49cf0 commit fd4821d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-houses-grin.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

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

0 comments on commit fd4821d

Please sign in to comment.