@contentful/field-editor-shared 1.5.4 → 1.6.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/utils/entityHelpers.js +7 -10
- package/dist/cjs/utils/entityHelpers.test.js +151 -0
- package/dist/esm/utils/entityHelpers.js +7 -10
- package/dist/esm/utils/entityHelpers.test.js +147 -0
- package/dist/types/utils/entityHelpers.d.ts +6 -4
- package/dist/types/utils/entityHelpers.test.d.ts +1 -0
- package/package.json +5 -5
|
@@ -175,23 +175,20 @@ function getEntityStatus(sys, localeCodes) {
|
|
|
175
175
|
}
|
|
176
176
|
if (sys.fieldStatus && localeCodes) {
|
|
177
177
|
let status = 'draft';
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
|
|
185
|
-
if (isMatchingLocale(localeCode)) {
|
|
178
|
+
const locales = Array.isArray(localeCodes) ? localeCodes : [
|
|
179
|
+
localeCodes
|
|
180
|
+
];
|
|
181
|
+
for (const [localeCode, fieldStatus] of Object.entries(sys.fieldStatus['*'])){
|
|
182
|
+
if (!locales || locales.includes(localeCode)) {
|
|
186
183
|
if (fieldStatus === 'changed') {
|
|
187
184
|
status = fieldStatus;
|
|
188
|
-
|
|
185
|
+
break;
|
|
189
186
|
}
|
|
190
187
|
if (fieldStatus === 'published') {
|
|
191
188
|
status = fieldStatus;
|
|
192
189
|
}
|
|
193
190
|
}
|
|
194
|
-
}
|
|
191
|
+
}
|
|
195
192
|
return status;
|
|
196
193
|
}
|
|
197
194
|
if (sys.publishedVersion) {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _entityHelpers = require("./entityHelpers");
|
|
6
|
+
describe('getEntityStatus', ()=>{
|
|
7
|
+
function createEntity(props) {
|
|
8
|
+
return props;
|
|
9
|
+
}
|
|
10
|
+
describe.each([
|
|
11
|
+
'Entry',
|
|
12
|
+
'Asset'
|
|
13
|
+
])('for entity type %s', (type)=>{
|
|
14
|
+
describe('archived', ()=>{
|
|
15
|
+
test('returns archived if there is an archivedVersion', ()=>{
|
|
16
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
17
|
+
archivedVersion: 1,
|
|
18
|
+
type,
|
|
19
|
+
version: 1
|
|
20
|
+
}));
|
|
21
|
+
expect(result).toEqual('archived');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('deleted', ()=>{
|
|
25
|
+
test('returns deleted if there is an deletedVersion', ()=>{
|
|
26
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
27
|
+
deletedVersion: 1,
|
|
28
|
+
type,
|
|
29
|
+
version: 1
|
|
30
|
+
}));
|
|
31
|
+
expect(result).toEqual('deleted');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('publish status', ()=>{
|
|
35
|
+
describe('by field status', ()=>{
|
|
36
|
+
test('returns changed if at least one fieldStatus is changed', ()=>{
|
|
37
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
38
|
+
fieldStatus: {
|
|
39
|
+
'*': {
|
|
40
|
+
'en-US': 'changed',
|
|
41
|
+
'de-DE': 'published',
|
|
42
|
+
'fr-FR': 'draft'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
type,
|
|
46
|
+
version: 1
|
|
47
|
+
}), [
|
|
48
|
+
'en-US',
|
|
49
|
+
'de-DE',
|
|
50
|
+
'fr-FR'
|
|
51
|
+
]);
|
|
52
|
+
expect(result).toEqual('changed');
|
|
53
|
+
});
|
|
54
|
+
test('returns published if at least one fieldStatus is published (and none changed)', ()=>{
|
|
55
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
56
|
+
fieldStatus: {
|
|
57
|
+
'*': {
|
|
58
|
+
'en-US': 'published',
|
|
59
|
+
'de-DE': 'published',
|
|
60
|
+
'fr-FR': 'draft'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
type,
|
|
64
|
+
version: 1
|
|
65
|
+
}), [
|
|
66
|
+
'en-US',
|
|
67
|
+
'de-DE',
|
|
68
|
+
'fr-FR'
|
|
69
|
+
]);
|
|
70
|
+
expect(result).toEqual('published');
|
|
71
|
+
});
|
|
72
|
+
test('returns published if that is the most advanced state for the selected locales', ()=>{
|
|
73
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
74
|
+
fieldStatus: {
|
|
75
|
+
'*': {
|
|
76
|
+
'en-US': 'changed',
|
|
77
|
+
'de-DE': 'published',
|
|
78
|
+
'fr-FR': 'draft'
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
type,
|
|
82
|
+
version: 1
|
|
83
|
+
}), [
|
|
84
|
+
'de-DE',
|
|
85
|
+
'fr-FR'
|
|
86
|
+
]);
|
|
87
|
+
expect(result).toEqual('published');
|
|
88
|
+
});
|
|
89
|
+
test('returns draft if at least one fieldStatus is draft (and none is changed or published)', ()=>{
|
|
90
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
91
|
+
fieldStatus: {
|
|
92
|
+
'*': {
|
|
93
|
+
'en-US': 'draft',
|
|
94
|
+
'de-DE': 'draft',
|
|
95
|
+
'fr-FR': 'draft'
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
type,
|
|
99
|
+
version: 1
|
|
100
|
+
}), [
|
|
101
|
+
'en-US',
|
|
102
|
+
'de-DE',
|
|
103
|
+
'fr-FR'
|
|
104
|
+
]);
|
|
105
|
+
expect(result).toEqual('draft');
|
|
106
|
+
});
|
|
107
|
+
test('returns draft if that is the most advanced state for the selected locales', ()=>{
|
|
108
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
109
|
+
fieldStatus: {
|
|
110
|
+
'*': {
|
|
111
|
+
'en-US': 'changed',
|
|
112
|
+
'de-DE': 'published',
|
|
113
|
+
'fr-FR': 'draft'
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
type,
|
|
117
|
+
version: 1
|
|
118
|
+
}), [
|
|
119
|
+
'fr-FR'
|
|
120
|
+
]);
|
|
121
|
+
expect(result).toEqual('draft');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('by version comparsion', ()=>{
|
|
125
|
+
test('returns changed if the version is greater than the publishedVersion + 1', ()=>{
|
|
126
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
127
|
+
publishedVersion: 1,
|
|
128
|
+
type,
|
|
129
|
+
version: 3
|
|
130
|
+
}));
|
|
131
|
+
expect(result).toEqual('changed');
|
|
132
|
+
});
|
|
133
|
+
test('returns published if there is a publishedVersion', ()=>{
|
|
134
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
135
|
+
publishedVersion: 1,
|
|
136
|
+
type,
|
|
137
|
+
version: 2
|
|
138
|
+
}));
|
|
139
|
+
expect(result).toEqual('published');
|
|
140
|
+
});
|
|
141
|
+
test('returns draft if there is no publishedVersion', ()=>{
|
|
142
|
+
const result = (0, _entityHelpers.getEntityStatus)(createEntity({
|
|
143
|
+
type,
|
|
144
|
+
version: 2
|
|
145
|
+
}));
|
|
146
|
+
expect(result).toEqual('draft');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -128,23 +128,20 @@ export function getEntityStatus(sys, localeCodes) {
|
|
|
128
128
|
}
|
|
129
129
|
if (sys.fieldStatus && localeCodes) {
|
|
130
130
|
let status = 'draft';
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
|
|
138
|
-
if (isMatchingLocale(localeCode)) {
|
|
131
|
+
const locales = Array.isArray(localeCodes) ? localeCodes : [
|
|
132
|
+
localeCodes
|
|
133
|
+
];
|
|
134
|
+
for (const [localeCode, fieldStatus] of Object.entries(sys.fieldStatus['*'])){
|
|
135
|
+
if (!locales || locales.includes(localeCode)) {
|
|
139
136
|
if (fieldStatus === 'changed') {
|
|
140
137
|
status = fieldStatus;
|
|
141
|
-
|
|
138
|
+
break;
|
|
142
139
|
}
|
|
143
140
|
if (fieldStatus === 'published') {
|
|
144
141
|
status = fieldStatus;
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
|
-
}
|
|
144
|
+
}
|
|
148
145
|
return status;
|
|
149
146
|
}
|
|
150
147
|
if (sys.publishedVersion) {
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { getEntityStatus } from './entityHelpers';
|
|
2
|
+
describe('getEntityStatus', ()=>{
|
|
3
|
+
function createEntity(props) {
|
|
4
|
+
return props;
|
|
5
|
+
}
|
|
6
|
+
describe.each([
|
|
7
|
+
'Entry',
|
|
8
|
+
'Asset'
|
|
9
|
+
])('for entity type %s', (type)=>{
|
|
10
|
+
describe('archived', ()=>{
|
|
11
|
+
test('returns archived if there is an archivedVersion', ()=>{
|
|
12
|
+
const result = getEntityStatus(createEntity({
|
|
13
|
+
archivedVersion: 1,
|
|
14
|
+
type,
|
|
15
|
+
version: 1
|
|
16
|
+
}));
|
|
17
|
+
expect(result).toEqual('archived');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('deleted', ()=>{
|
|
21
|
+
test('returns deleted if there is an deletedVersion', ()=>{
|
|
22
|
+
const result = getEntityStatus(createEntity({
|
|
23
|
+
deletedVersion: 1,
|
|
24
|
+
type,
|
|
25
|
+
version: 1
|
|
26
|
+
}));
|
|
27
|
+
expect(result).toEqual('deleted');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('publish status', ()=>{
|
|
31
|
+
describe('by field status', ()=>{
|
|
32
|
+
test('returns changed if at least one fieldStatus is changed', ()=>{
|
|
33
|
+
const result = getEntityStatus(createEntity({
|
|
34
|
+
fieldStatus: {
|
|
35
|
+
'*': {
|
|
36
|
+
'en-US': 'changed',
|
|
37
|
+
'de-DE': 'published',
|
|
38
|
+
'fr-FR': 'draft'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
type,
|
|
42
|
+
version: 1
|
|
43
|
+
}), [
|
|
44
|
+
'en-US',
|
|
45
|
+
'de-DE',
|
|
46
|
+
'fr-FR'
|
|
47
|
+
]);
|
|
48
|
+
expect(result).toEqual('changed');
|
|
49
|
+
});
|
|
50
|
+
test('returns published if at least one fieldStatus is published (and none changed)', ()=>{
|
|
51
|
+
const result = getEntityStatus(createEntity({
|
|
52
|
+
fieldStatus: {
|
|
53
|
+
'*': {
|
|
54
|
+
'en-US': 'published',
|
|
55
|
+
'de-DE': 'published',
|
|
56
|
+
'fr-FR': 'draft'
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
type,
|
|
60
|
+
version: 1
|
|
61
|
+
}), [
|
|
62
|
+
'en-US',
|
|
63
|
+
'de-DE',
|
|
64
|
+
'fr-FR'
|
|
65
|
+
]);
|
|
66
|
+
expect(result).toEqual('published');
|
|
67
|
+
});
|
|
68
|
+
test('returns published if that is the most advanced state for the selected locales', ()=>{
|
|
69
|
+
const result = getEntityStatus(createEntity({
|
|
70
|
+
fieldStatus: {
|
|
71
|
+
'*': {
|
|
72
|
+
'en-US': 'changed',
|
|
73
|
+
'de-DE': 'published',
|
|
74
|
+
'fr-FR': 'draft'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
type,
|
|
78
|
+
version: 1
|
|
79
|
+
}), [
|
|
80
|
+
'de-DE',
|
|
81
|
+
'fr-FR'
|
|
82
|
+
]);
|
|
83
|
+
expect(result).toEqual('published');
|
|
84
|
+
});
|
|
85
|
+
test('returns draft if at least one fieldStatus is draft (and none is changed or published)', ()=>{
|
|
86
|
+
const result = getEntityStatus(createEntity({
|
|
87
|
+
fieldStatus: {
|
|
88
|
+
'*': {
|
|
89
|
+
'en-US': 'draft',
|
|
90
|
+
'de-DE': 'draft',
|
|
91
|
+
'fr-FR': 'draft'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
type,
|
|
95
|
+
version: 1
|
|
96
|
+
}), [
|
|
97
|
+
'en-US',
|
|
98
|
+
'de-DE',
|
|
99
|
+
'fr-FR'
|
|
100
|
+
]);
|
|
101
|
+
expect(result).toEqual('draft');
|
|
102
|
+
});
|
|
103
|
+
test('returns draft if that is the most advanced state for the selected locales', ()=>{
|
|
104
|
+
const result = getEntityStatus(createEntity({
|
|
105
|
+
fieldStatus: {
|
|
106
|
+
'*': {
|
|
107
|
+
'en-US': 'changed',
|
|
108
|
+
'de-DE': 'published',
|
|
109
|
+
'fr-FR': 'draft'
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
type,
|
|
113
|
+
version: 1
|
|
114
|
+
}), [
|
|
115
|
+
'fr-FR'
|
|
116
|
+
]);
|
|
117
|
+
expect(result).toEqual('draft');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('by version comparsion', ()=>{
|
|
121
|
+
test('returns changed if the version is greater than the publishedVersion + 1', ()=>{
|
|
122
|
+
const result = getEntityStatus(createEntity({
|
|
123
|
+
publishedVersion: 1,
|
|
124
|
+
type,
|
|
125
|
+
version: 3
|
|
126
|
+
}));
|
|
127
|
+
expect(result).toEqual('changed');
|
|
128
|
+
});
|
|
129
|
+
test('returns published if there is a publishedVersion', ()=>{
|
|
130
|
+
const result = getEntityStatus(createEntity({
|
|
131
|
+
publishedVersion: 1,
|
|
132
|
+
type,
|
|
133
|
+
version: 2
|
|
134
|
+
}));
|
|
135
|
+
expect(result).toEqual('published');
|
|
136
|
+
});
|
|
137
|
+
test('returns draft if there is no publishedVersion', ()=>{
|
|
138
|
+
const result = getEntityStatus(createEntity({
|
|
139
|
+
type,
|
|
140
|
+
version: 2
|
|
141
|
+
}));
|
|
142
|
+
expect(result).toEqual('draft');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -59,22 +59,24 @@ type AsyncPublishStatus = 'draft' | 'published' | 'changed';
|
|
|
59
59
|
type FieldStatus = {
|
|
60
60
|
'*': Record<string, AsyncPublishStatus>;
|
|
61
61
|
};
|
|
62
|
+
export type EntitySys = (Entry['sys'] | Asset['sys']) & {
|
|
63
|
+
fieldStatus?: FieldStatus;
|
|
64
|
+
};
|
|
62
65
|
/**
|
|
63
66
|
* Returns the status of the entry/asset
|
|
64
67
|
* If a locale code(s) is provided it will pick up the most advanced state for these locale(s)
|
|
68
|
+
* (Not aggregated, this means published + draft is published and not changed)
|
|
65
69
|
* - deleted
|
|
66
70
|
* - archived
|
|
67
71
|
* - changed
|
|
68
72
|
* - published
|
|
69
73
|
* - draft
|
|
70
74
|
*/
|
|
71
|
-
export declare function getEntityStatus(sys:
|
|
72
|
-
fieldStatus?: FieldStatus;
|
|
73
|
-
}, localeCodes?: string | string[]): "draft" | "published" | "changed" | "deleted" | "archived";
|
|
75
|
+
export declare function getEntityStatus(sys: EntitySys, localeCodes?: string | string[]): AsyncPublishStatus | "deleted" | "archived";
|
|
74
76
|
/**@deprecated use `getEntityStatus` */
|
|
75
77
|
export declare function getEntryStatus(sys: Entry['sys'] & {
|
|
76
78
|
fieldStatus?: FieldStatus;
|
|
77
|
-
}, localeCodes?: string | string[]):
|
|
79
|
+
}, localeCodes?: string | string[]): AsyncPublishStatus | "deleted" | "archived";
|
|
78
80
|
/**
|
|
79
81
|
* Gets a promise resolving with a localized asset image field representing a
|
|
80
82
|
* given entities file. The promise may resolve with null.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"tsc": "tsc -p ./ --noEmit"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@contentful/app-sdk": "^4.
|
|
39
|
-
"@contentful/field-editor-test-utils": "^1.
|
|
38
|
+
"@contentful/app-sdk": "^4.29.0",
|
|
39
|
+
"@contentful/field-editor-test-utils": "^1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@contentful/f36-note": "^4.2.8",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"lodash": "^4.17.15"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@contentful/app-sdk": "^4.
|
|
49
|
+
"@contentful/app-sdk": "^4.29.0",
|
|
50
50
|
"react": ">=16.8.0"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"registry": "https://npm.pkg.github.com/"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "6598ec65e210c4e84bed073f8b50c8bdb883a9a4"
|
|
56
56
|
}
|