@contentful/field-editor-reference 5.8.6 → 5.10.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 +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/assets/MultipleMediaEditor.js +86 -0
- package/dist/cjs/assets/SingleMediaEditor.js +69 -0
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +125 -0
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +171 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +159 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +130 -0
- package/dist/cjs/assets/index.js +24 -0
- package/dist/cjs/common/EntityStore.js +420 -0
- package/dist/cjs/common/MultipleReferenceEditor.js +164 -0
- package/dist/cjs/common/ReferenceEditor.js +74 -0
- package/dist/cjs/common/SingleReferenceEditor.js +118 -0
- package/dist/cjs/common/SortableLinkList.js +95 -0
- package/dist/cjs/common/customCardTypes.js +44 -0
- package/dist/cjs/common/useAccessApi.js +19 -0
- package/dist/cjs/common/useContentTypePermissions.js +54 -0
- package/dist/cjs/common/useEditorPermissions.js +77 -0
- package/dist/cjs/common/useEditorPermissions.spec.js +205 -0
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +62 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +102 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +254 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +199 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +190 -0
- package/dist/cjs/components/CreateEntryLinkButton/useGlobalMouseUp.js +19 -0
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +167 -0
- package/dist/cjs/components/LinkActions/LinkActions.js +123 -0
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +186 -0
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +54 -0
- package/dist/cjs/components/LinkActions/helpers.js +78 -0
- package/dist/cjs/components/LinkActions/redesignStyles.js +44 -0
- package/dist/cjs/components/LinkActions/styles.js +33 -0
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +75 -0
- package/dist/cjs/components/MissingEntityCard/styles.js +29 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +75 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +81 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +45 -0
- package/dist/cjs/components/SpaceName/SpaceName.js +91 -0
- package/dist/cjs/components/index.js +44 -0
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +86 -0
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +74 -0
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +189 -0
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +181 -0
- package/dist/cjs/entries/index.js +24 -0
- package/dist/cjs/index.js +92 -0
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +87 -0
- package/dist/cjs/resources/Cards/ResourceCard.js +111 -0
- package/dist/cjs/resources/Cards/UnsupportedEntityCard.js +64 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +157 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +297 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +87 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +161 -0
- package/dist/cjs/resources/index.js +19 -0
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +121 -0
- package/dist/cjs/resources/useResourceLinkActions.js +88 -0
- package/dist/cjs/types.js +22 -0
- package/dist/cjs/utils/fromFieldValidations.js +54 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/assets/MultipleMediaEditor.js +37 -0
- package/dist/esm/assets/SingleMediaEditor.js +20 -0
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +63 -0
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +122 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +105 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +76 -0
- package/dist/esm/assets/index.js +3 -0
- package/dist/esm/common/EntityStore.js +347 -0
- package/dist/esm/common/MultipleReferenceEditor.js +111 -0
- package/dist/esm/common/ReferenceEditor.js +20 -0
- package/dist/esm/common/SingleReferenceEditor.js +70 -0
- package/dist/esm/common/SortableLinkList.js +41 -0
- package/dist/esm/common/customCardTypes.js +1 -0
- package/dist/esm/common/useAccessApi.js +9 -0
- package/dist/esm/common/useContentTypePermissions.js +44 -0
- package/dist/esm/common/useEditorPermissions.js +67 -0
- package/dist/esm/common/useEditorPermissions.spec.js +201 -0
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +13 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +48 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +206 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +145 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +142 -0
- package/dist/esm/components/CreateEntryLinkButton/useGlobalMouseUp.js +9 -0
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +118 -0
- package/dist/esm/components/LinkActions/LinkActions.js +66 -0
- package/dist/esm/components/LinkActions/LinkEntityActions.js +127 -0
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +5 -0
- package/dist/esm/components/LinkActions/helpers.js +57 -0
- package/dist/esm/components/LinkActions/redesignStyles.js +18 -0
- package/dist/esm/components/LinkActions/styles.js +10 -0
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +26 -0
- package/dist/esm/components/MissingEntityCard/styles.js +11 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +18 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +32 -0
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +19 -0
- package/dist/esm/components/SpaceName/SpaceName.js +37 -0
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +37 -0
- package/dist/esm/entries/SingleEntryReferenceEditor.js +25 -0
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +135 -0
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +127 -0
- package/dist/esm/entries/index.js +3 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +38 -0
- package/dist/esm/resources/Cards/ResourceCard.js +62 -0
- package/dist/esm/resources/Cards/UnsupportedEntityCard.js +15 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +104 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +254 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.js +33 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +118 -0
- package/dist/esm/resources/index.js +2 -0
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +103 -0
- package/dist/esm/resources/useResourceLinkActions.js +78 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/fromFieldValidations.js +39 -0
- package/dist/{__fixtures__ → types/__fixtures__}/FakeSdk.d.ts +8 -8
- package/dist/{__fixtures__ → types/__fixtures__}/asset/index.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/content-type/index.d.ts +2 -2
- package/dist/{__fixtures__ → types/__fixtures__}/entry/index.d.ts +5 -5
- package/dist/{__fixtures__ → types/__fixtures__}/fixtures.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/locale/index.d.ts +42 -42
- package/dist/{__fixtures__ → types/__fixtures__}/space/index.d.ts +2 -2
- package/dist/{assets → types/assets}/MultipleMediaEditor.d.ts +10 -10
- package/dist/types/assets/SingleMediaEditor.d.ts +10 -0
- package/dist/{assets → types/assets}/WrappedAssetCard/AssetCardActions.d.ts +11 -11
- package/dist/{assets → types/assets}/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +17 -17
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetCard.d.ts +24 -24
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetLink.d.ts +16 -16
- package/dist/{assets → types/assets}/index.d.ts +3 -3
- package/dist/{common → types/common}/EntityStore.d.ts +62 -62
- package/dist/{common → types/common}/MultipleReferenceEditor.d.ts +25 -25
- package/dist/{common → types/common}/ReferenceEditor.d.ts +46 -46
- package/dist/{common → types/common}/SingleReferenceEditor.d.ts +24 -24
- package/dist/{common → types/common}/SortableLinkList.d.ts +19 -19
- package/dist/{common → types/common}/customCardTypes.d.ts +29 -29
- package/dist/types/common/useAccessApi.d.ts +16 -0
- package/dist/{common → types/common}/useContentTypePermissions.d.ts +17 -17
- package/dist/{common → types/common}/useEditorPermissions.d.ts +17 -17
- package/dist/types/common/useEditorPermissions.spec.d.ts +1 -0
- package/dist/{components → types/components}/AssetThumbnail/AssetThumbnail.d.ts +7 -7
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +19 -19
- package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +31 -31
- package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/useGlobalMouseUp.d.ts +1 -1
- package/dist/{components → types/components}/LinkActions/CombinedLinkActions.d.ts +10 -10
- package/dist/{components → types/components}/LinkActions/LinkActions.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/LinkEntityActions.d.ts +24 -24
- package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -0
- package/dist/{components → types/components}/LinkActions/helpers.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/redesignStyles.d.ts +3 -3
- package/dist/{components → types/components}/LinkActions/styles.d.ts +2 -2
- package/dist/{components → types/components}/MissingEntityCard/MissingEntityCard.d.ts +8 -8
- package/dist/{components → types/components}/MissingEntityCard/styles.d.ts +2 -2
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +11 -11
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +10 -10
- package/dist/{components → types/components}/ScheduledIconWithTooltip/formatDateAndTime.d.ts +15 -15
- package/dist/types/components/SpaceName/SpaceName.d.ts +6 -0
- package/dist/{components → types/components}/index.d.ts +9 -9
- package/dist/{entries → types/entries}/MultipleEntryReferenceEditor.d.ts +3 -3
- package/dist/{entries → types/entries}/SingleEntryReferenceEditor.d.ts +8 -8
- package/dist/{entries → types/entries}/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +18 -18
- package/dist/{entries → types/entries}/WrappedEntryCard/WrappedEntryCard.d.ts +35 -35
- package/dist/{entries → types/entries}/index.d.ts +3 -3
- package/dist/{index.d.ts → types/index.d.ts} +9 -8
- package/dist/{resources → types/resources}/Cards/ContentfulEntryCard.d.ts +21 -21
- package/dist/{resources → types/resources}/Cards/ResourceCard.d.ts +12 -12
- package/dist/{resources → types/resources}/Cards/UnsupportedEntityCard.d.ts +4 -4
- package/dist/{resources → types/resources}/MultipleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/MultipleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/SingleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/SingleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/index.d.ts +2 -2
- package/dist/{resources → types/resources}/testHelpers/resourceEditorHelpers.d.ts +50 -50
- package/dist/{resources → types/resources}/useResourceLinkActions.d.ts +7 -7
- package/dist/{types.d.ts → types/types.d.ts} +104 -104
- package/dist/{utils → types/utils}/fromFieldValidations.d.ts +21 -21
- package/package.json +25 -11
- package/CHANGELOG.md +0 -854
- package/dist/assets/SingleMediaEditor.d.ts +0 -10
- package/dist/common/useAccessApi.d.ts +0 -16
- package/dist/components/LinkActions/NoLinkPermissionsInfo.d.ts +0 -2
- package/dist/components/SpaceName/SpaceName.d.ts +0 -6
- package/dist/field-editor-reference.cjs.development.js +0 -4395
- package/dist/field-editor-reference.cjs.development.js.map +0 -1
- package/dist/field-editor-reference.cjs.production.min.js +0 -2
- package/dist/field-editor-reference.cjs.production.min.js.map +0 -1
- package/dist/field-editor-reference.esm.js +0 -4369
- package/dist/field-editor-reference.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
+
import { useResource } from '../common/EntityStore';
|
|
5
|
+
import { SingleResourceReferenceEditor } from './SingleResourceReferenceEditor';
|
|
6
|
+
import { createFakeEntryResource, mockSdkForField } from './testHelpers/resourceEditorHelpers';
|
|
7
|
+
const mockedResources = {};
|
|
8
|
+
jest.mock('../common/EntityStore', ()=>{
|
|
9
|
+
const module = jest.requireActual('../common/EntityStore');
|
|
10
|
+
return {
|
|
11
|
+
...module,
|
|
12
|
+
useResource: jest.fn((linkType, urn)=>({
|
|
13
|
+
data: mockedResources[`${linkType}.${urn}`],
|
|
14
|
+
status: 'success'
|
|
15
|
+
}))
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
jest.mock('react-intersection-observer', ()=>{
|
|
19
|
+
const module = jest.requireActual('react-intersection-observer');
|
|
20
|
+
return {
|
|
21
|
+
...module,
|
|
22
|
+
useInView: ()=>({
|
|
23
|
+
inView: true
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const fieldDefinition = {
|
|
28
|
+
type: 'ResourceLink',
|
|
29
|
+
id: 'foo',
|
|
30
|
+
name: 'Foo',
|
|
31
|
+
allowedResources: [
|
|
32
|
+
{
|
|
33
|
+
source: 'foo',
|
|
34
|
+
contentTypes: [
|
|
35
|
+
'bar'
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
required: true,
|
|
40
|
+
validations: []
|
|
41
|
+
};
|
|
42
|
+
describe('Single resource editor', ()=>{
|
|
43
|
+
it('renders the action button when no value is set', async ()=>{
|
|
44
|
+
const sdk = mockSdkForField(fieldDefinition);
|
|
45
|
+
render(React.createElement(SingleResourceReferenceEditor, {
|
|
46
|
+
isInitiallyDisabled: false,
|
|
47
|
+
sdk: sdk,
|
|
48
|
+
hasCardEditActions: true,
|
|
49
|
+
viewType: "card",
|
|
50
|
+
parameters: {}
|
|
51
|
+
}));
|
|
52
|
+
const button = await screen.findByText('Add existing content');
|
|
53
|
+
expect(button).toBeDefined();
|
|
54
|
+
fireEvent.click(button);
|
|
55
|
+
const dialogFn = sdk.dialogs.selectSingleResourceEntry;
|
|
56
|
+
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
57
|
+
const options = dialogFn.mock.calls[0][0];
|
|
58
|
+
expect(options).toEqual({
|
|
59
|
+
allowedResources: fieldDefinition.allowedResources
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('renders custom actions when passed', async ()=>{
|
|
63
|
+
const sdk = mockSdkForField(fieldDefinition);
|
|
64
|
+
render(React.createElement(SingleResourceReferenceEditor, {
|
|
65
|
+
isInitiallyDisabled: false,
|
|
66
|
+
sdk: sdk,
|
|
67
|
+
hasCardEditActions: true,
|
|
68
|
+
viewType: "card",
|
|
69
|
+
parameters: {},
|
|
70
|
+
renderCustomActions: ()=>React.createElement("div", {
|
|
71
|
+
"data-testid": "custom-actions"
|
|
72
|
+
})
|
|
73
|
+
}));
|
|
74
|
+
const customActions = await screen.findByTestId('custom-actions');
|
|
75
|
+
expect(customActions).toBeDefined();
|
|
76
|
+
});
|
|
77
|
+
it('renders the card button when the value is set', async ()=>{
|
|
78
|
+
const sdk = mockSdkForField(fieldDefinition, {
|
|
79
|
+
sys: {
|
|
80
|
+
type: 'Link',
|
|
81
|
+
linkType: 'Contentful:Entry',
|
|
82
|
+
urn: 'crn:test:::content:spaces/x-space/entries/linkedEntryId'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const info = createFakeEntryResource({
|
|
86
|
+
title: 'Title of linked entry',
|
|
87
|
+
id: 'linkedEntryId',
|
|
88
|
+
space: {
|
|
89
|
+
id: 'x-space',
|
|
90
|
+
name: 'X Space'
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
mockedResources[`Contentful:Entry.crn:test:::content:spaces/x-space/entries/linkedEntryId`] = info;
|
|
94
|
+
render(React.createElement(SingleResourceReferenceEditor, {
|
|
95
|
+
isInitiallyDisabled: false,
|
|
96
|
+
sdk: sdk,
|
|
97
|
+
hasCardEditActions: true,
|
|
98
|
+
viewType: "card",
|
|
99
|
+
apiUrl: "test-contentful",
|
|
100
|
+
getEntryRouteHref: jest.fn(),
|
|
101
|
+
parameters: {}
|
|
102
|
+
}));
|
|
103
|
+
expect(useResource).toHaveBeenCalled();
|
|
104
|
+
const title = await screen.findByText('Title of linked entry');
|
|
105
|
+
await screen.findByText('X Space');
|
|
106
|
+
const theCard = title.closest('[data-test-id="cf-ui-entry-card"]');
|
|
107
|
+
const actionsBtn = theCard?.querySelector('[data-test-id="cf-ui-card-actions"]');
|
|
108
|
+
expect(actionsBtn).toBeDefined();
|
|
109
|
+
fireEvent.click(actionsBtn);
|
|
110
|
+
const removeBtn = await screen.findByText('Remove', {
|
|
111
|
+
selector: '[role="menuitem"]'
|
|
112
|
+
});
|
|
113
|
+
fireEvent.click(removeBtn);
|
|
114
|
+
expect(sdk.field.removeValue).toHaveBeenCalledWith();
|
|
115
|
+
const linkExistingBtn = screen.queryByText('Add existing content');
|
|
116
|
+
expect(linkExistingBtn).not.toBeInTheDocument();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export function mockSdkForField(fieldDefinition, fieldValue) {
|
|
2
|
+
return {
|
|
3
|
+
field: {
|
|
4
|
+
getValue: jest.fn(()=>fieldValue),
|
|
5
|
+
setValue: jest.fn(()=>Promise.resolve(undefined)),
|
|
6
|
+
removeValue: jest.fn(),
|
|
7
|
+
onSchemaErrorsChanged: ()=>{},
|
|
8
|
+
onIsDisabledChanged: ()=>{},
|
|
9
|
+
onValueChanged: ()=>{},
|
|
10
|
+
...fieldDefinition,
|
|
11
|
+
locale: 'en'
|
|
12
|
+
},
|
|
13
|
+
dialogs: {
|
|
14
|
+
selectSingleResourceEntry: jest.fn().mockResolvedValue({
|
|
15
|
+
sys: {
|
|
16
|
+
type: 'Entry',
|
|
17
|
+
id: 'linkedEntryId',
|
|
18
|
+
space: {
|
|
19
|
+
sys: {
|
|
20
|
+
type: 'Link',
|
|
21
|
+
linkType: 'Space',
|
|
22
|
+
id: 'x-space'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
selectMultipleResourceEntries: jest.fn().mockResolvedValue([
|
|
28
|
+
{
|
|
29
|
+
sys: {
|
|
30
|
+
type: 'Entry',
|
|
31
|
+
id: 'linkedEntryId',
|
|
32
|
+
space: {
|
|
33
|
+
sys: {
|
|
34
|
+
type: 'Link',
|
|
35
|
+
linkType: 'Space',
|
|
36
|
+
id: 'x-space'
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
])
|
|
42
|
+
},
|
|
43
|
+
ids: {
|
|
44
|
+
space: 'myTestSpace',
|
|
45
|
+
environment: 'master',
|
|
46
|
+
organization: 'acme',
|
|
47
|
+
user: 'norris_chuck',
|
|
48
|
+
field: fieldDefinition.id,
|
|
49
|
+
entry: 'testEntry',
|
|
50
|
+
contentType: 'testCT'
|
|
51
|
+
},
|
|
52
|
+
space: {
|
|
53
|
+
onEntityChanged: ()=>{}
|
|
54
|
+
},
|
|
55
|
+
navigator: {
|
|
56
|
+
onSlideInNavigation: ()=>()=>({})
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export const createFakeEntryResource = ({ title , id , space })=>{
|
|
61
|
+
const { id: spaceId , name: spaceName } = space;
|
|
62
|
+
return {
|
|
63
|
+
resource: {
|
|
64
|
+
sys: {
|
|
65
|
+
id,
|
|
66
|
+
type: 'Entry',
|
|
67
|
+
space: {
|
|
68
|
+
sys: {
|
|
69
|
+
id: spaceId
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
environment: {
|
|
73
|
+
sys: {
|
|
74
|
+
id: `${spaceId}-environment`
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
fields: {
|
|
79
|
+
title: {
|
|
80
|
+
en: title
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
contentType: {
|
|
85
|
+
sys: {
|
|
86
|
+
id: 'xTestCT'
|
|
87
|
+
},
|
|
88
|
+
displayField: 'title',
|
|
89
|
+
fields: [
|
|
90
|
+
{
|
|
91
|
+
type: 'Symbol',
|
|
92
|
+
id: 'title',
|
|
93
|
+
name: 'The title'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
localeCode: 'en',
|
|
98
|
+
defaultLocaleCode: 'en',
|
|
99
|
+
space: {
|
|
100
|
+
name: spaceName
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
const toLinkItem = (entry, apiUrl)=>({
|
|
3
|
+
sys: {
|
|
4
|
+
type: 'ResourceLink',
|
|
5
|
+
linkType: 'Contentful:Entry',
|
|
6
|
+
urn: entry.sys.urn ?? `crn:${apiUrl}:::content:spaces/${entry.sys.space.sys.id}/entries/${entry.sys.id}`
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
const getUpdatedValue = (field, entries, apiUrl)=>{
|
|
10
|
+
const multiple = field.type === 'Array';
|
|
11
|
+
if (multiple) {
|
|
12
|
+
const linkItems = entries.map((entry)=>toLinkItem(entry, apiUrl));
|
|
13
|
+
const prevValue = field.getValue() || [];
|
|
14
|
+
return [
|
|
15
|
+
...prevValue,
|
|
16
|
+
...linkItems
|
|
17
|
+
];
|
|
18
|
+
} else {
|
|
19
|
+
return toLinkItem(entries[0], apiUrl);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export function useResourceLinkActions({ dialogs , field , onAfterLink , apiUrl }) {
|
|
23
|
+
const handleAfterLink = useCallback((entries)=>{
|
|
24
|
+
if (!onAfterLink) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
entries.forEach(onAfterLink);
|
|
28
|
+
}, [
|
|
29
|
+
onAfterLink
|
|
30
|
+
]);
|
|
31
|
+
const onLinkedExisting = useMemo(()=>{
|
|
32
|
+
return (entries)=>{
|
|
33
|
+
const updatedValue = getUpdatedValue(field, entries, apiUrl);
|
|
34
|
+
field.setValue(updatedValue);
|
|
35
|
+
handleAfterLink(entries);
|
|
36
|
+
};
|
|
37
|
+
}, [
|
|
38
|
+
field,
|
|
39
|
+
handleAfterLink,
|
|
40
|
+
apiUrl
|
|
41
|
+
]);
|
|
42
|
+
const multiple = field.type === 'Array';
|
|
43
|
+
const onLinkExisting = useMemo(()=>{
|
|
44
|
+
const promptSelection = multiple ? async ()=>await dialogs.selectMultipleResourceEntries({
|
|
45
|
+
allowedResources: field.allowedResources
|
|
46
|
+
}) : async ()=>[
|
|
47
|
+
await dialogs.selectSingleResourceEntry({
|
|
48
|
+
allowedResources: field.allowedResources
|
|
49
|
+
})
|
|
50
|
+
];
|
|
51
|
+
return async ()=>{
|
|
52
|
+
const res = await promptSelection();
|
|
53
|
+
if (!res) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
onLinkedExisting(res);
|
|
57
|
+
};
|
|
58
|
+
}, [
|
|
59
|
+
dialogs,
|
|
60
|
+
field.allowedResources,
|
|
61
|
+
multiple,
|
|
62
|
+
onLinkedExisting
|
|
63
|
+
]);
|
|
64
|
+
return {
|
|
65
|
+
onLinkExisting,
|
|
66
|
+
onLinkedExisting,
|
|
67
|
+
entityType: 'Entry',
|
|
68
|
+
contentTypes: [],
|
|
69
|
+
canCreateEntity: false,
|
|
70
|
+
canLinkMultiple: multiple,
|
|
71
|
+
canLinkEntity: true,
|
|
72
|
+
isDisabled: false,
|
|
73
|
+
isEmpty: false,
|
|
74
|
+
isFull: false,
|
|
75
|
+
onCreate: async ()=>{},
|
|
76
|
+
onCreated: ()=>{}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Entry, File, Asset } from '@contentful/field-editor-shared';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import isNumber from 'lodash/isNumber';
|
|
2
|
+
export function fromFieldValidations(field) {
|
|
3
|
+
const validations = [
|
|
4
|
+
...field.validations,
|
|
5
|
+
...field.items?.validations ?? []
|
|
6
|
+
];
|
|
7
|
+
const linkContentTypeValidations = validations.find((v)=>'linkContentType' in v);
|
|
8
|
+
const linkMimetypeGroupValidations = validations.find((v)=>'linkMimetypeGroup' in v);
|
|
9
|
+
const sizeValidations = validations.find((v)=>'size' in v);
|
|
10
|
+
const size = sizeValidations && sizeValidations.size || {};
|
|
11
|
+
const min = size.min;
|
|
12
|
+
const max = size.max;
|
|
13
|
+
let numberOfLinks = undefined;
|
|
14
|
+
if (isNumber(min) && isNumber(max)) {
|
|
15
|
+
numberOfLinks = {
|
|
16
|
+
type: 'min-max',
|
|
17
|
+
min,
|
|
18
|
+
max
|
|
19
|
+
};
|
|
20
|
+
} else if (isNumber(min)) {
|
|
21
|
+
numberOfLinks = {
|
|
22
|
+
type: 'min',
|
|
23
|
+
min,
|
|
24
|
+
max: undefined
|
|
25
|
+
};
|
|
26
|
+
} else if (isNumber(max)) {
|
|
27
|
+
numberOfLinks = {
|
|
28
|
+
type: 'max',
|
|
29
|
+
max,
|
|
30
|
+
min: undefined
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const result = {
|
|
34
|
+
contentTypes: linkContentTypeValidations?.linkContentType ?? undefined,
|
|
35
|
+
mimetypeGroups: linkMimetypeGroupValidations?.linkMimetypeGroup ?? undefined,
|
|
36
|
+
numberOfLinks
|
|
37
|
+
};
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FieldExtensionSDK } from '@contentful/app-sdk';
|
|
2
|
-
import { Emitter } from 'mitt';
|
|
3
|
-
export
|
|
4
|
-
initialValue?: any;
|
|
5
|
-
validations?: any;
|
|
6
|
-
fetchDelay?: number;
|
|
7
|
-
};
|
|
8
|
-
export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldExtensionSDK, Emitter];
|
|
1
|
+
import { FieldExtensionSDK } from '@contentful/app-sdk';
|
|
2
|
+
import { Emitter } from 'mitt';
|
|
3
|
+
export type ReferenceEditorSdkProps = {
|
|
4
|
+
initialValue?: any;
|
|
5
|
+
validations?: any;
|
|
6
|
+
fetchDelay?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldExtensionSDK, Emitter];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import changed from './changed_asset.json';
|
|
2
|
-
import created from './created_asset.json';
|
|
3
|
-
import empty from './empty_asset.json';
|
|
4
|
-
import invalid from './invalid_asset.json';
|
|
5
|
-
import published from './published_asset.json';
|
|
6
|
-
export { changed, empty, published, invalid, created };
|
|
1
|
+
import changed from './changed_asset.json';
|
|
2
|
+
import created from './created_asset.json';
|
|
3
|
+
import empty from './empty_asset.json';
|
|
4
|
+
import invalid from './invalid_asset.json';
|
|
5
|
+
import published from './published_asset.json';
|
|
6
|
+
export { changed, empty, published, invalid, created };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import published from './published_content_type.json';
|
|
2
|
-
export { published };
|
|
1
|
+
import published from './published_content_type.json';
|
|
2
|
+
export { published };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import changed from './changed_entry.json';
|
|
2
|
-
import empty from './empty_entry.json';
|
|
3
|
-
import invalid from './invalid_entry.json';
|
|
4
|
-
import published from './published_entry.json';
|
|
5
|
-
export { changed, empty, published, invalid };
|
|
1
|
+
import changed from './changed_entry.json';
|
|
2
|
+
import empty from './empty_entry.json';
|
|
3
|
+
import invalid from './invalid_entry.json';
|
|
4
|
+
import published from './published_entry.json';
|
|
5
|
+
export { changed, empty, published, invalid };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as assets from './asset';
|
|
2
|
-
import * as contentTypes from './content-type';
|
|
3
|
-
import * as entries from './entry';
|
|
4
|
-
import * as locales from './locale';
|
|
5
|
-
import * as spaces from './space';
|
|
6
|
-
export { assets, contentTypes, entries, locales, spaces };
|
|
1
|
+
import * as assets from './asset';
|
|
2
|
+
import * as contentTypes from './content-type';
|
|
3
|
+
import * as entries from './entry';
|
|
4
|
+
import * as locales from './locale';
|
|
5
|
+
import * as spaces from './space';
|
|
6
|
+
export { assets, contentTypes, entries, locales, spaces };
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import englishDefault from './english_default_locale.json';
|
|
2
|
-
import german from './german_locale.json';
|
|
3
|
-
declare const list: {
|
|
4
|
-
sys: {
|
|
5
|
-
type: string;
|
|
6
|
-
};
|
|
7
|
-
total: number;
|
|
8
|
-
skip: number;
|
|
9
|
-
limit: number;
|
|
10
|
-
items: {
|
|
11
|
-
sys: {
|
|
12
|
-
id: string;
|
|
13
|
-
type: string;
|
|
14
|
-
createdAt: string;
|
|
15
|
-
updatedAt: string;
|
|
16
|
-
version: number;
|
|
17
|
-
space: {
|
|
18
|
-
sys: {
|
|
19
|
-
type: string;
|
|
20
|
-
linkType: string;
|
|
21
|
-
id: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
environment: {
|
|
25
|
-
sys: {
|
|
26
|
-
id: string;
|
|
27
|
-
type: string;
|
|
28
|
-
linkType: string;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
name: string;
|
|
33
|
-
code: string;
|
|
34
|
-
internal_code: string;
|
|
35
|
-
fallbackCode: null;
|
|
36
|
-
contentDeliveryApi: boolean;
|
|
37
|
-
contentManagementApi: boolean;
|
|
38
|
-
default: boolean;
|
|
39
|
-
optional: boolean;
|
|
40
|
-
}[];
|
|
41
|
-
};
|
|
42
|
-
export { englishDefault, german, list };
|
|
1
|
+
import englishDefault from './english_default_locale.json';
|
|
2
|
+
import german from './german_locale.json';
|
|
3
|
+
declare const list: {
|
|
4
|
+
sys: {
|
|
5
|
+
type: string;
|
|
6
|
+
};
|
|
7
|
+
total: number;
|
|
8
|
+
skip: number;
|
|
9
|
+
limit: number;
|
|
10
|
+
items: {
|
|
11
|
+
sys: {
|
|
12
|
+
id: string;
|
|
13
|
+
type: string;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
version: number;
|
|
17
|
+
space: {
|
|
18
|
+
sys: {
|
|
19
|
+
type: string;
|
|
20
|
+
linkType: string;
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
environment: {
|
|
25
|
+
sys: {
|
|
26
|
+
id: string;
|
|
27
|
+
type: string;
|
|
28
|
+
linkType: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
name: string;
|
|
33
|
+
code: string;
|
|
34
|
+
internal_code: string;
|
|
35
|
+
fallbackCode: null;
|
|
36
|
+
contentDeliveryApi: boolean;
|
|
37
|
+
contentManagementApi: boolean;
|
|
38
|
+
default: boolean;
|
|
39
|
+
optional: boolean;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
export { englishDefault, german, list };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import indifferent from './indifferent_space.json';
|
|
2
|
-
export { indifferent };
|
|
1
|
+
import indifferent from './indifferent_space.json';
|
|
2
|
+
export { indifferent };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { ReferenceEditorProps } from '../common/ReferenceEditor';
|
|
3
|
-
|
|
4
|
-
export declare function MultipleMediaEditor(props: EditorProps): JSX.Element;
|
|
5
|
-
export declare namespace MultipleMediaEditor {
|
|
6
|
-
var defaultProps: {
|
|
7
|
-
isInitiallyDisabled: boolean;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReferenceEditorProps } from '../common/ReferenceEditor';
|
|
3
|
+
type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
|
|
4
|
+
export declare function MultipleMediaEditor(props: EditorProps): React.JSX.Element;
|
|
5
|
+
export declare namespace MultipleMediaEditor {
|
|
6
|
+
var defaultProps: {
|
|
7
|
+
isInitiallyDisabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReferenceEditorProps } from '../common/ReferenceEditor';
|
|
3
|
+
type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
|
|
4
|
+
export declare function SingleMediaEditor(props: EditorProps): React.JSX.Element;
|
|
5
|
+
export declare namespace SingleMediaEditor {
|
|
6
|
+
var defaultProps: {
|
|
7
|
+
isInitiallyDisabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { File } from '../../types';
|
|
3
|
-
export declare function renderAssetInfo(props: {
|
|
4
|
-
entityFile: File;
|
|
5
|
-
}): any[];
|
|
6
|
-
export declare function renderActions(props: {
|
|
7
|
-
onEdit?: () => void;
|
|
8
|
-
onRemove?: () => void;
|
|
9
|
-
isDisabled: boolean;
|
|
10
|
-
entityFile?: File;
|
|
11
|
-
}): (JSX.Element | null)[];
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { File } from '../../types';
|
|
3
|
+
export declare function renderAssetInfo(props: {
|
|
4
|
+
entityFile: File;
|
|
5
|
+
}): any[];
|
|
6
|
+
export declare function renderActions(props: {
|
|
7
|
+
onEdit?: () => void;
|
|
8
|
+
onRemove?: () => void;
|
|
9
|
+
isDisabled: boolean;
|
|
10
|
+
entityFile?: File;
|
|
11
|
+
}): (React.JSX.Element | null)[];
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { CustomCardRenderer, RenderCustomMissingEntityCard } from '../../common/customCardTypes';
|
|
3
|
-
import { Action, FieldExtensionSDK, ViewType, RenderDragFn } from '../../types';
|
|
4
|
-
|
|
5
|
-
assetId: string;
|
|
6
|
-
isDisabled: boolean;
|
|
7
|
-
sdk: FieldExtensionSDK;
|
|
8
|
-
viewType: ViewType | 'big_card';
|
|
9
|
-
onRemove: () => void;
|
|
10
|
-
getEntityUrl?: (id: string) => string;
|
|
11
|
-
onAction?: (action: Action) => void;
|
|
12
|
-
renderDragHandle?: RenderDragFn;
|
|
13
|
-
renderCustomCard?: CustomCardRenderer;
|
|
14
|
-
renderCustomMissingEntityCard?: RenderCustomMissingEntityCard;
|
|
15
|
-
};
|
|
16
|
-
export declare function FetchingWrappedAssetCard(props: FetchingWrappedAssetCardProps): JSX.Element;
|
|
17
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CustomCardRenderer, RenderCustomMissingEntityCard } from '../../common/customCardTypes';
|
|
3
|
+
import { Action, FieldExtensionSDK, ViewType, RenderDragFn } from '../../types';
|
|
4
|
+
type FetchingWrappedAssetCardProps = {
|
|
5
|
+
assetId: string;
|
|
6
|
+
isDisabled: boolean;
|
|
7
|
+
sdk: FieldExtensionSDK;
|
|
8
|
+
viewType: ViewType | 'big_card';
|
|
9
|
+
onRemove: () => void;
|
|
10
|
+
getEntityUrl?: (id: string) => string;
|
|
11
|
+
onAction?: (action: Action) => void;
|
|
12
|
+
renderDragHandle?: RenderDragFn;
|
|
13
|
+
renderCustomCard?: CustomCardRenderer;
|
|
14
|
+
renderCustomMissingEntityCard?: RenderCustomMissingEntityCard;
|
|
15
|
+
};
|
|
16
|
+
export declare function FetchingWrappedAssetCard(props: FetchingWrappedAssetCardProps): React.JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import { SpaceAPI } from '@contentful/app-sdk';
|
|
3
|
-
import { Asset, RenderDragFn } from '../../types';
|
|
4
|
-
export interface WrappedAssetCardProps {
|
|
5
|
-
getEntityScheduledActions: SpaceAPI['getEntityScheduledActions'];
|
|
6
|
-
asset: Asset;
|
|
7
|
-
localeCode: string;
|
|
8
|
-
defaultLocaleCode: string;
|
|
9
|
-
getAssetUrl?: (assetId: string) => string;
|
|
10
|
-
className?: string;
|
|
11
|
-
isSelected?: boolean;
|
|
12
|
-
isDisabled: boolean;
|
|
13
|
-
onEdit?: () => void;
|
|
14
|
-
onRemove?: () => void;
|
|
15
|
-
size: 'default' | 'small';
|
|
16
|
-
renderDragHandle?: RenderDragFn;
|
|
17
|
-
isClickable: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare const WrappedAssetCard: {
|
|
20
|
-
(props: WrappedAssetCardProps): JSX.Element;
|
|
21
|
-
defaultProps: {
|
|
22
|
-
isClickable: boolean;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SpaceAPI } from '@contentful/app-sdk';
|
|
3
|
+
import { Asset, RenderDragFn } from '../../types';
|
|
4
|
+
export interface WrappedAssetCardProps {
|
|
5
|
+
getEntityScheduledActions: SpaceAPI['getEntityScheduledActions'];
|
|
6
|
+
asset: Asset;
|
|
7
|
+
localeCode: string;
|
|
8
|
+
defaultLocaleCode: string;
|
|
9
|
+
getAssetUrl?: (assetId: string) => string;
|
|
10
|
+
className?: string;
|
|
11
|
+
isSelected?: boolean;
|
|
12
|
+
isDisabled: boolean;
|
|
13
|
+
onEdit?: () => void;
|
|
14
|
+
onRemove?: () => void;
|
|
15
|
+
size: 'default' | 'small';
|
|
16
|
+
renderDragHandle?: RenderDragFn;
|
|
17
|
+
isClickable: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const WrappedAssetCard: {
|
|
20
|
+
(props: WrappedAssetCardProps): React.JSX.Element;
|
|
21
|
+
defaultProps: {
|
|
22
|
+
isClickable: boolean;
|
|
23
|
+
};
|
|
24
|
+
};
|