@contentful/field-editor-shared 1.7.1 → 2.0.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');
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useLocalePublishStatus", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useLocalePublishStatus;
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, localesApi) {
55
+ const entityStatus = _entityHelpers.getEntityStatus(entity.sys);
56
+ if ([
57
+ 'archived',
58
+ 'deleted'
59
+ ].includes(entityStatus)) {
60
+ return;
61
+ }
62
+ const statusMap = new Map(localesApi.available.map((localeCode)=>[
63
+ localeCode,
64
+ {
65
+ status: _entityHelpers.getEntityStatus(entity.sys, localeCode),
66
+ locale: {
67
+ code: localeCode,
68
+ default: localeCode === localesApi.default,
69
+ name: localesApi.names[localeCode]
70
+ }
71
+ }
72
+ ]));
73
+ return statusMap;
74
+ }
75
+ function useLocalePublishStatus(entity, locales) {
76
+ return (0, _react.useMemo)(()=>{
77
+ if (entity && locales) {
78
+ const localesApi = Array.isArray(locales) ? locales.reduce((api, locale)=>{
79
+ api.available.push(locale.code);
80
+ api.names[locale.code] = locale.name;
81
+ if (locale.default) {
82
+ api.default = locale.code;
83
+ }
84
+ return api;
85
+ }, {
86
+ available: [],
87
+ names: {},
88
+ default: ''
89
+ }) : locales;
90
+ return getLocalePublishStatusMap(entity, localesApi);
91
+ }
92
+ return undefined;
93
+ }, [
94
+ entity,
95
+ locales
96
+ ]);
97
+ }
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _reacthooks = require("@testing-library/react-hooks");
6
+ const _useLocalePublishStatus = require("./useLocalePublishStatus");
7
+ describe('useLocalePublishStatus', ()=>{
8
+ const enUS = {
9
+ code: 'en-US',
10
+ default: true,
11
+ name: 'English (US)'
12
+ };
13
+ const deDE = {
14
+ code: 'de-DE',
15
+ default: false,
16
+ name: 'German (Germany)'
17
+ };
18
+ const esES = {
19
+ code: 'es-ES',
20
+ default: false,
21
+ name: 'Spanish (Spain)'
22
+ };
23
+ const localesAPI = {
24
+ available: [
25
+ enUS.code,
26
+ deDE.code,
27
+ esES.code
28
+ ],
29
+ default: enUS.code,
30
+ names: {
31
+ [enUS.code]: enUS.name,
32
+ [deDE.code]: deDE.name,
33
+ [esES.code]: esES.name
34
+ },
35
+ fallbacks: {},
36
+ optional: {
37
+ [enUS.code]: false,
38
+ [deDE.code]: true,
39
+ [esES.code]: true
40
+ },
41
+ direction: {
42
+ [enUS.code]: 'ltr',
43
+ [deDE.code]: 'ltr',
44
+ [esES.code]: 'ltr'
45
+ }
46
+ };
47
+ describe('status from entity', ()=>{
48
+ it('returns the status from an entry', ()=>{
49
+ const entity = {
50
+ metadata: {
51
+ tags: []
52
+ },
53
+ sys: {
54
+ id: '1',
55
+ type: 'Entry',
56
+ createdAt: '2017-12-07T10:48:41Z',
57
+ createdBy: {
58
+ sys: {
59
+ type: 'Link',
60
+ linkType: 'User',
61
+ id: 'test-u1dc0g7uzh'
62
+ }
63
+ },
64
+ updatedAt: '2017-12-07T10:48:41Z',
65
+ updatedBy: {
66
+ sys: {
67
+ type: 'Link',
68
+ linkType: 'User',
69
+ id: 'test-u1dc0g7uzh'
70
+ }
71
+ },
72
+ space: {
73
+ sys: {
74
+ type: 'Link',
75
+ linkType: 'Space',
76
+ id: 'test-vllzslv98d'
77
+ }
78
+ },
79
+ environment: {
80
+ sys: {
81
+ type: 'Link',
82
+ linkType: 'Environment',
83
+ id: 'test-y0ftcnn4eq'
84
+ }
85
+ },
86
+ publishedCounter: 0,
87
+ version: 1,
88
+ fieldStatus: {
89
+ '*': {
90
+ 'en-US': 'published',
91
+ 'de-DE': 'changed',
92
+ 'es-ES': 'draft'
93
+ }
94
+ },
95
+ contentType: {
96
+ sys: {
97
+ type: 'Link',
98
+ linkType: 'ContentType',
99
+ id: 'content-type'
100
+ }
101
+ },
102
+ automationTags: []
103
+ },
104
+ fields: {}
105
+ };
106
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
107
+ expect(result.current).toEqual(new Map([
108
+ [
109
+ 'en-US',
110
+ {
111
+ status: 'published',
112
+ locale: enUS
113
+ }
114
+ ],
115
+ [
116
+ 'de-DE',
117
+ {
118
+ status: 'changed',
119
+ locale: deDE
120
+ }
121
+ ],
122
+ [
123
+ 'es-ES',
124
+ {
125
+ status: 'draft',
126
+ locale: esES
127
+ }
128
+ ]
129
+ ]));
130
+ });
131
+ it('returns the status from an asset', ()=>{
132
+ const entity = {
133
+ sys: {
134
+ id: '2',
135
+ type: 'Asset',
136
+ version: 1,
137
+ createdAt: '2017-12-07T10:48:41Z',
138
+ createdBy: {
139
+ sys: {
140
+ type: 'Link',
141
+ linkType: 'User',
142
+ id: 'test-5im75v0tq3'
143
+ }
144
+ },
145
+ updatedAt: '2017-12-07T10:48:41Z',
146
+ updatedBy: {
147
+ sys: {
148
+ type: 'Link',
149
+ linkType: 'User',
150
+ id: 'test-5im75v0tq3'
151
+ }
152
+ },
153
+ space: {
154
+ sys: {
155
+ type: 'Link',
156
+ linkType: 'Space',
157
+ id: 'test-xjlsyao0to'
158
+ }
159
+ },
160
+ environment: {
161
+ sys: {
162
+ type: 'Link',
163
+ linkType: 'Environment',
164
+ id: 'test-cyscfldxt8'
165
+ }
166
+ },
167
+ contentType: {
168
+ sys: {
169
+ type: 'Link',
170
+ linkType: 'ContentType',
171
+ id: 'contentful-builtin-asset-content-type'
172
+ }
173
+ },
174
+ fieldStatus: {
175
+ '*': {
176
+ 'en-US': 'changed',
177
+ 'de-DE': 'draft',
178
+ 'es-ES': 'published'
179
+ }
180
+ }
181
+ },
182
+ fields: {
183
+ title: {
184
+ 'en-US': 'Title for id 2'
185
+ },
186
+ description: {
187
+ 'en-US': 'Description for id 2'
188
+ },
189
+ file: {
190
+ 'en-US': {
191
+ fileName: '2.txt',
192
+ contentType: 'text/plain'
193
+ }
194
+ }
195
+ }
196
+ };
197
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
198
+ expect(result.current).toEqual(new Map([
199
+ [
200
+ 'en-US',
201
+ {
202
+ status: 'changed',
203
+ locale: enUS
204
+ }
205
+ ],
206
+ [
207
+ 'de-DE',
208
+ {
209
+ status: 'draft',
210
+ locale: deDE
211
+ }
212
+ ],
213
+ [
214
+ 'es-ES',
215
+ {
216
+ status: 'published',
217
+ locale: esES
218
+ }
219
+ ]
220
+ ]));
221
+ });
222
+ it('falls back to the entity status for entries if no fieldStatus is present', ()=>{
223
+ const entity = {
224
+ metadata: {
225
+ tags: []
226
+ },
227
+ sys: {
228
+ id: '1',
229
+ type: 'Entry',
230
+ createdAt: '2017-12-07T10:48:41Z',
231
+ createdBy: {
232
+ sys: {
233
+ type: 'Link',
234
+ linkType: 'User',
235
+ id: 'test-jm5uw542jo'
236
+ }
237
+ },
238
+ updatedAt: '2017-12-07T10:48:41Z',
239
+ updatedBy: {
240
+ sys: {
241
+ type: 'Link',
242
+ linkType: 'User',
243
+ id: 'test-jm5uw542jo'
244
+ }
245
+ },
246
+ space: {
247
+ sys: {
248
+ type: 'Link',
249
+ linkType: 'Space',
250
+ id: 'test-tyjchr7iyp'
251
+ }
252
+ },
253
+ environment: {
254
+ sys: {
255
+ type: 'Link',
256
+ linkType: 'Environment',
257
+ id: 'test-01ovjmre16'
258
+ }
259
+ },
260
+ publishedCounter: 0,
261
+ version: 1,
262
+ contentType: {
263
+ sys: {
264
+ type: 'Link',
265
+ linkType: 'ContentType',
266
+ id: 'content-type'
267
+ }
268
+ },
269
+ automationTags: [],
270
+ publishedVersion: 1
271
+ },
272
+ fields: {}
273
+ };
274
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
275
+ expect(result.current).toEqual(new Map([
276
+ [
277
+ 'en-US',
278
+ {
279
+ status: 'published',
280
+ locale: enUS
281
+ }
282
+ ],
283
+ [
284
+ 'de-DE',
285
+ {
286
+ status: 'published',
287
+ locale: deDE
288
+ }
289
+ ],
290
+ [
291
+ 'es-ES',
292
+ {
293
+ status: 'published',
294
+ locale: esES
295
+ }
296
+ ]
297
+ ]));
298
+ });
299
+ it('returns undefined as publishStatus if there is no entity provided', ()=>{
300
+ const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(undefined, localesAPI));
301
+ expect(result.current).toBeUndefined();
302
+ });
303
+ });
304
+ });
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/useLocalePublishStatus"), 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');
@@ -0,0 +1,46 @@
1
+ import { useMemo } from 'react';
2
+ import * as entityHelpers from '../utils/entityHelpers';
3
+ function getLocalePublishStatusMap(entity, localesApi) {
4
+ const entityStatus = entityHelpers.getEntityStatus(entity.sys);
5
+ if ([
6
+ 'archived',
7
+ 'deleted'
8
+ ].includes(entityStatus)) {
9
+ return;
10
+ }
11
+ const statusMap = new Map(localesApi.available.map((localeCode)=>[
12
+ localeCode,
13
+ {
14
+ status: entityHelpers.getEntityStatus(entity.sys, localeCode),
15
+ locale: {
16
+ code: localeCode,
17
+ default: localeCode === localesApi.default,
18
+ name: localesApi.names[localeCode]
19
+ }
20
+ }
21
+ ]));
22
+ return statusMap;
23
+ }
24
+ export function useLocalePublishStatus(entity, locales) {
25
+ return useMemo(()=>{
26
+ if (entity && locales) {
27
+ const localesApi = Array.isArray(locales) ? locales.reduce((api, locale)=>{
28
+ api.available.push(locale.code);
29
+ api.names[locale.code] = locale.name;
30
+ if (locale.default) {
31
+ api.default = locale.code;
32
+ }
33
+ return api;
34
+ }, {
35
+ available: [],
36
+ names: {},
37
+ default: ''
38
+ }) : locales;
39
+ return getLocalePublishStatusMap(entity, localesApi);
40
+ }
41
+ return undefined;
42
+ }, [
43
+ entity,
44
+ locales
45
+ ]);
46
+ }
@@ -0,0 +1,300 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { useLocalePublishStatus } from './useLocalePublishStatus';
3
+ describe('useLocalePublishStatus', ()=>{
4
+ const enUS = {
5
+ code: 'en-US',
6
+ default: true,
7
+ name: 'English (US)'
8
+ };
9
+ const deDE = {
10
+ code: 'de-DE',
11
+ default: false,
12
+ name: 'German (Germany)'
13
+ };
14
+ const esES = {
15
+ code: 'es-ES',
16
+ default: false,
17
+ name: 'Spanish (Spain)'
18
+ };
19
+ const localesAPI = {
20
+ available: [
21
+ enUS.code,
22
+ deDE.code,
23
+ esES.code
24
+ ],
25
+ default: enUS.code,
26
+ names: {
27
+ [enUS.code]: enUS.name,
28
+ [deDE.code]: deDE.name,
29
+ [esES.code]: esES.name
30
+ },
31
+ fallbacks: {},
32
+ optional: {
33
+ [enUS.code]: false,
34
+ [deDE.code]: true,
35
+ [esES.code]: true
36
+ },
37
+ direction: {
38
+ [enUS.code]: 'ltr',
39
+ [deDE.code]: 'ltr',
40
+ [esES.code]: 'ltr'
41
+ }
42
+ };
43
+ describe('status from entity', ()=>{
44
+ it('returns the status from an entry', ()=>{
45
+ const entity = {
46
+ metadata: {
47
+ tags: []
48
+ },
49
+ sys: {
50
+ id: '1',
51
+ type: 'Entry',
52
+ createdAt: '2017-12-07T10:48:41Z',
53
+ createdBy: {
54
+ sys: {
55
+ type: 'Link',
56
+ linkType: 'User',
57
+ id: 'test-u1dc0g7uzh'
58
+ }
59
+ },
60
+ updatedAt: '2017-12-07T10:48:41Z',
61
+ updatedBy: {
62
+ sys: {
63
+ type: 'Link',
64
+ linkType: 'User',
65
+ id: 'test-u1dc0g7uzh'
66
+ }
67
+ },
68
+ space: {
69
+ sys: {
70
+ type: 'Link',
71
+ linkType: 'Space',
72
+ id: 'test-vllzslv98d'
73
+ }
74
+ },
75
+ environment: {
76
+ sys: {
77
+ type: 'Link',
78
+ linkType: 'Environment',
79
+ id: 'test-y0ftcnn4eq'
80
+ }
81
+ },
82
+ publishedCounter: 0,
83
+ version: 1,
84
+ fieldStatus: {
85
+ '*': {
86
+ 'en-US': 'published',
87
+ 'de-DE': 'changed',
88
+ 'es-ES': 'draft'
89
+ }
90
+ },
91
+ contentType: {
92
+ sys: {
93
+ type: 'Link',
94
+ linkType: 'ContentType',
95
+ id: 'content-type'
96
+ }
97
+ },
98
+ automationTags: []
99
+ },
100
+ fields: {}
101
+ };
102
+ const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
103
+ expect(result.current).toEqual(new Map([
104
+ [
105
+ 'en-US',
106
+ {
107
+ status: 'published',
108
+ locale: enUS
109
+ }
110
+ ],
111
+ [
112
+ 'de-DE',
113
+ {
114
+ status: 'changed',
115
+ locale: deDE
116
+ }
117
+ ],
118
+ [
119
+ 'es-ES',
120
+ {
121
+ status: 'draft',
122
+ locale: esES
123
+ }
124
+ ]
125
+ ]));
126
+ });
127
+ it('returns the status from an asset', ()=>{
128
+ const entity = {
129
+ sys: {
130
+ id: '2',
131
+ type: 'Asset',
132
+ version: 1,
133
+ createdAt: '2017-12-07T10:48:41Z',
134
+ createdBy: {
135
+ sys: {
136
+ type: 'Link',
137
+ linkType: 'User',
138
+ id: 'test-5im75v0tq3'
139
+ }
140
+ },
141
+ updatedAt: '2017-12-07T10:48:41Z',
142
+ updatedBy: {
143
+ sys: {
144
+ type: 'Link',
145
+ linkType: 'User',
146
+ id: 'test-5im75v0tq3'
147
+ }
148
+ },
149
+ space: {
150
+ sys: {
151
+ type: 'Link',
152
+ linkType: 'Space',
153
+ id: 'test-xjlsyao0to'
154
+ }
155
+ },
156
+ environment: {
157
+ sys: {
158
+ type: 'Link',
159
+ linkType: 'Environment',
160
+ id: 'test-cyscfldxt8'
161
+ }
162
+ },
163
+ contentType: {
164
+ sys: {
165
+ type: 'Link',
166
+ linkType: 'ContentType',
167
+ id: 'contentful-builtin-asset-content-type'
168
+ }
169
+ },
170
+ fieldStatus: {
171
+ '*': {
172
+ 'en-US': 'changed',
173
+ 'de-DE': 'draft',
174
+ 'es-ES': 'published'
175
+ }
176
+ }
177
+ },
178
+ fields: {
179
+ title: {
180
+ 'en-US': 'Title for id 2'
181
+ },
182
+ description: {
183
+ 'en-US': 'Description for id 2'
184
+ },
185
+ file: {
186
+ 'en-US': {
187
+ fileName: '2.txt',
188
+ contentType: 'text/plain'
189
+ }
190
+ }
191
+ }
192
+ };
193
+ const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
194
+ expect(result.current).toEqual(new Map([
195
+ [
196
+ 'en-US',
197
+ {
198
+ status: 'changed',
199
+ locale: enUS
200
+ }
201
+ ],
202
+ [
203
+ 'de-DE',
204
+ {
205
+ status: 'draft',
206
+ locale: deDE
207
+ }
208
+ ],
209
+ [
210
+ 'es-ES',
211
+ {
212
+ status: 'published',
213
+ locale: esES
214
+ }
215
+ ]
216
+ ]));
217
+ });
218
+ it('falls back to the entity status for entries if no fieldStatus is present', ()=>{
219
+ const entity = {
220
+ metadata: {
221
+ tags: []
222
+ },
223
+ sys: {
224
+ id: '1',
225
+ type: 'Entry',
226
+ createdAt: '2017-12-07T10:48:41Z',
227
+ createdBy: {
228
+ sys: {
229
+ type: 'Link',
230
+ linkType: 'User',
231
+ id: 'test-jm5uw542jo'
232
+ }
233
+ },
234
+ updatedAt: '2017-12-07T10:48:41Z',
235
+ updatedBy: {
236
+ sys: {
237
+ type: 'Link',
238
+ linkType: 'User',
239
+ id: 'test-jm5uw542jo'
240
+ }
241
+ },
242
+ space: {
243
+ sys: {
244
+ type: 'Link',
245
+ linkType: 'Space',
246
+ id: 'test-tyjchr7iyp'
247
+ }
248
+ },
249
+ environment: {
250
+ sys: {
251
+ type: 'Link',
252
+ linkType: 'Environment',
253
+ id: 'test-01ovjmre16'
254
+ }
255
+ },
256
+ publishedCounter: 0,
257
+ version: 1,
258
+ contentType: {
259
+ sys: {
260
+ type: 'Link',
261
+ linkType: 'ContentType',
262
+ id: 'content-type'
263
+ }
264
+ },
265
+ automationTags: [],
266
+ publishedVersion: 1
267
+ },
268
+ fields: {}
269
+ };
270
+ const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
271
+ expect(result.current).toEqual(new Map([
272
+ [
273
+ 'en-US',
274
+ {
275
+ status: 'published',
276
+ locale: enUS
277
+ }
278
+ ],
279
+ [
280
+ 'de-DE',
281
+ {
282
+ status: 'published',
283
+ locale: deDE
284
+ }
285
+ ],
286
+ [
287
+ 'es-ES',
288
+ {
289
+ status: 'published',
290
+ locale: esES
291
+ }
292
+ ]
293
+ ]));
294
+ });
295
+ it('returns undefined as publishStatus if there is no entity provided', ()=>{
296
+ const { result } = renderHook(()=>useLocalePublishStatus(undefined, localesAPI));
297
+ expect(result.current).toBeUndefined();
298
+ });
299
+ });
300
+ });
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/useLocalePublishStatus';
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/useLocalePublishStatus';
8
4
  type LocalePublishingPopoverProps = {
9
5
  entity: EntryProps | AssetProps;
10
6
  jobs: ScheduledActionProps[];
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { LocaleProps } from 'contentful-management';
3
3
  type LocalePublishingStatusProps = {
4
- locale: LocaleProps;
4
+ locale: Pick<LocaleProps, 'code' | 'default' | 'name'>;
5
5
  status: 'draft' | 'published' | 'changed';
6
6
  isScheduled: boolean;
7
7
  };
@@ -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/useLocalePublishStatus';
4
4
  type LocalePublishingStatusListProps = {
5
5
  isScheduled: boolean;
6
6
  statusMap: LocalePublishStatusMap;
@@ -0,0 +1,11 @@
1
+ import type { LocalesAPI } from '@contentful/app-sdk';
2
+ import type { AssetProps, EntryProps, LocaleProps } from 'contentful-management/types';
3
+ export type LocalePublishStatus = {
4
+ status: 'draft' | 'published' | 'changed';
5
+ locale: Pick<LocaleProps, 'code' | 'default' | 'name'>;
6
+ };
7
+ export type LocalePublishStatusMap = Map<string, LocalePublishStatus>;
8
+ /**
9
+ * Get the publish status for each locale
10
+ */
11
+ export declare function useLocalePublishStatus(entity?: AssetProps | EntryProps, locales?: Pick<LocalesAPI, 'available' | 'default' | 'names'> | LocaleProps[] | null): LocalePublishStatusMap | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -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/useLocalePublishStatus';
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.1",
3
+ "version": "2.0.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": "4f029f8d8ad0d8b8e270db4619fa1e8fb278a509"
58
+ "gitHead": "a06fd0066556b1f5ab6649ade3a75441e4792fd3"
58
59
  }