@contentful/field-editor-reference 6.22.1-canary.2 → 6.22.1-canary.3
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/components/LinkActions/helpers.js +6 -2
- package/dist/cjs/components/LinkActions/helpers.spec.js +103 -0
- package/dist/esm/components/LinkActions/helpers.js +6 -2
- package/dist/esm/components/LinkActions/helpers.spec.js +99 -0
- package/dist/types/components/LinkActions/helpers.spec.d.ts +1 -0
- package/package.json +2 -2
|
@@ -20,6 +20,10 @@ _export(exports, {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const getContentTypeIds = (contentTypes)=>contentTypes.map((ct)=>ct.sys.id);
|
|
23
|
+
const getContentTypeFilter = (editorPermissions)=>{
|
|
24
|
+
const validationContentTypes = editorPermissions.validations.contentTypes;
|
|
25
|
+
return editorPermissions.availableContentTypes.length > 0 ? getContentTypeIds(editorPermissions.availableContentTypes) : validationContentTypes ?? [];
|
|
26
|
+
};
|
|
23
27
|
async function createEntity(props) {
|
|
24
28
|
if (props.entityType === 'Entry') {
|
|
25
29
|
if (!props.contentTypeId) {
|
|
@@ -46,7 +50,7 @@ async function selectSingleEntity(props) {
|
|
|
46
50
|
if (props.entityType === 'Entry') {
|
|
47
51
|
return await props.sdk.dialogs.selectSingleEntry({
|
|
48
52
|
locale: props.sdk.field.locale,
|
|
49
|
-
contentTypes:
|
|
53
|
+
contentTypes: getContentTypeFilter(props.editorPermissions)
|
|
50
54
|
});
|
|
51
55
|
} else {
|
|
52
56
|
return props.sdk.dialogs.selectSingleAsset({
|
|
@@ -63,7 +67,7 @@ async function selectMultipleEntities(props) {
|
|
|
63
67
|
if (props.entityType === 'Entry') {
|
|
64
68
|
return await props.sdk.dialogs.selectMultipleEntries({
|
|
65
69
|
locale: props.sdk.field.locale,
|
|
66
|
-
contentTypes:
|
|
70
|
+
contentTypes: getContentTypeFilter(props.editorPermissions),
|
|
67
71
|
min,
|
|
68
72
|
max
|
|
69
73
|
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _helpers = require("./helpers");
|
|
6
|
+
const makeContentType = (id)=>({
|
|
7
|
+
sys: {
|
|
8
|
+
id
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const makeSdk = ()=>({
|
|
12
|
+
field: {
|
|
13
|
+
locale: 'en-US',
|
|
14
|
+
getValue: jest.fn().mockReturnValue([])
|
|
15
|
+
},
|
|
16
|
+
dialogs: {
|
|
17
|
+
selectSingleEntry: jest.fn(),
|
|
18
|
+
selectMultipleEntries: jest.fn()
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
describe('LinkActions helpers', ()=>{
|
|
22
|
+
it('uses validation content types when availableContentTypes is empty (single)', async ()=>{
|
|
23
|
+
const sdk = makeSdk();
|
|
24
|
+
await (0, _helpers.selectSingleEntity)({
|
|
25
|
+
sdk: sdk,
|
|
26
|
+
entityType: 'Entry',
|
|
27
|
+
editorPermissions: {
|
|
28
|
+
canCreateEntity: true,
|
|
29
|
+
canLinkEntity: true,
|
|
30
|
+
creatableContentTypes: [],
|
|
31
|
+
availableContentTypes: [],
|
|
32
|
+
validations: {
|
|
33
|
+
contentTypes: [
|
|
34
|
+
'productListing',
|
|
35
|
+
'contextApp'
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
|
|
41
|
+
locale: 'en-US',
|
|
42
|
+
contentTypes: [
|
|
43
|
+
'productListing',
|
|
44
|
+
'contextApp'
|
|
45
|
+
]
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
it('uses validation content types when availableContentTypes is empty (multiple)', async ()=>{
|
|
49
|
+
const sdk = makeSdk();
|
|
50
|
+
await (0, _helpers.selectMultipleEntities)({
|
|
51
|
+
sdk: sdk,
|
|
52
|
+
entityType: 'Entry',
|
|
53
|
+
editorPermissions: {
|
|
54
|
+
canCreateEntity: true,
|
|
55
|
+
canLinkEntity: true,
|
|
56
|
+
creatableContentTypes: [],
|
|
57
|
+
availableContentTypes: [],
|
|
58
|
+
validations: {
|
|
59
|
+
contentTypes: [
|
|
60
|
+
'productListing',
|
|
61
|
+
'contextApp'
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
expect(sdk.dialogs.selectMultipleEntries).toHaveBeenCalledWith(expect.objectContaining({
|
|
67
|
+
locale: 'en-US',
|
|
68
|
+
contentTypes: [
|
|
69
|
+
'productListing',
|
|
70
|
+
'contextApp'
|
|
71
|
+
]
|
|
72
|
+
}));
|
|
73
|
+
});
|
|
74
|
+
it('prefers availableContentTypes when present', async ()=>{
|
|
75
|
+
const sdk = makeSdk();
|
|
76
|
+
await (0, _helpers.selectSingleEntity)({
|
|
77
|
+
sdk: sdk,
|
|
78
|
+
entityType: 'Entry',
|
|
79
|
+
editorPermissions: {
|
|
80
|
+
canCreateEntity: true,
|
|
81
|
+
canLinkEntity: true,
|
|
82
|
+
creatableContentTypes: [],
|
|
83
|
+
availableContentTypes: [
|
|
84
|
+
makeContentType('one'),
|
|
85
|
+
makeContentType('two')
|
|
86
|
+
],
|
|
87
|
+
validations: {
|
|
88
|
+
contentTypes: [
|
|
89
|
+
'productListing',
|
|
90
|
+
'contextApp'
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
|
|
96
|
+
locale: 'en-US',
|
|
97
|
+
contentTypes: [
|
|
98
|
+
'one',
|
|
99
|
+
'two'
|
|
100
|
+
]
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
const getContentTypeIds = (contentTypes)=>contentTypes.map((ct)=>ct.sys.id);
|
|
2
|
+
const getContentTypeFilter = (editorPermissions)=>{
|
|
3
|
+
const validationContentTypes = editorPermissions.validations.contentTypes;
|
|
4
|
+
return editorPermissions.availableContentTypes.length > 0 ? getContentTypeIds(editorPermissions.availableContentTypes) : validationContentTypes ?? [];
|
|
5
|
+
};
|
|
2
6
|
export async function createEntity(props) {
|
|
3
7
|
if (props.entityType === 'Entry') {
|
|
4
8
|
if (!props.contentTypeId) {
|
|
@@ -25,7 +29,7 @@ export async function selectSingleEntity(props) {
|
|
|
25
29
|
if (props.entityType === 'Entry') {
|
|
26
30
|
return await props.sdk.dialogs.selectSingleEntry({
|
|
27
31
|
locale: props.sdk.field.locale,
|
|
28
|
-
contentTypes:
|
|
32
|
+
contentTypes: getContentTypeFilter(props.editorPermissions)
|
|
29
33
|
});
|
|
30
34
|
} else {
|
|
31
35
|
return props.sdk.dialogs.selectSingleAsset({
|
|
@@ -42,7 +46,7 @@ export async function selectMultipleEntities(props) {
|
|
|
42
46
|
if (props.entityType === 'Entry') {
|
|
43
47
|
return await props.sdk.dialogs.selectMultipleEntries({
|
|
44
48
|
locale: props.sdk.field.locale,
|
|
45
|
-
contentTypes:
|
|
49
|
+
contentTypes: getContentTypeFilter(props.editorPermissions),
|
|
46
50
|
min,
|
|
47
51
|
max
|
|
48
52
|
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { selectMultipleEntities, selectSingleEntity } from './helpers';
|
|
2
|
+
const makeContentType = (id)=>({
|
|
3
|
+
sys: {
|
|
4
|
+
id
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
const makeSdk = ()=>({
|
|
8
|
+
field: {
|
|
9
|
+
locale: 'en-US',
|
|
10
|
+
getValue: jest.fn().mockReturnValue([])
|
|
11
|
+
},
|
|
12
|
+
dialogs: {
|
|
13
|
+
selectSingleEntry: jest.fn(),
|
|
14
|
+
selectMultipleEntries: jest.fn()
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
describe('LinkActions helpers', ()=>{
|
|
18
|
+
it('uses validation content types when availableContentTypes is empty (single)', async ()=>{
|
|
19
|
+
const sdk = makeSdk();
|
|
20
|
+
await selectSingleEntity({
|
|
21
|
+
sdk: sdk,
|
|
22
|
+
entityType: 'Entry',
|
|
23
|
+
editorPermissions: {
|
|
24
|
+
canCreateEntity: true,
|
|
25
|
+
canLinkEntity: true,
|
|
26
|
+
creatableContentTypes: [],
|
|
27
|
+
availableContentTypes: [],
|
|
28
|
+
validations: {
|
|
29
|
+
contentTypes: [
|
|
30
|
+
'productListing',
|
|
31
|
+
'contextApp'
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
|
|
37
|
+
locale: 'en-US',
|
|
38
|
+
contentTypes: [
|
|
39
|
+
'productListing',
|
|
40
|
+
'contextApp'
|
|
41
|
+
]
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
it('uses validation content types when availableContentTypes is empty (multiple)', async ()=>{
|
|
45
|
+
const sdk = makeSdk();
|
|
46
|
+
await selectMultipleEntities({
|
|
47
|
+
sdk: sdk,
|
|
48
|
+
entityType: 'Entry',
|
|
49
|
+
editorPermissions: {
|
|
50
|
+
canCreateEntity: true,
|
|
51
|
+
canLinkEntity: true,
|
|
52
|
+
creatableContentTypes: [],
|
|
53
|
+
availableContentTypes: [],
|
|
54
|
+
validations: {
|
|
55
|
+
contentTypes: [
|
|
56
|
+
'productListing',
|
|
57
|
+
'contextApp'
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
expect(sdk.dialogs.selectMultipleEntries).toHaveBeenCalledWith(expect.objectContaining({
|
|
63
|
+
locale: 'en-US',
|
|
64
|
+
contentTypes: [
|
|
65
|
+
'productListing',
|
|
66
|
+
'contextApp'
|
|
67
|
+
]
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
it('prefers availableContentTypes when present', async ()=>{
|
|
71
|
+
const sdk = makeSdk();
|
|
72
|
+
await selectSingleEntity({
|
|
73
|
+
sdk: sdk,
|
|
74
|
+
entityType: 'Entry',
|
|
75
|
+
editorPermissions: {
|
|
76
|
+
canCreateEntity: true,
|
|
77
|
+
canLinkEntity: true,
|
|
78
|
+
creatableContentTypes: [],
|
|
79
|
+
availableContentTypes: [
|
|
80
|
+
makeContentType('one'),
|
|
81
|
+
makeContentType('two')
|
|
82
|
+
],
|
|
83
|
+
validations: {
|
|
84
|
+
contentTypes: [
|
|
85
|
+
'productListing',
|
|
86
|
+
'contextApp'
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
|
|
92
|
+
locale: 'en-US',
|
|
93
|
+
contentTypes: [
|
|
94
|
+
'one',
|
|
95
|
+
'two'
|
|
96
|
+
]
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "6.22.1-canary.
|
|
3
|
+
"version": "6.22.1-canary.3+1daf7e10",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"registry": "https://npm.pkg.github.com/"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "1daf7e105fe9c564afb5e4600321535998f7908a"
|
|
72
72
|
}
|