@contentful/field-editor-reference 5.21.2 → 5.21.4
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/__fixtures__/FakeSdk.js +3 -3
- package/dist/cjs/__fixtures__/asset/index.js +10 -10
- package/dist/cjs/__fixtures__/content-type/index.js +1 -1
- package/dist/cjs/__fixtures__/entry/index.js +7 -7
- package/dist/cjs/__fixtures__/fixtures.js +6 -8
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/assets/MultipleMediaEditor.js +5 -7
- package/dist/cjs/assets/SingleMediaEditor.js +4 -6
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +19 -21
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +11 -18
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +11 -20
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +9 -12
- package/dist/cjs/assets/index.js +3 -3
- package/dist/cjs/common/EntityStore.js +32 -51
- package/dist/cjs/common/MultipleReferenceEditor.js +11 -20
- package/dist/cjs/common/ReferenceEditor.js +5 -7
- package/dist/cjs/common/SingleReferenceEditor.js +7 -11
- package/dist/cjs/common/SortableLinkList.js +14 -14
- package/dist/cjs/common/customCardTypes.js +2 -4
- package/dist/cjs/common/queryClient.js +9 -14
- package/dist/cjs/common/useContentTypePermissions.js +1 -3
- package/dist/cjs/common/useEditorPermissions.js +3 -15
- package/dist/cjs/common/useEditorPermissions.spec.js +11 -12
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +3 -5
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +9 -13
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +15 -17
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +19 -29
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +12 -14
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +21 -28
- package/dist/cjs/components/LinkActions/LinkActions.js +15 -17
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +17 -26
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +3 -5
- package/dist/cjs/components/LinkActions/helpers.js +5 -14
- package/dist/cjs/components/LinkActions/redesignStyles.js +4 -4
- package/dist/cjs/components/LinkActions/styles.js +1 -1
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +9 -11
- package/dist/cjs/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +4 -6
- package/dist/cjs/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +4 -6
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +8 -10
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +4 -9
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +4 -5
- package/dist/cjs/components/SpaceName/SpaceName.js +7 -9
- package/dist/cjs/components/index.js +12 -12
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +7 -9
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +5 -7
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +11 -20
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +17 -23
- package/dist/cjs/entries/index.js +3 -3
- package/dist/cjs/index.js +37 -37
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +4 -13
- package/dist/cjs/resources/Cards/ResourceCard.js +12 -16
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +17 -20
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +17 -20
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +13 -34
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +9 -11
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +6 -13
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +5 -12
- package/dist/cjs/resources/useResourceLinkActions.js +2 -11
- package/dist/cjs/types.js +3 -3
- package/dist/cjs/utils/fromFieldValidations.js +1 -2
- package/dist/cjs/utils/useSortIDs.js +4 -6
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/assets/MultipleMediaEditor.js +3 -3
- package/dist/esm/assets/SingleMediaEditor.js +2 -2
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +12 -12
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +9 -14
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +7 -15
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +6 -7
- package/dist/esm/common/EntityStore.js +22 -39
- package/dist/esm/common/MultipleReferenceEditor.js +9 -16
- package/dist/esm/common/ReferenceEditor.js +2 -2
- package/dist/esm/common/SingleReferenceEditor.js +5 -7
- package/dist/esm/common/SortableLinkList.js +12 -12
- package/dist/esm/common/queryClient.js +3 -10
- package/dist/esm/common/useContentTypePermissions.js +1 -3
- package/dist/esm/common/useEditorPermissions.js +3 -15
- package/dist/esm/common/useEditorPermissions.spec.js +11 -12
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +1 -1
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +5 -7
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +12 -12
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +15 -23
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +8 -9
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +19 -30
- package/dist/esm/components/LinkActions/LinkActions.js +9 -9
- package/dist/esm/components/LinkActions/LinkEntityActions.js +11 -18
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +1 -1
- package/dist/esm/components/LinkActions/helpers.js +2 -11
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +6 -6
- package/dist/esm/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +2 -2
- package/dist/esm/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +2 -2
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +3 -3
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +2 -5
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +2 -11
- package/dist/esm/components/SpaceName/SpaceName.js +4 -4
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +5 -5
- package/dist/esm/entries/SingleEntryReferenceEditor.js +3 -3
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +8 -15
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +14 -18
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +2 -9
- package/dist/esm/resources/Cards/ResourceCard.js +10 -12
- package/dist/esm/resources/Cards/ResourceCard.spec.js +11 -12
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +13 -14
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +11 -30
- package/dist/esm/resources/SingleResourceReferenceEditor.js +6 -6
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +4 -9
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +2 -9
- package/dist/esm/resources/useResourceLinkActions.js +2 -11
- package/dist/esm/utils/fromFieldValidations.js +0 -1
- package/dist/esm/utils/useSortIDs.js +2 -2
- package/dist/types/assets/MultipleMediaEditor.d.ts +2 -2
- package/dist/types/assets/SingleMediaEditor.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/AssetCardActions.d.ts +3 -3
- package/dist/types/assets/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/WrappedAssetCard.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/WrappedAssetLink.d.ts +2 -2
- package/dist/types/common/EntityStore.d.ts +1 -1
- package/dist/types/common/MultipleReferenceEditor.d.ts +1 -1
- package/dist/types/common/ReferenceEditor.d.ts +1 -1
- package/dist/types/common/SingleReferenceEditor.d.ts +1 -1
- package/dist/types/common/SortableLinkList.d.ts +1 -1
- package/dist/types/common/queryClient.d.ts +1 -1
- package/dist/types/components/AssetThumbnail/AssetThumbnail.d.ts +2 -2
- package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +1 -1
- package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +1 -1
- package/dist/types/components/LinkActions/CombinedLinkActions.d.ts +2 -2
- package/dist/types/components/LinkActions/LinkActions.d.ts +1 -1
- package/dist/types/components/LinkActions/LinkEntityActions.d.ts +2 -2
- package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -2
- package/dist/types/components/MissingEntityCard/MissingEntityCard.d.ts +2 -2
- package/dist/types/components/ResourceEntityErrorCard/ResourceEntityErrorCard.d.ts +2 -2
- package/dist/types/components/ResourceEntityErrorCard/UnsupportedEntityCard.d.ts +2 -2
- package/dist/types/components/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +1 -1
- package/dist/types/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +1 -1
- package/dist/types/components/SpaceName/SpaceName.d.ts +2 -2
- package/dist/types/entries/MultipleEntryReferenceEditor.d.ts +2 -2
- package/dist/types/entries/SingleEntryReferenceEditor.d.ts +2 -2
- package/dist/types/entries/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +2 -2
- package/dist/types/entries/WrappedEntryCard/WrappedEntryCard.d.ts +1 -1
- package/dist/types/resources/Cards/ContentfulEntryCard.d.ts +2 -2
- package/dist/types/resources/Cards/ResourceCard.d.ts +2 -2
- package/dist/types/resources/MultipleResourceReferenceEditor.d.ts +2 -2
- package/dist/types/resources/SingleResourceReferenceEditor.d.ts +2 -2
- package/package.json +7 -4
|
@@ -9,9 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
EntityProvider: function() {
|
|
13
|
-
return EntityProvider;
|
|
14
|
-
},
|
|
15
12
|
UnsupportedError: function() {
|
|
16
13
|
return UnsupportedError;
|
|
17
14
|
},
|
|
@@ -21,17 +18,20 @@ _export(exports, {
|
|
|
21
18
|
useEntity: function() {
|
|
22
19
|
return useEntity;
|
|
23
20
|
},
|
|
24
|
-
useEntityLoader: function() {
|
|
25
|
-
return useEntityLoader;
|
|
26
|
-
},
|
|
27
21
|
useResource: function() {
|
|
28
22
|
return useResource;
|
|
23
|
+
},
|
|
24
|
+
EntityProvider: function() {
|
|
25
|
+
return EntityProvider;
|
|
26
|
+
},
|
|
27
|
+
useEntityLoader: function() {
|
|
28
|
+
return useEntityLoader;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
const _react =
|
|
32
|
-
const _constate =
|
|
31
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
32
|
+
const _constate = _interop_require_default(require("constate"));
|
|
33
33
|
const _contentfulmanagement = require("contentful-management");
|
|
34
|
-
const _pqueue =
|
|
34
|
+
const _pqueue = _interop_require_default(require("p-queue"));
|
|
35
35
|
const _queryClient = require("./queryClient");
|
|
36
36
|
function _define_property(obj, key, value) {
|
|
37
37
|
if (key in obj) {
|
|
@@ -72,9 +72,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
72
72
|
if (cache && cache.has(obj)) {
|
|
73
73
|
return cache.get(obj);
|
|
74
74
|
}
|
|
75
|
-
var newObj = {
|
|
76
|
-
__proto__: null
|
|
77
|
-
};
|
|
75
|
+
var newObj = {};
|
|
78
76
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
79
77
|
for(var key in obj){
|
|
80
78
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -92,7 +90,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
92
90
|
}
|
|
93
91
|
return newObj;
|
|
94
92
|
}
|
|
95
|
-
// global queue for all requests, the actual number is picked without scientific research
|
|
96
93
|
const globalQueue = new _pqueue.default({
|
|
97
94
|
concurrency: 50
|
|
98
95
|
});
|
|
@@ -110,8 +107,7 @@ const isEntityQueryKey = (queryKey)=>{
|
|
|
110
107
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
111
108
|
};
|
|
112
109
|
async function fetchContentfulEntry(params) {
|
|
113
|
-
const { urn, fetch, options
|
|
114
|
-
// TODO use resource-names package EntryResourceName `fromString` method instead when the package becomes public
|
|
110
|
+
const { urn , fetch , options } = params;
|
|
115
111
|
const resourceId = urn.split(':', 6)[5];
|
|
116
112
|
const ENTITY_RESOURCE_ID_REGEX = RegExp("^spaces\\/(?<spaceId>[^/]+)(?:\\/environments\\/(?<environmentId>[^/]+))?\\/entries\\/(?<entityId>[^/]+)$");
|
|
117
113
|
const resourceIdMatch = resourceId.match(ENTITY_RESOURCE_ID_REGEX);
|
|
@@ -125,7 +121,7 @@ async function fetchContentfulEntry(params) {
|
|
|
125
121
|
fetch([
|
|
126
122
|
'space',
|
|
127
123
|
spaceId
|
|
128
|
-
], ({ cmaClient
|
|
124
|
+
], ({ cmaClient })=>cmaClient.space.get({
|
|
129
125
|
spaceId
|
|
130
126
|
}), options),
|
|
131
127
|
fetch([
|
|
@@ -133,7 +129,7 @@ async function fetchContentfulEntry(params) {
|
|
|
133
129
|
spaceId,
|
|
134
130
|
environmentId,
|
|
135
131
|
entryId
|
|
136
|
-
], ({ cmaClient
|
|
132
|
+
], ({ cmaClient })=>cmaClient.entry.get({
|
|
137
133
|
spaceId,
|
|
138
134
|
environmentId,
|
|
139
135
|
entryId
|
|
@@ -146,7 +142,7 @@ async function fetchContentfulEntry(params) {
|
|
|
146
142
|
spaceId,
|
|
147
143
|
environmentId,
|
|
148
144
|
contentTypeId
|
|
149
|
-
], ({ cmaClient
|
|
145
|
+
], ({ cmaClient })=>cmaClient.contentType.get({
|
|
150
146
|
contentTypeId,
|
|
151
147
|
spaceId,
|
|
152
148
|
environmentId
|
|
@@ -155,7 +151,7 @@ async function fetchContentfulEntry(params) {
|
|
|
155
151
|
'defaultLocale',
|
|
156
152
|
spaceId,
|
|
157
153
|
environmentId
|
|
158
|
-
], async ({ cmaClient
|
|
154
|
+
], async ({ cmaClient })=>{
|
|
159
155
|
const locales = await cmaClient.locale.getMany({
|
|
160
156
|
spaceId,
|
|
161
157
|
environmentId,
|
|
@@ -205,7 +201,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
205
201
|
props.queryConcurrency
|
|
206
202
|
]);
|
|
207
203
|
const fetch = (0, _react.useCallback)(function fetch(queryKey, fn, options = {}) {
|
|
208
|
-
const { priority, ...queryOptions } = options;
|
|
204
|
+
const { priority , ...queryOptions } = options;
|
|
209
205
|
return queryClient.fetchQuery(queryKey, ()=>queryQueue.add(()=>fn({
|
|
210
206
|
cmaClient
|
|
211
207
|
}), {
|
|
@@ -225,8 +221,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
225
221
|
spaceId,
|
|
226
222
|
environmentId
|
|
227
223
|
];
|
|
228
|
-
return fetch(queryKey,
|
|
229
|
-
({ cmaClient })=>{
|
|
224
|
+
return fetch(queryKey, ({ cmaClient })=>{
|
|
230
225
|
if (entityType === 'Entry') {
|
|
231
226
|
return cmaClient.entry.get({
|
|
232
227
|
entryId: entityId,
|
|
@@ -248,18 +243,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
248
243
|
currentSpaceId,
|
|
249
244
|
currentEnvironmentId
|
|
250
245
|
]);
|
|
251
|
-
|
|
252
|
-
* Fetch all scheduled actions for a given entity.
|
|
253
|
-
* This function fetches all schedules for all entries and then returns
|
|
254
|
-
* a filtered result based on the entityID provided.
|
|
255
|
-
*
|
|
256
|
-
* The result is then reused/cached for subsequent calls to this function.
|
|
257
|
-
*/ const getEntityScheduledActions = (0, _react.useCallback)(function getEntityScheduledActions(entityType, entityId, options) {
|
|
258
|
-
// This is fixed to force the cache to reuse previous results
|
|
246
|
+
const getEntityScheduledActions = (0, _react.useCallback)(function getEntityScheduledActions(entityType, entityId, options) {
|
|
259
247
|
const fixedEntityCacheId = 'scheduledActionEntityId';
|
|
260
|
-
// A space+environment combo can only have up to 500 scheduled actions
|
|
261
|
-
// With this request we fetch all schedules and can reuse the results.
|
|
262
|
-
// See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
|
|
263
248
|
const maxScheduledActions = 500;
|
|
264
249
|
const spaceId = options?.spaceId ?? currentSpaceId;
|
|
265
250
|
const environmentId = options?.environmentId ?? currentEnvironmentId;
|
|
@@ -270,8 +255,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
270
255
|
spaceId,
|
|
271
256
|
environmentId
|
|
272
257
|
];
|
|
273
|
-
|
|
274
|
-
return fetch(queryKey, async ({ cmaClient })=>{
|
|
258
|
+
return fetch(queryKey, async ({ cmaClient })=>{
|
|
275
259
|
const response = await cmaClient.scheduledActions.getMany({
|
|
276
260
|
spaceId,
|
|
277
261
|
query: {
|
|
@@ -315,7 +299,6 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
315
299
|
currentSpaceId,
|
|
316
300
|
environmentIds
|
|
317
301
|
]);
|
|
318
|
-
// @ts-expect-error ...
|
|
319
302
|
const onEntityChanged = props.sdk.space.onEntityChanged;
|
|
320
303
|
const onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
|
|
321
304
|
(0, _react.useEffect)(()=>{
|
|
@@ -326,16 +309,15 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
326
309
|
});
|
|
327
310
|
}
|
|
328
311
|
if (typeof onEntityChanged !== 'function') {
|
|
329
|
-
return onSlideInNavigation(({ oldSlideLevel, newSlideLevel
|
|
312
|
+
return onSlideInNavigation(({ oldSlideLevel , newSlideLevel })=>{
|
|
330
313
|
if (oldSlideLevel > newSlideLevel) {
|
|
331
314
|
findSameSpaceQueries().forEach((query)=>{
|
|
332
|
-
// automatically refetches the query
|
|
333
315
|
void queryClient.invalidateQueries(query.queryKey);
|
|
334
316
|
});
|
|
335
317
|
}
|
|
336
318
|
});
|
|
337
319
|
}
|
|
338
|
-
const subscribeQuery = ({ queryKey, queryHash
|
|
320
|
+
const subscribeQuery = ({ queryKey , queryHash })=>{
|
|
339
321
|
const [entityType, entityId] = queryKey;
|
|
340
322
|
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
341
323
|
queryClient.setQueryData(queryKey, data);
|
|
@@ -346,8 +328,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
346
328
|
if (!event) {
|
|
347
329
|
return;
|
|
348
330
|
}
|
|
349
|
-
const { type, query
|
|
350
|
-
const { queryKey, queryHash
|
|
331
|
+
const { type , query } = event;
|
|
332
|
+
const { queryKey , queryHash } = query;
|
|
351
333
|
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
352
334
|
return;
|
|
353
335
|
}
|
|
@@ -355,7 +337,6 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
355
337
|
subscribeQuery(query);
|
|
356
338
|
}
|
|
357
339
|
if (type === 'removed') {
|
|
358
|
-
// calling unsubscribe
|
|
359
340
|
entityChangeUnsubscribers.current[queryHash]?.();
|
|
360
341
|
}
|
|
361
342
|
});
|
|
@@ -380,24 +361,24 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
380
361
|
getEntity,
|
|
381
362
|
getEntityScheduledActions
|
|
382
363
|
};
|
|
383
|
-
}, ({ fetch
|
|
364
|
+
}, ({ fetch })=>fetch, ({ getResource , getEntity , getEntityScheduledActions })=>({
|
|
384
365
|
getResource,
|
|
385
366
|
getEntity,
|
|
386
367
|
getEntityScheduledActions
|
|
387
|
-
}), ({ ids
|
|
368
|
+
}), ({ ids })=>({
|
|
388
369
|
environment: ids.environmentAlias ?? ids.environment,
|
|
389
370
|
space: ids.space
|
|
390
371
|
}));
|
|
391
372
|
function useEntity(entityType, entityId, options) {
|
|
392
|
-
const { space, environment
|
|
393
|
-
const { getEntity
|
|
373
|
+
const { space , environment } = useCurrentIds();
|
|
374
|
+
const { getEntity } = useEntityLoader();
|
|
394
375
|
const queryKey = [
|
|
395
376
|
entityType,
|
|
396
377
|
entityId,
|
|
397
378
|
options?.spaceId ?? space,
|
|
398
379
|
options?.environmentId ?? environment
|
|
399
380
|
];
|
|
400
|
-
const { status, data
|
|
381
|
+
const { status , data } = (0, _queryClient.useQuery)(queryKey, ()=>getEntity(entityType, entityId, options), {
|
|
401
382
|
enabled: options?.enabled
|
|
402
383
|
});
|
|
403
384
|
return {
|
|
@@ -411,8 +392,8 @@ function useResource(resourceType, urn, options) {
|
|
|
411
392
|
resourceType,
|
|
412
393
|
urn
|
|
413
394
|
];
|
|
414
|
-
const { getResource
|
|
415
|
-
const { status, data, error
|
|
395
|
+
const { getResource } = useEntityLoader();
|
|
396
|
+
const { status , data , error } = (0, _queryClient.useQuery)(queryKey, ()=>getResource(resourceType, urn, options), {
|
|
416
397
|
enabled: options?.enabled
|
|
417
398
|
});
|
|
418
399
|
return {
|
|
@@ -421,6 +402,6 @@ function useResource(resourceType, urn, options) {
|
|
|
421
402
|
error
|
|
422
403
|
};
|
|
423
404
|
}
|
|
424
|
-
function EntityProvider({ children, ...props }) {
|
|
425
|
-
return
|
|
405
|
+
function EntityProvider({ children , ...props }) {
|
|
406
|
+
return _react.default.createElement(_queryClient.SharedQueryClientProvider, null, _react.default.createElement(InternalServiceProvider, props, children));
|
|
426
407
|
}
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "MultipleReferenceEditor", {
|
|
|
8
8
|
return MultipleReferenceEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _sortable = require("@dnd-kit/sortable");
|
|
13
13
|
const _components = require("../components");
|
|
14
14
|
const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
|
|
@@ -36,9 +36,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
36
36
|
if (cache && cache.has(obj)) {
|
|
37
37
|
return cache.get(obj);
|
|
38
38
|
}
|
|
39
|
-
var newObj = {
|
|
40
|
-
__proto__: null
|
|
41
|
-
};
|
|
39
|
+
var newObj = {};
|
|
42
40
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
41
|
for(var key in obj){
|
|
44
42
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -75,24 +73,18 @@ const nullableValue = {
|
|
|
75
73
|
}
|
|
76
74
|
};
|
|
77
75
|
function Editor(props) {
|
|
78
|
-
const { setValue, entityType, onSortingEnd, setIndexToUpdate
|
|
76
|
+
const { setValue , entityType , onSortingEnd , setIndexToUpdate } = props;
|
|
79
77
|
const editorPermissions = (0, _useEditorPermissions.useEditorPermissions)(props);
|
|
80
78
|
const items = _react.useMemo(()=>{
|
|
81
|
-
return (props.items || [])
|
|
82
|
-
// value for the multiref field, replace them with an object
|
|
83
|
-
// that has the shape of a Link to make the missing entry/asset
|
|
84
|
-
// card render
|
|
85
|
-
.map((link)=>link || nullableValue);
|
|
79
|
+
return (props.items || []).map((link)=>link || nullableValue);
|
|
86
80
|
}, [
|
|
87
81
|
props.items
|
|
88
82
|
]);
|
|
89
|
-
const { rearrangeSortIDs
|
|
83
|
+
const { rearrangeSortIDs } = (0, _useSortIDs.useSortIDs)(items);
|
|
90
84
|
const onSortStart = (0, _react.useCallback)(()=>{
|
|
91
85
|
document.body.classList.add('grabbing');
|
|
92
86
|
}, []);
|
|
93
|
-
const onSortEnd = (0, _react.useCallback)(({ oldIndex, newIndex
|
|
94
|
-
// custom callback that is invoked *before* we sort the array
|
|
95
|
-
// e.g. in Compose we want to sort the references in the referenceMap before re-rendering drag and drop
|
|
87
|
+
const onSortEnd = (0, _react.useCallback)(({ oldIndex , newIndex })=>{
|
|
96
88
|
onSortingEnd && onSortingEnd({
|
|
97
89
|
oldIndex,
|
|
98
90
|
newIndex
|
|
@@ -136,25 +128,24 @@ function Editor(props) {
|
|
|
136
128
|
onLink,
|
|
137
129
|
itemsLength: items.length
|
|
138
130
|
});
|
|
139
|
-
const customCardRenderer = (0, _react.useCallback)((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false,
|
|
140
|
-
[
|
|
131
|
+
const customCardRenderer = (0, _react.useCallback)((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, [
|
|
141
132
|
linkActionsProps
|
|
142
133
|
]);
|
|
143
|
-
return
|
|
134
|
+
return _react.createElement(_react.Fragment, null, props.children({
|
|
144
135
|
...props,
|
|
145
136
|
onSortStart,
|
|
146
137
|
onSortEnd,
|
|
147
138
|
onMove,
|
|
148
139
|
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
149
|
-
}),
|
|
140
|
+
}), _react.createElement(_components.LinkEntityActions, {
|
|
150
141
|
renderCustomActions: props.renderCustomActions,
|
|
151
142
|
...linkActionsProps
|
|
152
143
|
}));
|
|
153
144
|
}
|
|
154
145
|
function MultipleReferenceEditor(props) {
|
|
155
146
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
156
|
-
return
|
|
157
|
-
return
|
|
147
|
+
return _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value , disabled , setValue , externalReset })=>{
|
|
148
|
+
return _react.createElement(Editor, {
|
|
158
149
|
...props,
|
|
159
150
|
items: value || emptyArray,
|
|
160
151
|
isDisabled: disabled,
|
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "ReferenceEditor", {
|
|
|
8
8
|
return ReferenceEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
13
|
-
const _deepequal =
|
|
13
|
+
const _deepequal = _interop_require_default(require("deep-equal"));
|
|
14
14
|
const _EntityStore = require("./EntityStore");
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
@@ -38,9 +38,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
38
38
|
if (cache && cache.has(obj)) {
|
|
39
39
|
return cache.get(obj);
|
|
40
40
|
}
|
|
41
|
-
var newObj = {
|
|
42
|
-
__proto__: null
|
|
43
|
-
};
|
|
41
|
+
var newObj = {};
|
|
44
42
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
43
|
for(var key in obj){
|
|
46
44
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -59,9 +57,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
59
57
|
return newObj;
|
|
60
58
|
}
|
|
61
59
|
function ReferenceEditor(props) {
|
|
62
|
-
return
|
|
60
|
+
return _react.createElement(_EntityStore.EntityProvider, {
|
|
63
61
|
sdk: props.sdk
|
|
64
|
-
},
|
|
62
|
+
}, _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
65
63
|
debounce: 0,
|
|
66
64
|
field: props.sdk.field,
|
|
67
65
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "SingleReferenceEditor", {
|
|
|
8
8
|
return SingleReferenceEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _components = require("../components");
|
|
13
13
|
const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
|
|
14
14
|
const _ReferenceEditor = require("./ReferenceEditor");
|
|
@@ -34,9 +34,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
34
34
|
if (cache && cache.has(obj)) {
|
|
35
35
|
return cache.get(obj);
|
|
36
36
|
}
|
|
37
|
-
var newObj = {
|
|
38
|
-
__proto__: null
|
|
39
|
-
};
|
|
37
|
+
var newObj = {};
|
|
40
38
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
39
|
for(var key in obj){
|
|
42
40
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -55,7 +53,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
55
53
|
return newObj;
|
|
56
54
|
}
|
|
57
55
|
function Editor(props) {
|
|
58
|
-
const { setValue, entityType
|
|
56
|
+
const { setValue , entityType } = props;
|
|
59
57
|
const editorPermissions = (0, _useEditorPermissions.useEditorPermissions)(props);
|
|
60
58
|
const onCreate = (0, _react.useCallback)((id)=>void setValue({
|
|
61
59
|
sys: {
|
|
@@ -87,13 +85,11 @@ function Editor(props) {
|
|
|
87
85
|
onCreate,
|
|
88
86
|
onLink
|
|
89
87
|
});
|
|
90
|
-
|
|
91
|
-
const customCardRenderer = (0, _react.useCallback)((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
92
|
-
[
|
|
88
|
+
const customCardRenderer = (0, _react.useCallback)((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, [
|
|
93
89
|
linkActionsProps
|
|
94
90
|
]);
|
|
95
91
|
if (!props.entityId) {
|
|
96
|
-
return
|
|
92
|
+
return _react.createElement(_components.LinkEntityActions, {
|
|
97
93
|
renderCustomActions: props.renderCustomActions,
|
|
98
94
|
...linkActionsProps
|
|
99
95
|
});
|
|
@@ -105,8 +101,8 @@ function Editor(props) {
|
|
|
105
101
|
}
|
|
106
102
|
function SingleReferenceEditor(props) {
|
|
107
103
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
108
|
-
return
|
|
109
|
-
return
|
|
104
|
+
return _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value , setValue , disabled , externalReset })=>{
|
|
105
|
+
return _react.createElement(Editor, {
|
|
110
106
|
...props,
|
|
111
107
|
key: `${externalReset}-reference`,
|
|
112
108
|
entityId: value ? value.sys.id : '',
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "SortableLinkList", {
|
|
|
8
8
|
return SortableLinkList;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
12
|
-
const _f36tokens =
|
|
11
|
+
const _react = _interop_require_default(require("react"));
|
|
12
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
13
13
|
const _core = require("@dnd-kit/core");
|
|
14
14
|
const _sortable = require("@dnd-kit/sortable");
|
|
15
15
|
const _utilities = require("@dnd-kit/utilities");
|
|
@@ -35,8 +35,8 @@ const styles = {
|
|
|
35
35
|
display: 'flex'
|
|
36
36
|
})
|
|
37
37
|
};
|
|
38
|
-
const SortableLink = ({ id, items, item, isDisabled =
|
|
39
|
-
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging
|
|
38
|
+
const SortableLink = ({ id , items , item , isDisabled =false , index , children })=>{
|
|
39
|
+
const { listeners , setNodeRef , setActivatorNodeRef , transform , transition , isDragging } = (0, _sortable.useSortable)({
|
|
40
40
|
id
|
|
41
41
|
});
|
|
42
42
|
const style = {
|
|
@@ -49,16 +49,16 @@ const SortableLink = ({ id, items, item, isDisabled = false, index, children })=
|
|
|
49
49
|
};
|
|
50
50
|
const DragHandle = _react.default.useCallback((props)=>{
|
|
51
51
|
const SortableDragHandle = ()=>props.drag;
|
|
52
|
-
return
|
|
52
|
+
return _react.default.createElement("div", {
|
|
53
53
|
ref: setActivatorNodeRef,
|
|
54
54
|
className: styles.dragHandle,
|
|
55
55
|
...listeners
|
|
56
|
-
},
|
|
56
|
+
}, _react.default.createElement(SortableDragHandle, null));
|
|
57
57
|
}, [
|
|
58
58
|
listeners,
|
|
59
59
|
setActivatorNodeRef
|
|
60
60
|
]);
|
|
61
|
-
return
|
|
61
|
+
return _react.default.createElement("div", {
|
|
62
62
|
ref: setNodeRef,
|
|
63
63
|
style: style,
|
|
64
64
|
className: (0, _emotion.cx)(styles.item, {
|
|
@@ -72,8 +72,8 @@ const SortableLink = ({ id, items, item, isDisabled = false, index, children })=
|
|
|
72
72
|
DragHandle: isDisabled ? undefined : DragHandle
|
|
73
73
|
}));
|
|
74
74
|
};
|
|
75
|
-
const SortableLinkList = ({ items, isDisabled, className, children, onSortStart, onSortEnd, updateBeforeSortStart, sortingStrategy
|
|
76
|
-
const { sortIDs, rearrangeSortIDs
|
|
75
|
+
const SortableLinkList = ({ items , isDisabled , className , children , onSortStart , onSortEnd , updateBeforeSortStart , sortingStrategy })=>{
|
|
76
|
+
const { sortIDs , rearrangeSortIDs } = (0, _useSortIDs.useSortIDs)(items);
|
|
77
77
|
const onSortStartHandler = _react.default.useCallback((event)=>{
|
|
78
78
|
const index = sortIDs.findIndex((item)=>item.id === event.active.id);
|
|
79
79
|
updateBeforeSortStart?.({
|
|
@@ -86,7 +86,7 @@ const SortableLinkList = ({ items, isDisabled, className, children, onSortStart,
|
|
|
86
86
|
sortIDs
|
|
87
87
|
]);
|
|
88
88
|
const onSortEndHandler = _react.default.useCallback((event)=>{
|
|
89
|
-
const { active, over
|
|
89
|
+
const { active , over } = event;
|
|
90
90
|
if (active && over && active.id !== over.id) {
|
|
91
91
|
const oldIndex = sortIDs.findIndex((item)=>item.id === active.id);
|
|
92
92
|
const newIndex = sortIDs.findIndex((item)=>item.id === over.id);
|
|
@@ -101,17 +101,17 @@ const SortableLinkList = ({ items, isDisabled, className, children, onSortStart,
|
|
|
101
101
|
sortIDs,
|
|
102
102
|
rearrangeSortIDs
|
|
103
103
|
]);
|
|
104
|
-
return
|
|
104
|
+
return _react.default.createElement(_core.DndContext, {
|
|
105
105
|
onDragStart: onSortStartHandler,
|
|
106
106
|
onDragEnd: onSortEndHandler
|
|
107
|
-
},
|
|
107
|
+
}, _react.default.createElement(_sortable.SortableContext, {
|
|
108
108
|
items: sortIDs,
|
|
109
109
|
strategy: sortingStrategy
|
|
110
|
-
},
|
|
110
|
+
}, _react.default.createElement("div", {
|
|
111
111
|
className: (0, _emotion.cx)(styles.container, className)
|
|
112
112
|
}, items.map((item, index)=>{
|
|
113
113
|
const id = sortIDs[index]?.id;
|
|
114
|
-
return
|
|
114
|
+
return _react.default.createElement(SortableLink, {
|
|
115
115
|
key: id,
|
|
116
116
|
id: id,
|
|
117
117
|
items: items,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react =
|
|
5
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
6
6
|
function _getRequireWildcardCache(nodeInterop) {
|
|
7
7
|
if (typeof WeakMap !== "function") return null;
|
|
8
8
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -24,9 +24,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
24
24
|
if (cache && cache.has(obj)) {
|
|
25
25
|
return cache.get(obj);
|
|
26
26
|
}
|
|
27
|
-
var newObj = {
|
|
28
|
-
__proto__: null
|
|
29
|
-
};
|
|
27
|
+
var newObj = {};
|
|
30
28
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
31
29
|
for(var key in obj){
|
|
32
30
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -9,17 +9,17 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
useQueryClient: function() {
|
|
13
|
+
return useQueryClient;
|
|
14
14
|
},
|
|
15
15
|
useQuery: function() {
|
|
16
16
|
return useQuery;
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
return
|
|
18
|
+
SharedQueryClientProvider: function() {
|
|
19
|
+
return SharedQueryClientProvider;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
const _react =
|
|
22
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
23
23
|
const _reactquery = require("@tanstack/react-query");
|
|
24
24
|
function _getRequireWildcardCache(nodeInterop) {
|
|
25
25
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -42,9 +42,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
42
42
|
if (cache && cache.has(obj)) {
|
|
43
43
|
return cache.get(obj);
|
|
44
44
|
}
|
|
45
|
-
var newObj = {
|
|
46
|
-
__proto__: null
|
|
47
|
-
};
|
|
45
|
+
var newObj = {};
|
|
48
46
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
47
|
for(var key in obj){
|
|
50
48
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -62,10 +60,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
62
60
|
}
|
|
63
61
|
return newObj;
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
* A custom client context ensures zero conflict with host apps also using
|
|
67
|
-
* React Query.
|
|
68
|
-
*/ const clientContext = /*#__PURE__*/ _react.createContext(undefined);
|
|
63
|
+
const clientContext = _react.createContext(undefined);
|
|
69
64
|
function useQueryClient() {
|
|
70
65
|
const client = _react.useContext(clientContext);
|
|
71
66
|
return _react.useMemo(()=>{
|
|
@@ -94,9 +89,9 @@ const useQuery = (key, fn, opt)=>{
|
|
|
94
89
|
context: clientContext
|
|
95
90
|
});
|
|
96
91
|
};
|
|
97
|
-
function SharedQueryClientProvider({ children
|
|
92
|
+
function SharedQueryClientProvider({ children }) {
|
|
98
93
|
const client = useQueryClient();
|
|
99
|
-
return
|
|
94
|
+
return _react.createElement(clientContext.Provider, {
|
|
100
95
|
value: client
|
|
101
96
|
}, children);
|
|
102
97
|
}
|
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "useContentTypePermissions", {
|
|
|
11
11
|
const _react = require("react");
|
|
12
12
|
const _useAccessApi = require("./useAccessApi");
|
|
13
13
|
async function filter(arr, predicate) {
|
|
14
|
-
// intentionally parallel as we assume it's cached in the implementation of the access api
|
|
15
14
|
const fail = Symbol();
|
|
16
15
|
const results = await Promise.all(arr.map(async (item)=>await predicate(item) ? item : fail));
|
|
17
16
|
return results.filter((x)=>x !== fail);
|
|
@@ -31,7 +30,7 @@ function useContentTypePermissions(props) {
|
|
|
31
30
|
props.entityType
|
|
32
31
|
]);
|
|
33
32
|
const [creatableContentTypes, setCreatableContentTypes] = (0, _react.useState)(availableContentTypes);
|
|
34
|
-
const { canPerformActionOnEntryOfType
|
|
33
|
+
const { canPerformActionOnEntryOfType } = (0, _useAccessApi.useAccessApi)(props.sdk.access);
|
|
35
34
|
(0, _react.useEffect)(()=>{
|
|
36
35
|
function getContentTypes(action) {
|
|
37
36
|
return filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType(action, ct.sys.id));
|
|
@@ -41,7 +40,6 @@ function useContentTypePermissions(props) {
|
|
|
41
40
|
setCreatableContentTypes(creatable);
|
|
42
41
|
}
|
|
43
42
|
void checkContentTypeAccess();
|
|
44
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
45
43
|
}, [
|
|
46
44
|
availableContentTypes
|
|
47
45
|
]);
|
|
@@ -13,17 +13,17 @@ const _fromFieldValidations = require("../utils/fromFieldValidations");
|
|
|
13
13
|
const _useAccessApi = require("./useAccessApi");
|
|
14
14
|
const _useContentTypePermissions = require("./useContentTypePermissions");
|
|
15
15
|
function useEditorPermissions(props) {
|
|
16
|
-
const { sdk, entityType, parameters
|
|
16
|
+
const { sdk , entityType , parameters } = props;
|
|
17
17
|
const validations = (0, _react.useMemo)(()=>(0, _fromFieldValidations.fromFieldValidations)(props.sdk.field), [
|
|
18
18
|
props.sdk.field
|
|
19
19
|
]);
|
|
20
20
|
const [canCreateEntity, setCanCreateEntity] = (0, _react.useState)(true);
|
|
21
21
|
const [canLinkEntity, setCanLinkEntity] = (0, _react.useState)(true);
|
|
22
|
-
const { creatableContentTypes, availableContentTypes
|
|
22
|
+
const { creatableContentTypes , availableContentTypes } = (0, _useContentTypePermissions.useContentTypePermissions)({
|
|
23
23
|
...props,
|
|
24
24
|
validations
|
|
25
25
|
});
|
|
26
|
-
const { canPerformAction
|
|
26
|
+
const { canPerformAction } = (0, _useAccessApi.useAccessApi)(sdk.access);
|
|
27
27
|
(0, _react.useEffect)(()=>{
|
|
28
28
|
if (parameters.instance.showCreateEntityAction === false) {
|
|
29
29
|
setCanCreateEntity(false);
|
|
@@ -31,20 +31,15 @@ function useEditorPermissions(props) {
|
|
|
31
31
|
}
|
|
32
32
|
async function checkCreateAccess() {
|
|
33
33
|
if (entityType === 'Asset') {
|
|
34
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
35
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
36
34
|
const canCreate = await canPerformAction('create', 'Asset') || true;
|
|
37
35
|
setCanCreateEntity(canCreate);
|
|
38
36
|
}
|
|
39
37
|
if (entityType === 'Entry') {
|
|
40
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
41
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
42
38
|
const canCreate = creatableContentTypes.length > 0 || true;
|
|
43
39
|
setCanCreateEntity(canCreate);
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
42
|
void checkCreateAccess();
|
|
47
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
48
43
|
}, [
|
|
49
44
|
entityType,
|
|
50
45
|
parameters.instance,
|
|
@@ -57,22 +52,15 @@ function useEditorPermissions(props) {
|
|
|
57
52
|
}
|
|
58
53
|
async function checkLinkAccess() {
|
|
59
54
|
if (entityType === 'Asset') {
|
|
60
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
61
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
62
55
|
const canRead = await canPerformAction('read', 'Asset') || true;
|
|
63
56
|
setCanLinkEntity(canRead);
|
|
64
57
|
}
|
|
65
58
|
if (entityType === 'Entry') {
|
|
66
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
67
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
68
|
-
// TODO: always show every content type (it's just a filter) to avoid people not seeing
|
|
69
|
-
// their (partly limited) content types
|
|
70
59
|
const canRead = true;
|
|
71
60
|
setCanLinkEntity(canRead);
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
63
|
void checkLinkAccess();
|
|
75
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
76
64
|
}, [
|
|
77
65
|
entityType,
|
|
78
66
|
parameters.instance
|