Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
---

Check warning on line 1 in .changeset/curvy-houses-grin.md

View workflow job for this annotation

GitHub Actions / Lint

File ignored by default.
'@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