@contentful/field-editor-shared 1.7.0 → 1.8.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.
@@ -53,7 +53,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
53
53
  }
54
54
  return newObj;
55
55
  }
56
- it('does not rerender with outdated value after calling setValue', ()=>{
56
+ it('does not rerender with outdated value after calling setValue', async ()=>{
57
57
  function getChild() {
58
58
  return props.children.mock.calls[props.children.mock.calls.length - 1][0];
59
59
  }
@@ -75,7 +75,9 @@ it('does not rerender with outdated value after calling setValue', ()=>{
75
75
  let child = getChild();
76
76
  expect(child.value).toBe('initial value');
77
77
  const initialRenderCount = props.children.mock.calls.length;
78
- child.setValue('new value');
78
+ await (0, _react1.act)(async ()=>{
79
+ child.setValue('new value');
80
+ });
79
81
  onSchemaErrorsChanged.mock.calls.forEach(([cb])=>cb([]));
80
82
  child = getChild();
81
83
  expect(child.value).toBe('new value');
@@ -17,6 +17,12 @@ function _interop_require_default(obj) {
17
17
  default: obj
18
18
  };
19
19
  }
20
+ var ScheduledActionTypes;
21
+ (function(ScheduledActionTypes) {
22
+ ScheduledActionTypes["publish"] = "publish";
23
+ ScheduledActionTypes["unpublish"] = "unpublish";
24
+ ScheduledActionTypes["patch+publish"] = "patch+publish";
25
+ })(ScheduledActionTypes || (ScheduledActionTypes = {}));
20
26
  function ScheduledBanner({ entityId, jobs }) {
21
27
  const scheduledJobs = jobs.filter((job)=>job.entity.sys.id === entityId);
22
28
  const sortedScheduledJobs = (0, _lodash.orderBy)(scheduledJobs, [
@@ -30,7 +36,7 @@ function ScheduledBanner({ entityId, jobs }) {
30
36
  }
31
37
  const pendingJobsCount = scheduledJobs.length - 1;
32
38
  const lowerCaseAction = scheduledAction.action.toLowerCase();
33
- const action = lowerCaseAction === ScheduledActionTypes['patch+publish'] ? `${lowerCaseAction} (via Schedule Series)` : lowerCaseAction;
39
+ const action = lowerCaseAction === "patch+publish" ? `${lowerCaseAction} (via Schedule Series)` : lowerCaseAction;
34
40
  return _react.default.createElement(_Banner.Banner, {
35
41
  content: `All locales are scheduled to ${action} on:`,
36
42
  highlight: `${(0, _f36components.formatDateAndTime)(scheduledAction.scheduledFor.datetime)}${pendingJobsCount > 0 ? ` [and +${pendingJobsCount} more]` : ''}`
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useAsyncLocalePublishStatus", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useAsyncLocalePublishStatus;
9
+ }
10
+ });
11
+ const _react = require("react");
12
+ const _entityHelpers = _interop_require_wildcard(require("../utils/entityHelpers"));
13
+ function _getRequireWildcardCache(nodeInterop) {
14
+ if (typeof WeakMap !== "function") return null;
15
+ var cacheBabelInterop = new WeakMap();
16
+ var cacheNodeInterop = new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop) {
18
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {
35
+ __proto__: null
36
+ };
37
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
38
+ for(var key in obj){
39
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
40
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
41
+ if (desc && (desc.get || desc.set)) {
42
+ Object.defineProperty(newObj, key, desc);
43
+ } else {
44
+ newObj[key] = obj[key];
45
+ }
46
+ }
47
+ }
48
+ newObj.default = obj;
49
+ if (cache) {
50
+ cache.set(obj, newObj);
51
+ }
52
+ return newObj;
53
+ }
54
+ function getLocalePublishStatusMap(entity, locales) {
55
+ const entityStatus = _entityHelpers.getEntityStatus(entity.sys);
56
+ if ([
57
+ 'archived',
58
+ 'deleted'
59
+ ].includes(entityStatus)) {
60
+ return;
61
+ }
62
+ const statusMap = new Map(locales.map((locale)=>[
63
+ locale.code,
64
+ {
65
+ status: _entityHelpers.getEntityStatus(entity.sys, locale.code),
66
+ locale
67
+ }
68
+ ]));
69
+ return statusMap;
70
+ }
71
+ function useAsyncLocalePublishStatus(entity, privateLocales) {
72
+ return (0, _react.useMemo)(()=>{
73
+ if (entity && privateLocales) {
74
+ return getLocalePublishStatusMap(entity, privateLocales);
75
+ }
76
+ return undefined;
77
+ }, [
78
+ entity,
79
+ privateLocales
80
+ ]);
81
+ }
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _reacthooks = require("@testing-library/react-hooks");
6
+ const _useAsyncLocalePublishStatus = require("./useAsyncLocalePublishStatus");
7
+ describe('useAsyncLocalePublishStatus', ()=>{
8
+ const enUS = {
9
+ code: 'en-US',
10
+ name: 'en-US',
11
+ internal_code: 'en-US',
12
+ fallbackCode: null,
13
+ default: false,
14
+ contentManagementApi: true,
15
+ contentDeliveryApi: true,
16
+ optional: false,
17
+ sys: {
18
+ type: 'Locale',
19
+ id: 'en-US',
20
+ version: 1,
21
+ space: {
22
+ sys: {
23
+ type: 'Link',
24
+ linkType: 'Space',
25
+ id: 'test-xokbvvklfw'
26
+ }
27
+ },
28
+ environment: {
29
+ sys: {
30
+ type: 'Link',
31
+ linkType: 'Environment',
32
+ id: 'test-ak19mszr76'
33
+ }
34
+ },
35
+ createdBy: {
36
+ sys: {
37
+ type: 'Link',
38
+ linkType: 'User',
39
+ id: 'test-0olok52c12'
40
+ }
41
+ },
42
+ createdAt: '2017-01-23T10:17:55Z',
43
+ updatedBy: {
44
+ sys: {
45
+ type: 'Link',
46
+ linkType: 'User',
47
+ id: 'test-0olok52c12'
48
+ }
49
+ },
50
+ updatedAt: '2017-01-23T10:17:55Z'
51
+ }
52
+ };
53
+ const deDE = {
54
+ code: 'de-DE',
55
+ name: 'de-DE',
56
+ internal_code: 'de-DE',
57
+ fallbackCode: null,
58
+ default: false,
59
+ contentManagementApi: true,
60
+ contentDeliveryApi: true,
61
+ optional: false,
62
+ sys: {
63
+ type: 'Locale',
64
+ id: 'de-DE',
65
+ version: 1,
66
+ space: {
67
+ sys: {
68
+ type: 'Link',
69
+ linkType: 'Space',
70
+ id: 'test-tnw0g6rujf'
71
+ }
72
+ },
73
+ environment: {
74
+ sys: {
75
+ type: 'Link',
76
+ linkType: 'Environment',
77
+ id: 'test-wisyjo6pk4'
78
+ }
79
+ },
80
+ createdBy: {
81
+ sys: {
82
+ type: 'Link',
83
+ linkType: 'User',
84
+ id: 'test-j63uqcmqlx'
85
+ }
86
+ },
87
+ createdAt: '2017-01-23T10:17:55Z',
88
+ updatedBy: {
89
+ sys: {
90
+ type: 'Link',
91
+ linkType: 'User',
92
+ id: 'test-j63uqcmqlx'
93
+ }
94
+ },
95
+ updatedAt: '2017-01-23T10:17:55Z'
96
+ }
97
+ };
98
+ const esES = {
99
+ code: 'es-ES',
100
+ name: 'es-ES',
101
+ internal_code: 'es-ES',
102
+ fallbackCode: null,
103
+ default: false,
104
+ contentManagementApi: true,
105
+ contentDeliveryApi: true,
106
+ optional: false,
107
+ sys: {
108
+ type: 'Locale',
109
+ id: 'es-ES',
110
+ version: 1,
111
+ space: {
112
+ sys: {
113
+ type: 'Link',
114
+ linkType: 'Space',
115
+ id: 'test-h0e5p83kvo'
116
+ }
117
+ },
118
+ environment: {
119
+ sys: {
120
+ type: 'Link',
121
+ linkType: 'Environment',
122
+ id: 'test-extqkvjiub'
123
+ }
124
+ },
125
+ createdBy: {
126
+ sys: {
127
+ type: 'Link',
128
+ linkType: 'User',
129
+ id: 'test-1xpsnz99fa'
130
+ }
131
+ },
132
+ createdAt: '2017-01-23T10:17:55Z',
133
+ updatedBy: {
134
+ sys: {
135
+ type: 'Link',
136
+ linkType: 'User',
137
+ id: 'test-1xpsnz99fa'
138
+ }
139
+ },
140
+ updatedAt: '2017-01-23T10:17:55Z'
141
+ }
142
+ };
143
+ describe('status from entity', ()=>{
144
+ it('returns the status from an entry', ()=>{
145
+ const entity = {
146
+ metadata: {
147
+ tags: []
148
+ },
149
+ sys: {
150
+ id: '1',
151
+ type: 'Entry',
152
+ createdAt: '2017-12-07T10:48:41Z',
153
+ createdBy: {
154
+ sys: {
155
+ type: 'Link',
156
+ linkType: 'User',
157
+ id: 'test-u1dc0g7uzh'
158
+ }
159
+ },
160
+ updatedAt: '2017-12-07T10:48:41Z',
161
+ updatedBy: {
162
+ sys: {
163
+ type: 'Link',
164
+ linkType: 'User',
165
+ id: 'test-u1dc0g7uzh'
166
+ }
167
+ },
168
+ space: {
169
+ sys: {
170
+ type: 'Link',
171
+ linkType: 'Space',
172
+ id: 'test-vllzslv98d'
173
+ }
174
+ },
175
+ environment: {
176
+ sys: {
177
+ type: 'Link',
178
+ linkType: 'Environment',
179
+ id: 'test-y0ftcnn4eq'
180
+ }
181
+ },
182
+ publishedCounter: 0,
183
+ version: 1,
184
+ fieldStatus: {
185
+ '*': {
186
+ 'en-US': 'published',
187
+ 'de-DE': 'changed',
188
+ 'es-ES': 'draft'
189
+ }
190
+ },
191
+ contentType: {
192
+ sys: {
193
+ type: 'Link',
194
+ linkType: 'ContentType',
195
+ id: 'content-type'
196
+ }
197
+ },
198
+ automationTags: []
199
+ },
200
+ fields: {}
201
+ };
202
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useAsyncLocalePublishStatus.useAsyncLocalePublishStatus)(entity, [
203
+ enUS,
204
+ deDE,
205
+ esES
206
+ ]));
207
+ expect(result.current).toEqual(new Map([
208
+ [
209
+ 'en-US',
210
+ {
211
+ status: 'published',
212
+ locale: enUS
213
+ }
214
+ ],
215
+ [
216
+ 'de-DE',
217
+ {
218
+ status: 'changed',
219
+ locale: deDE
220
+ }
221
+ ],
222
+ [
223
+ 'es-ES',
224
+ {
225
+ status: 'draft',
226
+ locale: esES
227
+ }
228
+ ]
229
+ ]));
230
+ });
231
+ it('returns the status from an asset', ()=>{
232
+ const entity = {
233
+ sys: {
234
+ id: '2',
235
+ type: 'Asset',
236
+ version: 1,
237
+ createdAt: '2017-12-07T10:48:41Z',
238
+ createdBy: {
239
+ sys: {
240
+ type: 'Link',
241
+ linkType: 'User',
242
+ id: 'test-5im75v0tq3'
243
+ }
244
+ },
245
+ updatedAt: '2017-12-07T10:48:41Z',
246
+ updatedBy: {
247
+ sys: {
248
+ type: 'Link',
249
+ linkType: 'User',
250
+ id: 'test-5im75v0tq3'
251
+ }
252
+ },
253
+ space: {
254
+ sys: {
255
+ type: 'Link',
256
+ linkType: 'Space',
257
+ id: 'test-xjlsyao0to'
258
+ }
259
+ },
260
+ environment: {
261
+ sys: {
262
+ type: 'Link',
263
+ linkType: 'Environment',
264
+ id: 'test-cyscfldxt8'
265
+ }
266
+ },
267
+ contentType: {
268
+ sys: {
269
+ type: 'Link',
270
+ linkType: 'ContentType',
271
+ id: 'contentful-builtin-asset-content-type'
272
+ }
273
+ },
274
+ fieldStatus: {
275
+ '*': {
276
+ 'en-US': 'changed',
277
+ 'de-DE': 'draft',
278
+ 'es-ES': 'published'
279
+ }
280
+ }
281
+ },
282
+ fields: {
283
+ title: {
284
+ 'en-US': 'Title for id 2'
285
+ },
286
+ description: {
287
+ 'en-US': 'Description for id 2'
288
+ },
289
+ file: {
290
+ 'en-US': {
291
+ fileName: '2.txt',
292
+ contentType: 'text/plain'
293
+ }
294
+ }
295
+ }
296
+ };
297
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useAsyncLocalePublishStatus.useAsyncLocalePublishStatus)(entity, [
298
+ enUS,
299
+ deDE,
300
+ esES
301
+ ]));
302
+ expect(result.current).toEqual(new Map([
303
+ [
304
+ 'en-US',
305
+ {
306
+ status: 'changed',
307
+ locale: enUS
308
+ }
309
+ ],
310
+ [
311
+ 'de-DE',
312
+ {
313
+ status: 'draft',
314
+ locale: deDE
315
+ }
316
+ ],
317
+ [
318
+ 'es-ES',
319
+ {
320
+ status: 'published',
321
+ locale: esES
322
+ }
323
+ ]
324
+ ]));
325
+ });
326
+ it('falls back to the entity status for entries if no fieldStatus is present', ()=>{
327
+ const entity = {
328
+ metadata: {
329
+ tags: []
330
+ },
331
+ sys: {
332
+ id: '1',
333
+ type: 'Entry',
334
+ createdAt: '2017-12-07T10:48:41Z',
335
+ createdBy: {
336
+ sys: {
337
+ type: 'Link',
338
+ linkType: 'User',
339
+ id: 'test-jm5uw542jo'
340
+ }
341
+ },
342
+ updatedAt: '2017-12-07T10:48:41Z',
343
+ updatedBy: {
344
+ sys: {
345
+ type: 'Link',
346
+ linkType: 'User',
347
+ id: 'test-jm5uw542jo'
348
+ }
349
+ },
350
+ space: {
351
+ sys: {
352
+ type: 'Link',
353
+ linkType: 'Space',
354
+ id: 'test-tyjchr7iyp'
355
+ }
356
+ },
357
+ environment: {
358
+ sys: {
359
+ type: 'Link',
360
+ linkType: 'Environment',
361
+ id: 'test-01ovjmre16'
362
+ }
363
+ },
364
+ publishedCounter: 0,
365
+ version: 1,
366
+ contentType: {
367
+ sys: {
368
+ type: 'Link',
369
+ linkType: 'ContentType',
370
+ id: 'content-type'
371
+ }
372
+ },
373
+ automationTags: [],
374
+ publishedVersion: 1
375
+ },
376
+ fields: {}
377
+ };
378
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useAsyncLocalePublishStatus.useAsyncLocalePublishStatus)(entity, [
379
+ enUS,
380
+ deDE,
381
+ esES
382
+ ]));
383
+ expect(result.current).toEqual(new Map([
384
+ [
385
+ 'en-US',
386
+ {
387
+ status: 'published',
388
+ locale: enUS
389
+ }
390
+ ],
391
+ [
392
+ 'de-DE',
393
+ {
394
+ status: 'published',
395
+ locale: deDE
396
+ }
397
+ ],
398
+ [
399
+ 'es-ES',
400
+ {
401
+ status: 'published',
402
+ locale: esES
403
+ }
404
+ ]
405
+ ]));
406
+ });
407
+ it('returns undefined as publishStatus if there is no entity provided', ()=>{
408
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useAsyncLocalePublishStatus.useAsyncLocalePublishStatus)(undefined, [
409
+ enUS,
410
+ deDE,
411
+ esES
412
+ ]));
413
+ expect(result.current).toBeUndefined();
414
+ });
415
+ });
416
+ });
package/dist/cjs/index.js CHANGED
@@ -111,6 +111,7 @@ const _PredefinedValuesError = require("./PredefinedValuesError");
111
111
  const _typesEntity = require("./typesEntity");
