@contentful/field-editor-reference 5.19.0 → 5.20.0
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 +8 -6
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/assets/MultipleMediaEditor.js +7 -5
- package/dist/cjs/assets/SingleMediaEditor.js +6 -4
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +21 -19
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +18 -11
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +20 -11
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +12 -9
- package/dist/cjs/assets/index.js +3 -3
- package/dist/cjs/common/EntityStore.js +53 -53
- package/dist/cjs/common/MultipleReferenceEditor.js +20 -11
- package/dist/cjs/common/ReferenceEditor.js +7 -5
- package/dist/cjs/common/SingleReferenceEditor.js +11 -7
- package/dist/cjs/common/SortableLinkList.js +14 -14
- package/dist/cjs/common/customCardTypes.js +4 -2
- package/dist/cjs/common/queryClient.js +102 -0
- package/dist/cjs/common/useContentTypePermissions.js +3 -1
- package/dist/cjs/common/useEditorPermissions.js +15 -3
- package/dist/cjs/common/useEditorPermissions.spec.js +13 -12
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +5 -3
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +13 -9
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +17 -15
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +29 -19
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +14 -12
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +28 -21
- package/dist/cjs/components/LinkActions/LinkActions.js +17 -15
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +26 -17
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +5 -3
- package/dist/cjs/components/LinkActions/helpers.js +10 -5
- 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 +11 -9
- package/dist/cjs/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +6 -4
- package/dist/cjs/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +6 -4
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +10 -8
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +9 -4
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +5 -4
- package/dist/cjs/components/SpaceName/SpaceName.js +9 -7
- package/dist/cjs/components/index.js +12 -12
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +9 -7
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +7 -5
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +20 -11
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +23 -17
- package/dist/cjs/entries/index.js +3 -3
- package/dist/cjs/index.js +38 -34
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +13 -4
- package/dist/cjs/resources/Cards/ResourceCard.js +16 -12
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +20 -17
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +20 -17
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +34 -13
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +11 -9
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +13 -6
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +12 -5
- package/dist/cjs/resources/useResourceLinkActions.js +11 -2
- package/dist/cjs/types.js +3 -3
- package/dist/cjs/utils/fromFieldValidations.js +2 -1
- package/dist/cjs/utils/useSortIDs.js +6 -4
- 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 +14 -9
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +15 -7
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +7 -6
- package/dist/esm/common/EntityStore.js +40 -42
- package/dist/esm/common/MultipleReferenceEditor.js +16 -9
- package/dist/esm/common/ReferenceEditor.js +2 -2
- package/dist/esm/common/SingleReferenceEditor.js +7 -5
- package/dist/esm/common/SortableLinkList.js +12 -12
- package/dist/esm/common/queryClient.js +44 -0
- package/dist/esm/common/useContentTypePermissions.js +3 -1
- package/dist/esm/common/useEditorPermissions.js +15 -3
- package/dist/esm/common/useEditorPermissions.spec.js +13 -12
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +1 -1
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +7 -5
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +12 -12
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +23 -15
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +9 -8
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +30 -19
- package/dist/esm/components/LinkActions/LinkActions.js +9 -9
- package/dist/esm/components/LinkActions/LinkEntityActions.js +18 -11
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +1 -1
- package/dist/esm/components/LinkActions/helpers.js +7 -2
- 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 +5 -2
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +11 -2
- package/dist/esm/components/SpaceName/SpaceName.js +4 -4
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +5 -5
- package/dist/esm/entries/SingleEntryReferenceEditor.js +3 -3
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +15 -8
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +18 -14
- package/dist/esm/index.js +1 -0
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +9 -2
- package/dist/esm/resources/Cards/ResourceCard.js +12 -10
- package/dist/esm/resources/Cards/ResourceCard.spec.js +12 -11
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +14 -13
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +30 -11
- package/dist/esm/resources/SingleResourceReferenceEditor.js +6 -6
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +9 -4
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +9 -2
- package/dist/esm/resources/useResourceLinkActions.js +11 -2
- package/dist/esm/utils/fromFieldValidations.js +1 -0
- package/dist/esm/utils/useSortIDs.js +2 -2
- package/dist/types/common/EntityStore.d.ts +1 -1
- package/dist/types/common/queryClient.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "ResourceCard", {
|
|
|
8
8
|
return ResourceCard;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _reactintersectionobserver = require("react-intersection-observer");
|
|
13
13
|
const _f36components = require("@contentful/f36-components");
|
|
14
14
|
const _EntityStore = require("../../common/EntityStore");
|
|
@@ -35,7 +35,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
35
35
|
if (cache && cache.has(obj)) {
|
|
36
36
|
return cache.get(obj);
|
|
37
37
|
}
|
|
38
|
-
var newObj = {
|
|
38
|
+
var newObj = {
|
|
39
|
+
__proto__: null
|
|
40
|
+
};
|
|
39
41
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
42
|
for(var key in obj){
|
|
41
43
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -54,28 +56,29 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
54
56
|
return newObj;
|
|
55
57
|
}
|
|
56
58
|
function ResourceCardSkeleton() {
|
|
57
|
-
return _react.createElement(_f36components.EntryCard, {
|
|
59
|
+
return /*#__PURE__*/ _react.createElement(_f36components.EntryCard, {
|
|
58
60
|
size: "small",
|
|
59
61
|
isLoading: true
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
64
|
function ExistingResourceCard(props) {
|
|
63
|
-
const { resourceLink
|
|
65
|
+
const { resourceLink, inView, index = 0 } = props;
|
|
64
66
|
const resourceOptions = {
|
|
65
67
|
priority: index * -1,
|
|
66
68
|
enabled: inView
|
|
67
69
|
};
|
|
68
|
-
const { data
|
|
70
|
+
const { data, error } = (0, _EntityStore.useResource)(resourceLink.sys.linkType, resourceLink.sys.urn, resourceOptions);
|
|
69
71
|
if (!data && !error) {
|
|
70
|
-
return _react.createElement(ResourceCardSkeleton, null);
|
|
72
|
+
return /*#__PURE__*/ _react.createElement(ResourceCardSkeleton, null);
|
|
71
73
|
}
|
|
72
74
|
if (data) {
|
|
73
|
-
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
return /*#__PURE__*/ _react.createElement(_ContentfulEntryCard.ContentfulEntryCard, {
|
|
74
77
|
info: data,
|
|
75
78
|
...props
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
|
-
return _react.createElement(_components.ResourceEntityErrorCard, {
|
|
81
|
+
return /*#__PURE__*/ _react.createElement(_components.ResourceEntityErrorCard, {
|
|
79
82
|
linkType: resourceLink.sys.linkType,
|
|
80
83
|
error: error,
|
|
81
84
|
isDisabled: props.isDisabled,
|
|
@@ -86,20 +89,21 @@ function ResourceCardWrapper(props) {
|
|
|
86
89
|
if (!props.resourceLink) {
|
|
87
90
|
return null;
|
|
88
91
|
}
|
|
89
|
-
return _react.createElement(ExistingResourceCard, {
|
|
92
|
+
return /*#__PURE__*/ _react.createElement(ExistingResourceCard, {
|
|
90
93
|
...props,
|
|
91
94
|
resourceLink: props.resourceLink,
|
|
92
95
|
getEntryRouteHref: props.getEntryRouteHref
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
function ResourceCard(props) {
|
|
96
|
-
const { ref
|
|
99
|
+
const { ref, inView } = (0, _reactintersectionobserver.useInView)({
|
|
97
100
|
triggerOnce: true,
|
|
98
101
|
rootMargin: '300px 0px 0px 300px'
|
|
99
102
|
});
|
|
100
|
-
|
|
103
|
+
// Forma does not offer us to pass refs, so we need an additional wrapper here
|
|
104
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
101
105
|
ref: ref
|
|
102
|
-
}, _react.createElement(ResourceCardWrapper, {
|
|
106
|
+
}, /*#__PURE__*/ _react.createElement(ResourceCardWrapper, {
|
|
103
107
|
...props,
|
|
104
108
|
inView: inView
|
|
105
109
|
}));
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
require("@testing-library/jest-dom");
|
|
7
7
|
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
8
8
|
const _react1 = require("@testing-library/react");
|
|
9
|
-
const _published_content_typejson = _interop_require_default(require("../../__fixtures__/content-type/published_content_type.json"));
|
|
10
|
-
const _published_entry_non_masterjson = _interop_require_default(require("../../__fixtures__/entry/published_entry_non_master.json"));
|
|
11
|
-
const _published_entryjson = _interop_require_default(require("../../__fixtures__/entry/published_entry.json"));
|
|
12
|
-
const _indifferent_spacejson = _interop_require_default(require("../../__fixtures__/space/indifferent_space.json"));
|
|
9
|
+
const _published_content_typejson = /*#__PURE__*/ _interop_require_default(require("../../__fixtures__/content-type/published_content_type.json"));
|
|
10
|
+
const _published_entry_non_masterjson = /*#__PURE__*/ _interop_require_default(require("../../__fixtures__/entry/published_entry_non_master.json"));
|
|
11
|
+
const _published_entryjson = /*#__PURE__*/ _interop_require_default(require("../../__fixtures__/entry/published_entry.json"));
|
|
12
|
+
const _indifferent_spacejson = /*#__PURE__*/ _interop_require_default(require("../../__fixtures__/space/indifferent_space.json"));
|
|
13
13
|
const _EntityStore = require("../../common/EntityStore");
|
|
14
14
|
const _ResourceCard = require("./ResourceCard");
|
|
15
15
|
function _interop_require_default(obj) {
|
|
@@ -38,7 +38,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
38
38
|
if (cache && cache.has(obj)) {
|
|
39
39
|
return cache.get(obj);
|
|
40
40
|
}
|
|
41
|
-
var newObj = {
|
|
41
|
+
var newObj = {
|
|
42
|
+
__proto__: null
|
|
43
|
+
};
|
|
42
44
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
45
|
for(var key in obj){
|
|
44
46
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -62,6 +64,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
62
64
|
jest.mock('react-intersection-observer', ()=>({
|
|
63
65
|
useInView: jest.fn().mockReturnValue({})
|
|
64
66
|
}));
|
|
67
|
+
// explicit master
|
|
65
68
|
const resolvableEntryUrn = 'crn:contentful:::content:spaces/space-id/entries/linked-entry-urn';
|
|
66
69
|
const resolvableEntryUrnWithExplicitMaster = 'crn:contentful:::content:spaces/space-id/environments/master/entries/linked-entry-urn';
|
|
67
70
|
const resolvableEntryUrnWithAnotherEnvironment = 'crn:contentful:::content:spaces/space-id/environments/my-test-environment/entries/linked-entry-urn';
|
|
@@ -75,7 +78,7 @@ const sdk = {
|
|
|
75
78
|
get: jest.fn().mockReturnValue(_published_content_typejson.default)
|
|
76
79
|
},
|
|
77
80
|
Entry: {
|
|
78
|
-
get: jest.fn().mockImplementation(({ spaceId
|
|
81
|
+
get: jest.fn().mockImplementation(({ spaceId, environmentId, entryId })=>{
|
|
79
82
|
if (spaceId === 'space-id' && environmentId === 'master' && entryId === 'linked-entry-urn') {
|
|
80
83
|
return Promise.resolve(_published_entryjson.default);
|
|
81
84
|
}
|
|
@@ -114,10 +117,10 @@ const sdk = {
|
|
|
114
117
|
environment: 'environment-id'
|
|
115
118
|
}
|
|
116
119
|
};
|
|
117
|
-
function renderResourceCard({ linkType ='Contentful:Entry'
|
|
118
|
-
return (0, _react1.render)(_react.createElement(_EntityStore.EntityProvider, {
|
|
120
|
+
function renderResourceCard({ linkType = 'Contentful:Entry', entryUrn = resolvableEntryUrn } = {}) {
|
|
121
|
+
return (0, _react1.render)(/*#__PURE__*/ _react.createElement(_EntityStore.EntityProvider, {
|
|
119
122
|
sdk: sdk
|
|
120
|
-
}, _react.createElement(_ResourceCard.ResourceCard, {
|
|
123
|
+
}, /*#__PURE__*/ _react.createElement(_ResourceCard.ResourceCard, {
|
|
121
124
|
isDisabled: false,
|
|
122
125
|
getEntryRouteHref: ()=>'',
|
|
123
126
|
resourceLink: {
|
|
@@ -131,7 +134,7 @@ function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvabl
|
|
|
131
134
|
}
|
|
132
135
|
describe('ResourceCard', ()=>{
|
|
133
136
|
it('renders entry card with implicit master crn', async ()=>{
|
|
134
|
-
const { getByTestId
|
|
137
|
+
const { getByTestId, getByText } = renderResourceCard();
|
|
135
138
|
const tooltipContent = `Space: ${_indifferent_spacejson.default.name} (Env.: ${_published_entryjson.default.sys.environment.sys.id})`;
|
|
136
139
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
137
140
|
expect(getByText(_published_entryjson.default.fields.exField['en-US'])).toBeDefined();
|
|
@@ -140,7 +143,7 @@ describe('ResourceCard', ()=>{
|
|
|
140
143
|
await (0, _react1.waitFor)(()=>expect(getByText(tooltipContent)).toBeDefined());
|
|
141
144
|
});
|
|
142
145
|
it('renders entry card with explicit master crn', async ()=>{
|
|
143
|
-
const { getByTestId
|
|
146
|
+
const { getByTestId, getByText } = renderResourceCard({
|
|
144
147
|
entryUrn: resolvableEntryUrnWithExplicitMaster
|
|
145
148
|
});
|
|
146
149
|
const tooltipContent = `Space: ${_indifferent_spacejson.default.name} (Env.: ${_published_entryjson.default.sys.environment.sys.id})`;
|
|
@@ -151,7 +154,7 @@ describe('ResourceCard', ()=>{
|
|
|
151
154
|
await (0, _react1.waitFor)(()=>expect(getByText(tooltipContent)).toBeDefined());
|
|
152
155
|
});
|
|
153
156
|
it('renders entry card with a non master environment', async ()=>{
|
|
154
|
-
const { getByTestId
|
|
157
|
+
const { getByTestId, getByText } = renderResourceCard({
|
|
155
158
|
entryUrn: resolvableEntryUrnWithAnotherEnvironment
|
|
156
159
|
});
|
|
157
160
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
@@ -162,23 +165,23 @@ describe('ResourceCard', ()=>{
|
|
|
162
165
|
await (0, _react1.waitFor)(()=>expect(getByText(tooltipContent)).toBeDefined());
|
|
163
166
|
});
|
|
164
167
|
it('renders skeleton when no data is provided', ()=>{
|
|
165
|
-
const { getByTestId
|
|
168
|
+
const { getByTestId } = renderResourceCard();
|
|
166
169
|
expect(getByTestId('cf-ui-skeleton-form')).toBeDefined();
|
|
167
170
|
});
|
|
168
171
|
it('renders unsupported entity card when unsupported link is passed', async ()=>{
|
|
169
|
-
const { getByText
|
|
172
|
+
const { getByText } = renderResourceCard({
|
|
170
173
|
linkType: 'Contentful:UnsupportedLink'
|
|
171
174
|
});
|
|
172
175
|
await (0, _react1.waitFor)(()=>expect(getByText('Resource type Contentful:UnsupportedLink is currently not supported')).toBeDefined());
|
|
173
176
|
});
|
|
174
177
|
it('renders missing entity card when unknown error is returned', async ()=>{
|
|
175
|
-
const { getByTestId
|
|
178
|
+
const { getByTestId } = renderResourceCard({
|
|
176
179
|
entryUrn: unknownEntryUrn
|
|
177
180
|
});
|
|
178
181
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
179
182
|
});
|
|
180
183
|
it('renders missing entity card when crn is invalid', async ()=>{
|
|
181
|
-
const { getByTestId
|
|
184
|
+
const { getByTestId } = renderResourceCard({
|
|
182
185
|
entryUrn: ''
|
|
183
186
|
});
|
|
184
187
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
@@ -8,11 +8,11 @@ Object.defineProperty(exports, "MultipleResourceReferenceEditor", {
|
|
|
8
8
|
return MultipleResourceReferenceEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
13
13
|
const _sortable = require("@dnd-kit/sortable");
|
|
14
|
-
const _deepequal = _interop_require_default(require("deep-equal"));
|
|
15
|
-
const _noop = _interop_require_default(require("lodash/noop"));
|
|
14
|
+
const _deepequal = /*#__PURE__*/ _interop_require_default(require("deep-equal"));
|
|
15
|
+
const _noop = /*#__PURE__*/ _interop_require_default(require("lodash/noop"));
|
|
16
16
|
const _EntityStore = require("../common/EntityStore");
|
|
17
17
|
const _SortableLinkList = require("../common/SortableLinkList");
|
|
18
18
|
const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
|
|
@@ -44,7 +44,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
44
44
|
if (cache && cache.has(obj)) {
|
|
45
45
|
return cache.get(obj);
|
|
46
46
|
}
|
|
47
|
-
var newObj = {
|
|
47
|
+
var newObj = {
|
|
48
|
+
__proto__: null
|
|
49
|
+
};
|
|
48
50
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
51
|
for(var key in obj){
|
|
50
52
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -63,9 +65,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
63
65
|
return newObj;
|
|
64
66
|
}
|
|
65
67
|
function ResourceEditor(props) {
|
|
66
|
-
const { setValue
|
|
68
|
+
const { setValue, items, apiUrl } = props;
|
|
67
69
|
const onSortStart = ()=>(0, _noop.default)();
|
|
68
|
-
const onSortEnd = (0, _react.useCallback)(({ oldIndex
|
|
70
|
+
const onSortEnd = (0, _react.useCallback)(({ oldIndex, newIndex })=>{
|
|
69
71
|
const newItems = (0, _sortable.arrayMove)(items, oldIndex, newIndex);
|
|
70
72
|
setValue(newItems);
|
|
71
73
|
}, [
|
|
@@ -85,24 +87,25 @@ function ResourceEditor(props) {
|
|
|
85
87
|
items,
|
|
86
88
|
setValue
|
|
87
89
|
]);
|
|
88
|
-
const { dialogs
|
|
90
|
+
const { dialogs, field } = props.sdk;
|
|
89
91
|
const linkActionsProps = (0, _useResourceLinkActions.useResourceLinkActions)({
|
|
90
92
|
dialogs,
|
|
91
93
|
field,
|
|
92
94
|
apiUrl
|
|
93
95
|
});
|
|
94
|
-
return _react.createElement(_react.Fragment, null, props.children({
|
|
96
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, props.children({
|
|
95
97
|
...props,
|
|
96
98
|
onSortStart,
|
|
97
99
|
onSortEnd,
|
|
98
100
|
onMove,
|
|
99
101
|
onRemoteItemAtIndex
|
|
100
|
-
}), _react.createElement(_LinkEntityActions.CombinedLinkEntityActions, {
|
|
102
|
+
}), /*#__PURE__*/ _react.createElement(_LinkEntityActions.CombinedLinkEntityActions, {
|
|
101
103
|
...linkActionsProps,
|
|
102
104
|
renderCustomActions: props.renderCustomActions
|
|
103
105
|
}));
|
|
104
106
|
}
|
|
105
|
-
|
|
107
|
+
// provides memoized callbacks bound to a given item
|
|
108
|
+
function WithPerItemCallbacks({ listLength, index, onMove, onRemoteItemAtIndex, children }) {
|
|
106
109
|
const handleMoveTop = _react.useMemo(()=>index > 0 ? ()=>onMove(index, 0) : undefined, [
|
|
107
110
|
index,
|
|
108
111
|
onMove
|
|
@@ -116,7 +119,7 @@ function WithPerItemCallbacks({ listLength , index , onMove , onRemoteItemAtInde
|
|
|
116
119
|
index,
|
|
117
120
|
onRemoteItemAtIndex
|
|
118
121
|
]);
|
|
119
|
-
return _react.createElement(_react.Fragment, null, children({
|
|
122
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, children({
|
|
120
123
|
onMoveBottom: handleMoveBottom,
|
|
121
124
|
onMoveTop: handleMoveTop,
|
|
122
125
|
onRemove: handleRemove
|
|
@@ -124,28 +127,28 @@ function WithPerItemCallbacks({ listLength , index , onMove , onRemoteItemAtInde
|
|
|
124
127
|
}
|
|
125
128
|
const EMPTY_ARRAY = [];
|
|
126
129
|
function MultipleResourceReferenceEditor(props) {
|
|
127
|
-
return _react.createElement(_EntityStore.EntityProvider, {
|
|
130
|
+
return /*#__PURE__*/ _react.createElement(_EntityStore.EntityProvider, {
|
|
128
131
|
sdk: props.sdk
|
|
129
|
-
}, _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
132
|
+
}, /*#__PURE__*/ _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
130
133
|
debounce: 0,
|
|
131
134
|
field: props.sdk.field,
|
|
132
135
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
133
136
|
isEqualValues: _deepequal.default
|
|
134
|
-
}, ({ value
|
|
135
|
-
return _react.createElement(ResourceEditor, {
|
|
137
|
+
}, ({ value, disabled, setValue, externalReset })=>{
|
|
138
|
+
return /*#__PURE__*/ _react.createElement(ResourceEditor, {
|
|
136
139
|
...props,
|
|
137
140
|
items: value || EMPTY_ARRAY,
|
|
138
141
|
isDisabled: disabled,
|
|
139
142
|
setValue: setValue,
|
|
140
143
|
renderCustomActions: props.renderCustomActions,
|
|
141
144
|
key: `${externalReset}-list`
|
|
142
|
-
}, (editorProps)
|
|
145
|
+
}, (editorProps)=>/*#__PURE__*/ _react.createElement(_SortableLinkList.SortableLinkList, editorProps, ({ item, isDisabled, DragHandle, index })=>/*#__PURE__*/ _react.createElement(WithPerItemCallbacks, {
|
|
143
146
|
key: index,
|
|
144
147
|
index: index,
|
|
145
148
|
onMove: editorProps.onMove,
|
|
146
149
|
onRemoteItemAtIndex: editorProps.onRemoteItemAtIndex,
|
|
147
150
|
listLength: value?.length || 0
|
|
148
|
-
}, ({ onMoveBottom
|
|
151
|
+
}, ({ onMoveBottom, onMoveTop, onRemove })=>/*#__PURE__*/ _react.createElement(_ResourceCard.ResourceCard, {
|
|
149
152
|
key: index,
|
|
150
153
|
index: index,
|
|
151
154
|
resourceLink: item,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
require("@testing-library/jest-dom/extend-expect");
|
|
7
7
|
const _react1 = require("@testing-library/react");
|
|
8
8
|
const _EntityStore = require("../common/EntityStore");
|
|
@@ -29,7 +29,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
29
29
|
if (cache && cache.has(obj)) {
|
|
30
30
|
return cache.get(obj);
|
|
31
31
|
}
|
|
32
|
-
var newObj = {
|
|
32
|
+
var newObj = {
|
|
33
|
+
__proto__: null
|
|
34
|
+
};
|
|
33
35
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
36
|
for(var key in obj){
|
|
35
37
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -89,16 +91,18 @@ const fieldDefinition = {
|
|
|
89
91
|
describe('Multiple resource editor', ()=>{
|
|
90
92
|
it('renders the action button when no value is set', async ()=>{
|
|
91
93
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition);
|
|
92
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
94
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
93
95
|
isInitiallyDisabled: false,
|
|
94
96
|
sdk: sdk,
|
|
95
97
|
hasCardEditActions: true,
|
|
96
98
|
viewType: "card",
|
|
99
|
+
// @ts-expect-error unused...
|
|
97
100
|
parameters: {}
|
|
98
101
|
}));
|
|
99
102
|
const button = await _react1.screen.findByText('Add existing content');
|
|
100
103
|
expect(button).toBeDefined();
|
|
101
104
|
_react1.fireEvent.click(button);
|
|
105
|
+
// @ts-expect-error wait app-sdk version update
|
|
102
106
|
const dialogFn = sdk.dialogs.selectMultipleResourceEntries;
|
|
103
107
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
104
108
|
const options = dialogFn.mock.calls[0][0];
|
|
@@ -108,13 +112,14 @@ describe('Multiple resource editor', ()=>{
|
|
|
108
112
|
});
|
|
109
113
|
it('renders custom actions when passed', async ()=>{
|
|
110
114
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition);
|
|
111
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
115
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
112
116
|
isInitiallyDisabled: false,
|
|
113
117
|
sdk: sdk,
|
|
114
118
|
hasCardEditActions: true,
|
|
115
119
|
viewType: "card",
|
|
120
|
+
// @ts-expect-error unused...
|
|
116
121
|
parameters: {},
|
|
117
|
-
renderCustomActions: ()
|
|
122
|
+
renderCustomActions: ()=>/*#__PURE__*/ _react.createElement("div", {
|
|
118
123
|
"data-testid": "custom-actions"
|
|
119
124
|
})
|
|
120
125
|
}));
|
|
@@ -123,22 +128,24 @@ describe('Multiple resource editor', ()=>{
|
|
|
123
128
|
});
|
|
124
129
|
describe('with value', ()=>{
|
|
125
130
|
it('renders the cards', async ()=>{
|
|
126
|
-
const { entryLinks
|
|
131
|
+
const { entryLinks, entryInfos } = generateMultipleTestResources();
|
|
127
132
|
mockedResources = {};
|
|
128
133
|
for (const [spaceId, link] of Object.entries(entryLinks)){
|
|
129
134
|
mockedResources[`${link.sys.linkType}.${link.sys.urn}`] = entryInfos[spaceId];
|
|
130
135
|
}
|
|
131
136
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition, Object.values(entryLinks));
|
|
132
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
137
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
133
138
|
isInitiallyDisabled: false,
|
|
134
139
|
sdk: sdk,
|
|
135
140
|
hasCardEditActions: true,
|
|
136
141
|
viewType: "card",
|
|
137
142
|
apiUrl: "test-contentful",
|
|
138
143
|
getEntryRouteHref: ()=>'',
|
|
144
|
+
// @ts-expect-error unused...
|
|
139
145
|
parameters: {}
|
|
140
146
|
}));
|
|
141
147
|
expect(_EntityStore.useResource).toHaveBeenCalledTimes(Object.values(entryInfos).length);
|
|
148
|
+
// ensure the card is rendered for every value
|
|
142
149
|
const cards = [];
|
|
143
150
|
const entriesArray = Object.values(entryInfos);
|
|
144
151
|
for (const info of Array.from(entriesArray.values())){
|
|
@@ -150,49 +157,58 @@ describe('Multiple resource editor', ()=>{
|
|
|
150
157
|
});
|
|
151
158
|
describe('card actions', ()=>{
|
|
152
159
|
it('should have a move to top button', async ()=>{
|
|
153
|
-
const { entryLinks
|
|
160
|
+
const { entryLinks, entryInfos } = generateMultipleTestResources();
|
|
154
161
|
mockedResources = {};
|
|
155
162
|
for (const [spaceId, link] of Object.entries(entryLinks)){
|
|
156
163
|
mockedResources[`${link.sys.linkType}.${link.sys.urn}`] = entryInfos[spaceId];
|
|
157
164
|
}
|
|
158
165
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition, Object.values(entryLinks));
|
|
159
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
166
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
160
167
|
isInitiallyDisabled: false,
|
|
161
168
|
sdk: sdk,
|
|
162
169
|
hasCardEditActions: true,
|
|
163
170
|
viewType: "card",
|
|
164
171
|
apiUrl: "test-contentful",
|
|
165
172
|
getEntryRouteHref: ()=>'',
|
|
173
|
+
// @ts-expect-error unused...
|
|
166
174
|
parameters: {}
|
|
167
175
|
}));
|
|
176
|
+
// expect(useResource).toHaveBeenCalledTimes(Object.values(entryInfos).length);
|
|
177
|
+
// linking more is available
|
|
168
178
|
const linkExistingBtn = _react1.screen.queryByText('Add existing content');
|
|
169
179
|
expect(linkExistingBtn).toBeInTheDocument();
|
|
180
|
+
// ensure the card is rendered for every value
|
|
170
181
|
const entriesArray = Object.values(entryInfos);
|
|
171
182
|
const firstItem = entriesArray[0];
|
|
172
183
|
await expectToNotHaveMoveButton(firstItem, 'Move to top');
|
|
173
184
|
const allButFirst = entriesArray.slice(1);
|
|
185
|
+
// move actions are available
|
|
174
186
|
for (const info of allButFirst){
|
|
175
187
|
await expectToHaveMoveButton(info, 'Move to top');
|
|
176
188
|
}
|
|
177
189
|
});
|
|
178
190
|
it('should have a move to bottom button', async ()=>{
|
|
179
|
-
const { entryLinks
|
|
191
|
+
const { entryLinks, entryInfos } = generateMultipleTestResources();
|
|
180
192
|
mockedResources = {};
|
|
181
193
|
for (const [spaceId, link] of Object.entries(entryLinks)){
|
|
182
194
|
mockedResources[`${link.sys.linkType}.${link.sys.urn}`] = entryInfos[spaceId];
|
|
183
195
|
}
|
|
184
196
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition, Object.values(entryLinks));
|
|
185
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
197
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
186
198
|
isInitiallyDisabled: false,
|
|
187
199
|
sdk: sdk,
|
|
188
200
|
hasCardEditActions: true,
|
|
189
201
|
viewType: "card",
|
|
190
202
|
apiUrl: "test-contentful",
|
|
191
203
|
getEntryRouteHref: ()=>'',
|
|
204
|
+
// @ts-expect-error unused...
|
|
192
205
|
parameters: {}
|
|
193
206
|
}));
|
|
207
|
+
// expect(useResource).toHaveBeenCalledTimes(Object.values(entryInfos).length);
|
|
208
|
+
// linking more is available
|
|
194
209
|
const linkExistingBtn = _react1.screen.queryByText('Add existing content');
|
|
195
210
|
expect(linkExistingBtn).toBeInTheDocument();
|
|
211
|
+
// ensure the card is rendered for every value
|
|
196
212
|
const entriesArray = Object.values(entryInfos);
|
|
197
213
|
const lastItem = entriesArray[entriesArray.length - 1];
|
|
198
214
|
await expectToNotHaveMoveButton(lastItem, 'Move to bottom');
|
|
@@ -202,23 +218,27 @@ describe('Multiple resource editor', ()=>{
|
|
|
202
218
|
}
|
|
203
219
|
});
|
|
204
220
|
it('works when using remove action', async ()=>{
|
|
205
|
-
const { entryLinks
|
|
221
|
+
const { entryLinks, entryInfos } = generateMultipleTestResources();
|
|
206
222
|
mockedResources = {};
|
|
207
223
|
for (const [spaceId, link] of Object.entries(entryLinks)){
|
|
208
224
|
mockedResources[`${link.sys.linkType}.${link.sys.urn}`] = entryInfos[spaceId];
|
|
209
225
|
}
|
|
210
226
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition, Object.values(entryLinks));
|
|
211
|
-
(0, _react1.render)(_react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
227
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_MultipleResourceReferenceEditor.MultipleResourceReferenceEditor, {
|
|
212
228
|
isInitiallyDisabled: false,
|
|
213
229
|
sdk: sdk,
|
|
214
230
|
hasCardEditActions: true,
|
|
215
231
|
viewType: "card",
|
|
216
232
|
apiUrl: "test-contentful",
|
|
217
233
|
getEntryRouteHref: ()=>'',
|
|
234
|
+
// @ts-expect-error unused...
|
|
218
235
|
parameters: {}
|
|
219
236
|
}));
|
|
237
|
+
// expect(useResource).toHaveBeenCalledTimes(Object.values(entryInfos).length);
|
|
238
|
+
// linking more is available
|
|
220
239
|
const linkExistingBtn = _react1.screen.queryByText('Add existing content');
|
|
221
240
|
expect(linkExistingBtn).toBeInTheDocument();
|
|
241
|
+
// ensure the card is rendered for every value
|
|
222
242
|
const entriesArray = Object.values(entryInfos);
|
|
223
243
|
for (const info of entriesArray){
|
|
224
244
|
await clickCardActionsButton(info);
|
|
@@ -227,6 +247,7 @@ describe('Multiple resource editor', ()=>{
|
|
|
227
247
|
});
|
|
228
248
|
_react1.fireEvent.click(removeBtn);
|
|
229
249
|
}
|
|
250
|
+
// all cards were deleted
|
|
230
251
|
expect(sdk.field.setValue).toHaveBeenCalledTimes(3);
|
|
231
252
|
expect(sdk.field.setValue).toHaveBeenCalledWith([]);
|
|
232
253
|
});
|
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "SingleResourceReferenceEditor", {
|
|
|
8
8
|
return SingleResourceReferenceEditor;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
13
|
-
const _deepequal = _interop_require_default(require("deep-equal"));
|
|
13
|
+
const _deepequal = /*#__PURE__*/ _interop_require_default(require("deep-equal"));
|
|
14
14
|
const _EntityStore = require("../common/EntityStore");
|
|
15
15
|
const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
|
|
16
16
|
const _ResourceCard = require("./Cards/ResourceCard");
|
|
@@ -41,7 +41,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
41
41
|
if (cache && cache.has(obj)) {
|
|
42
42
|
return cache.get(obj);
|
|
43
43
|
}
|
|
44
|
-
var newObj = {
|
|
44
|
+
var newObj = {
|
|
45
|
+
__proto__: null
|
|
46
|
+
};
|
|
45
47
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
46
48
|
for(var key in obj){
|
|
47
49
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -60,26 +62,26 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
60
62
|
return newObj;
|
|
61
63
|
}
|
|
62
64
|
function SingleResourceReferenceEditor(props) {
|
|
63
|
-
const { dialogs
|
|
65
|
+
const { dialogs, field } = props.sdk;
|
|
64
66
|
const linkActionsProps = (0, _useResourceLinkActions.useResourceLinkActions)({
|
|
65
67
|
dialogs,
|
|
66
68
|
field,
|
|
67
69
|
apiUrl: props.apiUrl
|
|
68
70
|
});
|
|
69
|
-
return _react.createElement(_EntityStore.EntityProvider, {
|
|
71
|
+
return /*#__PURE__*/ _react.createElement(_EntityStore.EntityProvider, {
|
|
70
72
|
sdk: props.sdk
|
|
71
|
-
}, _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
73
|
+
}, /*#__PURE__*/ _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
72
74
|
debounce: 0,
|
|
73
75
|
field: props.sdk.field,
|
|
74
76
|
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
75
77
|
isEqualValues: _deepequal.default
|
|
76
|
-
}, ({ value
|
|
77
|
-
return value ? _react.createElement(_ResourceCard.ResourceCard, {
|
|
78
|
+
}, ({ value, disabled })=>{
|
|
79
|
+
return value ? /*#__PURE__*/ _react.createElement(_ResourceCard.ResourceCard, {
|
|
78
80
|
onRemove: ()=>props.sdk.field.removeValue(),
|
|
79
81
|
resourceLink: value,
|
|
80
82
|
isDisabled: disabled,
|
|
81
83
|
getEntryRouteHref: props.getEntryRouteHref
|
|
82
|
-
}) : _react.createElement(_LinkEntityActions.CombinedLinkEntityActions, {
|
|
84
|
+
}) : /*#__PURE__*/ _react.createElement(_LinkEntityActions.CombinedLinkEntityActions, {
|
|
83
85
|
...linkActionsProps,
|
|
84
86
|
renderCustomActions: props.renderCustomActions
|
|
85
87
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
require("@testing-library/jest-dom/extend-expect");
|
|
7
7
|
const _react1 = require("@testing-library/react");
|
|
8
8
|
const _EntityStore = require("../common/EntityStore");
|
|
@@ -29,7 +29,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
29
29
|
if (cache && cache.has(obj)) {
|
|
30
30
|
return cache.get(obj);
|
|
31
31
|
}
|
|
32
|
-
var newObj = {
|
|
32
|
+
var newObj = {
|
|
33
|
+
__proto__: null
|
|
34
|
+
};
|
|
33
35
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
36
|
for(var key in obj){
|
|
35
37
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -85,16 +87,18 @@ const fieldDefinition = {
|
|
|
85
87
|
describe('Single resource editor', ()=>{
|
|
86
88
|
it('renders the action button when no value is set', async ()=>{
|
|
87
89
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition);
|
|
88
|
-
(0, _react1.render)(_react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
90
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
89
91
|
isInitiallyDisabled: false,
|
|
90
92
|
sdk: sdk,
|
|
91
93
|
hasCardEditActions: true,
|
|
92
94
|
viewType: "card",
|
|
95
|
+
// @ts-expect-error unused...
|
|
93
96
|
parameters: {}
|
|
94
97
|
}));
|
|
95
98
|
const button = await _react1.screen.findByText('Add existing content');
|
|
96
99
|
expect(button).toBeDefined();
|
|
97
100
|
_react1.fireEvent.click(button);
|
|
101
|
+
// @ts-expect-error wait app-sdk version update
|
|
98
102
|
const dialogFn = sdk.dialogs.selectSingleResourceEntry;
|
|
99
103
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
100
104
|
const options = dialogFn.mock.calls[0][0];
|
|
@@ -104,13 +108,14 @@ describe('Single resource editor', ()=>{
|
|
|
104
108
|
});
|
|
105
109
|
it('renders custom actions when passed', async ()=>{
|
|
106
110
|
const sdk = (0, _resourceEditorHelpers.mockSdkForField)(fieldDefinition);
|
|
107
|
-
(0, _react1.render)(_react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
111
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
108
112
|
isInitiallyDisabled: false,
|
|
109
113
|
sdk: sdk,
|
|
110
114
|
hasCardEditActions: true,
|
|
111
115
|
viewType: "card",
|
|
116
|
+
// @ts-expect-error unused...
|
|
112
117
|
parameters: {},
|
|
113
|
-
renderCustomActions: ()
|
|
118
|
+
renderCustomActions: ()=>/*#__PURE__*/ _react.createElement("div", {
|
|
114
119
|
"data-testid": "custom-actions"
|
|
115
120
|
})
|
|
116
121
|
}));
|
|
@@ -134,16 +139,18 @@ describe('Single resource editor', ()=>{
|
|
|
134
139
|
}
|
|
135
140
|
});
|
|
136
141
|
mockedResources[`Contentful:Entry.crn:test:::content:spaces/x-space/entries/linkedEntryId`] = info;
|
|
137
|
-
(0, _react1.render)(_react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
142
|
+
(0, _react1.render)(/*#__PURE__*/ _react.createElement(_SingleResourceReferenceEditor.SingleResourceReferenceEditor, {
|
|
138
143
|
isInitiallyDisabled: false,
|
|
139
144
|
sdk: sdk,
|
|
140
145
|
hasCardEditActions: true,
|
|
141
146
|
viewType: "card",
|
|
142
147
|
apiUrl: "test-contentful",
|
|
143
148
|
getEntryRouteHref: jest.fn(),
|
|
149
|
+
// @ts-expect-error unused...
|
|
144
150
|
parameters: {}
|
|
145
151
|
}));
|
|
146
152
|
expect(_EntityStore.useResource).toHaveBeenCalled();
|
|
153
|
+
// ensure the card is rendered
|
|
147
154
|
const title = await _react1.screen.findByText('Title of linked entry');
|
|
148
155
|
await _react1.screen.findByText('X Space');
|
|
149
156
|
const theCard = title.closest('[data-test-id="cf-ui-entry-card"]');
|