@contentful/field-editor-shared 1.8.0 → 2.1.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/hooks/{useAsyncLocalePublishStatus.js → useLocalePublishStatus.js} +27 -11
- package/dist/cjs/hooks/{useAsyncLocalePublishStatus.spec.js → useLocalePublishStatus.spec.js} +33 -145
- package/dist/cjs/index.js +1 -1
- package/dist/esm/hooks/useLocalePublishStatus.js +46 -0
- package/dist/esm/hooks/{useAsyncLocalePublishStatus.spec.js → useLocalePublishStatus.spec.js} +33 -145
- package/dist/esm/index.js +1 -1
- package/dist/types/LocalePublishingEntityStatusBadge/LocalePublishingPopover.d.ts +2 -2
- package/dist/types/LocalePublishingEntityStatusBadge/LocalePublishingStatus.d.ts +1 -1
- package/dist/types/LocalePublishingEntityStatusBadge/LocalePublishingStatusList.d.ts +2 -2
- package/dist/types/hooks/useLocalePublishStatus.d.ts +11 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/esm/hooks/useAsyncLocalePublishStatus.js +0 -30
- package/dist/types/hooks/useAsyncLocalePublishStatus.d.ts +0 -10
- /package/dist/types/hooks/{useAsyncLocalePublishStatus.spec.d.ts → useLocalePublishStatus.spec.d.ts} +0 -0
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "useLocalePublishStatus", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return useLocalePublishStatus;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = require("react");
|
|
@@ -51,7 +51,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
51
51
|
}
|
|
52
52
|
return newObj;
|
|
53
53
|
}
|
|
54
|
-
function getLocalePublishStatusMap(entity,
|
|
54
|
+
function getLocalePublishStatusMap(entity, localesApi) {
|
|
55
55
|
const entityStatus = _entityHelpers.getEntityStatus(entity.sys);
|
|
56
56
|
if ([
|
|
57
57
|
'archived',
|
|
@@ -59,23 +59,39 @@ function getLocalePublishStatusMap(entity, locales) {
|
|
|
59
59
|
].includes(entityStatus)) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const statusMap = new Map(
|
|
63
|
-
|
|
62
|
+
const statusMap = new Map(localesApi.available.map((localeCode)=>[
|
|
63
|
+
localeCode,
|
|
64
64
|
{
|
|
65
|
-
status: _entityHelpers.getEntityStatus(entity.sys,
|
|
66
|
-
locale
|
|
65
|
+
status: _entityHelpers.getEntityStatus(entity.sys, localeCode),
|
|
66
|
+
locale: {
|
|
67
|
+
code: localeCode,
|
|
68
|
+
default: localeCode === localesApi.default,
|
|
69
|
+
name: localesApi.names[localeCode]
|
|
70
|
+
}
|
|
67
71
|
}
|
|
68
72
|
]));
|
|
69
73
|
return statusMap;
|
|
70
74
|
}
|
|
71
|
-
function
|
|
75
|
+
function useLocalePublishStatus(entity, locales) {
|
|
72
76
|
return (0, _react.useMemo)(()=>{
|
|
73
|
-
if (entity &&
|
|
74
|
-
|
|
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);
|
|
75
91
|
}
|
|
76
92
|
return undefined;
|
|
77
93
|
}, [
|
|
78
94
|
entity,
|
|
79
|
-
|
|
95
|
+
locales
|
|
80
96
|
]);
|
|
81
97
|
}
|
package/dist/cjs/hooks/{useAsyncLocalePublishStatus.spec.js → useLocalePublishStatus.spec.js}
RENAMED
|
@@ -3,141 +3,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
const _reacthooks = require("@testing-library/react-hooks");
|
|
6
|
-
const
|
|
7
|
-
describe('
|
|
6
|
+
const _useLocalePublishStatus = require("./useLocalePublishStatus");
|
|
7
|
+
describe('useLocalePublishStatus', ()=>{
|
|
8
8
|
const enUS = {
|
|
9
9
|
code: 'en-US',
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
10
|
+
default: true,
|
|
11
|
+
name: 'English (US)'
|
|
52
12
|
};
|
|
53
13
|
const deDE = {
|
|
54
14
|
code: 'de-DE',
|
|
55
|
-
name: 'de-DE',
|
|
56
|
-
internal_code: 'de-DE',
|
|
57
|
-
fallbackCode: null,
|
|
58
15
|
default: false,
|
|
59
|
-
|
|
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
|
-
}
|
|
16
|
+
name: 'German (Germany)'
|
|
97
17
|
};
|
|
98
18
|
const esES = {
|
|
99
19
|
code: 'es-ES',
|
|
100
|
-
name: 'es-ES',
|
|
101
|
-
internal_code: 'es-ES',
|
|
102
|
-
fallbackCode: null,
|
|
103
20
|
default: false,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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'
|
|
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'
|
|
141
45
|
}
|
|
142
46
|
};
|
|
143
47
|
describe('status from entity', ()=>{
|
|
@@ -199,11 +103,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
199
103
|
},
|
|
200
104
|
fields: {}
|
|
201
105
|
};
|
|
202
|
-
const { result } = (0, _reacthooks.renderHook)(()=>(0,
|
|
203
|
-
enUS,
|
|
204
|
-
deDE,
|
|
205
|
-
esES
|
|
206
|
-
]));
|
|
106
|
+
const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
|
|
207
107
|
expect(result.current).toEqual(new Map([
|
|
208
108
|
[
|
|
209
109
|
'en-US',
|
|
@@ -294,11 +194,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
294
194
|
}
|
|
295
195
|
}
|
|
296
196
|
};
|
|
297
|
-
const { result } = (0, _reacthooks.renderHook)(()=>(0,
|
|
298
|
-
enUS,
|
|
299
|
-
deDE,
|
|
300
|
-
esES
|
|
301
|
-
]));
|
|
197
|
+
const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
|
|
302
198
|
expect(result.current).toEqual(new Map([
|
|
303
199
|
[
|
|
304
200
|
'en-US',
|
|
@@ -375,11 +271,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
375
271
|
},
|
|
376
272
|
fields: {}
|
|
377
273
|
};
|
|
378
|
-
const { result } = (0, _reacthooks.renderHook)(()=>(0,
|
|
379
|
-
enUS,
|
|
380
|
-
deDE,
|
|
381
|
-
esES
|
|
382
|
-
]));
|
|
274
|
+
const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(entity, localesAPI));
|
|
383
275
|
expect(result.current).toEqual(new Map([
|
|
384
276
|
[
|
|
385
277
|
'en-US',
|
|
@@ -405,11 +297,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
405
297
|
]));
|
|
406
298
|
});
|
|
407
299
|
it('returns undefined as publishStatus if there is no entity provided', ()=>{
|
|
408
|
-
const { result } = (0, _reacthooks.renderHook)(()=>(0,
|
|
409
|
-
enUS,
|
|
410
|
-
deDE,
|
|
411
|
-
esES
|
|
412
|
-
]));
|
|
300
|
+
const { result } = (0, _reacthooks.renderHook)(()=>(0, _useLocalePublishStatus.useLocalePublishStatus)(undefined, localesAPI));
|
|
413
301
|
expect(result.current).toBeUndefined();
|
|
414
302
|
});
|
|
415
303
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -111,7 +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/
|
|
114
|
+
_export_star(require("./hooks/useLocalePublishStatus"), exports);
|
|
115
115
|
_export_star(require("./LocalePublishingEntityStatusBadge"), exports);
|
|
116
116
|
const _ModalDialogLauncher = _interop_require_wildcard(require("./ModalDialogLauncher"));
|
|
117
117
|
const _constraints = _interop_require_wildcard(require("./utils/constraints"));
|
|
@@ -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
|
+
}
|
package/dist/esm/hooks/{useAsyncLocalePublishStatus.spec.js → useLocalePublishStatus.spec.js}
RENAMED
|
@@ -1,139 +1,43 @@
|
|
|
1
1
|
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
-
import {
|
|
3
|
-
describe('
|
|
2
|
+
import { useLocalePublishStatus } from './useLocalePublishStatus';
|
|
3
|
+
describe('useLocalePublishStatus', ()=>{
|
|
4
4
|
const enUS = {
|
|
5
5
|
code: 'en-US',
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}
|
|
6
|
+
default: true,
|
|
7
|
+
name: 'English (US)'
|
|
48
8
|
};
|
|
49
9
|
const deDE = {
|
|
50
10
|
code: 'de-DE',
|
|
51
|
-
name: 'de-DE',
|
|
52
|
-
internal_code: 'de-DE',
|
|
53
|
-
fallbackCode: null,
|
|
54
11
|
default: false,
|
|
55
|
-
|
|
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
|
-
}
|
|
12
|
+
name: 'German (Germany)'
|
|
93
13
|
};
|
|
94
14
|
const esES = {
|
|
95
15
|
code: 'es-ES',
|
|
96
|
-
name: 'es-ES',
|
|
97
|
-
internal_code: 'es-ES',
|
|
98
|
-
fallbackCode: null,
|
|
99
16
|
default: false,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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'
|
|
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'
|
|
137
41
|
}
|
|
138
42
|
};
|
|
139
43
|
describe('status from entity', ()=>{
|
|
@@ -195,11 +99,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
195
99
|
},
|
|
196
100
|
fields: {}
|
|
197
101
|
};
|
|
198
|
-
const { result } = renderHook(()=>
|
|
199
|
-
enUS,
|
|
200
|
-
deDE,
|
|
201
|
-
esES
|
|
202
|
-
]));
|
|
102
|
+
const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
|
|
203
103
|
expect(result.current).toEqual(new Map([
|
|
204
104
|
[
|
|
205
105
|
'en-US',
|
|
@@ -290,11 +190,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
290
190
|
}
|
|
291
191
|
}
|
|
292
192
|
};
|
|
293
|
-
const { result } = renderHook(()=>
|
|
294
|
-
enUS,
|
|
295
|
-
deDE,
|
|
296
|
-
esES
|
|
297
|
-
]));
|
|
193
|
+
const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
|
|
298
194
|
expect(result.current).toEqual(new Map([
|
|
299
195
|
[
|
|
300
196
|
'en-US',
|
|
@@ -371,11 +267,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
371
267
|
},
|
|
372
268
|
fields: {}
|
|
373
269
|
};
|
|
374
|
-
const { result } = renderHook(()=>
|
|
375
|
-
enUS,
|
|
376
|
-
deDE,
|
|
377
|
-
esES
|
|
378
|
-
]));
|
|
270
|
+
const { result } = renderHook(()=>useLocalePublishStatus(entity, localesAPI));
|
|
379
271
|
expect(result.current).toEqual(new Map([
|
|
380
272
|
[
|
|
381
273
|
'en-US',
|
|
@@ -401,11 +293,7 @@ describe('useAsyncLocalePublishStatus', ()=>{
|
|
|
401
293
|
]));
|
|
402
294
|
});
|
|
403
295
|
it('returns undefined as publishStatus if there is no entity provided', ()=>{
|
|
404
|
-
const { result } = renderHook(()=>
|
|
405
|
-
enUS,
|
|
406
|
-
deDE,
|
|
407
|
-
esES
|
|
408
|
-
]));
|
|
296
|
+
const { result } = renderHook(()=>useLocalePublishStatus(undefined, localesAPI));
|
|
409
297
|
expect(result.current).toBeUndefined();
|
|
410
298
|
});
|
|
411
299
|
});
|
package/dist/esm/index.js
CHANGED
|
@@ -6,7 +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/
|
|
9
|
+
export * from './hooks/useLocalePublishStatus';
|
|
10
10
|
export { ModalDialogLauncher };
|
|
11
11
|
export { entityHelpers };
|
|
12
12
|
export { ConstraintsUtils };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { LocaleProps, EntryProps, AssetProps, ScheduledActionProps } from 'contentful-management';
|
|
3
|
-
import { LocalePublishStatusMap } from '../hooks/
|
|
3
|
+
import { LocalePublishStatusMap } from '../hooks/useLocalePublishStatus';
|
|
4
4
|
type LocalePublishingPopoverProps = {
|
|
5
5
|
entity: EntryProps | AssetProps;
|
|
6
6
|
jobs: ScheduledActionProps[];
|
|
7
7
|
isScheduled: boolean;
|
|
8
|
-
activeLocales
|
|
8
|
+
activeLocales?: Pick<LocaleProps, 'code'>[];
|
|
9
9
|
localesStatusMap?: LocalePublishStatusMap;
|
|
10
10
|
};
|
|
11
11
|
export declare function LocalePublishingPopover({ entity, jobs, isScheduled, localesStatusMap, activeLocales, }: LocalePublishingPopoverProps): React.JSX.Element;
|
|
@@ -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,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { LocaleProps } from 'contentful-management';
|
|
3
|
-
import type { LocalePublishStatusMap } from '../hooks/
|
|
3
|
+
import type { LocalePublishStatusMap } from '../hooks/useLocalePublishStatus';
|
|
4
4
|
type LocalePublishingStatusListProps = {
|
|
5
5
|
isScheduled: boolean;
|
|
6
6
|
statusMap: LocalePublishStatusMap;
|
|
7
|
-
activeLocales
|
|
7
|
+
activeLocales?: Pick<LocaleProps, 'code'>[];
|
|
8
8
|
};
|
|
9
9
|
export declare function LocalePublishingStatusList({ isScheduled, statusMap, activeLocales, }: LocalePublishingStatusListProps): React.JSX.Element;
|
|
10
10
|
export {};
|
|
@@ -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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,7 +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/
|
|
10
|
+
export * from './hooks/useLocalePublishStatus';
|
|
11
11
|
export { ModalDialogLauncher };
|
|
12
12
|
export { entityHelpers };
|
|
13
13
|
export { ConstraintsUtils };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.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": "7eb324a42380b43ee842dfb521f7bc7db0d2eba4"
|
|
59
59
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
/package/dist/types/hooks/{useAsyncLocalePublishStatus.spec.d.ts → useLocalePublishStatus.spec.d.ts}
RENAMED
|
File without changes
|