@contentful/field-editor-shared 2.1.0 → 2.2.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.
|
@@ -30,6 +30,9 @@ _export(exports, {
|
|
|
30
30
|
getFieldValue: function() {
|
|
31
31
|
return getFieldValue;
|
|
32
32
|
},
|
|
33
|
+
hasDifferentLocaleStatuses: function() {
|
|
34
|
+
return hasDifferentLocaleStatuses;
|
|
35
|
+
},
|
|
33
36
|
isAssetField: function() {
|
|
34
37
|
return isAssetField;
|
|
35
38
|
},
|
|
@@ -236,3 +239,18 @@ const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
|
|
|
236
239
|
return null;
|
|
237
240
|
}
|
|
238
241
|
};
|
|
242
|
+
function hasDifferentLocaleStatuses(localesStatusMap) {
|
|
243
|
+
if (!localesStatusMap) return false;
|
|
244
|
+
let firstStatus;
|
|
245
|
+
for (const localeStatus of localesStatusMap.values()){
|
|
246
|
+
if (!localeStatus) continue;
|
|
247
|
+
if (firstStatus === undefined) {
|
|
248
|
+
firstStatus = localeStatus.status;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (localeStatus.status !== firstStatus) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
@@ -148,4 +148,70 @@ describe('getEntityStatus', ()=>{
|
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
|
+
describe('hasDifferentLocaleStatuses', ()=>{
|
|
152
|
+
test('returns false if all locales have the same status', ()=>{
|
|
153
|
+
const statusMap = new Map([
|
|
154
|
+
[
|
|
155
|
+
'en-US',
|
|
156
|
+
{
|
|
157
|
+
status: 'published',
|
|
158
|
+
locale: {
|
|
159
|
+
code: 'en-US'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
'fr-FR',
|
|
165
|
+
{
|
|
166
|
+
status: 'published',
|
|
167
|
+
locale: {
|
|
168
|
+
code: 'fr-FR'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
'de-DE',
|
|
174
|
+
{
|
|
175
|
+
status: 'published',
|
|
176
|
+
locale: {
|
|
177
|
+
code: 'de-DE'
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
]);
|
|
182
|
+
expect((0, _entityHelpers.hasDifferentLocaleStatuses)(statusMap)).toBeFalsy();
|
|
183
|
+
});
|
|
184
|
+
test('returns true if locales have different statuses', ()=>{
|
|
185
|
+
const statusMap = new Map([
|
|
186
|
+
[
|
|
187
|
+
'en-US',
|
|
188
|
+
{
|
|
189
|
+
status: 'published',
|
|
190
|
+
locale: {
|
|
191
|
+
code: 'en-US'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
'fr-FR',
|
|
197
|
+
{
|
|
198
|
+
status: 'draft',
|
|
199
|
+
locale: {
|
|
200
|
+
code: 'fr-FR'
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
'de-DE',
|
|
206
|
+
{
|
|
207
|
+
status: 'published',
|
|
208
|
+
locale: {
|
|
209
|
+
code: 'de-DE'
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
]);
|
|
214
|
+
expect((0, _entityHelpers.hasDifferentLocaleStatuses)(statusMap)).toBeTruthy();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
151
217
|
});
|
|
@@ -189,3 +189,18 @@ export const getEntryImage = async ({ entry, contentType, localeCode }, getAsset
|
|
|
189
189
|
return null;
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
+
export function hasDifferentLocaleStatuses(localesStatusMap) {
|
|
193
|
+
if (!localesStatusMap) return false;
|
|
194
|
+
let firstStatus;
|
|
195
|
+
for (const localeStatus of localesStatusMap.values()){
|
|
196
|
+
if (!localeStatus) continue;
|
|
197
|
+
if (firstStatus === undefined) {
|
|
198
|
+
firstStatus = localeStatus.status;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (localeStatus.status !== firstStatus) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getEntityStatus } from './entityHelpers';
|
|
1
|
+
import { getEntityStatus, hasDifferentLocaleStatuses } from './entityHelpers';
|
|
2
2
|
describe('getEntityStatus', ()=>{
|
|
3
3
|
function createEntity(props) {
|
|
4
4
|
return props;
|
|
@@ -144,4 +144,70 @@ describe('getEntityStatus', ()=>{
|
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
+
describe('hasDifferentLocaleStatuses', ()=>{
|
|
148
|
+
test('returns false if all locales have the same status', ()=>{
|
|
149
|
+
const statusMap = new Map([
|
|
150
|
+
[
|
|
151
|
+
'en-US',
|
|
152
|
+
{
|
|
153
|
+
status: 'published',
|
|
154
|
+
locale: {
|
|
155
|
+
code: 'en-US'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
'fr-FR',
|
|
161
|
+
{
|
|
162
|
+
status: 'published',
|
|
163
|
+
locale: {
|
|
164
|
+
code: 'fr-FR'
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
'de-DE',
|
|
170
|
+
{
|
|
171
|
+
status: 'published',
|
|
172
|
+
locale: {
|
|
173
|
+
code: 'de-DE'
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
]);
|
|
178
|
+
expect(hasDifferentLocaleStatuses(statusMap)).toBeFalsy();
|
|
179
|
+
});
|
|
180
|
+
test('returns true if locales have different statuses', ()=>{
|
|
181
|
+
const statusMap = new Map([
|
|
182
|
+
[
|
|
183
|
+
'en-US',
|
|
184
|
+
{
|
|
185
|
+
status: 'published',
|
|
186
|
+
locale: {
|
|
187
|
+
code: 'en-US'
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
[
|
|
192
|
+
'fr-FR',
|
|
193
|
+
{
|
|
194
|
+
status: 'draft',
|
|
195
|
+
locale: {
|
|
196
|
+
code: 'fr-FR'
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
'de-DE',
|
|
202
|
+
{
|
|
203
|
+
status: 'published',
|
|
204
|
+
locale: {
|
|
205
|
+
code: 'de-DE'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
]);
|
|
210
|
+
expect(hasDifferentLocaleStatuses(statusMap)).toBeTruthy();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
147
213
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalePublishStatusMap } from 'hooks/useLocalePublishStatus';
|
|
1
2
|
import { Asset, ContentType, ContentTypeField, Entry, File } from '../typesEntity';
|
|
2
3
|
export declare function getFieldValue({
|
|
3
4
|
/**
|
|
@@ -87,4 +88,11 @@ export declare const getEntryImage: ({ entry, contentType, localeCode, }: {
|
|
|
87
88
|
localeCode: string;
|
|
88
89
|
defaultLocaleCode: string;
|
|
89
90
|
}, getAsset: (assetId: string) => Promise<unknown>) => Promise<null | File>;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a locale status map contains different statuses across its locales
|
|
93
|
+
* Returns true if there are at least two different statuses (e.g. published and draft)
|
|
94
|
+
* @param localesStatusMap
|
|
95
|
+
* @returns boolean indicating if there are different statuses
|
|
96
|
+
*/
|
|
97
|
+
export declare function hasDifferentLocaleStatuses(localesStatusMap: LocalePublishStatusMap | null): boolean;
|
|
90
98
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"registry": "https://npm.pkg.github.com/"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "69ca4f654ac6d3a4435dd5ce33e771f8537e9d3d"
|
|
59
59
|
}
|