fix: various fixes and tweaks (#701)

This commit is contained in:
Daniel Lautzenheiser
2023-04-14 13:52:11 -04:00
committed by GitHub
parent 422b7798da
commit 364612e9ae
22 changed files with 101 additions and 32 deletions

View File

@ -185,10 +185,12 @@ function entryDraftReducer(
}
case DRAFT_VALIDATION_ERRORS: {
const { path, errors, i18n } = action.payload;
const { path, errors, i18n, isMeta } = action.payload;
const fieldsErrors = { ...state.fieldsErrors };
const dataPath = (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data'];
const dataPath = isMeta
? ['meta']
: (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data'];
const fullPath = `${dataPath.join('.')}.${path}`;
if (errors.length === 0) {

View File

@ -3,13 +3,16 @@ import { getDataPath } from '@staticcms/core/lib/i18n';
import type { I18nSettings } from '@staticcms/core/interface';
import type { RootState } from '@staticcms/core/store';
export const getEntryDataPath = (i18n: I18nSettings | undefined) => {
return (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data'];
export const getEntryDataPath = (i18n: I18nSettings | undefined, isMeta: boolean | undefined) => {
return isMeta
? ['meta']
: (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data'];
};
export const selectFieldErrors =
(path: string, i18n: I18nSettings | undefined) => (state: RootState) => {
const dataPath = getEntryDataPath(i18n);
(path: string, i18n: I18nSettings | undefined, isMeta: boolean | undefined) =>
(state: RootState) => {
const dataPath = getEntryDataPath(i18n, isMeta);
const fullPath = `${dataPath.join('.')}.${path}`;
return state.entryDraft.fieldsErrors[fullPath] ?? [];
};