@contentful/field-editor-reference 6.21.0 → 6.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.
@@ -26,6 +26,9 @@ function useContentTypePermissions({ entityType, validations, sdk, allContentTyp
26
26
  if (entityType === 'Asset') {
27
27
  return [];
28
28
  }
29
+ if (validations.contentTypes && allContentTypes.length === 0) {
30
+ return [];
31
+ }
29
32
  if (validations.contentTypes) {
30
33
  return allContentTypes.filter((ct)=>validations.contentTypes?.includes(ct.sys.id));
31
34
  }
@@ -38,21 +41,15 @@ function useContentTypePermissions({ entityType, validations, sdk, allContentTyp
38
41
  const [creatableContentTypes, setCreatableContentTypes] = (0, _react.useState)(availableContentTypes);
39
42
  const { canPerformActionOnEntryOfType } = (0, _useAccessApi.useAccessApi)(sdk.access);
40
43
  (0, _react.useEffect)(()=>{
41
- function getContentTypes(action) {
42
- return filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType(action, ct.sys.id));
43
- }
44
44
  async function checkContentTypeAccess() {
45
- const creatable = await getContentTypes('create');
46
- if (!(0, _isEqual.default)(creatable, creatableContentTypes)) {
47
- setCreatableContentTypes(creatable);
48
- }
45
+ const creatable = await filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType('create', ct.sys.id));
46
+ setCreatableContentTypes((creatableContentTypes)=>(0, _isEqual.default)(creatable, creatableContentTypes) ? creatableContentTypes : creatable);
49
47
  }
50
48
  if (availableContentTypes.length > 0) {
51
49
  void checkContentTypeAccess();
52
50
  }
53
51
  }, [
54
- availableContentTypes,
55
- creatableContentTypes
52
+ availableContentTypes
56
53
  ]);
57
54
  return {
58
55
  creatableContentTypes,
@@ -13,8 +13,12 @@ const _fromFieldValidations = require("../utils/fromFieldValidations");
13
13
  const _useAccessApi = require("./useAccessApi");
14
14
  const _useContentTypePermissions = require("./useContentTypePermissions");
15
15
  function useEditorPermissions({ sdk, entityType, parameters, allContentTypes }) {
16
+ const fieldValidations = sdk.field.validations;
17
+ const itemsValidations = sdk.field.type === 'Array' ? sdk.field.items?.validations : undefined;
16
18
  const validations = (0, _react.useMemo)(()=>(0, _fromFieldValidations.fromFieldValidations)(sdk.field), [
17
- sdk.field
19
+ sdk.field,
20
+ JSON.stringify(fieldValidations),
21
+ JSON.stringify(itemsValidations)
18
22
  ]);
19
23
  const [canCreateEntity, setCanCreateEntity] = (0, _react.useState)(true);
20
24
  const [canLinkEntity, setCanLinkEntity] = (0, _react.useState)(true);
@@ -130,6 +130,7 @@ function useLinkActionsProps(props) {
130
130
  }, [
131
131
  sdk,
132
132
  entityType,
133
+ editorPermissions,
133
134
  onLinkedExisting
134
135
  ]);
135
136
  const onLinkSeveralExisting = _react.useCallback(async (index)=>{
@@ -145,6 +146,7 @@ function useLinkActionsProps(props) {
145
146
  }, [
146
147
  sdk,
147
148
  entityType,
149
+ editorPermissions,
148
150
  onLinkedExisting
149
151
  ]);
150
152
  return (0, _react.useMemo)(()=>({
@@ -11,6 +11,9 @@ export function useContentTypePermissions({ entityType, validations, sdk, allCon
11
11
  if (entityType === 'Asset') {
12
12
  return [];
13
13
  }
14
+ if (validations.contentTypes && allContentTypes.length === 0) {
15
+ return [];
16
+ }
14
17
  if (validations.contentTypes) {
15
18
  return allContentTypes.filter((ct)=>validations.contentTypes?.includes(ct.sys.id));
16
19
  }
@@ -23,21 +26,15 @@ export function useContentTypePermissions({ entityType, validations, sdk, allCon
23
26
  const [creatableContentTypes, setCreatableContentTypes] = useState(availableContentTypes);
24
27
  const { canPerformActionOnEntryOfType } = useAccessApi(sdk.access);
25
28
  useEffect(()=>{
26
- function getContentTypes(action) {
27
- return filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType(action, ct.sys.id));
28
- }
29
29
  async function checkContentTypeAccess() {
30
- const creatable = await getContentTypes('create');
31
- if (!isEqual(creatable, creatableContentTypes)) {
32
- setCreatableContentTypes(creatable);
33
- }
30
+ const creatable = await filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType('create', ct.sys.id));
31
+ setCreatableContentTypes((creatableContentTypes)=>isEqual(creatable, creatableContentTypes) ? creatableContentTypes : creatable);
34
32
  }
35
33
  if (availableContentTypes.length > 0) {
36
34
  void checkContentTypeAccess();
37
35
  }
38
36
  }, [
39
- availableContentTypes,
40
- creatableContentTypes
37
+ availableContentTypes
41
38
  ]);
42
39
  return {
43
40
  creatableContentTypes,
@@ -3,8 +3,12 @@ import { fromFieldValidations } from '../utils/fromFieldValidations';
3
3
  import { useAccessApi } from './useAccessApi';
4
4
  import { useContentTypePermissions } from './useContentTypePermissions';
5
5
  export function useEditorPermissions({ sdk, entityType, parameters, allContentTypes }) {
6
+ const fieldValidations = sdk.field.validations;
7
+ const itemsValidations = sdk.field.type === 'Array' ? sdk.field.items?.validations : undefined;
6
8
  const validations = useMemo(()=>fromFieldValidations(sdk.field), [
7
- sdk.field
9
+ sdk.field,
10
+ JSON.stringify(fieldValidations),
11
+ JSON.stringify(itemsValidations)
8
12
  ]);
9
13
  const [canCreateEntity, setCanCreateEntity] = useState(true);
10
14
  const [canLinkEntity, setCanLinkEntity] = useState(true);
@@ -69,6 +69,7 @@ export function useLinkActionsProps(props) {
69
69
  }, [
70
70
  sdk,
71
71
  entityType,
72
+ editorPermissions,
72
73
  onLinkedExisting
73
74
  ]);
74
75
  const onLinkSeveralExisting = React.useCallback(async (index)=>{
@@ -84,6 +85,7 @@ export function useLinkActionsProps(props) {
84
85
  }, [
85
86
  sdk,
86
87
  entityType,
88
+ editorPermissions,
87
89
  onLinkedExisting
88
90
  ]);
89
91
  return useMemo(()=>({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-reference",
3
- "version": "6.21.0",
3
+ "version": "6.21.2",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "registry": "https://npm.pkg.github.com/"
70
70
  },
71
- "gitHead": "333fb851812fea920a1ddd113bd8d918922b53d5"
71
+ "gitHead": "cd410dabfce5b53342a2211863edbe0cc00e7c87"
72
72
  }