Merge branch 'main' into next
This commit is contained in:
commit
9872a0ddb7
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"useWorkspaces": true,
|
||||
"version": "1.2.8"
|
||||
"version": "1.2.9"
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@staticcms/app",
|
||||
"version": "1.2.8",
|
||||
"version": "1.2.9",
|
||||
"license": "MIT",
|
||||
"description": "Static CMS application.",
|
||||
"repository": "https://github.com/StaticJsCMS/static-cms",
|
||||
@ -35,7 +35,7 @@
|
||||
"@babel/eslint-parser": "7.19.1",
|
||||
"@babel/runtime": "7.21.0",
|
||||
"@emotion/babel-preset-css-prop": "11.10.0",
|
||||
"@staticcms/core": "^1.2.8",
|
||||
"@staticcms/core": "^1.2.9",
|
||||
"buffer": "6.0.3",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@staticcms/core",
|
||||
"version": "1.2.8",
|
||||
"version": "1.2.9",
|
||||
"license": "MIT",
|
||||
"description": "Static CMS core application.",
|
||||
"repository": "https://github.com/StaticJsCMS/static-cms",
|
||||
@ -112,7 +112,7 @@
|
||||
"jwt-decode": "3.1.2",
|
||||
"localforage": "1.10.0",
|
||||
"lodash": "4.17.21",
|
||||
"minimatch": "7.1.0",
|
||||
"minimatch": "7.1.1",
|
||||
"moment": "2.29.4",
|
||||
"node-polyglot": "2.5.0",
|
||||
"ol": "7.2.2",
|
||||
@ -141,10 +141,10 @@
|
||||
"sanitize-filename": "1.6.3",
|
||||
"scheduler": "0.23.0",
|
||||
"semaphore": "1.1.0",
|
||||
"slate": "0.91.3",
|
||||
"slate": "0.91.4",
|
||||
"slate-history": "0.86.0",
|
||||
"slate-hyperscript": "0.77.0",
|
||||
"slate-react": "0.91.3",
|
||||
"slate-react": "0.91.4",
|
||||
"stream-browserify": "3.0.0",
|
||||
"styled-components": "5.3.6",
|
||||
"symbol-observable": "4.0.0",
|
||||
|
@ -383,16 +383,16 @@ export function duplicateI18nFields(
|
||||
field: Field,
|
||||
locales: string[],
|
||||
defaultLocale: string,
|
||||
fieldPath: string[] = [field.name],
|
||||
fieldPath: string,
|
||||
) {
|
||||
const value = get(entryDraft, ['entry', 'data', ...fieldPath]);
|
||||
const value = get(entryDraft, ['entry', 'data', ...fieldPath.split('.')]);
|
||||
if (field.i18n === I18N_FIELD.DUPLICATE) {
|
||||
locales
|
||||
.filter(l => l !== defaultLocale)
|
||||
.forEach(l => {
|
||||
entryDraft = set(
|
||||
entryDraft,
|
||||
['entry', ...getDataPath(l, defaultLocale), ...fieldPath].join('.'),
|
||||
['entry', ...getDataPath(l, defaultLocale), fieldPath].join('.'),
|
||||
value,
|
||||
);
|
||||
});
|
||||
@ -400,10 +400,13 @@ export function duplicateI18nFields(
|
||||
|
||||
if ('fields' in field && !Array.isArray(value)) {
|
||||
field.fields?.forEach(field => {
|
||||
entryDraft = duplicateI18nFields(entryDraft, field, locales, defaultLocale, [
|
||||
...fieldPath,
|
||||
field.name,
|
||||
]);
|
||||
entryDraft = duplicateI18nFields(
|
||||
entryDraft,
|
||||
field,
|
||||
locales,
|
||||
defaultLocale,
|
||||
`${fieldPath}.${field.name}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { DRAFT_CHANGE_FIELD, DRAFT_CREATE_EMPTY } from '@staticcms/core/constant
|
||||
import mockEntry from '@staticcms/core/lib/test-utils/mock-data/MockEntry';
|
||||
import entryDraftReducer from '../entryDraft';
|
||||
|
||||
import type { I18nSettings, StringOrTextField } from '@staticcms/core/interface';
|
||||
import type { EntryDraftState } from '../entryDraft';
|
||||
|
||||
describe('entryDraft', () => {
|
||||
@ -72,6 +73,119 @@ describe('entryDraft', () => {
|
||||
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||
});
|
||||
});
|
||||
|
||||
describe('i18n', () => {
|
||||
it('duplicate values to other locales', () => {
|
||||
const state = entryDraftReducer(startState, {
|
||||
type: DRAFT_CHANGE_FIELD,
|
||||
payload: {
|
||||
path: 'path1.path2',
|
||||
field: {
|
||||
widget: 'string',
|
||||
name: 'stringInput',
|
||||
i18n: 'duplicate',
|
||||
},
|
||||
value: 'newValue',
|
||||
i18n: {
|
||||
locales: ['en', 'fr', 'es'],
|
||||
defaultLocale: 'en',
|
||||
currentLocale: 'en',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(state.entry?.data).toEqual({
|
||||
path1: {
|
||||
path2: 'newValue',
|
||||
},
|
||||
});
|
||||
|
||||
expect(state.entry?.i18n).toEqual({
|
||||
fr: {
|
||||
data: {
|
||||
path1: {
|
||||
path2: 'newValue',
|
||||
},
|
||||
},
|
||||
},
|
||||
es: {
|
||||
data: {
|
||||
path1: {
|
||||
path2: 'newValue',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should duplicate values to other locales for singleton list', () => {
|
||||
const field: StringOrTextField = {
|
||||
widget: 'string',
|
||||
name: 'stringInput',
|
||||
i18n: 'duplicate',
|
||||
};
|
||||
|
||||
const i18n: I18nSettings = {
|
||||
locales: ['en', 'fr', 'es'],
|
||||
defaultLocale: 'en',
|
||||
currentLocale: 'en',
|
||||
};
|
||||
|
||||
let state = entryDraftReducer(startState, {
|
||||
type: DRAFT_CHANGE_FIELD,
|
||||
payload: {
|
||||
path: 'path1',
|
||||
field,
|
||||
value: ['newValue1', 'newValue2', 'newValue3'],
|
||||
i18n,
|
||||
},
|
||||
});
|
||||
|
||||
expect(state.entry?.data).toEqual({
|
||||
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||
});
|
||||
|
||||
expect(state.entry?.i18n).toEqual({
|
||||
fr: {
|
||||
data: {
|
||||
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||
},
|
||||
},
|
||||
es: {
|
||||
data: {
|
||||
path1: ['newValue1', 'newValue2', 'newValue3'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
state = entryDraftReducer(state, {
|
||||
type: DRAFT_CHANGE_FIELD,
|
||||
payload: {
|
||||
path: 'path1.1',
|
||||
field,
|
||||
value: 'newValue2Updated',
|
||||
i18n,
|
||||
},
|
||||
});
|
||||
|
||||
expect(state.entry?.data).toEqual({
|
||||
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||
});
|
||||
|
||||
expect(state.entry?.i18n).toEqual({
|
||||
fr: {
|
||||
data: {
|
||||
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||
},
|
||||
},
|
||||
es: {
|
||||
data: {
|
||||
path1: ['newValue1', 'newValue2Updated', 'newValue3'],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -163,7 +163,7 @@ function entryDraftReducer(
|
||||
};
|
||||
|
||||
if (i18n) {
|
||||
newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale);
|
||||
newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale, path);
|
||||
}
|
||||
|
||||
const newData = get(newState.entry, dataPath) ?? {};
|
||||
|
@ -21,7 +21,7 @@
|
||||
"date-fns": "2.29.3",
|
||||
"gray-matter": "4.0.3",
|
||||
"js-yaml": "4.1.0",
|
||||
"next": "13.2.0",
|
||||
"next": "13.2.1",
|
||||
"next-mdx-remote": "4.3.0",
|
||||
"next-pwa": "5.6.0",
|
||||
"prismjs": "1.29.0",
|
||||
@ -35,8 +35,8 @@
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.21.0",
|
||||
"@emotion/eslint-plugin": "11.10.0",
|
||||
"@next/bundle-analyzer": "13.2.0",
|
||||
"@next/eslint-plugin-next": "13.2.0",
|
||||
"@next/bundle-analyzer": "13.2.1",
|
||||
"@next/eslint-plugin-next": "13.2.1",
|
||||
"@types/js-yaml": "4.0.5",
|
||||
"@types/node": "16.18.12",
|
||||
"@types/prettier": "2.7.2",
|
||||
@ -47,7 +47,7 @@
|
||||
"@typescript-eslint/parser": "5.53.0",
|
||||
"babel-eslint": "10.1.0",
|
||||
"eslint": "8.34.0",
|
||||
"eslint-config-next": "13.2.0",
|
||||
"eslint-config-next": "13.2.1",
|
||||
"eslint-config-prettier": "8.6.0",
|
||||
"eslint-plugin-babel": "5.3.1",
|
||||
"eslint-plugin-unicorn": "45.0.2",
|
||||
|
Loading…
x
Reference in New Issue
Block a user