@contentful/field-editor-reference 8.5.1-canary.0 → 8.5.1-canary.11
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/assets/WrappedAssetCard/WrappedAssetCard.js +9 -2
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +6 -0
- package/dist/cjs/common/EntityStore.js +16 -4
- package/dist/cjs/common/entityStatus.test.js +87 -0
- package/dist/cjs/common/fetchingEntityStatus.test.js +119 -0
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +9 -2
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +9 -2
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +6 -0
- package/dist/esm/common/EntityStore.js +16 -4
- package/dist/esm/common/entityStatus.test.js +78 -0
- package/dist/esm/common/fetchingEntityStatus.test.js +110 -0
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +9 -2
- package/dist/types/common/entityStatus.test.d.ts +1 -0
- package/dist/types/common/fetchingEntityStatus.test.d.ts +1 -0
- package/dist/types/components/ResourceEntityErrorCard/FunctionInvocationErrorCard.d.ts +1 -1
- package/package.json +4 -4
|
@@ -88,8 +88,7 @@ function getFileType(file) {
|
|
|
88
88
|
}
|
|
89
89
|
const THUMBNAIL_SIZE = 150;
|
|
90
90
|
const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCode, activeLocales, localesStatusMap, isDisabled, isSelected, isClickable, useLocalizedEntityStatus, renderDragHandle, getEntityScheduledActions, onEdit, getAssetUrl, onRemove, releaseEntityStatus, releaseStatusMap, release, onAddToRelease })=>{
|
|
91
|
-
const
|
|
92
|
-
const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
91
|
+
const entityFile = asset?.fields?.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
93
92
|
const imageUrl = _react.useMemo(()=>{
|
|
94
93
|
if (!entityFile?.url) return '';
|
|
95
94
|
if (size === 'small') {
|
|
@@ -106,6 +105,14 @@ const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCod
|
|
|
106
105
|
entityFile?.url,
|
|
107
106
|
size
|
|
108
107
|
]);
|
|
108
|
+
if (!asset?.sys?.id) {
|
|
109
|
+
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
110
|
+
asSquare: true,
|
|
111
|
+
isDisabled: isDisabled,
|
|
112
|
+
onRemove: onRemove
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const status = _fieldeditorshared.entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
109
116
|
if (status === 'deleted') {
|
|
110
117
|
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
111
118
|
asSquare: true,
|
|
@@ -56,6 +56,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
56
|
}
|
|
57
57
|
const WrappedAssetLink = (props)=>{
|
|
58
58
|
const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
|
|
59
|
+
if (!props.asset?.sys?.id) {
|
|
60
|
+
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
61
|
+
isDisabled: isDisabled,
|
|
62
|
+
onRemove: onRemove
|
|
63
|
+
});
|
|
64
|
+
}
|
|
59
65
|
const status = _fieldeditorshared.entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
|
|
60
66
|
if (status === 'deleted') {
|
|
61
67
|
return /*#__PURE__*/ _react.createElement(_components.MissingAssetCard, {
|
|
@@ -149,6 +149,12 @@ function handleResourceFetchError(resourceFetchError, resourceTypeEntity) {
|
|
|
149
149
|
}
|
|
150
150
|
throw resourceFetchError;
|
|
151
151
|
}
|
|
152
|
+
function assertEntityMetadata(entityType, entity) {
|
|
153
|
+
if (!(0, _lodash.get)(entity, 'sys.id') || entityType === 'Entry' && !(0, _lodash.get)(entity, 'sys.contentType.sys.id')) {
|
|
154
|
+
throw new Error('Invalid entity metadata');
|
|
155
|
+
}
|
|
156
|
+
return entity;
|
|
157
|
+
}
|
|
152
158
|
const isEntityQueryKey = (queryKey)=>{
|
|
153
159
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && (queryKey.length === 4 || queryKey.length === 5);
|
|
154
160
|
};
|
|
@@ -322,7 +328,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
322
328
|
environmentId,
|
|
323
329
|
releaseId
|
|
324
330
|
});
|
|
325
|
-
return entity;
|
|
331
|
+
return assertEntityMetadata('Entry', entity);
|
|
326
332
|
} catch (error) {
|
|
327
333
|
if (isReleaseRequestError(error, spaceId, environmentId)) {
|
|
328
334
|
const currentEntry = await cmaClient.entry.get({
|
|
@@ -331,6 +337,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
331
337
|
environmentId,
|
|
332
338
|
releaseId: undefined
|
|
333
339
|
});
|
|
340
|
+
assertEntityMetadata('Entry', currentEntry);
|
|
334
341
|
currentEntry.sys.release = {
|
|
335
342
|
sys: {
|
|
336
343
|
type: 'Link',
|
|
@@ -351,7 +358,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
351
358
|
environmentId,
|
|
352
359
|
releaseId
|
|
353
360
|
});
|
|
354
|
-
return entity;
|
|
361
|
+
return assertEntityMetadata('Asset', entity);
|
|
355
362
|
} catch (error) {
|
|
356
363
|
if (isReleaseRequestError(error, spaceId, environmentId)) {
|
|
357
364
|
const currentAsset = await cmaClient.asset.get({
|
|
@@ -360,6 +367,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
360
367
|
environmentId,
|
|
361
368
|
releaseId: undefined
|
|
362
369
|
});
|
|
370
|
+
assertEntityMetadata('Asset', currentAsset);
|
|
363
371
|
currentAsset.sys.release = {
|
|
364
372
|
sys: {
|
|
365
373
|
type: 'Link',
|
|
@@ -497,7 +505,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
497
505
|
});
|
|
498
506
|
return;
|
|
499
507
|
}
|
|
500
|
-
queryClient.setQueryData(query.queryKey, freshData);
|
|
508
|
+
queryClient.setQueryData(query.queryKey, assertEntityMetadata(entityType, freshData));
|
|
501
509
|
} catch (error) {
|
|
502
510
|
await queryClient.invalidateQueries({
|
|
503
511
|
queryKey: query.queryKey
|
|
@@ -511,7 +519,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
511
519
|
const [entityType, entityId, , , releaseId] = queryKey;
|
|
512
520
|
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
513
521
|
const dataReleaseId = (0, _lodash.get)(data, 'sys.release.id');
|
|
514
|
-
if (
|
|
522
|
+
if (!(0, _lodash.get)(data, 'sys.id')) {
|
|
523
|
+
void queryClient.invalidateQueries({
|
|
524
|
+
queryKey
|
|
525
|
+
});
|
|
526
|
+
} else if (dataReleaseId === releaseId) {
|
|
515
527
|
queryClient.setQueryData(queryKey, data);
|
|
516
528
|
} else if (releaseId && !dataReleaseId) {
|
|
517
529
|
void queryClient.invalidateQueries({
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
6
|
+
const _react1 = require("@testing-library/react");
|
|
7
|
+
const _vitest = require("vitest");
|
|
8
|
+
const _published_assetjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/asset/published_asset.json"));
|
|
9
|
+
const _published_entryjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/entry/published_entry.json"));
|
|
10
|
+
const _WrappedAssetCard = require("../assets/WrappedAssetCard/WrappedAssetCard");
|
|
11
|
+
const _WrappedAssetLink = require("../assets/WrappedAssetCard/WrappedAssetLink");
|
|
12
|
+
const _WrappedEntryCard = require("../entries/WrappedEntryCard/WrappedEntryCard");
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
(0, _react1.configure)({
|
|
19
|
+
testIdAttribute: 'data-test-id'
|
|
20
|
+
});
|
|
21
|
+
const sharedProps = {
|
|
22
|
+
isDisabled: false,
|
|
23
|
+
localeCode: 'en-US',
|
|
24
|
+
defaultLocaleCode: 'en-US'
|
|
25
|
+
};
|
|
26
|
+
const cards = [
|
|
27
|
+
{
|
|
28
|
+
name: 'entry',
|
|
29
|
+
loadedEntity: _published_entryjson.default,
|
|
30
|
+
missingTestId: 'cf-ui-missing-entity-card',
|
|
31
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedEntryCard.WrappedEntryCard, {
|
|
32
|
+
...sharedProps,
|
|
33
|
+
entry: entity,
|
|
34
|
+
size: "small",
|
|
35
|
+
hasCardEditActions: false,
|
|
36
|
+
getAsset: _vitest.vi.fn().mockResolvedValue(undefined),
|
|
37
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'asset card',
|
|
42
|
+
loadedEntity: _published_assetjson.default,
|
|
43
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
44
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedAssetCard.WrappedAssetCard, {
|
|
45
|
+
...sharedProps,
|
|
46
|
+
asset: entity,
|
|
47
|
+
size: "small",
|
|
48
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'asset link',
|
|
53
|
+
loadedEntity: _published_assetjson.default,
|
|
54
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
55
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ _react.default.createElement(_WrappedAssetLink.WrappedAssetLink, {
|
|
56
|
+
...sharedProps,
|
|
57
|
+
asset: entity,
|
|
58
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
_vitest.describe.each(cards)('$name status', ({ renderEntity, missingTestId, loadedEntity })=>{
|
|
63
|
+
_vitest.test.each([
|
|
64
|
+
undefined,
|
|
65
|
+
{
|
|
66
|
+
sys: {}
|
|
67
|
+
}
|
|
68
|
+
])('shows a missing card instead of inferring a status for %j', (entity)=>{
|
|
69
|
+
const getEntityScheduledActions = _vitest.vi.fn().mockResolvedValue([]);
|
|
70
|
+
(0, _react1.render)(renderEntity(entity, getEntityScheduledActions));
|
|
71
|
+
(0, _vitest.expect)(_react1.screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
72
|
+
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
73
|
+
(0, _vitest.expect)(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
(0, _vitest.test)('handles missing-to-loaded-to-missing transitions', async ()=>{
|
|
76
|
+
const getEntityScheduledActions = _vitest.vi.fn().mockResolvedValue([]);
|
|
77
|
+
const { rerender } = (0, _react1.render)(renderEntity(undefined, getEntityScheduledActions));
|
|
78
|
+
await (0, _react1.act)(async ()=>{
|
|
79
|
+
rerender(renderEntity(loadedEntity, getEntityScheduledActions));
|
|
80
|
+
});
|
|
81
|
+
(0, _vitest.expect)(_react1.screen.getByText('published')).toBeInTheDocument();
|
|
82
|
+
(0, _vitest.expect)(_react1.screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
83
|
+
rerender(renderEntity(undefined, getEntityScheduledActions));
|
|
84
|
+
(0, _vitest.expect)(_react1.screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
85
|
+
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
6
|
+
const _react1 = require("@testing-library/react");
|
|
7
|
+
const _vitest = require("vitest");
|
|
8
|
+
const _FetchingWrappedAssetCard = require("../assets/WrappedAssetCard/FetchingWrappedAssetCard");
|
|
9
|
+
const _FetchingWrappedEntryCard = require("../entries/WrappedEntryCard/FetchingWrappedEntryCard");
|
|
10
|
+
const _EntityStore = require("./EntityStore");
|
|
11
|
+
function _interop_require_default(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : {
|
|
13
|
+
default: obj
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
(0, _react1.configure)({
|
|
17
|
+
testIdAttribute: 'data-test-id'
|
|
18
|
+
});
|
|
19
|
+
function createSdk(entity) {
|
|
20
|
+
return {
|
|
21
|
+
locales: {
|
|
22
|
+
available: [
|
|
23
|
+
'en-US'
|
|
24
|
+
],
|
|
25
|
+
default: 'en-US',
|
|
26
|
+
names: {
|
|
27
|
+
'en-US': 'English'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
field: {
|
|
31
|
+
locale: 'en-US'
|
|
32
|
+
},
|
|
33
|
+
parameters: {
|
|
34
|
+
instance: {}
|
|
35
|
+
},
|
|
36
|
+
ids: {
|
|
37
|
+
space: 'space-id',
|
|
38
|
+
environment: 'environment-id'
|
|
39
|
+
},
|
|
40
|
+
cma: {
|
|
41
|
+
entry: {
|
|
42
|
+
get: _vitest.vi.fn().mockResolvedValue(entity)
|
|
43
|
+
},
|
|
44
|
+
asset: {
|
|
45
|
+
get: _vitest.vi.fn().mockResolvedValue(entity)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
space: {
|
|
49
|
+
onEntityChanged: _vitest.vi.fn(()=>()=>{}),
|
|
50
|
+
getEntityScheduledActions: _vitest.vi.fn().mockResolvedValue([])
|
|
51
|
+
},
|
|
52
|
+
navigator: {
|
|
53
|
+
onSlideInNavigation: _vitest.vi.fn()
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const props = {
|
|
58
|
+
viewType: 'link',
|
|
59
|
+
isDisabled: false,
|
|
60
|
+
onRemove: _vitest.vi.fn()
|
|
61
|
+
};
|
|
62
|
+
const cards = [
|
|
63
|
+
{
|
|
64
|
+
name: 'entry',
|
|
65
|
+
missingTestId: 'cf-ui-missing-entity-card',
|
|
66
|
+
renderCard: (sdk)=>/*#__PURE__*/ _react.default.createElement(_FetchingWrappedEntryCard.FetchingWrappedEntryCard, {
|
|
67
|
+
...props,
|
|
68
|
+
sdk: sdk,
|
|
69
|
+
entryId: "linked-id",
|
|
70
|
+
allContentTypes: [],
|
|
71
|
+
isInitiallyDisabled: false,
|
|
72
|
+
hasCardEditActions: false,
|
|
73
|
+
parameters: {
|
|
74
|
+
instance: {}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'asset',
|
|
80
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
81
|
+
renderCard: (sdk)=>/*#__PURE__*/ _react.default.createElement(_FetchingWrappedAssetCard.FetchingWrappedAssetCard, {
|
|
82
|
+
...props,
|
|
83
|
+
sdk: sdk,
|
|
84
|
+
assetId: "linked-id"
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
_vitest.describe.each(cards)('fetching $name status', ({ name, renderCard, missingTestId })=>{
|
|
89
|
+
_vitest.test.each([
|
|
90
|
+
{},
|
|
91
|
+
{
|
|
92
|
+
sys: {}
|
|
93
|
+
},
|
|
94
|
+
...name === 'entry' ? [
|
|
95
|
+
{
|
|
96
|
+
sys: {
|
|
97
|
+
id: 'linked-id'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
] : []
|
|
101
|
+
])('shows a missing card when the CMA returns malformed metadata (%j)', async (entity)=>{
|
|
102
|
+
const sdk = createSdk(entity);
|
|
103
|
+
(0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStore.EntityProvider, {
|
|
104
|
+
sdk: sdk
|
|
105
|
+
}, renderCard(sdk)));
|
|
106
|
+
(0, _vitest.expect)(await _react1.screen.findByTestId(missingTestId)).toBeInTheDocument();
|
|
107
|
+
(0, _vitest.expect)(_react1.screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
108
|
+
});
|
|
109
|
+
(0, _vitest.test)('preserves the loading card while the entity is being fetched', ()=>{
|
|
110
|
+
const sdk = createSdk(undefined);
|
|
111
|
+
_vitest.vi.mocked(sdk.cma.entry.get).mockReturnValue(new Promise(()=>{}));
|
|
112
|
+
_vitest.vi.mocked(sdk.cma.asset.get).mockReturnValue(new Promise(()=>{}));
|
|
113
|
+
(0, _react1.render)(/*#__PURE__*/ _react.default.createElement(_EntityStore.EntityProvider, {
|
|
114
|
+
sdk: sdk
|
|
115
|
+
}, renderCard(sdk)));
|
|
116
|
+
(0, _vitest.expect)(_react1.screen.getByTestId('cf-ui-skeleton-form')).toBeInTheDocument();
|
|
117
|
+
(0, _vitest.expect)(_react1.screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -66,7 +66,7 @@ function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales, localeC
|
|
|
66
66
|
const [file, setFile] = _react.useState(null);
|
|
67
67
|
_react.useEffect(()=>{
|
|
68
68
|
let mounted = true;
|
|
69
|
-
if (entry) {
|
|
69
|
+
if (entry?.sys?.id) {
|
|
70
70
|
getEntryImage({
|
|
71
71
|
entry,
|
|
72
72
|
contentType,
|
|
@@ -92,7 +92,14 @@ function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales, localeC
|
|
|
92
92
|
localeCode,
|
|
93
93
|
defaultLocaleCode
|
|
94
94
|
]);
|
|
95
|
-
|
|
95
|
+
if (!entry?.sys?.id) {
|
|
96
|
+
return /*#__PURE__*/ _react.createElement(_components.MissingEntityCard, {
|
|
97
|
+
isDisabled: isDisabled,
|
|
98
|
+
onRemove: onRemove,
|
|
99
|
+
providerName: "Contentful"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const status = getEntityStatus(entry.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
96
103
|
if (status === 'deleted') {
|
|
97
104
|
return /*#__PURE__*/ _react.createElement(_components.MissingEntityCard, {
|
|
98
105
|
isDisabled: isDisabled,
|
|
@@ -32,8 +32,7 @@ function getFileType(file) {
|
|
|
32
32
|
}
|
|
33
33
|
const THUMBNAIL_SIZE = 150;
|
|
34
34
|
export const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCode, activeLocales, localesStatusMap, isDisabled, isSelected, isClickable, useLocalizedEntityStatus, renderDragHandle, getEntityScheduledActions, onEdit, getAssetUrl, onRemove, releaseEntityStatus, releaseStatusMap, release, onAddToRelease })=>{
|
|
35
|
-
const
|
|
36
|
-
const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
35
|
+
const entityFile = asset?.fields?.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
37
36
|
const imageUrl = React.useMemo(()=>{
|
|
38
37
|
if (!entityFile?.url) return '';
|
|
39
38
|
if (size === 'small') {
|
|
@@ -50,6 +49,14 @@ export const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLo
|
|
|
50
49
|
entityFile?.url,
|
|
51
50
|
size
|
|
52
51
|
]);
|
|
52
|
+
if (!asset?.sys?.id) {
|
|
53
|
+
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
54
|
+
asSquare: true,
|
|
55
|
+
isDisabled: isDisabled,
|
|
56
|
+
onRemove: onRemove
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const status = entityHelpers.getEntityStatus(asset.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
53
60
|
if (status === 'deleted') {
|
|
54
61
|
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
55
62
|
asSquare: true,
|
|
@@ -5,6 +5,12 @@ import { AssetThumbnail, EntityStatusBadge, MissingAssetCard } from '../../compo
|
|
|
5
5
|
import { renderActions, renderAssetInfo } from './AssetCardActions';
|
|
6
6
|
export const WrappedAssetLink = (props)=>{
|
|
7
7
|
const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
|
|
8
|
+
if (!props.asset?.sys?.id) {
|
|
9
|
+
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
10
|
+
isDisabled: isDisabled,
|
|
11
|
+
onRemove: onRemove
|
|
12
|
+
});
|
|
13
|
+
}
|
|
8
14
|
const status = entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
|
|
9
15
|
if (status === 'deleted') {
|
|
10
16
|
return /*#__PURE__*/ React.createElement(MissingAssetCard, {
|
|
@@ -61,6 +61,12 @@ function handleResourceFetchError(resourceFetchError, resourceTypeEntity) {
|
|
|
61
61
|
}
|
|
62
62
|
throw resourceFetchError;
|
|
63
63
|
}
|
|
64
|
+
function assertEntityMetadata(entityType, entity) {
|
|
65
|
+
if (!get(entity, 'sys.id') || entityType === 'Entry' && !get(entity, 'sys.contentType.sys.id')) {
|
|
66
|
+
throw new Error('Invalid entity metadata');
|
|
67
|
+
}
|
|
68
|
+
return entity;
|
|
69
|
+
}
|
|
64
70
|
const isEntityQueryKey = (queryKey)=>{
|
|
65
71
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && (queryKey.length === 4 || queryKey.length === 5);
|
|
66
72
|
};
|
|
@@ -234,7 +240,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
234
240
|
environmentId,
|
|
235
241
|
releaseId
|
|
236
242
|
});
|
|
237
|
-
return entity;
|
|
243
|
+
return assertEntityMetadata('Entry', entity);
|
|
238
244
|
} catch (error) {
|
|
239
245
|
if (isReleaseRequestError(error, spaceId, environmentId)) {
|
|
240
246
|
const currentEntry = await cmaClient.entry.get({
|
|
@@ -243,6 +249,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
243
249
|
environmentId,
|
|
244
250
|
releaseId: undefined
|
|
245
251
|
});
|
|
252
|
+
assertEntityMetadata('Entry', currentEntry);
|
|
246
253
|
currentEntry.sys.release = {
|
|
247
254
|
sys: {
|
|
248
255
|
type: 'Link',
|
|
@@ -263,7 +270,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
263
270
|
environmentId,
|
|
264
271
|
releaseId
|
|
265
272
|
});
|
|
266
|
-
return entity;
|
|
273
|
+
return assertEntityMetadata('Asset', entity);
|
|
267
274
|
} catch (error) {
|
|
268
275
|
if (isReleaseRequestError(error, spaceId, environmentId)) {
|
|
269
276
|
const currentAsset = await cmaClient.asset.get({
|
|
@@ -272,6 +279,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
272
279
|
environmentId,
|
|
273
280
|
releaseId: undefined
|
|
274
281
|
});
|
|
282
|
+
assertEntityMetadata('Asset', currentAsset);
|
|
275
283
|
currentAsset.sys.release = {
|
|
276
284
|
sys: {
|
|
277
285
|
type: 'Link',
|
|
@@ -409,7 +417,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
409
417
|
});
|
|
410
418
|
return;
|
|
411
419
|
}
|
|
412
|
-
queryClient.setQueryData(query.queryKey, freshData);
|
|
420
|
+
queryClient.setQueryData(query.queryKey, assertEntityMetadata(entityType, freshData));
|
|
413
421
|
} catch (error) {
|
|
414
422
|
await queryClient.invalidateQueries({
|
|
415
423
|
queryKey: query.queryKey
|
|
@@ -423,7 +431,11 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
423
431
|
const [entityType, entityId, , , releaseId] = queryKey;
|
|
424
432
|
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
425
433
|
const dataReleaseId = get(data, 'sys.release.id');
|
|
426
|
-
if (
|
|
434
|
+
if (!get(data, 'sys.id')) {
|
|
435
|
+
void queryClient.invalidateQueries({
|
|
436
|
+
queryKey
|
|
437
|
+
});
|
|
438
|
+
} else if (dataReleaseId === releaseId) {
|
|
427
439
|
queryClient.setQueryData(queryKey, data);
|
|
428
440
|
} else if (releaseId && !dataReleaseId) {
|
|
429
441
|
void queryClient.invalidateQueries({
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, configure, render, screen } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
+
import publishedAsset from '../__fixtures__/asset/published_asset.json';
|
|
5
|
+
import publishedEntry from '../__fixtures__/entry/published_entry.json';
|
|
6
|
+
import { WrappedAssetCard } from '../assets/WrappedAssetCard/WrappedAssetCard';
|
|
7
|
+
import { WrappedAssetLink } from '../assets/WrappedAssetCard/WrappedAssetLink';
|
|
8
|
+
import { WrappedEntryCard } from '../entries/WrappedEntryCard/WrappedEntryCard';
|
|
9
|
+
configure({
|
|
10
|
+
testIdAttribute: 'data-test-id'
|
|
11
|
+
});
|
|
12
|
+
const sharedProps = {
|
|
13
|
+
isDisabled: false,
|
|
14
|
+
localeCode: 'en-US',
|
|
15
|
+
defaultLocaleCode: 'en-US'
|
|
16
|
+
};
|
|
17
|
+
const cards = [
|
|
18
|
+
{
|
|
19
|
+
name: 'entry',
|
|
20
|
+
loadedEntity: publishedEntry,
|
|
21
|
+
missingTestId: 'cf-ui-missing-entity-card',
|
|
22
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedEntryCard, {
|
|
23
|
+
...sharedProps,
|
|
24
|
+
entry: entity,
|
|
25
|
+
size: "small",
|
|
26
|
+
hasCardEditActions: false,
|
|
27
|
+
getAsset: vi.fn().mockResolvedValue(undefined),
|
|
28
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'asset card',
|
|
33
|
+
loadedEntity: publishedAsset,
|
|
34
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
35
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedAssetCard, {
|
|
36
|
+
...sharedProps,
|
|
37
|
+
asset: entity,
|
|
38
|
+
size: "small",
|
|
39
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'asset link',
|
|
44
|
+
loadedEntity: publishedAsset,
|
|
45
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
46
|
+
renderEntity: (entity, getEntityScheduledActions)=>/*#__PURE__*/ React.createElement(WrappedAssetLink, {
|
|
47
|
+
...sharedProps,
|
|
48
|
+
asset: entity,
|
|
49
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
describe.each(cards)('$name status', ({ renderEntity, missingTestId, loadedEntity })=>{
|
|
54
|
+
test.each([
|
|
55
|
+
undefined,
|
|
56
|
+
{
|
|
57
|
+
sys: {}
|
|
58
|
+
}
|
|
59
|
+
])('shows a missing card instead of inferring a status for %j', (entity)=>{
|
|
60
|
+
const getEntityScheduledActions = vi.fn().mockResolvedValue([]);
|
|
61
|
+
render(renderEntity(entity, getEntityScheduledActions));
|
|
62
|
+
expect(screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
63
|
+
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
64
|
+
expect(getEntityScheduledActions).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
test('handles missing-to-loaded-to-missing transitions', async ()=>{
|
|
67
|
+
const getEntityScheduledActions = vi.fn().mockResolvedValue([]);
|
|
68
|
+
const { rerender } = render(renderEntity(undefined, getEntityScheduledActions));
|
|
69
|
+
await act(async ()=>{
|
|
70
|
+
rerender(renderEntity(loadedEntity, getEntityScheduledActions));
|
|
71
|
+
});
|
|
72
|
+
expect(screen.getByText('published')).toBeInTheDocument();
|
|
73
|
+
expect(screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
74
|
+
rerender(renderEntity(undefined, getEntityScheduledActions));
|
|
75
|
+
expect(screen.getByTestId(missingTestId)).toBeInTheDocument();
|
|
76
|
+
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { configure, render, screen } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
4
|
+
import { FetchingWrappedAssetCard } from '../assets/WrappedAssetCard/FetchingWrappedAssetCard';
|
|
5
|
+
import { FetchingWrappedEntryCard } from '../entries/WrappedEntryCard/FetchingWrappedEntryCard';
|
|
6
|
+
import { EntityProvider } from './EntityStore';
|
|
7
|
+
configure({
|
|
8
|
+
testIdAttribute: 'data-test-id'
|
|
9
|
+
});
|
|
10
|
+
function createSdk(entity) {
|
|
11
|
+
return {
|
|
12
|
+
locales: {
|
|
13
|
+
available: [
|
|
14
|
+
'en-US'
|
|
15
|
+
],
|
|
16
|
+
default: 'en-US',
|
|
17
|
+
names: {
|
|
18
|
+
'en-US': 'English'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
field: {
|
|
22
|
+
locale: 'en-US'
|
|
23
|
+
},
|
|
24
|
+
parameters: {
|
|
25
|
+
instance: {}
|
|
26
|
+
},
|
|
27
|
+
ids: {
|
|
28
|
+
space: 'space-id',
|
|
29
|
+
environment: 'environment-id'
|
|
30
|
+
},
|
|
31
|
+
cma: {
|
|
32
|
+
entry: {
|
|
33
|
+
get: vi.fn().mockResolvedValue(entity)
|
|
34
|
+
},
|
|
35
|
+
asset: {
|
|
36
|
+
get: vi.fn().mockResolvedValue(entity)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
space: {
|
|
40
|
+
onEntityChanged: vi.fn(()=>()=>{}),
|
|
41
|
+
getEntityScheduledActions: vi.fn().mockResolvedValue([])
|
|
42
|
+
},
|
|
43
|
+
navigator: {
|
|
44
|
+
onSlideInNavigation: vi.fn()
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const props = {
|
|
49
|
+
viewType: 'link',
|
|
50
|
+
isDisabled: false,
|
|
51
|
+
onRemove: vi.fn()
|
|
52
|
+
};
|
|
53
|
+
const cards = [
|
|
54
|
+
{
|
|
55
|
+
name: 'entry',
|
|
56
|
+
missingTestId: 'cf-ui-missing-entity-card',
|
|
57
|
+
renderCard: (sdk)=>/*#__PURE__*/ React.createElement(FetchingWrappedEntryCard, {
|
|
58
|
+
...props,
|
|
59
|
+
sdk: sdk,
|
|
60
|
+
entryId: "linked-id",
|
|
61
|
+
allContentTypes: [],
|
|
62
|
+
isInitiallyDisabled: false,
|
|
63
|
+
hasCardEditActions: false,
|
|
64
|
+
parameters: {
|
|
65
|
+
instance: {}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'asset',
|
|
71
|
+
missingTestId: 'cf-ui-missing-asset-card',
|
|
72
|
+
renderCard: (sdk)=>/*#__PURE__*/ React.createElement(FetchingWrappedAssetCard, {
|
|
73
|
+
...props,
|
|
74
|
+
sdk: sdk,
|
|
75
|
+
assetId: "linked-id"
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
describe.each(cards)('fetching $name status', ({ name, renderCard, missingTestId })=>{
|
|
80
|
+
test.each([
|
|
81
|
+
{},
|
|
82
|
+
{
|
|
83
|
+
sys: {}
|
|
84
|
+
},
|
|
85
|
+
...name === 'entry' ? [
|
|
86
|
+
{
|
|
87
|
+
sys: {
|
|
88
|
+
id: 'linked-id'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
] : []
|
|
92
|
+
])('shows a missing card when the CMA returns malformed metadata (%j)', async (entity)=>{
|
|
93
|
+
const sdk = createSdk(entity);
|
|
94
|
+
render(/*#__PURE__*/ React.createElement(EntityProvider, {
|
|
95
|
+
sdk: sdk
|
|
96
|
+
}, renderCard(sdk)));
|
|
97
|
+
expect(await screen.findByTestId(missingTestId)).toBeInTheDocument();
|
|
98
|
+
expect(screen.queryByTestId('cf-ui-badge')).not.toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
test('preserves the loading card while the entity is being fetched', ()=>{
|
|
101
|
+
const sdk = createSdk(undefined);
|
|
102
|
+
vi.mocked(sdk.cma.entry.get).mockReturnValue(new Promise(()=>{}));
|
|
103
|
+
vi.mocked(sdk.cma.asset.get).mockReturnValue(new Promise(()=>{}));
|
|
104
|
+
render(/*#__PURE__*/ React.createElement(EntityProvider, {
|
|
105
|
+
sdk: sdk
|
|
106
|
+
}, renderCard(sdk)));
|
|
107
|
+
expect(screen.getByTestId('cf-ui-skeleton-form')).toBeInTheDocument();
|
|
108
|
+
expect(screen.queryByTestId(missingTestId)).not.toBeInTheDocument();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -15,7 +15,7 @@ export function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales,
|
|
|
15
15
|
const [file, setFile] = React.useState(null);
|
|
16
16
|
React.useEffect(()=>{
|
|
17
17
|
let mounted = true;
|
|
18
|
-
if (entry) {
|
|
18
|
+
if (entry?.sys?.id) {
|
|
19
19
|
getEntryImage({
|
|
20
20
|
entry,
|
|
21
21
|
contentType,
|
|
@@ -41,7 +41,14 @@ export function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales,
|
|
|
41
41
|
localeCode,
|
|
42
42
|
defaultLocaleCode
|
|
43
43
|
]);
|
|
44
|
-
|
|
44
|
+
if (!entry?.sys?.id) {
|
|
45
|
+
return /*#__PURE__*/ React.createElement(MissingEntityCard, {
|
|
46
|
+
isDisabled: isDisabled,
|
|
47
|
+
onRemove: onRemove,
|
|
48
|
+
providerName: "Contentful"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const status = getEntityStatus(entry.sys, useLocalizedEntityStatus ? localeCode : undefined);
|
|
45
52
|
if (status === 'deleted') {
|
|
46
53
|
return /*#__PURE__*/ React.createElement(MissingEntityCard, {
|
|
47
54
|
isDisabled: isDisabled,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,5 +7,5 @@ type FunctionInvocationErrorCardProps = {
|
|
|
7
7
|
onRemove?: Function;
|
|
8
8
|
providerName?: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function FunctionInvocationErrorCard({ providerName, organizationId, appDefinitionId, isDisabled, isSelected, onRemove }: FunctionInvocationErrorCardProps): React.JSX.Element;
|
|
10
|
+
export declare function FunctionInvocationErrorCard({ providerName, organizationId, appDefinitionId, isDisabled, isSelected, onRemove, }: FunctionInvocationErrorCardProps): React.JSX.Element;
|
|
11
11
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "8.5.1-canary.
|
|
3
|
+
"version": "8.5.1-canary.11+1c274d54",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@contentful/f36-components": "^6.7.1",
|
|
42
42
|
"@contentful/f36-icons": "^6.7.1",
|
|
43
43
|
"@contentful/f36-tokens": "^6.1.2",
|
|
44
|
-
"@contentful/field-editor-shared": "^4.6.
|
|
45
|
-
"@contentful/mimetype": "^2.
|
|
44
|
+
"@contentful/field-editor-shared": "^4.6.1-canary.11+1c274d54",
|
|
45
|
+
"@contentful/mimetype": "^2.2.29",
|
|
46
46
|
"@dnd-kit/core": "^6.0.8",
|
|
47
47
|
"@dnd-kit/sortable": "^8.0.0",
|
|
48
48
|
"@dnd-kit/utilities": "^3.2.2",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"prettier --write"
|
|
79
79
|
]
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "1c274d5409daa55a20528bf7d9e6eece47d0a5e3"
|
|
82
82
|
}
|