@contentful/field-editor-reference 5.21.1 → 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 +8 -11
- 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 +5 -6
- 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
|
@@ -16,7 +16,6 @@ import constate from 'constate';
|
|
|
16
16
|
import { createClient } from 'contentful-management';
|
|
17
17
|
import PQueue from 'p-queue';
|
|
18
18
|
import { SharedQueryClientProvider, useQuery, useQueryClient } from './queryClient';
|
|
19
|
-
// global queue for all requests, the actual number is picked without scientific research
|
|
20
19
|
const globalQueue = new PQueue({
|
|
21
20
|
concurrency: 50
|
|
22
21
|
});
|
|
@@ -34,8 +33,7 @@ const isEntityQueryKey = (queryKey)=>{
|
|
|
34
33
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
35
34
|
};
|
|
36
35
|
async function fetchContentfulEntry(params) {
|
|
37
|
-
const { urn, fetch, options
|
|
38
|
-
// TODO use resource-names package EntryResourceName `fromString` method instead when the package becomes public
|
|
36
|
+
const { urn , fetch , options } = params;
|
|
39
37
|
const resourceId = urn.split(':', 6)[5];
|
|
40
38
|
const ENTITY_RESOURCE_ID_REGEX = RegExp("^spaces\\/(?<spaceId>[^/]+)(?:\\/environments\\/(?<environmentId>[^/]+))?\\/entries\\/(?<entityId>[^/]+)$");
|
|
41
39
|
const resourceIdMatch = resourceId.match(ENTITY_RESOURCE_ID_REGEX);
|
|
@@ -49,7 +47,7 @@ async function fetchContentfulEntry(params) {
|
|
|
49
47
|
fetch([
|
|
50
48
|
'space',
|
|
51
49
|
spaceId
|
|
52
|
-
], ({ cmaClient
|
|
50
|
+
], ({ cmaClient })=>cmaClient.space.get({
|
|
53
51
|
spaceId
|
|
54
52
|
}), options),
|
|
55
53
|
fetch([
|
|
@@ -57,7 +55,7 @@ async function fetchContentfulEntry(params) {
|
|
|
57
55
|
spaceId,
|
|
58
56
|
environmentId,
|
|
59
57
|
entryId
|
|
60
|
-
], ({ cmaClient
|
|
58
|
+
], ({ cmaClient })=>cmaClient.entry.get({
|
|
61
59
|
spaceId,
|
|
62
60
|
environmentId,
|
|
63
61
|
entryId
|
|
@@ -70,7 +68,7 @@ async function fetchContentfulEntry(params) {
|
|
|
70
68
|
spaceId,
|
|
71
69
|
environmentId,
|
|
72
70
|
contentTypeId
|
|
73
|
-
], ({ cmaClient
|
|
71
|
+
], ({ cmaClient })=>cmaClient.contentType.get({
|
|
74
72
|
contentTypeId,
|
|
75
73
|
spaceId,
|
|
76
74
|
environmentId
|
|
@@ -79,7 +77,7 @@ async function fetchContentfulEntry(params) {
|
|
|
79
77
|
'defaultLocale',
|
|
80
78
|
spaceId,
|
|
81
79
|
environmentId
|
|
82
|
-
], async ({ cmaClient
|
|
80
|
+
], async ({ cmaClient })=>{
|
|
83
81
|
const locales = await cmaClient.locale.getMany({
|
|
84
82
|
spaceId,
|
|
85
83
|
environmentId,
|
|
@@ -129,7 +127,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
129
127
|
props.queryConcurrency
|
|
130
128
|
]);
|
|
131
129
|
const fetch = useCallback(function fetch(queryKey, fn, options = {}) {
|
|
132
|
-
const { priority, ...queryOptions } = options;
|
|
130
|
+
const { priority , ...queryOptions } = options;
|
|
133
131
|
return queryClient.fetchQuery(queryKey, ()=>queryQueue.add(()=>fn({
|
|
134
132
|
cmaClient
|
|
135
133
|
}), {
|
|
@@ -149,8 +147,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
149
147
|
spaceId,
|
|
150
148
|
environmentId
|
|
151
149
|
];
|
|
152
|
-
return fetch(queryKey,
|
|
153
|
-
({ cmaClient })=>{
|
|
150
|
+
return fetch(queryKey, ({ cmaClient })=>{
|
|
154
151
|
if (entityType === 'Entry') {
|
|
155
152
|
return cmaClient.entry.get({
|
|
156
153
|
entryId: entityId,
|
|
@@ -172,18 +169,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
172
169
|
currentSpaceId,
|
|
173
170
|
currentEnvironmentId
|
|
174
171
|
]);
|
|
175
|
-
|
|
176
|
-
* Fetch all scheduled actions for a given entity.
|
|
177
|
-
* This function fetches all schedules for all entries and then returns
|
|
178
|
-
* a filtered result based on the entityID provided.
|
|
179
|
-
*
|
|
180
|
-
* The result is then reused/cached for subsequent calls to this function.
|
|
181
|
-
*/ const getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
|
|
182
|
-
// This is fixed to force the cache to reuse previous results
|
|
172
|
+
const getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
|
|
183
173
|
const fixedEntityCacheId = 'scheduledActionEntityId';
|
|
184
|
-
// A space+environment combo can only have up to 500 scheduled actions
|
|
185
|
-
// With this request we fetch all schedules and can reuse the results.
|
|
186
|
-
// See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
|
|
187
174
|
const maxScheduledActions = 500;
|
|
188
175
|
const spaceId = options?.spaceId ?? currentSpaceId;
|
|
189
176
|
const environmentId = options?.environmentId ?? currentEnvironmentId;
|
|
@@ -194,8 +181,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
194
181
|
spaceId,
|
|
195
182
|
environmentId
|
|
196
183
|
];
|
|
197
|
-
|
|
198
|
-
return fetch(queryKey, async ({ cmaClient })=>{
|
|
184
|
+
return fetch(queryKey, async ({ cmaClient })=>{
|
|
199
185
|
const response = await cmaClient.scheduledActions.getMany({
|
|
200
186
|
spaceId,
|
|
201
187
|
query: {
|
|
@@ -239,7 +225,6 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
239
225
|
currentSpaceId,
|
|
240
226
|
environmentIds
|
|
241
227
|
]);
|
|
242
|
-
// @ts-expect-error ...
|
|
243
228
|
const onEntityChanged = props.sdk.space.onEntityChanged;
|
|
244
229
|
const onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
|
|
245
230
|
useEffect(()=>{
|
|
@@ -250,16 +235,15 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
250
235
|
});
|
|
251
236
|
}
|
|
252
237
|
if (typeof onEntityChanged !== 'function') {
|
|
253
|
-
return onSlideInNavigation(({ oldSlideLevel, newSlideLevel
|
|
238
|
+
return onSlideInNavigation(({ oldSlideLevel , newSlideLevel })=>{
|
|
254
239
|
if (oldSlideLevel > newSlideLevel) {
|
|
255
240
|
findSameSpaceQueries().forEach((query)=>{
|
|
256
|
-
// automatically refetches the query
|
|
257
241
|
void queryClient.invalidateQueries(query.queryKey);
|
|
258
242
|
});
|
|
259
243
|
}
|
|
260
244
|
});
|
|
261
245
|
}
|
|
262
|
-
const subscribeQuery = ({ queryKey, queryHash
|
|
246
|
+
const subscribeQuery = ({ queryKey , queryHash })=>{
|
|
263
247
|
const [entityType, entityId] = queryKey;
|
|
264
248
|
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
265
249
|
queryClient.setQueryData(queryKey, data);
|
|
@@ -270,8 +254,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
270
254
|
if (!event) {
|
|
271
255
|
return;
|
|
272
256
|
}
|
|
273
|
-
const { type, query
|
|
274
|
-
const { queryKey, queryHash
|
|
257
|
+
const { type , query } = event;
|
|
258
|
+
const { queryKey , queryHash } = query;
|
|
275
259
|
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
276
260
|
return;
|
|
277
261
|
}
|
|
@@ -279,7 +263,6 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
279
263
|
subscribeQuery(query);
|
|
280
264
|
}
|
|
281
265
|
if (type === 'removed') {
|
|
282
|
-
// calling unsubscribe
|
|
283
266
|
entityChangeUnsubscribers.current[queryHash]?.();
|
|
284
267
|
}
|
|
285
268
|
});
|
|
@@ -304,24 +287,24 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
304
287
|
getEntity,
|
|
305
288
|
getEntityScheduledActions
|
|
306
289
|
};
|
|
307
|
-
}, ({ fetch
|
|
290
|
+
}, ({ fetch })=>fetch, ({ getResource , getEntity , getEntityScheduledActions })=>({
|
|
308
291
|
getResource,
|
|
309
292
|
getEntity,
|
|
310
293
|
getEntityScheduledActions
|
|
311
|
-
}), ({ ids
|
|
294
|
+
}), ({ ids })=>({
|
|
312
295
|
environment: ids.environmentAlias ?? ids.environment,
|
|
313
296
|
space: ids.space
|
|
314
297
|
}));
|
|
315
298
|
export function useEntity(entityType, entityId, options) {
|
|
316
|
-
const { space, environment
|
|
317
|
-
const { getEntity
|
|
299
|
+
const { space , environment } = useCurrentIds();
|
|
300
|
+
const { getEntity } = useEntityLoader();
|
|
318
301
|
const queryKey = [
|
|
319
302
|
entityType,
|
|
320
303
|
entityId,
|
|
321
304
|
options?.spaceId ?? space,
|
|
322
305
|
options?.environmentId ?? environment
|
|
323
306
|
];
|
|
324
|
-
const { status, data
|
|
307
|
+
const { status , data } = useQuery(queryKey, ()=>getEntity(entityType, entityId, options), {
|
|
325
308
|
enabled: options?.enabled
|
|
326
309
|
});
|
|
327
310
|
return {
|
|
@@ -335,8 +318,8 @@ export function useResource(resourceType, urn, options) {
|
|
|
335
318
|
resourceType,
|
|
336
319
|
urn
|
|
337
320
|
];
|
|
338
|
-
const { getResource
|
|
339
|
-
const { status, data, error
|
|
321
|
+
const { getResource } = useEntityLoader();
|
|
322
|
+
const { status , data , error } = useQuery(queryKey, ()=>getResource(resourceType, urn, options), {
|
|
340
323
|
enabled: options?.enabled
|
|
341
324
|
});
|
|
342
325
|
return {
|
|
@@ -345,7 +328,7 @@ export function useResource(resourceType, urn, options) {
|
|
|
345
328
|
error
|
|
346
329
|
};
|
|
347
330
|
}
|
|
348
|
-
function EntityProvider({ children, ...props }) {
|
|
349
|
-
return
|
|
331
|
+
function EntityProvider({ children , ...props }) {
|
|
332
|
+
return React.createElement(SharedQueryClientProvider, null, React.createElement(InternalServiceProvider, props, children));
|
|
350
333
|
}
|
|
351
334
|
export { EntityProvider, useEntityLoader };
|
|
@@ -25,24 +25,18 @@ const nullableValue = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
function Editor(props) {
|
|
28
|
-
const { setValue, entityType, onSortingEnd, setIndexToUpdate
|
|
28
|
+
const { setValue , entityType , onSortingEnd , setIndexToUpdate } = props;
|
|
29
29
|
const editorPermissions = useEditorPermissions(props);
|
|
30
30
|
const items = React.useMemo(()=>{
|
|
31
|
-
return (props.items || [])
|
|
32
|
-
// value for the multiref field, replace them with an object
|
|
33
|
-
// that has the shape of a Link to make the missing entry/asset
|
|
34
|
-
// card render
|
|
35
|
-
.map((link)=>link || nullableValue);
|
|
31
|
+
return (props.items || []).map((link)=>link || nullableValue);
|
|
36
32
|
}, [
|
|
37
33
|
props.items
|
|
38
34
|
]);
|
|
39
|
-
const { rearrangeSortIDs
|
|
35
|
+
const { rearrangeSortIDs } = useSortIDs(items);
|
|
40
36
|
const onSortStart = useCallback(()=>{
|
|
41
37
|
document.body.classList.add('grabbing');
|
|
42
38
|
}, []);
|
|
43
|
-
const onSortEnd = useCallback(({ oldIndex, newIndex
|
|
44
|
-
// custom callback that is invoked *before* we sort the array
|
|
45
|
-
// e.g. in Compose we want to sort the references in the referenceMap before re-rendering drag and drop
|
|
39
|
+
const onSortEnd = useCallback(({ oldIndex , newIndex })=>{
|
|
46
40
|
onSortingEnd && onSortingEnd({
|
|
47
41
|
oldIndex,
|
|
48
42
|
newIndex
|
|
@@ -86,25 +80,24 @@ function Editor(props) {
|
|
|
86
80
|
onLink,
|
|
87
81
|
itemsLength: items.length
|
|
88
82
|
});
|
|
89
|
-
const customCardRenderer = useCallback((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false,
|
|
90
|
-
[
|
|
83
|
+
const customCardRenderer = useCallback((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, [
|
|
91
84
|
linkActionsProps
|
|
92
85
|
]);
|
|
93
|
-
return
|
|
86
|
+
return React.createElement(React.Fragment, null, props.children({
|
|
94
87
|
...props,
|
|
95
88
|
onSortStart,
|
|
96
89
|
onSortEnd,
|
|
97
90
|
onMove,
|
|
98
91
|
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
99
|
-
}),
|
|
92
|
+
}), React.createElement(LinkEntityActions, {
|
|
100
93
|
renderCustomActions: props.renderCustomActions,
|
|
101
94
|
...linkActionsProps
|
|
102
95
|
}));
|
|
103
96
|
}
|
|
104
97
|
export function MultipleReferenceEditor(props) {
|
|
105
98
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
106
|
-
return
|
|
107
|
-
return
|
|
99
|
+
return React.createElement(ReferenceEditor, props, ({ value , disabled , setValue , externalReset })=>{
|
|
100
|
+
return React.createElement(Editor, {
|
|
108
101
|
...props,
|
|
109
102
|
items: value || emptyArray,
|
|
110
103
|
isDisabled: disabled,
|
|
@@ -3,9 +3,9 @@ import { FieldConnector } from '@contentful/field-editor-shared';
|
|
|
3
3
|
import deepEqual from 'deep-equal';
|
|
4
4
|
import { EntityProvider } from './EntityStore';
|
|
5
5
|
export function ReferenceEditor(props) {
|
|
6
|
-
return
|
|
6
|
+
return React.createElement(EntityProvider, {
|
|
7
7
|
sdk: props.sdk
|
|
8
|
-
},
|
|
8
|
+
}, React.createElement(FieldConnector, {
|
|
9
9
|
debounce: 0,
|
|
10
10
|
field: props.sdk.field,
|
|
11
11
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
@@ -5,7 +5,7 @@ import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions
|
|
|
5
5
|
import { ReferenceEditor } from './ReferenceEditor';
|
|
6
6
|
import { useEditorPermissions } from './useEditorPermissions';
|
|
7
7
|
function Editor(props) {
|
|
8
|
-
const { setValue, entityType
|
|
8
|
+
const { setValue , entityType } = props;
|
|
9
9
|
const editorPermissions = useEditorPermissions(props);
|
|
10
10
|
const onCreate = useCallback((id)=>void setValue({
|
|
11
11
|
sys: {
|
|
@@ -37,13 +37,11 @@ function Editor(props) {
|
|
|
37
37
|
onCreate,
|
|
38
38
|
onLink
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
const customCardRenderer = useCallback((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
42
|
-
[
|
|
40
|
+
const customCardRenderer = useCallback((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, [
|
|
43
41
|
linkActionsProps
|
|
44
42
|
]);
|
|
45
43
|
if (!props.entityId) {
|
|
46
|
-
return
|
|
44
|
+
return React.createElement(LinkEntityActions, {
|
|
47
45
|
renderCustomActions: props.renderCustomActions,
|
|
48
46
|
...linkActionsProps
|
|
49
47
|
});
|
|
@@ -55,8 +53,8 @@ function Editor(props) {
|
|
|
55
53
|
}
|
|
56
54
|
export function SingleReferenceEditor(props) {
|
|
57
55
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
58
|
-
return
|
|
59
|
-
return
|
|
56
|
+
return React.createElement(ReferenceEditor, props, ({ value , setValue , disabled , externalReset })=>{
|
|
57
|
+
return React.createElement(Editor, {
|
|
60
58
|
...props,
|
|
61
59
|
key: `${externalReset}-reference`,
|
|
62
60
|
entityId: value ? value.sys.id : '',
|
|
@@ -20,8 +20,8 @@ const styles = {
|
|
|
20
20
|
display: 'flex'
|
|
21
21
|
})
|
|
22
22
|
};
|
|
23
|
-
const SortableLink = ({ id, items, item, isDisabled =
|
|
24
|
-
const { listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging
|
|
23
|
+
const SortableLink = ({ id , items , item , isDisabled =false , index , children })=>{
|
|
24
|
+
const { listeners , setNodeRef , setActivatorNodeRef , transform , transition , isDragging } = useSortable({
|
|
25
25
|
id
|
|
26
26
|
});
|
|
27
27
|
const style = {
|
|
@@ -34,16 +34,16 @@ const SortableLink = ({ id, items, item, isDisabled = false, index, children })=
|
|
|
34
34
|
};
|
|
35
35
|
const DragHandle = React.useCallback((props)=>{
|
|
36
36
|
const SortableDragHandle = ()=>props.drag;
|
|
37
|
-
return
|
|
37
|
+
return React.createElement("div", {
|
|
38
38
|
ref: setActivatorNodeRef,
|
|
39
39
|
className: styles.dragHandle,
|
|
40
40
|
...listeners
|
|
41
|
-
},
|
|
41
|
+
}, React.createElement(SortableDragHandle, null));
|
|
42
42
|
}, [
|
|
43
43
|
listeners,
|
|
44
44
|
setActivatorNodeRef
|
|
45
45
|
]);
|
|
46
|
-
return
|
|
46
|
+
return React.createElement("div", {
|
|
47
47
|
ref: setNodeRef,
|
|
48
48
|
style: style,
|
|
49
49
|
className: cx(styles.item, {
|
|
@@ -57,8 +57,8 @@ const SortableLink = ({ id, items, item, isDisabled = false, index, children })=
|
|
|
57
57
|
DragHandle: isDisabled ? undefined : DragHandle
|
|
58
58
|
}));
|
|
59
59
|
};
|
|
60
|
-
export const SortableLinkList = ({ items, isDisabled, className, children, onSortStart, onSortEnd, updateBeforeSortStart, sortingStrategy
|
|
61
|
-
const { sortIDs, rearrangeSortIDs
|
|
60
|
+
export const SortableLinkList = ({ items , isDisabled , className , children , onSortStart , onSortEnd , updateBeforeSortStart , sortingStrategy })=>{
|
|
61
|
+
const { sortIDs , rearrangeSortIDs } = useSortIDs(items);
|
|
62
62
|
const onSortStartHandler = React.useCallback((event)=>{
|
|
63
63
|
const index = sortIDs.findIndex((item)=>item.id === event.active.id);
|
|
64
64
|
updateBeforeSortStart?.({
|
|
@@ -71,7 +71,7 @@ export const SortableLinkList = ({ items, isDisabled, className, children, onSor
|
|
|
71
71
|
sortIDs
|
|
72
72
|
]);
|
|
73
73
|
const onSortEndHandler = React.useCallback((event)=>{
|
|
74
|
-
const { active, over
|
|
74
|
+
const { active , over } = event;
|
|
75
75
|
if (active && over && active.id !== over.id) {
|
|
76
76
|
const oldIndex = sortIDs.findIndex((item)=>item.id === active.id);
|
|
77
77
|
const newIndex = sortIDs.findIndex((item)=>item.id === over.id);
|
|
@@ -86,17 +86,17 @@ export const SortableLinkList = ({ items, isDisabled, className, children, onSor
|
|
|
86
86
|
sortIDs,
|
|
87
87
|
rearrangeSortIDs
|
|
88
88
|
]);
|
|
89
|
-
return
|
|
89
|
+
return React.createElement(DndContext, {
|
|
90
90
|
onDragStart: onSortStartHandler,
|
|
91
91
|
onDragEnd: onSortEndHandler
|
|
92
|
-
},
|
|
92
|
+
}, React.createElement(SortableContext, {
|
|
93
93
|
items: sortIDs,
|
|
94
94
|
strategy: sortingStrategy
|
|
95
|
-
},
|
|
95
|
+
}, React.createElement("div", {
|
|
96
96
|
className: cx(styles.container, className)
|
|
97
97
|
}, items.map((item, index)=>{
|
|
98
98
|
const id = sortIDs[index]?.id;
|
|
99
|
-
return
|
|
99
|
+
return React.createElement(SortableLink, {
|
|
100
100
|
key: id,
|
|
101
101
|
id: id,
|
|
102
102
|
items: items,
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { QueryClient, useQuery as useRQ } from '@tanstack/react-query';
|
|
3
|
-
|
|
4
|
-
* A custom client context ensures zero conflict with host apps also using
|
|
5
|
-
* React Query.
|
|
6
|
-
*/ const clientContext = /*#__PURE__*/ React.createContext(undefined);
|
|
3
|
+
const clientContext = React.createContext(undefined);
|
|
7
4
|
export function useQueryClient() {
|
|
8
5
|
const client = React.useContext(clientContext);
|
|
9
6
|
return React.useMemo(()=>{
|
|
@@ -26,19 +23,15 @@ export function useQueryClient() {
|
|
|
26
23
|
client
|
|
27
24
|
]);
|
|
28
25
|
}
|
|
29
|
-
// @ts-expect-error
|
|
30
26
|
export const useQuery = (key, fn, opt)=>{
|
|
31
27
|
return useRQ(key, fn, {
|
|
32
28
|
...opt,
|
|
33
29
|
context: clientContext
|
|
34
30
|
});
|
|
35
31
|
};
|
|
36
|
-
|
|
37
|
-
* Provides access to a query client either by sharing an existing client or
|
|
38
|
-
* creating a new one.
|
|
39
|
-
*/ export function SharedQueryClientProvider({ children }) {
|
|
32
|
+
export function SharedQueryClientProvider({ children }) {
|
|
40
33
|
const client = useQueryClient();
|
|
41
|
-
return
|
|
34
|
+
return React.createElement(clientContext.Provider, {
|
|
42
35
|
value: client
|
|
43
36
|
}, children);
|
|
44
37
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useAccessApi } from './useAccessApi';
|
|
3
3
|
async function filter(arr, predicate) {
|
|
4
|
-
// intentionally parallel as we assume it's cached in the implementation of the access api
|
|
5
4
|
const fail = Symbol();
|
|
6
5
|
const results = await Promise.all(arr.map(async (item)=>await predicate(item) ? item : fail));
|
|
7
6
|
return results.filter((x)=>x !== fail);
|
|
@@ -21,7 +20,7 @@ export function useContentTypePermissions(props) {
|
|
|
21
20
|
props.entityType
|
|
22
21
|
]);
|
|
23
22
|
const [creatableContentTypes, setCreatableContentTypes] = useState(availableContentTypes);
|
|
24
|
-
const { canPerformActionOnEntryOfType
|
|
23
|
+
const { canPerformActionOnEntryOfType } = useAccessApi(props.sdk.access);
|
|
25
24
|
useEffect(()=>{
|
|
26
25
|
function getContentTypes(action) {
|
|
27
26
|
return filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType(action, ct.sys.id));
|
|
@@ -31,7 +30,6 @@ export function useContentTypePermissions(props) {
|
|
|
31
30
|
setCreatableContentTypes(creatable);
|
|
32
31
|
}
|
|
33
32
|
void checkContentTypeAccess();
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
35
33
|
}, [
|
|
36
34
|
availableContentTypes
|
|
37
35
|
]);
|
|
@@ -3,17 +3,17 @@ import { fromFieldValidations } from '../utils/fromFieldValidations';
|
|
|
3
3
|
import { useAccessApi } from './useAccessApi';
|
|
4
4
|
import { useContentTypePermissions } from './useContentTypePermissions';
|
|
5
5
|
export function useEditorPermissions(props) {
|
|
6
|
-
const { sdk, entityType, parameters
|
|
6
|
+
const { sdk , entityType , parameters } = props;
|
|
7
7
|
const validations = useMemo(()=>fromFieldValidations(props.sdk.field), [
|
|
8
8
|
props.sdk.field
|
|
9
9
|
]);
|
|
10
10
|
const [canCreateEntity, setCanCreateEntity] = useState(true);
|
|
11
11
|
const [canLinkEntity, setCanLinkEntity] = useState(true);
|
|
12
|
-
const { creatableContentTypes, availableContentTypes
|
|
12
|
+
const { creatableContentTypes , availableContentTypes } = useContentTypePermissions({
|
|
13
13
|
...props,
|
|
14
14
|
validations
|
|
15
15
|
});
|
|
16
|
-
const { canPerformAction
|
|
16
|
+
const { canPerformAction } = useAccessApi(sdk.access);
|
|
17
17
|
useEffect(()=>{
|
|
18
18
|
if (parameters.instance.showCreateEntityAction === false) {
|
|
19
19
|
setCanCreateEntity(false);
|
|
@@ -21,20 +21,15 @@ export function useEditorPermissions(props) {
|
|
|
21
21
|
}
|
|
22
22
|
async function checkCreateAccess() {
|
|
23
23
|
if (entityType === 'Asset') {
|
|
24
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
25
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
26
24
|
const canCreate = await canPerformAction('create', 'Asset') || true;
|
|
27
25
|
setCanCreateEntity(canCreate);
|
|
28
26
|
}
|
|
29
27
|
if (entityType === 'Entry') {
|
|
30
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
31
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
32
28
|
const canCreate = creatableContentTypes.length > 0 || true;
|
|
33
29
|
setCanCreateEntity(canCreate);
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
void checkCreateAccess();
|
|
37
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
38
33
|
}, [
|
|
39
34
|
entityType,
|
|
40
35
|
parameters.instance,
|
|
@@ -47,22 +42,15 @@ export function useEditorPermissions(props) {
|
|
|
47
42
|
}
|
|
48
43
|
async function checkLinkAccess() {
|
|
49
44
|
if (entityType === 'Asset') {
|
|
50
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
51
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
52
45
|
const canRead = await canPerformAction('read', 'Asset') || true;
|
|
53
46
|
setCanLinkEntity(canRead);
|
|
54
47
|
}
|
|
55
48
|
if (entityType === 'Entry') {
|
|
56
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
57
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
58
|
-
// TODO: always show every content type (it's just a filter) to avoid people not seeing
|
|
59
|
-
// their (partly limited) content types
|
|
60
49
|
const canRead = true;
|
|
61
50
|
setCanLinkEntity(canRead);
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
53
|
void checkLinkAccess();
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
66
54
|
}, [
|
|
67
55
|
entityType,
|
|
68
56
|
parameters.instance
|
|
@@ -14,7 +14,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
14
14
|
id
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
const renderEditorPermissions = async ({ entityType, params =
|
|
17
|
+
const renderEditorPermissions = async ({ entityType , params ={} , allContentTypes =[] , customizeMock , customizeSdk })=>{
|
|
18
18
|
const sdk = makeFieldAppSDK(customizeMock);
|
|
19
19
|
customizeSdk?.(sdk);
|
|
20
20
|
const renderResult = renderHook(()=>useEditorPermissions({
|
|
@@ -33,7 +33,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
33
33
|
};
|
|
34
34
|
describe(`behaviour on Asset`, ()=>{
|
|
35
35
|
it(`wont check access when turned off via instance params`, async ()=>{
|
|
36
|
-
const { result, sdk
|
|
36
|
+
const { result , sdk } = await renderEditorPermissions({
|
|
37
37
|
entityType: 'Asset',
|
|
38
38
|
params: {
|
|
39
39
|
showCreateEntityAction: false,
|
|
@@ -45,20 +45,20 @@ describe('useEditorPermissions', ()=>{
|
|
|
45
45
|
expect(sdk.access.can).not.toHaveBeenCalledWith();
|
|
46
46
|
});
|
|
47
47
|
it(`checks basic access`, async ()=>{
|
|
48
|
-
const { sdk
|
|
48
|
+
const { sdk } = await renderEditorPermissions({
|
|
49
49
|
entityType: 'Asset'
|
|
50
50
|
});
|
|
51
51
|
expect(sdk.access.can).toHaveBeenCalledWith('create', 'Asset');
|
|
52
52
|
expect(sdk.access.can).toHaveBeenCalledWith('read', 'Asset');
|
|
53
53
|
});
|
|
54
54
|
it(`defaults link asset action visibility to true`, async ()=>{
|
|
55
|
-
const { result
|
|
55
|
+
const { result } = await renderEditorPermissions({
|
|
56
56
|
entityType: 'Asset'
|
|
57
57
|
});
|
|
58
58
|
expect(result.current.canLinkEntity).toBeTruthy();
|
|
59
59
|
});
|
|
60
60
|
it(`returns empty contentTypes`, async ()=>{
|
|
61
|
-
const { result
|
|
61
|
+
const { result } = await renderEditorPermissions({
|
|
62
62
|
entityType: 'Asset',
|
|
63
63
|
allContentTypes: [
|
|
64
64
|
makeContentType('one')
|
|
@@ -77,7 +77,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
79
|
it(`wont check access when turned off via instance params`, async ()=>{
|
|
80
|
-
const { result, sdk
|
|
80
|
+
const { result , sdk } = await renderEditorPermissions({
|
|
81
81
|
entityType: 'Entry',
|
|
82
82
|
params: {
|
|
83
83
|
showCreateEntityAction: false,
|
|
@@ -93,7 +93,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
93
93
|
makeContentType('one'),
|
|
94
94
|
makeContentType('two')
|
|
95
95
|
];
|
|
96
|
-
const { result
|
|
96
|
+
const { result } = await renderEditorPermissions({
|
|
97
97
|
entityType: 'Entry',
|
|
98
98
|
allContentTypes,
|
|
99
99
|
customizeSdk: (sdk)=>{
|
|
@@ -107,7 +107,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
107
107
|
makeContentType('one'),
|
|
108
108
|
makeContentType('two')
|
|
109
109
|
];
|
|
110
|
-
const { result
|
|
110
|
+
const { result } = await renderEditorPermissions({
|
|
111
111
|
entityType: 'Entry',
|
|
112
112
|
allContentTypes,
|
|
113
113
|
customizeSdk: (sdk)=>{
|
|
@@ -121,7 +121,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
121
121
|
makeContentType('one'),
|
|
122
122
|
makeContentType('two')
|
|
123
123
|
];
|
|
124
|
-
const { result
|
|
124
|
+
const { result } = await renderEditorPermissions({
|
|
125
125
|
entityType: 'Entry',
|
|
126
126
|
allContentTypes,
|
|
127
127
|
customizeSdk: (sdk)=>{
|
|
@@ -130,13 +130,12 @@ describe('useEditorPermissions', ()=>{
|
|
|
130
130
|
});
|
|
131
131
|
expect(result.current.canLinkEntity).toBe(true);
|
|
132
132
|
});
|
|
133
|
-
// eslint-disable-next-line -- TODO: describe this disable jest/no-test-prefixes
|
|
134
133
|
it.skip(`denies creation when no content-type can be read`, async ()=>{
|
|
135
134
|
const allContentTypes = [
|
|
136
135
|
makeContentType('one'),
|
|
137
136
|
makeContentType('two')
|
|
138
137
|
];
|
|
139
|
-
const { result
|
|
138
|
+
const { result } = await renderEditorPermissions({
|
|
140
139
|
entityType: 'Entry',
|
|
141
140
|
allContentTypes,
|
|
142
141
|
customizeSdk: (sdk)=>{
|
|
@@ -150,7 +149,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
150
149
|
makeContentType('one'),
|
|
151
150
|
makeContentType('two')
|
|
152
151
|
];
|
|
153
|
-
const { result
|
|
152
|
+
const { result } = await renderEditorPermissions({
|
|
154
153
|
entityType: 'Entry',
|
|
155
154
|
allContentTypes,
|
|
156
155
|
customizeMock: (field)=>{
|
|
@@ -4,7 +4,7 @@ const dimensions = {
|
|
|
4
4
|
height: 70
|
|
5
5
|
};
|
|
6
6
|
export function AssetThumbnail(props) {
|
|
7
|
-
return
|
|
7
|
+
return React.createElement("img", {
|
|
8
8
|
alt: props.file.fileName,
|
|
9
9
|
src: `${props.file.url}?w=${dimensions.width}&h=${dimensions.height}&fit=thumb`,
|
|
10
10
|
height: dimensions.height,
|
|
@@ -19,17 +19,15 @@ const redesignStyles = {
|
|
|
19
19
|
maxWidth: '300px'
|
|
20
20
|
})
|
|
21
21
|
};
|
|
22
|
-
export const CreateEntryLinkButton = ({ contentTypes, onSelect, customDropdownItems, text, testId, hasPlusIcon =
|
|
22
|
+
export const CreateEntryLinkButton = ({ contentTypes , onSelect , customDropdownItems , text , testId , hasPlusIcon =false , useExperimentalStyles , suggestedContentTypeId , dropdownSettings , disabled =false })=>{
|
|
23
23
|
contentTypes = contentTypes.sort((a, b)=>a.name.localeCompare(b.name));
|
|
24
24
|
const suggestedContentType = contentTypes.find((ct)=>ct.sys.id === suggestedContentTypeId);
|
|
25
25
|
const buttonText = text || `Add ${get(suggestedContentType || (contentTypes.length === 1 ? contentTypes[0] : {}), 'name', 'entry')}`;
|
|
26
26
|
const hasDropdown = contentTypes.length > 1 || customDropdownItems;
|
|
27
|
-
|
|
28
|
-
const plusIcon = hasPlusIcon ? /*#__PURE__*/ React.createElement(PlusIcon, null) : undefined;
|
|
29
|
-
// TODO: Always use "New content" here if we fully switch to new layout.
|
|
27
|
+
const plusIcon = hasPlusIcon ? React.createElement(PlusIcon, null) : undefined;
|
|
30
28
|
const contentTypesLabel = useExperimentalStyles ? 'New content' : undefined;
|
|
31
29
|
const styles = useExperimentalStyles ? redesignStyles : standardStyles;
|
|
32
|
-
return
|
|
30
|
+
return React.createElement(CreateEntryMenuTrigger, {
|
|
33
31
|
contentTypes: contentTypes,
|
|
34
32
|
suggestedContentTypeId: suggestedContentTypeId,
|
|
35
33
|
contentTypesLabel: contentTypesLabel,
|
|
@@ -37,8 +35,8 @@ export const CreateEntryLinkButton = ({ contentTypes, onSelect, customDropdownIt
|
|
|
37
35
|
testId: testId,
|
|
38
36
|
dropdownSettings: dropdownSettings,
|
|
39
37
|
customDropdownItems: customDropdownItems
|
|
40
|
-
}, ({ isSelecting
|
|
41
|
-
endIcon: hasDropdown ?
|
|
38
|
+
}, ({ isSelecting })=>React.createElement(Button, {
|
|
39
|
+
endIcon: hasDropdown ? React.createElement(ChevronDownIcon, null) : undefined,
|
|
42
40
|
variant: "secondary",
|
|
43
41
|
className: styles.action,
|
|
44
42
|
isDisabled: disabled || isSelecting,
|