112
112
  const _isValidImage = require("./utils/isValidImage");
113
113
  const _shortenStorageUnit = require("./utils/shortenStorageUnit");
114
+ _export_star(require("./hooks/useAsyncLocalePublishStatus"), exports);
114
115
  _export_star(require("./LocalePublishingEntityStatusBadge"), exports);
115
116
  const _ModalDialogLauncher = _interop_require_wildcard(require("./ModalDialogLauncher"));
116
117
  const _constraints = _interop_require_wildcard(require("./utils/constraints"));
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { createFakeFieldAPI } from '@contentful/field-editor-test-utils';
3
- import { render } from '@testing-library/react';
3
+ import { act, render } from '@testing-library/react';
4
4
  import noop from 'lodash/noop';
5
5
  import { FieldConnector } from './FieldConnector';
6
- it('does not rerender with outdated value after calling setValue', ()=>{
6
+ it('does not rerender with outdated value after calling setValue', async ()=>{
7
7
  function getChild() {
8
8
  return props.children.mock.calls[props.children.mock.calls.length - 1][0];
9
9
  }
@@ -25,7 +25,9 @@ it('does not rerender with outdated value after calling setValue', ()=>{
25
25
  let child = getChild();
26
26
  expect(child.value).toBe('initial value');
27
27
  const initialRenderCount = props.children.mock.calls.length;
28
- child.setValue('new value');
28
+ await act(async ()=>{
29
+ child.setValue('new value');
30
+ });
29
31
  onSchemaErrorsChanged.mock.calls.forEach(([cb])=>cb([]));
30
32
  child = getChild();
31
33
  expect(child.value).toBe('new value');
@@ -2,6 +2,12 @@ import React from 'react';
2
2
  import { formatDateAndTime } from '@contentful/f36-components';
3
3
  import { orderBy } from 'lodash';
4
4
  import { Banner } from './Banner';
5
+ var ScheduledActionTypes;
6
+ (function(ScheduledActionTypes) {
7
+ ScheduledActionTypes["publish"] = "publish";
8
+ ScheduledActionTypes["unpublish"] = "unpublish";
9
+ ScheduledActionTypes["patch+publish"] = "patch+publish";
10
+ })(ScheduledActionTypes || (ScheduledActionTypes = {}));
5
11
  export function ScheduledBanner({ entityId, jobs }) {
6
12
  const scheduledJobs = jobs.filter((job)=>job.entity.sys.id === entityId);
7
13
  const sortedScheduledJobs = orderBy(scheduledJobs, [
@@ -15,7 +21,7 @@ export function ScheduledBanner({ entityId, jobs }) {
15
21
  }
16
22
  const pendingJobsCount = scheduledJobs.length - 1;
17
23
  const lowerCaseAction = scheduledAction.action.toLowerCase();
18
- const action = lowerCaseAction === ScheduledActionTypes['patch+publish'] ? `${lowerCaseAction} (via Schedule Series)` : lowerCaseAction;
24
+ const action = lowerCaseAction === "patch+publish" ? `${lowerCaseAction} (via Schedule Series)` : lowerCaseAction;
19
25
  return React.createElement(Banner, {
20
26
  content: `All locales are scheduled to ${action} on:`,
21
27
  highlight: `${formatDateAndTime(scheduledAction.scheduledFor.datetime)}${pendingJobsCount > 0 ? ` [and +${pendingJobsCount} more]` : ''}`
@@ -0,0 +1,30 @@
1
+ import { useMemo } from 'react';
2
+ import * as entityHelpers from '../utils/entityHelpers';
3
+ function getLocalePublishStatusMap(entity, locales) {
4
+ const entityStatus = entityHelpers.getEntityStatus(entity.sys);
5
+ if ([
6
+ 'archived',
7
+ 'deleted'
8
+ ].includes(entityStatus)) {
9
+ return;
10
+ }
11
+ const statusMap = new Map(locales.map((locale)=>[
12
+ locale.code,
13
+ {
14
+ status: entityHelpers.getEntityStatus(entity.sys, locale.code),
15
+ locale
16
+ }
17
+ ]));
18
+ return statusMap;
19
+ }
20
+ export function useAsyncLocalePublishStatus(entity, privateLocales) {
21
+ return useMemo(()=>{
22
+ if (entity && privateLocales) {
23
+ return getLocalePublishStatusMap(entity, privateLocales);
24
+ }
25
+ return undefined;
26
+ }, [
27
+ entity,
28
+ privateLocales
29
+ ]);
30
+ }
@@ -0,0 +1,412 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { useAsyncLocalePublishStatus } from './useAsyncLocalePublishStatus';
3
+ describe('useAsyncLocalePublishStatus', ()=>{
4
+ const enUS = {
5
+ code: 'en-US',
6
+ name: 'en-US',
7
+ internal_code: 'en-US',
8
+ fallbackCode: null,
9
+ default: false,
10
+ contentManagementApi: true,
11
+ contentDeliveryApi: true,
12
+ optional: false,
13
+ sys: {
14
+ type: 'Locale',
15
+ id: 'en-US',
16
+ version: 1,
17
+ space: {
18
+ sys: {
19
+ type: 'Link',
20
+ linkType: 'Space',
21
+ id: 'test-xokbvvklfw'
22
+ }
23
+ },
24
+ environment: {
25
+ sys: {
26
+ type: 'Link',
27
+ linkType: 'Environment',
28
+ id: 'test-ak19mszr76'
29
+ }
30
+ },
31
+ createdBy: {
32
+ sys: {
33
+ type: 'Link',
34
+ linkType: 'User',
35
+ id: 'test-0olok52c12'
36
+ }
37
+ },
38
+ createdAt: '2017-01-23T10:17:55Z',
39
+ updatedBy: {
40
+ sys: {
41
+ type: 'Link',
42
+ linkType: 'User',
43
+ id: 'test-0olok52c12'
44
+ }
45
+ },
46
+ updatedAt: '2017-01-23T10:17:55Z'
47
+ }
48
+ };
49
+ const deDE = {
50
+ code: 'de-DE',
51
+ name: 'de-DE',
52
+ internal_code: 'de-DE',
53
+ fallbackCode: null,
54
+ default: false,
55
+ contentManagementApi: true,
56
+ contentDeliveryApi: true,
57
+ optional: false,
58
+ sys: {
59
+ type: 'Locale',
60
+ id: 'de-DE',
61
+ version: 1,
62
+ space: {
63
+ sys: {
64
+ type: 'Link',
65
+ linkType: 'Space',
66
+ id: 'test-tnw0g6rujf'
67
+ }
68
+ },
69
+ environment: {
70
+ sys: {
71
+ type: 'Link',
72
+ linkType: 'Environment',
73
+ id: 'test-wisyjo6pk4'
74
+ }
75
+ },
76
+ createdBy: {
77
+ sys: {
78
+ type: 'Link',
79
+ linkType: 'User',
80
+ id: 'test-j63uqcmqlx'
81
+ }
82
+ },
83
+ createdAt: '2017-01-23T10:17:55Z',
84
+ updatedBy: {
85
+ sys: {
86
+ type: 'Link',
87
+ linkType: 'User',
88
+ id: 'test-j63uqcmqlx'
89
+ }
90
+ },
91
+ updatedAt: '2017-01-23T10:17:55Z'
92
+ }
93
+ };
94
+ const esES = {
95
+ code: 'es-ES',
96
+ name: 'es-ES',
97
+ internal_code: 'es-ES',
98
+ fallbackCode: null,
99
+ default: false,
100
+ contentManagementApi: true,
101
+ contentDeliveryApi: true,
102
+ optional: false,
103
+ sys: {
104
+ type: 'Locale',
105
+ id: 'es-ES',
106
+ version: 1,
107
+ space: {
108
+ sys: {
109
+ type: 'Link',
110
+ linkType: 'Space',
111
+ id: 'test-h0e5p83kvo'
112
+ }
113
+ },
114
+ environment: {
115
+ sys: {
116
+ type: 'Link',
117
+ linkType: 'Environment',
118
+ id: 'test-extqkvjiub'
119
+ }
120
+ },
121
+ createdBy: {
122
+ sys: {
123
+ type: 'Link',
124
+ linkType: 'User',
125
+ id: 'test-1xpsnz99fa'
126
+ }
127
+ },
128
+ createdAt: '2017-01-23T10:17:55Z',
129
+ updatedBy: {
130
+ sys: {
131
+ type: 'Link',
132
+ linkType: 'User',
133
+ id: 'test-1xpsnz99fa'
134
+ }
135
+ },
136
+ updatedAt: '2017-01-23T10:17:55Z'
137
+ }
138
+ };
139
+ describe('status from entity', ()=>{
140
+ it('returns the status from an entry', ()=>{
141
+ const entity = {
142
+ metadata: {
143
+ tags: []
144
+ },
145
+ sys: {
146
+ id: '1',
147
+ type: 'Entry',
148
+ createdAt: '2017-12-07T10:48:41Z',
149
+ createdBy: {
150
+ sys: {
151
+ type: 'Link',
152
+ linkType: 'User',
153
+ id: 'test-u1dc0g7uzh'
154
+ }
155
+ },
156
+ updatedAt: '2017-12-07T10:48:41Z',
157
+ updatedBy: {
158
+ sys: {
159
+ type: 'Link',
160
+ linkType: 'User',
161
+ id: 'test-u1dc0g7uzh'
162
+ }
163
+ },
164
+ space: {
165
+ sys: {
166
+ type: 'Link',
167
+ linkType: 'Space',
168
+ id: 'test-vllzslv98d'
169
+ }
170
+ },
171
+ environment: {
172
+ sys: {
173
+ type: 'Link',
174
+ linkType: 'Environment',
175
+ id: 'test-y0ftcnn4eq'
176
+ }
177
+ },
178
+ publishedCounter: 0,
179
+ version: 1,
180
+ fieldStatus: {
181
+ '*': {
182
+ 'en-US': 'published',
183
+ 'de-DE': 'changed',
184
+ 'es-ES': 'draft'
185
+ }
186
+ },
187
+ contentType: {
188
+ sys: {
189
+ type: 'Link',
190
+ linkType: 'ContentType',
191
+ id: 'content-type'
192
+ }
193
+ },
194
+ automationTags: []
195
+ },
196
+ fields: {}
197
+ };
198
+ const { result } = renderHook(()=>useAsyncLocalePublishStatus(entity, [
199
+ enUS,
200
+ deDE,
201
+ esES
202
+ ]));
203
+ expect(result.current).toEqual(new Map([
204
+ [
205
+ 'en-US',
206
+ {
207
+ status: 'published',
208
+ locale: enUS
209
+ }
210
+ ],
211
+ [
212
+ 'de-DE',
213
+ {
214
+ status: 'changed',
215
+ locale: deDE
216
+ }
217
+ ],
218
+ [
219
+ 'es-ES',
220
+ {
221
+ status: 'draft',
222
+ locale: esES
223
+ }
224
+ ]
225
+ ]));
226
+ });
227
+ it('returns the status from an asset', ()=>{
228
+ const entity = {
229
+ sys: {
230
+ id: '2',
231
+ type: 'Asset',
232
+ version: 1,
233
+ createdAt: '2017-12-07T10:48:41Z',
234
+ createdBy: {
235
+ sys: {
236
+ type: 'Link',
237
+ linkType: 'User',
238
+ id: 'test-5im75v0tq3'
239
+ }
240
+ },
241
+ updatedAt: '2017-12-07T10:48:41Z',
242
+ updatedBy: {
243
+ sys: {
244
+ type: 'Link',
245
+ linkType: 'User',
246
+ id: 'test-5im75v0tq3'
247
+ }
248
+ },
249
+ space: {
250
+ sys: {
251
+ type: 'Link',
252
+ linkType: 'Space',
253
+ id: 'test-xjlsyao0to'
254
+ }
255
+ },
256
+ environment: {
257
+ sys: {
258
+ type: 'Link',
259
+ linkType: 'Environment',
260
+ id: 'test-cyscfldxt8'
261
+ }
262
+ },
263
+ contentType: {
264
+ sys: {
265
+ type: 'Link',
266
+ linkType: 'ContentType',
267
+ id: 'contentful-builtin-asset-content-type'
268
+ }
269
+ },
270
+ fieldStatus: {
271
+ '*': {
272
+ 'en-US': 'changed',
273
+ 'de-DE': 'draft',
274
+ 'es-ES': 'published'
275
+ }
276
+ }
277
+ },
278
+ fields: {
279
+ title: {
280
+ 'en-US': 'Title for id 2'
281
+ },
282
+ description: {
283
+ 'en-US': 'Description for id 2'
284
+ },
285
+ file: {
286
+ 'en-US': {
287
+ fileName: '2.txt',
288
+ contentType: 'text/plain'
289
+ }
290
+ }
291
+ }
292
+ };
293
+ const { result } = renderHook(()=>useAsyncLocalePublishStatus(entity, [
294
+ enUS,
295
+ deDE,
296
+ esES
297
+ ]));
298
+ expect(result.current).toEqual(new Map([
299
+ [
300
+ 'en-US',
301
+ {
302
+ status: 'changed',
303
+ locale: enUS
304
+ }
305
+ ],
306
+ [
307
+ 'de-DE',
308
+ {
309
+ status: 'draft',
310
+ locale: deDE
311
+ }
312
+ ],
313
+ [
314
+ 'es-ES',
315
+ {
316
+ status: 'published',
317
+ locale: esES
318
+ }
319
+ ]
320
+ ]));
321
+ });
322
+ it('falls back to the entity status for entries if no fieldStatus is present', ()=>{
323
+ const entity = {
324
+ metadata: {
325
+ tags: []
326
+ },
327
+ sys: {
328
+ id: '1',
329
+ type: 'Entry',
330
+ createdAt: '2017-12-07T10:48:41Z',
331
+ createdBy: {
332
+ sys: {
333
+ type: 'Link',
334
+ linkType: 'User',
335
+ id: 'test-jm5uw542jo'
336
+ }
337
+ },
338
+ updatedAt: '2017-12-07T10:48:41Z',
339
+ updatedBy: {
340
+ sys: {
341
+ type: 'Link',
342
+ linkType: 'User',
343
+ id: 'test-jm5uw542jo'
344
+ }
345
+ },
346
+ space: {
347
+ sys: {
348
+ type: 'Link',
349
+ linkType: 'Space',
350
+ id: 'test-tyjchr7iyp'
351
+ }
352
+ },
353
+ environment: {
354
+ sys: {
355
+ type: 'Link',
356
+ linkType: 'Environment',
357
+ id: 'test-01ovjmre16'
358
+ }
359
+ },
360
+ publishedCounter: 0,
361
+ version: 1,
362
+ contentType: {
363
+ sys: {
364
+ type: 'Link',
365
+ linkType: 'ContentType',
366
+ id: 'content-type'
367
+ }
368
+ },
369
+ automationTags: [],
370
+ publishedVersion: 1
371
+ },
372
+ fields: {}
373
+ };
374
+ const { result } = renderHook(()=>useAsyncLocalePublishStatus(entity, [
375
+ enUS,
376
+ deDE,
377
+ esES
378
+ ]));
379
+ expect(result.current).toEqual(new Map([
380
+ [
381
+ 'en-US',
382
+ {
383
+ status: 'published',
384
+ locale: enUS
385
+ }
386
+ ],
387
+ [
388
+ 'de-DE',
389
+ {
390
+ status: 'published',
391
+ locale: deDE
392
+ }
393
+ ],
394
+ [
395
+ 'es-ES',
396
+ {
397
+ status: 'published',
398
+ locale: esES
399
+ }
400
+ ]
401
+ ]));
402
+ });
403
+ it('returns undefined as publishStatus if there is no entity provided', ()=>{
404
+ const { result } = renderHook(()=>useAsyncLocalePublishStatus(undefined, [
405
+ enUS,
406
+ deDE,
407
+ esES
408
+ ]));
409
+ expect(result.current).toBeUndefined();
410
+ });
411
+ });
412
+ });
package/dist/esm/index.js CHANGED
@@ -6,6 +6,7 @@ export { PredefinedValuesError } from './PredefinedValuesError';
6
6
  export { Asset, Entry, File } from './typesEntity';
7
7
  export { isValidImage } from './utils/isValidImage';
8
8
  export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
9
+ export * from './hooks/useAsyncLocalePublishStatus';
9
10
  export { ModalDialogLauncher };
10
11
  export { entityHelpers };
11
12
  export { ConstraintsUtils };
@@ -1,10 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { LocaleProps, EntryProps, AssetProps, ScheduledActionProps } from 'contentful-management';
3
- export type LocalePublishStatus = {
4
- status: 'draft' | 'published' | 'changed';
5
- locale: LocaleProps;
6
- };
7
- export type LocalePublishStatusMap = Map<string, LocalePublishStatus>;
3
+ import { LocalePublishStatusMap } from '../hooks/useAsyncLocalePublishStatus';
8
4
  type LocalePublishingPopoverProps = {
9
5
  entity: EntryProps | AssetProps;
10
6
  jobs: ScheduledActionProps[];
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { LocaleProps } from 'contentful-management';
3
- import type { LocalePublishStatusMap } from './LocalePublishingPopover';
3
+ import type { LocalePublishStatusMap } from '../hooks/useAsyncLocalePublishStatus';
4
4
  type LocalePublishingStatusListProps = {
5
5
  isScheduled: boolean;
6
6
  statusMap: LocalePublishStatusMap;
@@ -0,0 +1,10 @@
1
+ import type { AssetProps, EntryProps, LocaleProps } from 'contentful-management/types';
2
+ export type LocalePublishStatus = {
3
+ status: 'draft' | 'published' | 'changed';
4
+ locale: LocaleProps;
5
+ };
6
+ export type LocalePublishStatusMap = Map<string, LocalePublishStatus>;
7
+ /**
8
+ * Get the publish status for each locale
9
+ */
10
+ export declare function useAsyncLocalePublishStatus(entity?: AssetProps | EntryProps, privateLocales?: LocaleProps[] | null): LocalePublishStatusMap | undefined;
@@ -7,6 +7,7 @@ export { PredefinedValuesError } from './PredefinedValuesError';
7
7
  export { Asset, Entry, File } from './typesEntity';
8
8
  export { isValidImage } from './utils/isValidImage';
9
9
  export { shortenStorageUnit, toLocaleString } from './utils/shortenStorageUnit';
10
+ export * from './hooks/useAsyncLocalePublishStatus';
10
11
  export { ModalDialogLauncher };
11
12
  export { entityHelpers };
12
13
  export { ConstraintsUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -36,7 +36,8 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@contentful/app-sdk": "^4.29.0",
39
- "@contentful/field-editor-test-utils": "^1.5.2"
39
+ "@contentful/field-editor-test-utils": "^1.5.2",
40
+ "@testing-library/react": "16.0.1"
40
41
  },
41
42
  "dependencies": {
42
43
  "@contentful/f36-components": "^4.70.0",
@@ -54,5 +55,5 @@
54
55
  "publishConfig": {
55
56
  "registry": "https://npm.pkg.github.com/"
56
57
  },
57
- "gitHead": "d734036ff89da141dbb91ade0342fb7f82cfe167"
58
+ "gitHead": "afd5e2f336925d0b1eefbf19b716d66abc37f672"
58
59
  }