@contentful/field-editor-validation-errors 1.7.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -100,10 +100,12 @@ function UniquenessError(props) {
|
|
|
100
100
|
...state,
|
|
101
101
|
loading: true
|
|
102
102
|
}));
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
props.cma.entry.getMany({
|
|
104
|
+
query: {
|
|
105
|
+
'sys.id[in]': conflictIds.join(',')
|
|
106
|
+
},
|
|
107
|
+
releaseId: undefined
|
|
108
|
+
}).then(({ items })=>{
|
|
107
109
|
const entries = items.map((entry)=>({
|
|
108
110
|
id: entry.sys.id,
|
|
109
111
|
title: getTitle(entry),
|
|
@@ -118,7 +120,7 @@ function UniquenessError(props) {
|
|
|
118
120
|
getTitle,
|
|
119
121
|
state.entries,
|
|
120
122
|
conflicting,
|
|
121
|
-
props.
|
|
123
|
+
props.cma,
|
|
122
124
|
props.getEntryURL
|
|
123
125
|
]);
|
|
124
126
|
return /*#__PURE__*/ _react.createElement(_f36components.List, {
|
|
@@ -139,15 +141,15 @@ function UniquenessError(props) {
|
|
|
139
141
|
rel: "noopener noreferrer"
|
|
140
142
|
}, entry.title))));
|
|
141
143
|
}
|
|
142
|
-
function ValidationErrors(
|
|
144
|
+
function ValidationErrors({ field, space, cma, locales, errorMessageOverride, getEntryURL }) {
|
|
143
145
|
const [errors, setErrors] = _react.useState([]);
|
|
144
146
|
_react.useEffect(()=>{
|
|
145
147
|
const onErrors = (errors)=>{
|
|
146
148
|
setErrors(errors || []);
|
|
147
149
|
};
|
|
148
|
-
return
|
|
150
|
+
return field.onSchemaErrorsChanged(onErrors);
|
|
149
151
|
}, [
|
|
150
|
-
|
|
152
|
+
field
|
|
151
153
|
]);
|
|
152
154
|
if (errors.length === 0) {
|
|
153
155
|
return null;
|
|
@@ -166,12 +168,13 @@ function ValidationErrors(props) {
|
|
|
166
168
|
color: _f36tokens.default.colorNegative
|
|
167
169
|
}), /*#__PURE__*/ _react.createElement("div", {
|
|
168
170
|
className: _styles.errorMessage
|
|
169
|
-
},
|
|
171
|
+
}, errorMessageOverride?.(error.message) ?? error.message, error.name === 'unique' && /*#__PURE__*/ _react.createElement(UniquenessError, {
|
|
172
|
+
cma: cma,
|
|
170
173
|
error: error,
|
|
171
|
-
space:
|
|
172
|
-
localeCode:
|
|
173
|
-
defaultLocaleCode:
|
|
174
|
-
getEntryURL:
|
|
174
|
+
space: space,
|
|
175
|
+
localeCode: field.locale,
|
|
176
|
+
defaultLocaleCode: locales.default,
|
|
177
|
+
getEntryURL: getEntryURL
|
|
175
178
|
})));
|
|
176
179
|
}));
|
|
177
180
|
}
|
|
@@ -81,12 +81,20 @@ const createEntry = (id)=>({
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
+
const cma = {
|
|
85
|
+
entry: {
|
|
86
|
+
getMany: jest.fn().mockReturnValue({
|
|
87
|
+
items: []
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
};
|
|
84
91
|
describe('ValidationErrors', ()=>{
|
|
85
92
|
afterEach(_react1.cleanup);
|
|
86
93
|
it('renders without crashing', ()=>{
|
|
87
94
|
const [field] = _fieldeditortestutils.createFakeFieldAPI();
|
|
88
95
|
const { container } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_ValidationErrors.ValidationErrors, {
|
|
89
96
|
field: field,
|
|
97
|
+
cma: cma,
|
|
90
98
|
space: _fieldeditortestutils.createFakeSpaceAPI(),
|
|
91
99
|
locales: _fieldeditortestutils.createFakeLocalesAPI(),
|
|
92
100
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -104,6 +112,7 @@ describe('ValidationErrors', ()=>{
|
|
|
104
112
|
const [field, emitter] = _fieldeditortestutils.createFakeFieldAPI();
|
|
105
113
|
const { findByText } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_ValidationErrors.ValidationErrors, {
|
|
106
114
|
field: field,
|
|
115
|
+
cma: cma,
|
|
107
116
|
space: _fieldeditortestutils.createFakeSpaceAPI(),
|
|
108
117
|
locales: _fieldeditortestutils.createFakeLocalesAPI(),
|
|
109
118
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -142,13 +151,14 @@ describe('ValidationErrors', ()=>{
|
|
|
142
151
|
const [field, emitter] = _fieldeditortestutils.createFakeFieldAPI();
|
|
143
152
|
const space = _fieldeditortestutils.createFakeSpaceAPI((api)=>({
|
|
144
153
|
...api,
|
|
145
|
-
getCachedContentTypes
|
|
146
|
-
getEntries: jest.fn().mockResolvedValue({
|
|
147
|
-
items: ids.map(createEntry)
|
|
148
|
-
})
|
|
154
|
+
getCachedContentTypes
|
|
149
155
|
}));
|
|
156
|
+
cma.entry.getMany.mockResolvedValue({
|
|
157
|
+
items: ids.map(createEntry)
|
|
158
|
+
});
|
|
150
159
|
const { findByText, findAllByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_ValidationErrors.ValidationErrors, {
|
|
151
160
|
field: field,
|
|
161
|
+
cma: cma,
|
|
152
162
|
space: space,
|
|
153
163
|
locales: _fieldeditortestutils.createFakeLocalesAPI(),
|
|
154
164
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -44,10 +44,12 @@ function UniquenessError(props) {
|
|
|
44
44
|
...state,
|
|
45
45
|
loading: true
|
|
46
46
|
}));
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
props.cma.entry.getMany({
|
|
48
|
+
query: {
|
|
49
|
+
'sys.id[in]': conflictIds.join(',')
|
|
50
|
+
},
|
|
51
|
+
releaseId: undefined
|
|
52
|
+
}).then(({ items })=>{
|
|
51
53
|
const entries = items.map((entry)=>({
|
|
52
54
|
id: entry.sys.id,
|
|
53
55
|
title: getTitle(entry),
|
|
@@ -62,7 +64,7 @@ function UniquenessError(props) {
|
|
|
62
64
|
getTitle,
|
|
63
65
|
state.entries,
|
|
64
66
|
conflicting,
|
|
65
|
-
props.
|
|
67
|
+
props.cma,
|
|
66
68
|
props.getEntryURL
|
|
67
69
|
]);
|
|
68
70
|
return /*#__PURE__*/ React.createElement(List, {
|
|
@@ -83,15 +85,15 @@ function UniquenessError(props) {
|
|
|
83
85
|
rel: "noopener noreferrer"
|
|
84
86
|
}, entry.title))));
|
|
85
87
|
}
|
|
86
|
-
export function ValidationErrors(
|
|
88
|
+
export function ValidationErrors({ field, space, cma, locales, errorMessageOverride, getEntryURL }) {
|
|
87
89
|
const [errors, setErrors] = React.useState([]);
|
|
88
90
|
React.useEffect(()=>{
|
|
89
91
|
const onErrors = (errors)=>{
|
|
90
92
|
setErrors(errors || []);
|
|
91
93
|
};
|
|
92
|
-
return
|
|
94
|
+
return field.onSchemaErrorsChanged(onErrors);
|
|
93
95
|
}, [
|
|
94
|
-
|
|
96
|
+
field
|
|
95
97
|
]);
|
|
96
98
|
if (errors.length === 0) {
|
|
97
99
|
return null;
|
|
@@ -110,12 +112,13 @@ export function ValidationErrors(props) {
|
|
|
110
112
|
color: tokens.colorNegative
|
|
111
113
|
}), /*#__PURE__*/ React.createElement("div", {
|
|
112
114
|
className: styles.errorMessage
|
|
113
|
-
},
|
|
115
|
+
}, errorMessageOverride?.(error.message) ?? error.message, error.name === 'unique' && /*#__PURE__*/ React.createElement(UniquenessError, {
|
|
116
|
+
cma: cma,
|
|
114
117
|
error: error,
|
|
115
|
-
space:
|
|
116
|
-
localeCode:
|
|
117
|
-
defaultLocaleCode:
|
|
118
|
-
getEntryURL:
|
|
118
|
+
space: space,
|
|
119
|
+
localeCode: field.locale,
|
|
120
|
+
defaultLocaleCode: locales.default,
|
|
121
|
+
getEntryURL: getEntryURL
|
|
119
122
|
})));
|
|
120
123
|
}));
|
|
121
124
|
}
|
|
@@ -36,12 +36,20 @@ const createEntry = (id)=>({
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
+
const cma = {
|
|
40
|
+
entry: {
|
|
41
|
+
getMany: jest.fn().mockReturnValue({
|
|
42
|
+
items: []
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
};
|
|
39
46
|
describe('ValidationErrors', ()=>{
|
|
40
47
|
afterEach(cleanup);
|
|
41
48
|
it('renders without crashing', ()=>{
|
|
42
49
|
const [field] = utils.createFakeFieldAPI();
|
|
43
50
|
const { container } = render(/*#__PURE__*/ React.createElement(ValidationErrors, {
|
|
44
51
|
field: field,
|
|
52
|
+
cma: cma,
|
|
45
53
|
space: utils.createFakeSpaceAPI(),
|
|
46
54
|
locales: utils.createFakeLocalesAPI(),
|
|
47
55
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -59,6 +67,7 @@ describe('ValidationErrors', ()=>{
|
|
|
59
67
|
const [field, emitter] = utils.createFakeFieldAPI();
|
|
60
68
|
const { findByText } = render(/*#__PURE__*/ React.createElement(ValidationErrors, {
|
|
61
69
|
field: field,
|
|
70
|
+
cma: cma,
|
|
62
71
|
space: utils.createFakeSpaceAPI(),
|
|
63
72
|
locales: utils.createFakeLocalesAPI(),
|
|
64
73
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -97,13 +106,14 @@ describe('ValidationErrors', ()=>{
|
|
|
97
106
|
const [field, emitter] = utils.createFakeFieldAPI();
|
|
98
107
|
const space = utils.createFakeSpaceAPI((api)=>({
|
|
99
108
|
...api,
|
|
100
|
-
getCachedContentTypes
|
|
101
|
-
getEntries: jest.fn().mockResolvedValue({
|
|
102
|
-
items: ids.map(createEntry)
|
|
103
|
-
})
|
|
109
|
+
getCachedContentTypes
|
|
104
110
|
}));
|
|
111
|
+
cma.entry.getMany.mockResolvedValue({
|
|
112
|
+
items: ids.map(createEntry)
|
|
113
|
+
});
|
|
105
114
|
const { findByText, findAllByTestId } = render(/*#__PURE__*/ React.createElement(ValidationErrors, {
|
|
106
115
|
field: field,
|
|
116
|
+
cma: cma,
|
|
107
117
|
space: space,
|
|
108
118
|
locales: utils.createFakeLocalesAPI(),
|
|
109
119
|
getEntryURL: (entry)=>`url.${entry.sys.id}`
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { Entry, FieldAPI, LocalesAPI, SpaceAPI } from '@contentful/field-editor-shared';
|
|
3
|
+
import type { PlainClientAPI } from 'contentful-management';
|
|
3
4
|
export interface ValidationErrorsProps {
|
|
4
5
|
field: FieldAPI;
|
|
5
6
|
space: SpaceAPI;
|
|
7
|
+
cma: PlainClientAPI;
|
|
6
8
|
locales: LocalesAPI;
|
|
7
9
|
errorMessageOverride?: (message: string | undefined) => React.ReactNode;
|
|
8
10
|
getEntryURL: (entry: Entry) => string;
|
|
9
11
|
}
|
|
10
|
-
export declare function ValidationErrors(
|
|
12
|
+
export declare function ValidationErrors({ field, space, cma, locales, errorMessageOverride, getEntryURL, }: ValidationErrorsProps): React.JSX.Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-validation-errors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@contentful/f36-components": "^5.4.1",
|
|
40
40
|
"@contentful/f36-icons": "^5.4.1",
|
|
41
41
|
"@contentful/f36-tokens": "^5.1.0",
|
|
42
|
-
"@contentful/field-editor-shared": "^2.13.
|
|
42
|
+
"@contentful/field-editor-shared": "^2.13.8",
|
|
43
43
|
"emotion": "^10.0.17"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"registry": "https://npm.pkg.github.com/"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "84767c885db51a13c76ee44481f81bdbda708d3e"
|
|
57
57
|
}
|