diff --git a/packages/core/package.json b/packages/core/package.json index fc15015ef..8bb4d5473 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -110,6 +110,7 @@ "gray-matter": "4.0.3", "history": "5.3.0", "immer": "10.0.1", + "immutable": "4.3.4", "ini": "4.1.0", "is-hotkey": "0.2.0", "js-base64": "3.7.5", diff --git a/packages/core/src/actions/entries.ts b/packages/core/src/actions/entries.ts index 23195fbc5..e60518a28 100644 --- a/packages/core/src/actions/entries.ts +++ b/packages/core/src/actions/entries.ts @@ -877,6 +877,7 @@ export function createEmptyDraft(collection: Collection, search: string) { mediaFiles: [], }); newEntry = await backend.processEntry(state, collection, newEntry); + console.log('EQUAL?', newEntry.i18n?.de === newEntry.i18n?.['fr']); dispatch(emptyDraftCreated(newEntry)); }; } diff --git a/packages/core/src/backend.ts b/packages/core/src/backend.ts index a5154b63b..bc11e5ae1 100644 --- a/packages/core/src/backend.ts +++ b/packages/core/src/backend.ts @@ -3,7 +3,6 @@ import attempt from 'lodash/attempt'; import flatten from 'lodash/flatten'; import get from 'lodash/get'; import isError from 'lodash/isError'; -import set from 'lodash/set'; import uniq from 'lodash/uniq'; import { dirname, extname } from 'path'; @@ -53,6 +52,7 @@ import { DRAFT_MEDIA_FILES, selectMediaFilePublicPath } from './lib/util/media.u import { selectCustomPath, slugFromCustomPath } from './lib/util/nested.util'; import { isNotNullish, isNullish } from './lib/util/null.util'; import { fileSearch, sortByScore } from './lib/util/search.util'; +import set from './lib/util/set.util'; import { dateParsers, expandPath, extractTemplateVars } from './lib/widgets/stringTemplate'; import { getUseWorkflow } from './reducers/selectors/config'; import createEntry from './valueObjects/createEntry'; diff --git a/packages/core/src/formats/YamlFormatter.ts b/packages/core/src/formats/YamlFormatter.ts index 1b525e2e9..34f7faa80 100644 --- a/packages/core/src/formats/YamlFormatter.ts +++ b/packages/core/src/formats/YamlFormatter.ts @@ -33,7 +33,7 @@ class YamlFormatter extends FileFormatter { } toFile(data: object, sortedKeys: string[] = [], comments: Record = {}) { - const doc = new yaml.Document(); + const doc = new yaml.Document({ aliasDuplicateObjects: false }); const contents = doc.createNode(data) as YAMLMap; addComments(contents.items as Pair[], comments); diff --git a/packages/core/src/lib/formatters.ts b/packages/core/src/lib/formatters.ts index 50a64e509..a6bda2c8c 100644 --- a/packages/core/src/lib/formatters.ts +++ b/packages/core/src/lib/formatters.ts @@ -1,10 +1,10 @@ import get from 'lodash/get'; -import set from 'lodash/set'; import { COMMIT_AUTHOR, COMMIT_DATE } from '../constants/commitProps'; import { sanitizeSlug } from './urlHelper'; import { getFields, selectIdentifier, selectInferredField } from './util/collection.util'; import { getField, selectField } from './util/field.util'; +import set from './util/set.util'; import { isEmpty } from './util/string.util'; import { addFileTemplateFields, diff --git a/packages/core/src/lib/i18n.ts b/packages/core/src/lib/i18n.ts index 708bcb791..c9f4f91bd 100644 --- a/packages/core/src/lib/i18n.ts +++ b/packages/core/src/lib/i18n.ts @@ -1,9 +1,9 @@ import escapeRegExp from 'lodash/escapeRegExp'; import get from 'lodash/get'; import groupBy from 'lodash/groupBy'; -import set from 'lodash/set'; import { fileForEntry, selectEntrySlug } from './util/collection.util'; +import set from './util/set.util'; import type { BaseField, diff --git a/packages/core/src/lib/util/set.util.ts b/packages/core/src/lib/util/set.util.ts new file mode 100644 index 000000000..b09249f94 --- /dev/null +++ b/packages/core/src/lib/util/set.util.ts @@ -0,0 +1,5 @@ +import { setIn } from 'immutable'; + +export default function set(object: T, path: string, value: unknown): T { + return setIn(object, path.split('.'), value); +} diff --git a/packages/core/src/reducers/entries.ts b/packages/core/src/reducers/entries.ts index 775896ae3..5895bdc63 100644 --- a/packages/core/src/reducers/entries.ts +++ b/packages/core/src/reducers/entries.ts @@ -1,5 +1,4 @@ import once from 'lodash/once'; -import set from 'lodash/set'; import sortBy from 'lodash/sortBy'; import { @@ -24,6 +23,7 @@ import { SORT_ENTRIES_SUCCESS, } from '../constants'; import { VIEW_STYLES, VIEW_STYLE_TABLE } from '../constants/views'; +import set from '../lib/util/set.util'; import type { EntriesAction } from '../actions/entries'; import type { SearchAction } from '../actions/search'; diff --git a/packages/core/src/reducers/entryDraft.ts b/packages/core/src/reducers/entryDraft.ts index 153f94544..64b30960b 100644 --- a/packages/core/src/reducers/entryDraft.ts +++ b/packages/core/src/reducers/entryDraft.ts @@ -1,9 +1,7 @@ import cloneDeep from 'lodash/cloneDeep'; import isEqual from 'lodash/isEqual'; -import set from 'lodash/set'; import { v4 as uuid } from 'uuid'; -import {} from '../actions/editorialWorkflow'; import { ADD_DRAFT_ENTRY_MEDIA_FILE, DRAFT_CHANGE_FIELD, @@ -35,6 +33,7 @@ import { import { duplicateI18nFields, getDataPath } from '../lib/i18n'; import { fileForEntry } from '../lib/util/collection.util'; import { applyDefaultsToDraftData } from '../lib/util/entry.util'; +import set from '../lib/util/set.util'; import type { EditorialWorkflowAction } from '../actions/editorialWorkflow'; import type { EntriesAction } from '../actions/entries'; @@ -216,15 +215,20 @@ function entryDraftReducer( : (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data']; const newEntry = cloneDeep(newState.entry); + console.log('newEntry', cloneDeep(newEntry)); + console.log('equal 1?', newEntry.i18n?.fr === newEntry.i18n?.de); newState = { ...newState, entry: set(newEntry, `${dataPath.join('.')}.${path}`, value), }; + console.log('setting', `${dataPath.join('.')}.${path}`, 'to', `"${value}"`); if (i18n) { newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale, path); } + console.log('newState.entry', cloneDeep(newState.entry)); + console.log('equal 2?', newState.entry?.i18n?.fr === newState.entry?.i18n?.de); let hasChanged = !isEqual(newEntry?.meta, newState.original?.meta) || diff --git a/yarn.lock b/yarn.lock index 276b8d051..ddf3f037e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10459,6 +10459,11 @@ immer@^9.0.21, immer@^9.0.6: resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.21.tgz#1e025ea31a40f24fb064f1fef23e931496330176" integrity sha512-bc4NBHqOqSfRW7POMkHd51LvClaeMXpm8dx0e8oE2GORbq5aRK7Bxl4FyzVLdGtLmvLKL7BTDBG5ACQm4HWjTA== +immutable@4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.4.tgz#2e07b33837b4bb7662f288c244d1ced1ef65a78f" + integrity sha512-fsXeu4J4i6WNWSikpI88v/PcVflZz+6kMhUfIwc5SY+poQRPnaf5V7qds6SUyUN3cVxEzuCab7QIoLOQ+DQ1wA== + import-fresh@^3.2.1, import-fresh@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"