@contentful/field-editor-reference 5.21.0 → 5.21.2
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.
- package/dist/cjs/common/useContentTypePermissions.js +0 -4
- package/dist/cjs/common/useEditorPermissions.js +2 -4
- package/dist/cjs/common/useEditorPermissions.spec.js +0 -27
- package/dist/cjs/components/LinkActions/helpers.js +6 -2
- package/dist/cjs/components/SpaceName/SpaceName.js +1 -2
- package/dist/esm/common/useContentTypePermissions.js +0 -4
- package/dist/esm/common/useEditorPermissions.js +2 -4
- package/dist/esm/common/useEditorPermissions.spec.js +0 -27
- package/dist/esm/components/LinkActions/helpers.js +6 -2
- package/dist/esm/components/SpaceName/SpaceName.js +1 -2
- package/dist/types/common/useContentTypePermissions.d.ts +0 -1
- package/dist/types/common/useEditorPermissions.d.ts +0 -1
- package/package.json +2 -2
|
@@ -31,7 +31,6 @@ function useContentTypePermissions(props) {
|
|
|
31
31
|
props.entityType
|
|
32
32
|
]);
|
|
33
33
|
const [creatableContentTypes, setCreatableContentTypes] = (0, _react.useState)(availableContentTypes);
|
|
34
|
-
const [readableContentTypes, setReadableContentTypes] = (0, _react.useState)(availableContentTypes);
|
|
35
34
|
const { canPerformActionOnEntryOfType } = (0, _useAccessApi.useAccessApi)(props.sdk.access);
|
|
36
35
|
(0, _react.useEffect)(()=>{
|
|
37
36
|
function getContentTypes(action) {
|
|
@@ -39,9 +38,7 @@ function useContentTypePermissions(props) {
|
|
|
39
38
|
}
|
|
40
39
|
async function checkContentTypeAccess() {
|
|
41
40
|
const creatable = await getContentTypes('create');
|
|
42
|
-
const readable = await getContentTypes('read');
|
|
43
41
|
setCreatableContentTypes(creatable);
|
|
44
|
-
setReadableContentTypes(readable);
|
|
45
42
|
}
|
|
46
43
|
void checkContentTypeAccess();
|
|
47
44
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
@@ -50,7 +47,6 @@ function useContentTypePermissions(props) {
|
|
|
50
47
|
]);
|
|
51
48
|
return {
|
|
52
49
|
creatableContentTypes,
|
|
53
|
-
readableContentTypes,
|
|
54
50
|
availableContentTypes
|
|
55
51
|
};
|
|
56
52
|
}
|
|
@@ -19,7 +19,7 @@ function useEditorPermissions(props) {
|
|
|
19
19
|
]);
|
|
20
20
|
const [canCreateEntity, setCanCreateEntity] = (0, _react.useState)(true);
|
|
21
21
|
const [canLinkEntity, setCanLinkEntity] = (0, _react.useState)(true);
|
|
22
|
-
const { creatableContentTypes,
|
|
22
|
+
const { creatableContentTypes, availableContentTypes } = (0, _useContentTypePermissions.useContentTypePermissions)({
|
|
23
23
|
...props,
|
|
24
24
|
validations
|
|
25
25
|
});
|
|
@@ -75,14 +75,12 @@ function useEditorPermissions(props) {
|
|
|
75
75
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
76
76
|
}, [
|
|
77
77
|
entityType,
|
|
78
|
-
parameters.instance
|
|
79
|
-
readableContentTypes
|
|
78
|
+
parameters.instance
|
|
80
79
|
]);
|
|
81
80
|
return {
|
|
82
81
|
canCreateEntity,
|
|
83
82
|
canLinkEntity,
|
|
84
83
|
creatableContentTypes,
|
|
85
|
-
readableContentTypes,
|
|
86
84
|
availableContentTypes,
|
|
87
85
|
validations
|
|
88
86
|
};
|
|
@@ -69,7 +69,6 @@ describe('useEditorPermissions', ()=>{
|
|
|
69
69
|
]
|
|
70
70
|
});
|
|
71
71
|
expect(result.current.creatableContentTypes).toEqual([]);
|
|
72
|
-
expect(result.current.readableContentTypes).toEqual([]);
|
|
73
72
|
});
|
|
74
73
|
});
|
|
75
74
|
describe(`behaviour on Entry`, ()=>{
|
|
@@ -176,31 +175,5 @@ describe('useEditorPermissions', ()=>{
|
|
|
176
175
|
allContentTypes[1]
|
|
177
176
|
]);
|
|
178
177
|
});
|
|
179
|
-
it(`returns readableContentTypes from validations that can be read`, async ()=>{
|
|
180
|
-
const allContentTypes = [
|
|
181
|
-
makeContentType('one'),
|
|
182
|
-
makeContentType('two')
|
|
183
|
-
];
|
|
184
|
-
const { result } = await renderEditorPermissions({
|
|
185
|
-
entityType: 'Entry',
|
|
186
|
-
allContentTypes,
|
|
187
|
-
customizeMock: (field)=>{
|
|
188
|
-
field.validations = [
|
|
189
|
-
{
|
|
190
|
-
linkContentType: [
|
|
191
|
-
'two'
|
|
192
|
-
]
|
|
193
|
-
}
|
|
194
|
-
];
|
|
195
|
-
return field;
|
|
196
|
-
},
|
|
197
|
-
customizeSdk: (sdk)=>{
|
|
198
|
-
allowContentTypes(sdk, 'read', 'two');
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
expect(result.current.readableContentTypes).toEqual([
|
|
202
|
-
allContentTypes[1]
|
|
203
|
-
]);
|
|
204
|
-
});
|
|
205
178
|
});
|
|
206
179
|
});
|
|
@@ -46,7 +46,9 @@ async function selectSingleEntity(props) {
|
|
|
46
46
|
if (props.entityType === 'Entry') {
|
|
47
47
|
return await props.sdk.dialogs.selectSingleEntry({
|
|
48
48
|
locale: props.sdk.field.locale,
|
|
49
|
-
|
|
49
|
+
// readable CTs do not cover cases where user has partial access to a CT entry,
|
|
50
|
+
// e.g. via tags so we're passing in all available CTs (based on field validations)
|
|
51
|
+
contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes)
|
|
50
52
|
});
|
|
51
53
|
} else {
|
|
52
54
|
return props.sdk.dialogs.selectSingleAsset({
|
|
@@ -68,7 +70,9 @@ async function selectMultipleEntities(props) {
|
|
|
68
70
|
if (props.entityType === 'Entry') {
|
|
69
71
|
return await props.sdk.dialogs.selectMultipleEntries({
|
|
70
72
|
locale: props.sdk.field.locale,
|
|
71
|
-
|
|
73
|
+
// readable CTs do not cover cases where user has partial access to a CT entry,
|
|
74
|
+
// e.g. via tags so we're passing in all available CTs (based on field validations)
|
|
75
|
+
contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes),
|
|
72
76
|
min,
|
|
73
77
|
max
|
|
74
78
|
});
|
|
@@ -83,8 +83,7 @@ function SpaceName(props) {
|
|
|
83
83
|
content: content
|
|
84
84
|
}, /*#__PURE__*/ _react.createElement(_f36components.Flex, {
|
|
85
85
|
alignItems: "center",
|
|
86
|
-
gap: "spacingXs"
|
|
87
|
-
marginRight: "spacingS"
|
|
86
|
+
gap: "spacingXs"
|
|
88
87
|
}, /*#__PURE__*/ _react.createElement(_f36icons.FolderOpenTrimmedIcon, {
|
|
89
88
|
className: styles.spaceIcon,
|
|
90
89
|
size: "tiny",
|
|
@@ -21,7 +21,6 @@ export function useContentTypePermissions(props) {
|
|
|
21
21
|
props.entityType
|
|
22
22
|
]);
|
|
23
23
|
const [creatableContentTypes, setCreatableContentTypes] = useState(availableContentTypes);
|
|
24
|
-
const [readableContentTypes, setReadableContentTypes] = useState(availableContentTypes);
|
|
25
24
|
const { canPerformActionOnEntryOfType } = useAccessApi(props.sdk.access);
|
|
26
25
|
useEffect(()=>{
|
|
27
26
|
function getContentTypes(action) {
|
|
@@ -29,9 +28,7 @@ export function useContentTypePermissions(props) {
|
|
|
29
28
|
}
|
|
30
29
|
async function checkContentTypeAccess() {
|
|
31
30
|
const creatable = await getContentTypes('create');
|
|
32
|
-
const readable = await getContentTypes('read');
|
|
33
31
|
setCreatableContentTypes(creatable);
|
|
34
|
-
setReadableContentTypes(readable);
|
|
35
32
|
}
|
|
36
33
|
void checkContentTypeAccess();
|
|
37
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
@@ -40,7 +37,6 @@ export function useContentTypePermissions(props) {
|
|
|
40
37
|
]);
|
|
41
38
|
return {
|
|
42
39
|
creatableContentTypes,
|
|
43
|
-
readableContentTypes,
|
|
44
40
|
availableContentTypes
|
|
45
41
|
};
|
|
46
42
|
}
|
|
@@ -9,7 +9,7 @@ export function useEditorPermissions(props) {
|
|
|
9
9
|
]);
|
|
10
10
|
const [canCreateEntity, setCanCreateEntity] = useState(true);
|
|
11
11
|
const [canLinkEntity, setCanLinkEntity] = useState(true);
|
|
12
|
-
const { creatableContentTypes,
|
|
12
|
+
const { creatableContentTypes, availableContentTypes } = useContentTypePermissions({
|
|
13
13
|
...props,
|
|
14
14
|
validations
|
|
15
15
|
});
|
|
@@ -65,14 +65,12 @@ export function useEditorPermissions(props) {
|
|
|
65
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
66
66
|
}, [
|
|
67
67
|
entityType,
|
|
68
|
-
parameters.instance
|
|
69
|
-
readableContentTypes
|
|
68
|
+
parameters.instance
|
|
70
69
|
]);
|
|
71
70
|
return {
|
|
72
71
|
canCreateEntity,
|
|
73
72
|
canLinkEntity,
|
|
74
73
|
creatableContentTypes,
|
|
75
|
-
readableContentTypes,
|
|
76
74
|
availableContentTypes,
|
|
77
75
|
validations
|
|
78
76
|
};
|
|
@@ -65,7 +65,6 @@ describe('useEditorPermissions', ()=>{
|
|
|
65
65
|
]
|
|
66
66
|
});
|
|
67
67
|
expect(result.current.creatableContentTypes).toEqual([]);
|
|
68
|
-
expect(result.current.readableContentTypes).toEqual([]);
|
|
69
68
|
});
|
|
70
69
|
});
|
|
71
70
|
describe(`behaviour on Entry`, ()=>{
|
|
@@ -172,31 +171,5 @@ describe('useEditorPermissions', ()=>{
|
|
|
172
171
|
allContentTypes[1]
|
|
173
172
|
]);
|
|
174
173
|
});
|
|
175
|
-
it(`returns readableContentTypes from validations that can be read`, async ()=>{
|
|
176
|
-
const allContentTypes = [
|
|
177
|
-
makeContentType('one'),
|
|
178
|
-
makeContentType('two')
|
|
179
|
-
];
|
|
180
|
-
const { result } = await renderEditorPermissions({
|
|
181
|
-
entityType: 'Entry',
|
|
182
|
-
allContentTypes,
|
|
183
|
-
customizeMock: (field)=>{
|
|
184
|
-
field.validations = [
|
|
185
|
-
{
|
|
186
|
-
linkContentType: [
|
|
187
|
-
'two'
|
|
188
|
-
]
|
|
189
|
-
}
|
|
190
|
-
];
|
|
191
|
-
return field;
|
|
192
|
-
},
|
|
193
|
-
customizeSdk: (sdk)=>{
|
|
194
|
-
allowContentTypes(sdk, 'read', 'two');
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
expect(result.current.readableContentTypes).toEqual([
|
|
198
|
-
allContentTypes[1]
|
|
199
|
-
]);
|
|
200
|
-
});
|
|
201
174
|
});
|
|
202
175
|
});
|
|
@@ -25,7 +25,9 @@ export async function selectSingleEntity(props) {
|
|
|
25
25
|
if (props.entityType === 'Entry') {
|
|
26
26
|
return await props.sdk.dialogs.selectSingleEntry({
|
|
27
27
|
locale: props.sdk.field.locale,
|
|
28
|
-
|
|
28
|
+
// readable CTs do not cover cases where user has partial access to a CT entry,
|
|
29
|
+
// e.g. via tags so we're passing in all available CTs (based on field validations)
|
|
30
|
+
contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes)
|
|
29
31
|
});
|
|
30
32
|
} else {
|
|
31
33
|
return props.sdk.dialogs.selectSingleAsset({
|
|
@@ -47,7 +49,9 @@ export async function selectMultipleEntities(props) {
|
|
|
47
49
|
if (props.entityType === 'Entry') {
|
|
48
50
|
return await props.sdk.dialogs.selectMultipleEntries({
|
|
49
51
|
locale: props.sdk.field.locale,
|
|
50
|
-
|
|
52
|
+
// readable CTs do not cover cases where user has partial access to a CT entry,
|
|
53
|
+
// e.g. via tags so we're passing in all available CTs (based on field validations)
|
|
54
|
+
contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes),
|
|
51
55
|
min,
|
|
52
56
|
max
|
|
53
57
|
});
|
|
@@ -27,8 +27,7 @@ export function SpaceName(props) {
|
|
|
27
27
|
content: content
|
|
28
28
|
}, /*#__PURE__*/ React.createElement(Flex, {
|
|
29
29
|
alignItems: "center",
|
|
30
|
-
gap: "spacingXs"
|
|
31
|
-
marginRight: "spacingS"
|
|
30
|
+
gap: "spacingXs"
|
|
32
31
|
}, /*#__PURE__*/ React.createElement(FolderOpenTrimmedIcon, {
|
|
33
32
|
className: styles.spaceIcon,
|
|
34
33
|
size: "tiny",
|
|
@@ -10,7 +10,6 @@ type ContentTypePermissionsProps = {
|
|
|
10
10
|
};
|
|
11
11
|
type ContentTypePermissions = {
|
|
12
12
|
creatableContentTypes: ContentType[];
|
|
13
|
-
readableContentTypes: ContentType[];
|
|
14
13
|
availableContentTypes: ContentType[];
|
|
15
14
|
};
|
|
16
15
|
export declare function useContentTypePermissions(props: ContentTypePermissionsProps): ContentTypePermissions;
|
|
@@ -10,7 +10,6 @@ export declare function useEditorPermissions(props: EditorPermissionsProps): {
|
|
|
10
10
|
canCreateEntity: boolean;
|
|
11
11
|
canLinkEntity: boolean;
|
|
12
12
|
creatableContentTypes: ContentType[];
|
|
13
|
-
readableContentTypes: ContentType[];
|
|
14
13
|
availableContentTypes: ContentType[];
|
|
15
14
|
validations: import("../utils/fromFieldValidations").ReferenceValidations;
|
|
16
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "5.21.
|
|
3
|
+
"version": "5.21.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@contentful/app-sdk": "^4.17.1",
|
|
65
65
|
"react": ">=16.8.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "03940a9d0badbb781a4b00daea6930b8d11bdbf6"
|
|
68
68
|
}
|