@contentful/field-editor-reference 5.21.4 → 5.21.5
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 +5 -5
- package/dist/cjs/__fixtures__/entry/index.js +3 -3
- package/dist/cjs/__fixtures__/fixtures.js +3 -1
- package/dist/cjs/assets/MultipleMediaEditor.js +4 -2
- package/dist/cjs/assets/SingleMediaEditor.js +4 -2
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +8 -6
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +8 -6
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +4 -2
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +4 -2
- package/dist/cjs/assets/index.js +3 -3
- package/dist/cjs/common/EntityStore.js +29 -27
- package/dist/cjs/common/MultipleReferenceEditor.js +7 -5
- package/dist/cjs/common/ReferenceEditor.js +3 -1
- package/dist/cjs/common/SingleReferenceEditor.js +5 -3
- package/dist/cjs/common/SortableLinkList.js +5 -5
- package/dist/cjs/common/customCardTypes.js +3 -1
- package/dist/cjs/common/queryClient.js +8 -6
- package/dist/cjs/common/useContentTypePermissions.js +1 -1
- package/dist/cjs/common/useEditorPermissions.js +3 -3
- package/dist/cjs/common/useEditorPermissions.spec.js +11 -11
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +3 -1
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +5 -3
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +15 -13
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +5 -3
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +8 -6
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +3 -1
- package/dist/cjs/components/LinkActions/LinkActions.js +6 -4
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +11 -9
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +3 -1
- package/dist/cjs/components/LinkActions/helpers.js +5 -5
- package/dist/cjs/components/LinkActions/redesignStyles.js +3 -3
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +3 -1
- package/dist/cjs/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +3 -1
- package/dist/cjs/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +3 -1
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +8 -6
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +4 -2
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +3 -3
- package/dist/cjs/components/SpaceName/SpaceName.js +3 -1
- package/dist/cjs/components/index.js +12 -12
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +5 -3
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +4 -2
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +8 -6
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +5 -3
- package/dist/cjs/entries/index.js +3 -3
- package/dist/cjs/index.js +37 -37
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +4 -2
- package/dist/cjs/resources/Cards/ResourceCard.js +6 -4
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +12 -10
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +10 -8
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +7 -5
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +5 -3
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +3 -1
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +5 -5
- package/dist/cjs/resources/useResourceLinkActions.js +1 -1
- package/dist/cjs/types.js +3 -3
- package/dist/cjs/utils/useSortIDs.js +5 -3
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/assets/MultipleMediaEditor.js +1 -1
- package/dist/esm/assets/SingleMediaEditor.js +1 -1
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +2 -2
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +5 -5
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +1 -1
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +1 -1
- package/dist/esm/common/EntityStore.js +20 -20
- package/dist/esm/common/MultipleReferenceEditor.js +4 -4
- package/dist/esm/common/SingleReferenceEditor.js +2 -2
- package/dist/esm/common/SortableLinkList.js +5 -5
- package/dist/esm/common/queryClient.js +1 -1
- package/dist/esm/common/useContentTypePermissions.js +1 -1
- package/dist/esm/common/useEditorPermissions.js +3 -3
- package/dist/esm/common/useEditorPermissions.spec.js +11 -11
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +2 -2
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +12 -12
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +2 -2
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +5 -5
- package/dist/esm/components/LinkActions/LinkEntityActions.js +4 -4
- package/dist/esm/components/LinkActions/helpers.js +2 -2
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +2 -2
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +1 -1
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +2 -2
- package/dist/esm/entries/SingleEntryReferenceEditor.js +1 -1
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +5 -5
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +2 -2
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +1 -1
- package/dist/esm/resources/Cards/ResourceCard.js +3 -3
- package/dist/esm/resources/Cards/ResourceCard.spec.js +9 -9
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +7 -7
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +4 -4
- package/dist/esm/resources/SingleResourceReferenceEditor.js +2 -2
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +2 -2
- package/dist/esm/resources/useResourceLinkActions.js +1 -1
- package/dist/esm/utils/useSortIDs.js +2 -2
- package/package.json +3 -3
|
@@ -31,7 +31,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
31
31
|
if (cache && cache.has(obj)) {
|
|
32
32
|
return cache.get(obj);
|
|
33
33
|
}
|
|
34
|
-
var newObj = {
|
|
34
|
+
var newObj = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
};
|
|
35
37
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
36
38
|
for(var key in obj){
|
|
37
39
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -51,7 +53,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
51
53
|
}
|
|
52
54
|
const useSortIDs = (items)=>{
|
|
53
55
|
const ids = (items || []).map((item, index)=>{
|
|
54
|
-
const { type
|
|
56
|
+
const { type } = item.sys;
|
|
55
57
|
return {
|
|
56
58
|
id: type === 'ResourceLink' ? `${item.sys.urn}-${index}` : `${item.sys.id}-${index}`
|
|
57
59
|
};
|
|
@@ -60,7 +62,7 @@ const useSortIDs = (items)=>{
|
|
|
60
62
|
_react.default.useEffect(()=>{
|
|
61
63
|
if (items.length !== sortIDs.length) {
|
|
62
64
|
const ids = items.map((item, index)=>{
|
|
63
|
-
const { type
|
|
65
|
+
const { type } = item.sys;
|
|
64
66
|
return {
|
|
65
67
|
id: type === 'ResourceLink' ? `${item.sys.urn}-${index}` : `${item.sys.id}-${index}`
|
|
66
68
|
};
|
|
@@ -49,7 +49,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
49
49
|
locales,
|
|
50
50
|
cmaAdapter: createFakeCMAAdapter({
|
|
51
51
|
Entry: {
|
|
52
|
-
get: async ({ entryId
|
|
52
|
+
get: async ({ entryId })=>{
|
|
53
53
|
if (props?.fetchDelay) {
|
|
54
54
|
await delay(props.fetchDelay);
|
|
55
55
|
}
|
|
@@ -66,7 +66,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
Asset: {
|
|
69
|
-
get: async ({ assetId
|
|
69
|
+
get: async ({ assetId })=>{
|
|
70
70
|
if (props?.fetchDelay) {
|
|
71
71
|
await delay(props.fetchDelay);
|
|
72
72
|
}
|
|
@@ -91,7 +91,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
ContentType: {
|
|
94
|
-
get: async ({ contentTypeId
|
|
94
|
+
get: async ({ contentTypeId })=>{
|
|
95
95
|
if (contentTypeId === contentTypes.published.sys.id) {
|
|
96
96
|
return contentTypes.published;
|
|
97
97
|
}
|
|
@@ -21,7 +21,7 @@ export function MultipleMediaEditor(props) {
|
|
|
21
21
|
className: cx({
|
|
22
22
|
[styles.gridContainer]: childrenProps.viewType === 'card'
|
|
23
23
|
})
|
|
24
|
-
}, ({ items
|
|
24
|
+
}, ({ items, item, index, isDisabled, DragHandle })=>React.createElement(FetchingWrappedAssetCard, {
|
|
25
25
|
...childrenProps,
|
|
26
26
|
isDisabled: isDisabled,
|
|
27
27
|
key: `${item.sys.id}-${index}`,
|
|
@@ -5,7 +5,7 @@ export function SingleMediaEditor(props) {
|
|
|
5
5
|
return React.createElement(SingleReferenceEditor, {
|
|
6
6
|
...props,
|
|
7
7
|
entityType: "Asset"
|
|
8
|
-
}, ({ entityId
|
|
8
|
+
}, ({ entityId, isDisabled, setValue })=>React.createElement(FetchingWrappedAssetCard, {
|
|
9
9
|
...props,
|
|
10
10
|
viewType: "big_card",
|
|
11
11
|
assetId: entityId,
|
|
@@ -42,7 +42,7 @@ function downloadAsset(url) {
|
|
|
42
42
|
window.open(url, '_blank', 'noopener,noreferrer');
|
|
43
43
|
}
|
|
44
44
|
export function renderAssetInfo(props) {
|
|
45
|
-
const { entityFile
|
|
45
|
+
const { entityFile } = props;
|
|
46
46
|
const fileName = get(entityFile, 'fileName');
|
|
47
47
|
const mimeType = get(entityFile, 'contentType');
|
|
48
48
|
const fileSize = get(entityFile, 'details.size');
|
|
@@ -67,7 +67,7 @@ export function renderAssetInfo(props) {
|
|
|
67
67
|
];
|
|
68
68
|
}
|
|
69
69
|
export function renderActions(props) {
|
|
70
|
-
const { entityFile
|
|
70
|
+
const { entityFile, isDisabled, onEdit, onRemove } = props;
|
|
71
71
|
return [
|
|
72
72
|
React.createElement(Menu.SectionTitle, {
|
|
73
73
|
key: "section-title"
|
|
@@ -5,8 +5,8 @@ import { MissingEntityCard } from '../../components';
|
|
|
5
5
|
import { WrappedAssetCard } from './WrappedAssetCard';
|
|
6
6
|
import { WrappedAssetLink } from './WrappedAssetLink';
|
|
7
7
|
export function FetchingWrappedAssetCard(props) {
|
|
8
|
-
const { data: asset
|
|
9
|
-
const { getEntityScheduledActions
|
|
8
|
+
const { data: asset, status } = useEntity('Asset', props.assetId);
|
|
9
|
+
const { getEntityScheduledActions } = useEntityLoader();
|
|
10
10
|
const loadEntityScheduledActions = React.useCallback(()=>getEntityScheduledActions('Asset', props.assetId), [
|
|
11
11
|
getEntityScheduledActions,
|
|
12
12
|
props.assetId
|
|
@@ -22,7 +22,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
22
22
|
asset
|
|
23
23
|
]);
|
|
24
24
|
const onEdit = async ()=>{
|
|
25
|
-
const { slide
|
|
25
|
+
const { slide } = await props.sdk.navigator.openAsset(props.assetId, {
|
|
26
26
|
slideIn: true
|
|
27
27
|
});
|
|
28
28
|
props.onAction && props.onAction({
|
|
@@ -61,7 +61,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
61
61
|
}
|
|
62
62
|
return card;
|
|
63
63
|
}
|
|
64
|
-
const { getEntityUrl
|
|
64
|
+
const { getEntityUrl } = props;
|
|
65
65
|
const size = props.viewType === 'big_card' ? 'default' : 'small';
|
|
66
66
|
const commonProps = {
|
|
67
67
|
asset,
|
|
@@ -98,7 +98,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
98
98
|
...commonProps,
|
|
99
99
|
...props,
|
|
100
100
|
getEntityScheduledActions: loadEntityScheduledActions,
|
|
101
|
-
asset:
|
|
101
|
+
asset: props?.entity || commonProps.asset,
|
|
102
102
|
getAssetUrl: getEntityUrl
|
|
103
103
|
};
|
|
104
104
|
return React.createElement(WrappedAssetCard, builtinCardProps);
|
|
@@ -39,7 +39,7 @@ function getFileType(file) {
|
|
|
39
39
|
return groupToIconMap[groupName] || 'archive';
|
|
40
40
|
}
|
|
41
41
|
export const WrappedAssetCard = (props)=>{
|
|
42
|
-
const { className
|
|
42
|
+
const { className, onEdit, getAssetUrl, onRemove, size, isDisabled, isSelected, isClickable } = props;
|
|
43
43
|
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
44
44
|
if (status === 'deleted') {
|
|
45
45
|
return React.createElement(MissingEntityCard, {
|
|
@@ -12,7 +12,7 @@ const styles = {
|
|
|
12
12
|
})
|
|
13
13
|
};
|
|
14
14
|
export const WrappedAssetLink = (props)=>{
|
|
15
|
-
const { className
|
|
15
|
+
const { className, href, onEdit, onRemove, isDisabled } = props;
|
|
16
16
|
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
17
17
|
if (status === 'deleted') {
|
|
18
18
|
return React.createElement(MissingEntityCard, {
|
|
@@ -33,7 +33,7 @@ const isEntityQueryKey = (queryKey)=>{
|
|
|
33
33
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
34
34
|
};
|
|
35
35
|
async function fetchContentfulEntry(params) {
|
|
36
|
-
const { urn
|
|
36
|
+
const { urn, fetch, options } = params;
|
|
37
37
|
const resourceId = urn.split(':', 6)[5];
|
|
38
38
|
const ENTITY_RESOURCE_ID_REGEX = RegExp("^spaces\\/(?<spaceId>[^/]+)(?:\\/environments\\/(?<environmentId>[^/]+))?\\/entries\\/(?<entityId>[^/]+)$");
|
|
39
39
|
const resourceIdMatch = resourceId.match(ENTITY_RESOURCE_ID_REGEX);
|
|
@@ -47,7 +47,7 @@ async function fetchContentfulEntry(params) {
|
|
|
47
47
|
fetch([
|
|
48
48
|
'space',
|
|
49
49
|
spaceId
|
|
50
|
-
], ({ cmaClient
|
|
50
|
+
], ({ cmaClient })=>cmaClient.space.get({
|
|
51
51
|
spaceId
|
|
52
52
|
}), options),
|
|
53
53
|
fetch([
|
|
@@ -55,7 +55,7 @@ async function fetchContentfulEntry(params) {
|
|
|
55
55
|
spaceId,
|
|
56
56
|
environmentId,
|
|
57
57
|
entryId
|
|
58
|
-
], ({ cmaClient
|
|
58
|
+
], ({ cmaClient })=>cmaClient.entry.get({
|
|
59
59
|
spaceId,
|
|
60
60
|
environmentId,
|
|
61
61
|
entryId
|
|
@@ -68,7 +68,7 @@ async function fetchContentfulEntry(params) {
|
|
|
68
68
|
spaceId,
|
|
69
69
|
environmentId,
|
|
70
70
|
contentTypeId
|
|
71
|
-
], ({ cmaClient
|
|
71
|
+
], ({ cmaClient })=>cmaClient.contentType.get({
|
|
72
72
|
contentTypeId,
|
|
73
73
|
spaceId,
|
|
74
74
|
environmentId
|
|
@@ -77,7 +77,7 @@ async function fetchContentfulEntry(params) {
|
|
|
77
77
|
'defaultLocale',
|
|
78
78
|
spaceId,
|
|
79
79
|
environmentId
|
|
80
|
-
], async ({ cmaClient
|
|
80
|
+
], async ({ cmaClient })=>{
|
|
81
81
|
const locales = await cmaClient.locale.getMany({
|
|
82
82
|
spaceId,
|
|
83
83
|
environmentId,
|
|
@@ -127,7 +127,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
127
127
|
props.queryConcurrency
|
|
128
128
|
]);
|
|
129
129
|
const fetch = useCallback(function fetch(queryKey, fn, options = {}) {
|
|
130
|
-
const { priority
|
|
130
|
+
const { priority, ...queryOptions } = options;
|
|
131
131
|
return queryClient.fetchQuery(queryKey, ()=>queryQueue.add(()=>fn({
|
|
132
132
|
cmaClient
|
|
133
133
|
}), {
|
|
@@ -147,7 +147,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
147
147
|
spaceId,
|
|
148
148
|
environmentId
|
|
149
149
|
];
|
|
150
|
-
return fetch(queryKey, ({ cmaClient
|
|
150
|
+
return fetch(queryKey, ({ cmaClient })=>{
|
|
151
151
|
if (entityType === 'Entry') {
|
|
152
152
|
return cmaClient.entry.get({
|
|
153
153
|
entryId: entityId,
|
|
@@ -181,7 +181,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
181
181
|
spaceId,
|
|
182
182
|
environmentId
|
|
183
183
|
];
|
|
184
|
-
return fetch(queryKey, async ({ cmaClient
|
|
184
|
+
return fetch(queryKey, async ({ cmaClient })=>{
|
|
185
185
|
const response = await cmaClient.scheduledActions.getMany({
|
|
186
186
|
spaceId,
|
|
187
187
|
query: {
|
|
@@ -235,7 +235,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
if (typeof onEntityChanged !== 'function') {
|
|
238
|
-
return onSlideInNavigation(({ oldSlideLevel
|
|
238
|
+
return onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
|
|
239
239
|
if (oldSlideLevel > newSlideLevel) {
|
|
240
240
|
findSameSpaceQueries().forEach((query)=>{
|
|
241
241
|
void queryClient.invalidateQueries(query.queryKey);
|
|
@@ -243,7 +243,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
243
243
|
}
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
|
-
const subscribeQuery = ({ queryKey
|
|
246
|
+
const subscribeQuery = ({ queryKey, queryHash })=>{
|
|
247
247
|
const [entityType, entityId] = queryKey;
|
|
248
248
|
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
249
249
|
queryClient.setQueryData(queryKey, data);
|
|
@@ -254,8 +254,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
254
254
|
if (!event) {
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
|
-
const { type
|
|
258
|
-
const { queryKey
|
|
257
|
+
const { type, query } = event;
|
|
258
|
+
const { queryKey, queryHash } = query;
|
|
259
259
|
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -287,24 +287,24 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
287
287
|
getEntity,
|
|
288
288
|
getEntityScheduledActions
|
|
289
289
|
};
|
|
290
|
-
}, ({ fetch
|
|
290
|
+
}, ({ fetch })=>fetch, ({ getResource, getEntity, getEntityScheduledActions })=>({
|
|
291
291
|
getResource,
|
|
292
292
|
getEntity,
|
|
293
293
|
getEntityScheduledActions
|
|
294
|
-
}), ({ ids
|
|
294
|
+
}), ({ ids })=>({
|
|
295
295
|
environment: ids.environmentAlias ?? ids.environment,
|
|
296
296
|
space: ids.space
|
|
297
297
|
}));
|
|
298
298
|
export function useEntity(entityType, entityId, options) {
|
|
299
|
-
const { space
|
|
300
|
-
const { getEntity
|
|
299
|
+
const { space, environment } = useCurrentIds();
|
|
300
|
+
const { getEntity } = useEntityLoader();
|
|
301
301
|
const queryKey = [
|
|
302
302
|
entityType,
|
|
303
303
|
entityId,
|
|
304
304
|
options?.spaceId ?? space,
|
|
305
305
|
options?.environmentId ?? environment
|
|
306
306
|
];
|
|
307
|
-
const { status
|
|
307
|
+
const { status, data } = useQuery(queryKey, ()=>getEntity(entityType, entityId, options), {
|
|
308
308
|
enabled: options?.enabled
|
|
309
309
|
});
|
|
310
310
|
return {
|
|
@@ -318,8 +318,8 @@ export function useResource(resourceType, urn, options) {
|
|
|
318
318
|
resourceType,
|
|
319
319
|
urn
|
|
320
320
|
];
|
|
321
|
-
const { getResource
|
|
322
|
-
const { status
|
|
321
|
+
const { getResource } = useEntityLoader();
|
|
322
|
+
const { status, data, error } = useQuery(queryKey, ()=>getResource(resourceType, urn, options), {
|
|
323
323
|
enabled: options?.enabled
|
|
324
324
|
});
|
|
325
325
|
return {
|
|
@@ -328,7 +328,7 @@ export function useResource(resourceType, urn, options) {
|
|
|
328
328
|
error
|
|
329
329
|
};
|
|
330
330
|
}
|
|
331
|
-
function EntityProvider({ children
|
|
331
|
+
function EntityProvider({ children, ...props }) {
|
|
332
332
|
return React.createElement(SharedQueryClientProvider, null, React.createElement(InternalServiceProvider, props, children));
|
|
333
333
|
}
|
|
334
334
|
export { EntityProvider, useEntityLoader };
|
|
@@ -25,18 +25,18 @@ const nullableValue = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
function Editor(props) {
|
|
28
|
-
const { setValue
|
|
28
|
+
const { setValue, entityType, onSortingEnd, setIndexToUpdate } = props;
|
|
29
29
|
const editorPermissions = useEditorPermissions(props);
|
|
30
30
|
const items = React.useMemo(()=>{
|
|
31
31
|
return (props.items || []).map((link)=>link || nullableValue);
|
|
32
32
|
}, [
|
|
33
33
|
props.items
|
|
34
34
|
]);
|
|
35
|
-
const { rearrangeSortIDs
|
|
35
|
+
const { rearrangeSortIDs } = useSortIDs(items);
|
|
36
36
|
const onSortStart = useCallback(()=>{
|
|
37
37
|
document.body.classList.add('grabbing');
|
|
38
38
|
}, []);
|
|
39
|
-
const onSortEnd = useCallback(({ oldIndex
|
|
39
|
+
const onSortEnd = useCallback(({ oldIndex, newIndex })=>{
|
|
40
40
|
onSortingEnd && onSortingEnd({
|
|
41
41
|
oldIndex,
|
|
42
42
|
newIndex
|
|
@@ -96,7 +96,7 @@ function Editor(props) {
|
|
|
96
96
|
}
|
|
97
97
|
export function MultipleReferenceEditor(props) {
|
|
98
98
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
99
|
-
return React.createElement(ReferenceEditor, props, ({ value
|
|
99
|
+
return React.createElement(ReferenceEditor, props, ({ value, disabled, setValue, externalReset })=>{
|
|
100
100
|
return React.createElement(Editor, {
|
|
101
101
|
...props,
|
|
102
102
|
items: value || emptyArray,
|
|
@@ -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
|
|
8
|
+
const { setValue, entityType } = props;
|
|
9
9
|
const editorPermissions = useEditorPermissions(props);
|
|
10
10
|
const onCreate = useCallback((id)=>void setValue({
|
|
11
11
|
sys: {
|
|
@@ -53,7 +53,7 @@ function Editor(props) {
|
|
|
53
53
|
}
|
|
54
54
|
export function SingleReferenceEditor(props) {
|
|
55
55
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
56
|
-
return React.createElement(ReferenceEditor, props, ({ value
|
|
56
|
+
return React.createElement(ReferenceEditor, props, ({ value, setValue, disabled, externalReset })=>{
|
|
57
57
|
return React.createElement(Editor, {
|
|
58
58
|
...props,
|
|
59
59
|
key: `${externalReset}-reference`,
|
|
@@ -20,8 +20,8 @@ const styles = {
|
|
|
20
20
|
display: 'flex'
|
|
21
21
|
})
|
|
22
22
|
};
|
|
23
|
-
const SortableLink = ({ id
|
|
24
|
-
const { listeners
|
|
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 = {
|
|
@@ -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
|
|
61
|
-
const { sortIDs
|
|
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 , o
|
|
|
71
71
|
sortIDs
|
|
72
72
|
]);
|
|
73
73
|
const onSortEndHandler = React.useCallback((event)=>{
|
|
74
|
-
const { active
|
|
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);
|
|
@@ -29,7 +29,7 @@ export const useQuery = (key, fn, opt)=>{
|
|
|
29
29
|
context: clientContext
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
export function SharedQueryClientProvider({ children
|
|
32
|
+
export function SharedQueryClientProvider({ children }) {
|
|
33
33
|
const client = useQueryClient();
|
|
34
34
|
return React.createElement(clientContext.Provider, {
|
|
35
35
|
value: client
|
|
@@ -20,7 +20,7 @@ export function useContentTypePermissions(props) {
|
|
|
20
20
|
props.entityType
|
|
21
21
|
]);
|
|
22
22
|
const [creatableContentTypes, setCreatableContentTypes] = useState(availableContentTypes);
|
|
23
|
-
const { canPerformActionOnEntryOfType
|
|
23
|
+
const { canPerformActionOnEntryOfType } = useAccessApi(props.sdk.access);
|
|
24
24
|
useEffect(()=>{
|
|
25
25
|
function getContentTypes(action) {
|
|
26
26
|
return filter(availableContentTypes, (ct)=>canPerformActionOnEntryOfType(action, ct.sys.id));
|
|
@@ -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
|
|
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
|
|
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);
|
|
@@ -14,7 +14,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
14
14
|
id
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
const renderEditorPermissions = async ({ entityType
|
|
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
|
|
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
|
|
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)=>{
|
|
@@ -135,7 +135,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
135
135
|
makeContentType('one'),
|
|
136
136
|
makeContentType('two')
|
|
137
137
|
];
|
|
138
|
-
const { result
|
|
138
|
+
const { result } = await renderEditorPermissions({
|
|
139
139
|
entityType: 'Entry',
|
|
140
140
|
allContentTypes,
|
|
141
141
|
customizeSdk: (sdk)=>{
|
|
@@ -149,7 +149,7 @@ describe('useEditorPermissions', ()=>{
|
|
|
149
149
|
makeContentType('one'),
|
|
150
150
|
makeContentType('two')
|
|
151
151
|
];
|
|
152
|
-
const { result
|
|
152
|
+
const { result } = await renderEditorPermissions({
|
|
153
153
|
entityType: 'Entry',
|
|
154
154
|
allContentTypes,
|
|
155
155
|
customizeMock: (field)=>{
|
|
@@ -19,7 +19,7 @@ const redesignStyles = {
|
|
|
19
19
|
maxWidth: '300px'
|
|
20
20
|
})
|
|
21
21
|
};
|
|
22
|
-
export const CreateEntryLinkButton = ({ contentTypes
|
|
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')}`;
|
|
@@ -35,7 +35,7 @@ export const CreateEntryLinkButton = ({ contentTypes , onSelect , customDropdown
|
|
|
35
35
|
testId: testId,
|
|
36
36
|
dropdownSettings: dropdownSettings,
|
|
37
37
|
customDropdownItems: customDropdownItems
|
|
38
|
-
}, ({ isSelecting
|
|
38
|
+
}, ({ isSelecting })=>React.createElement(Button, {
|
|
39
39
|
endIcon: hasDropdown ? React.createElement(ChevronDownIcon, null) : undefined,
|
|
40
40
|
variant: "secondary",
|
|
41
41
|
className: styles.action,
|
|
@@ -37,14 +37,14 @@ describe('CreateEntryLinkButton general', ()=>{
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
it('renders with multiple content types as list', ()=>{
|
|
40
|
-
const { getByTestId
|
|
40
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, props));
|
|
41
41
|
expect(getByTestId('create-entry-button-menu-trigger')).toBeDefined();
|
|
42
42
|
const link = findButton(getByTestId);
|
|
43
43
|
expect(link).toBeDefined();
|
|
44
44
|
expect(link.textContent).toBe('Add entry');
|
|
45
45
|
});
|
|
46
46
|
it('renders dropdown menu on click when with multiple content types', ()=>{
|
|
47
|
-
const { getByTestId
|
|
47
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, props));
|
|
48
48
|
fireEvent.click(findButton(getByTestId));
|
|
49
49
|
const menu = getByTestId('add-entry-menu');
|
|
50
50
|
expect(menu).toBeDefined();
|
|
@@ -54,7 +54,7 @@ describe('CreateEntryLinkButton general', ()=>{
|
|
|
54
54
|
});
|
|
55
55
|
it('renders suggestedContentType as text when given', ()=>{
|
|
56
56
|
const suggestedContentTypeId = 'ID_2';
|
|
57
|
-
const { getByTestId
|
|
57
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
58
58
|
...props,
|
|
59
59
|
suggestedContentTypeId: suggestedContentTypeId
|
|
60
60
|
}));
|
|
@@ -64,7 +64,7 @@ describe('CreateEntryLinkButton general', ()=>{
|
|
|
64
64
|
expect(button.textContent).toBe(`Add ${CONTENT_TYPE_2.name}`);
|
|
65
65
|
});
|
|
66
66
|
it('renders the name of the content type as part of the text if only 1 content type is given', ()=>{
|
|
67
|
-
const { getByTestId
|
|
67
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
68
68
|
onSelect: props.onSelect,
|
|
69
69
|
contentTypes: [
|
|
70
70
|
CONTENT_TYPE_1
|
|
@@ -80,7 +80,7 @@ describe('CreateEntryLinkButton general', ()=>{
|
|
|
80
80
|
text: 'CUSTOM_TEXT',
|
|
81
81
|
hasPlusIcon: true
|
|
82
82
|
};
|
|
83
|
-
const { getByTestId
|
|
83
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
84
84
|
...props,
|
|
85
85
|
...propsOverrides
|
|
86
86
|
}));
|
|
@@ -101,13 +101,13 @@ describe('CreateEntryLinkButton with multiple entries', ()=>{
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
it('should render dropdown items for each content type', ()=>{
|
|
104
|
-
const { getByTestId
|
|
104
|
+
const { getByTestId, getAllByTestId } = render(React.createElement(CreateEntryLinkButton, props));
|
|
105
105
|
fireEvent.click(findButton(getByTestId));
|
|
106
106
|
expect(getAllByTestId('contentType')).toHaveLength(props.contentTypes.length);
|
|
107
107
|
});
|
|
108
108
|
it('calls onSelect after click on menu item', ()=>{
|
|
109
109
|
const selectSpy = jest.fn();
|
|
110
|
-
const { getByTestId
|
|
110
|
+
const { getByTestId, getAllByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
111
111
|
...props,
|
|
112
112
|
onSelect: selectSpy
|
|
113
113
|
}));
|
|
@@ -127,7 +127,7 @@ describe('CreateEntryLinkButton with a single entry', ()=>{
|
|
|
127
127
|
};
|
|
128
128
|
it('should fire the onSelect function when clicked', ()=>{
|
|
129
129
|
const onSelectStub = jest.fn();
|
|
130
|
-
const { getByTestId
|
|
130
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
131
131
|
...props,
|
|
132
132
|
onSelect: onSelectStub
|
|
133
133
|
}));
|
|
@@ -139,7 +139,7 @@ describe('CreateEntryLinkButton with a single entry', ()=>{
|
|
|
139
139
|
describe('CreateEntryLinkButton common', ()=>{
|
|
140
140
|
it('should render a spinner if onSelect returns a promise', async ()=>{
|
|
141
141
|
const onSelect = jest.fn(()=>new Promise((resolve)=>setTimeout(resolve, 1000)));
|
|
142
|
-
const { getByTestId
|
|
142
|
+
const { getByTestId, container } = render(React.createElement(CreateEntryLinkButton, {
|
|
143
143
|
contentTypes: [
|
|
144
144
|
CONTENT_TYPE_1
|
|
145
145
|
],
|
|
@@ -155,7 +155,7 @@ describe('CreateEntryLinkButton common', ()=>{
|
|
|
155
155
|
});
|
|
156
156
|
it('should hide a spinner after the promise from onSelect resolves', async ()=>{
|
|
157
157
|
const onSelect = jest.fn(()=>new Promise((resolve)=>setTimeout(resolve, 500)));
|
|
158
|
-
const { getByTestId
|
|
158
|
+
const { getByTestId, container } = render(React.createElement(CreateEntryLinkButton, {
|
|
159
159
|
contentTypes: [
|
|
160
160
|
CONTENT_TYPE_1
|
|
161
161
|
],
|
|
@@ -172,7 +172,7 @@ describe('CreateEntryLinkButton common', ()=>{
|
|
|
172
172
|
});
|
|
173
173
|
it('does not emit onSelect on subsequent click before the promise from onSelect resolves', async ()=>{
|
|
174
174
|
const onSelect = jest.fn(()=>new Promise((resolve)=>setTimeout(()=>resolve(undefined), 200)));
|
|
175
|
-
const { getByTestId
|
|
175
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
176
176
|
contentTypes: [
|
|
177
177
|
CONTENT_TYPE_1
|
|
178
178
|
],
|
|
@@ -188,7 +188,7 @@ describe('CreateEntryLinkButton common', ()=>{
|
|
|
188
188
|
});
|
|
189
189
|
it('emits onSelect on subsequent click after the promise from onSelect resolves', async ()=>{
|
|
190
190
|
const onSelect = jest.fn(()=>Promise.resolve());
|
|
191
|
-
const { getByTestId
|
|
191
|
+
const { getByTestId } = render(React.createElement(CreateEntryLinkButton, {
|
|
192
192
|
contentTypes: [
|
|
193
193
|
CONTENT_TYPE_1
|
|
194
194
|
],
|