@contentful/field-editor-reference 6.4.4 → 6.5.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/__fixtures__/fixtures.js +4 -2
- package/dist/cjs/common/EntityStore.js +16 -6
- package/dist/cjs/resources/Cards/ResourceCard.js +2 -1
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +2 -1
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +1 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +2 -1
- package/dist/cjs/resources/useResourceLinkActions.js +5 -2
- package/dist/esm/__fixtures__/fixtures.js +5 -3
- package/dist/esm/common/EntityStore.js +16 -6
- package/dist/esm/resources/Cards/ResourceCard.js +2 -1
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +2 -1
- package/dist/esm/resources/SingleResourceReferenceEditor.js +1 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +2 -1
- package/dist/esm/resources/useResourceLinkActions.js +5 -2
- package/dist/types/__fixtures__/fixtures.d.ts +4 -3
- package/dist/types/common/EntityStore.d.ts +3 -1
- package/dist/types/resources/Cards/ResourceCard.d.ts +1 -0
- package/package.json +4 -4
|
@@ -10,13 +10,13 @@ function _export(target, all) {
|
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
12
|
assets: function() {
|
|
13
|
-
return
|
|
13
|
+
return assets;
|
|
14
14
|
},
|
|
15
15
|
contentTypes: function() {
|
|
16
16
|
return _contenttype;
|
|
17
17
|
},
|
|
18
18
|
entries: function() {
|
|
19
|
-
return
|
|
19
|
+
return entries;
|
|
20
20
|
},
|
|
21
21
|
locales: function() {
|
|
22
22
|
return _locale;
|
|
@@ -71,3 +71,5 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
71
71
|
}
|
|
72
72
|
return newObj;
|
|
73
73
|
}
|
|
74
|
+
const assets = _asset;
|
|
75
|
+
const entries = _entry;
|
|
@@ -217,7 +217,7 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
|
|
|
217
217
|
contentType: contentType
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
-
async function fetchExternalResource({ urn, fetch, options, spaceId, environmentId, resourceType }) {
|
|
220
|
+
async function fetchExternalResource({ urn, fetch, options, spaceId, environmentId, resourceType, locale }) {
|
|
221
221
|
let resourceFetchError;
|
|
222
222
|
const [resource, resourceTypes] = await Promise.all([
|
|
223
223
|
fetch([
|
|
@@ -231,7 +231,8 @@ async function fetchExternalResource({ urn, fetch, options, spaceId, environment
|
|
|
231
231
|
environmentId,
|
|
232
232
|
resourceTypeId: resourceType,
|
|
233
233
|
query: {
|
|
234
|
-
'sys.urn[in]': urn
|
|
234
|
+
'sys.urn[in]': urn,
|
|
235
|
+
locale
|
|
235
236
|
}
|
|
236
237
|
}).then(({ items })=>{
|
|
237
238
|
return items[0] ?? null;
|
|
@@ -370,7 +371,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
370
371
|
const queryKey = [
|
|
371
372
|
'Resource',
|
|
372
373
|
resourceType,
|
|
373
|
-
urn
|
|
374
|
+
urn,
|
|
375
|
+
options?.locale
|
|
374
376
|
];
|
|
375
377
|
return fetch(queryKey, ()=>{
|
|
376
378
|
if (resourceType === 'Contentful:Entry') {
|
|
@@ -386,6 +388,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = (0,
|
|
|
386
388
|
return fetchExternalResource({
|
|
387
389
|
fetch,
|
|
388
390
|
urn,
|
|
391
|
+
locale: options?.locale,
|
|
389
392
|
options,
|
|
390
393
|
resourceType,
|
|
391
394
|
spaceId: currentSpaceId,
|
|
@@ -509,14 +512,21 @@ function useEntity(entityType, entityId, options) {
|
|
|
509
512
|
data
|
|
510
513
|
};
|
|
511
514
|
}
|
|
512
|
-
function useResource(resourceType, urn, options) {
|
|
515
|
+
function useResource(resourceType, urn, { locale, ...options } = {}) {
|
|
516
|
+
if (resourceType.startsWith('Contentful:')) {
|
|
517
|
+
locale = undefined;
|
|
518
|
+
}
|
|
513
519
|
const queryKey = [
|
|
514
520
|
'Resource',
|
|
515
521
|
resourceType,
|
|
516
|
-
urn
|
|
522
|
+
urn,
|
|
523
|
+
locale
|
|
517
524
|
];
|
|
518
525
|
const { getResource } = useEntityLoader();
|
|
519
|
-
const { status, data, error } = (0, _queryClient.useQuery)(queryKey, ()=>getResource(resourceType, urn,
|
|
526
|
+
const { status, data, error } = (0, _queryClient.useQuery)(queryKey, ()=>getResource(resourceType, urn, {
|
|
527
|
+
...options,
|
|
528
|
+
locale
|
|
529
|
+
}), {
|
|
520
530
|
enabled: options?.enabled
|
|
521
531
|
});
|
|
522
532
|
return {
|
|
@@ -63,8 +63,9 @@ function ResourceCardSkeleton() {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
function ExistingResourceCard(props) {
|
|
66
|
-
const { resourceLink, inView, index = 0 } = props;
|
|
66
|
+
const { resourceLink, inView, index = 0, locale } = props;
|
|
67
67
|
const resourceOptions = {
|
|
68
|
+
locale,
|
|
68
69
|
priority: index * -1,
|
|
69
70
|
enabled: inView,
|
|
70
71
|
allowExternal: true
|
|
@@ -117,7 +117,8 @@ describe('Multiple resource editor', ()=>{
|
|
|
117
117
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
118
118
|
const options = dialogFn.mock.calls[0][0];
|
|
119
119
|
expect(options).toEqual({
|
|
120
|
-
allowedResources: fieldDefinition.allowedResources
|
|
120
|
+
allowedResources: fieldDefinition.allowedResources,
|
|
121
|
+
locale: 'en'
|
|
121
122
|
});
|
|
122
123
|
});
|
|
123
124
|
it('hides the action button when insufficient permissions', async ()=>{
|
|
@@ -70,6 +70,7 @@ function SingleResourceReferenceEditor(props) {
|
|
|
70
70
|
return value ? _react.createElement(_ResourceCard.ResourceCard, {
|
|
71
71
|
onRemove: ()=>props.sdk.field.removeValue(),
|
|
72
72
|
resourceLink: value,
|
|
73
|
+
locale: props.sdk.field.locale,
|
|
73
74
|
isDisabled: disabled,
|
|
74
75
|
getEntryRouteHref: props.getEntryRouteHref
|
|
75
76
|
}) : _react.createElement(_LinkEntityActions.CombinedLinkEntityActions, {
|
|
@@ -113,7 +113,8 @@ describe('Single resource editor', ()=>{
|
|
|
113
113
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
114
114
|
const options = dialogFn.mock.calls[0][0];
|
|
115
115
|
expect(options).toEqual({
|
|
116
|
-
allowedResources: fieldDefinition.allowedResources
|
|
116
|
+
allowedResources: fieldDefinition.allowedResources,
|
|
117
|
+
locale: 'en'
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
it('renders no the action button when permissions insufficient', async ()=>{
|
|
@@ -37,10 +37,12 @@ function useResourceLinkActions({ parameters, sdk }) {
|
|
|
37
37
|
const multiple = field.type === 'Array';
|
|
38
38
|
const onLinkExisting = (0, _react.useMemo)(()=>{
|
|
39
39
|
const promptSelection = multiple ? async ()=>await dialogs.selectMultipleResourceEntities({
|
|
40
|
-
allowedResources: field.allowedResources
|
|
40
|
+
allowedResources: field.allowedResources,
|
|
41
|
+
locale: field.locale
|
|
41
42
|
}) : async ()=>[
|
|
42
43
|
await dialogs.selectSingleResourceEntity({
|
|
43
|
-
allowedResources: field.allowedResources
|
|
44
|
+
allowedResources: field.allowedResources,
|
|
45
|
+
locale: field.locale
|
|
44
46
|
})
|
|
45
47
|
];
|
|
46
48
|
return async ()=>{
|
|
@@ -49,6 +51,7 @@ function useResourceLinkActions({ parameters, sdk }) {
|
|
|
49
51
|
}, [
|
|
50
52
|
dialogs,
|
|
51
53
|
field.allowedResources,
|
|
54
|
+
field.locale,
|
|
52
55
|
multiple,
|
|
53
56
|
onLinkedExisting
|
|
54
57
|
]);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as assetsFixtures from './asset';
|
|
2
2
|
import * as contentTypes from './content-type';
|
|
3
|
-
import * as
|
|
3
|
+
import * as entriesFixtures from './entry';
|
|
4
4
|
import * as locales from './locale';
|
|
5
5
|
import * as spaces from './space';
|
|
6
|
-
export
|
|
6
|
+
export const assets = assetsFixtures;
|
|
7
|
+
export const entries = entriesFixtures;
|
|
8
|
+
export { contentTypes, locales, spaces };
|
|
@@ -129,7 +129,7 @@ async function fetchContentfulEntry({ urn, fetch, options }) {
|
|
|
129
129
|
contentType: contentType
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
-
async function fetchExternalResource({ urn, fetch, options, spaceId, environmentId, resourceType }) {
|
|
132
|
+
async function fetchExternalResource({ urn, fetch, options, spaceId, environmentId, resourceType, locale }) {
|
|
133
133
|
let resourceFetchError;
|
|
134
134
|
const [resource, resourceTypes] = await Promise.all([
|
|
135
135
|
fetch([
|
|
@@ -143,7 +143,8 @@ async function fetchExternalResource({ urn, fetch, options, spaceId, environment
|
|
|
143
143
|
environmentId,
|
|
144
144
|
resourceTypeId: resourceType,
|
|
145
145
|
query: {
|
|
146
|
-
'sys.urn[in]': urn
|
|
146
|
+
'sys.urn[in]': urn,
|
|
147
|
+
locale
|
|
147
148
|
}
|
|
148
149
|
}).then(({ items })=>{
|
|
149
150
|
return items[0] ?? null;
|
|
@@ -282,7 +283,8 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
282
283
|
const queryKey = [
|
|
283
284
|
'Resource',
|
|
284
285
|
resourceType,
|
|
285
|
-
urn
|
|
286
|
+
urn,
|
|
287
|
+
options?.locale
|
|
286
288
|
];
|
|
287
289
|
return fetch(queryKey, ()=>{
|
|
288
290
|
if (resourceType === 'Contentful:Entry') {
|
|
@@ -298,6 +300,7 @@ const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = cons
|
|
|
298
300
|
return fetchExternalResource({
|
|
299
301
|
fetch,
|
|
300
302
|
urn,
|
|
303
|
+
locale: options?.locale,
|
|
301
304
|
options,
|
|
302
305
|
resourceType,
|
|
303
306
|
spaceId: currentSpaceId,
|
|
@@ -421,14 +424,21 @@ export function useEntity(entityType, entityId, options) {
|
|
|
421
424
|
data
|
|
422
425
|
};
|
|
423
426
|
}
|
|
424
|
-
export function useResource(resourceType, urn, options) {
|
|
427
|
+
export function useResource(resourceType, urn, { locale, ...options } = {}) {
|
|
428
|
+
if (resourceType.startsWith('Contentful:')) {
|
|
429
|
+
locale = undefined;
|
|
430
|
+
}
|
|
425
431
|
const queryKey = [
|
|
426
432
|
'Resource',
|
|
427
433
|
resourceType,
|
|
428
|
-
urn
|
|
434
|
+
urn,
|
|
435
|
+
locale
|
|
429
436
|
];
|
|
430
437
|
const { getResource } = useEntityLoader();
|
|
431
|
-
const { status, data, error } = useQuery(queryKey, ()=>getResource(resourceType, urn,
|
|
438
|
+
const { status, data, error } = useQuery(queryKey, ()=>getResource(resourceType, urn, {
|
|
439
|
+
...options,
|
|
440
|
+
locale
|
|
441
|
+
}), {
|
|
432
442
|
enabled: options?.enabled
|
|
433
443
|
});
|
|
434
444
|
return {
|
|
@@ -12,8 +12,9 @@ function ResourceCardSkeleton() {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
function ExistingResourceCard(props) {
|
|
15
|
-
const { resourceLink, inView, index = 0 } = props;
|
|
15
|
+
const { resourceLink, inView, index = 0, locale } = props;
|
|
16
16
|
const resourceOptions = {
|
|
17
|
+
locale,
|
|
17
18
|
priority: index * -1,
|
|
18
19
|
enabled: inView,
|
|
19
20
|
allowExternal: true
|
|
@@ -72,7 +72,8 @@ describe('Multiple resource editor', ()=>{
|
|
|
72
72
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
73
73
|
const options = dialogFn.mock.calls[0][0];
|
|
74
74
|
expect(options).toEqual({
|
|
75
|
-
allowedResources: fieldDefinition.allowedResources
|
|
75
|
+
allowedResources: fieldDefinition.allowedResources,
|
|
76
|
+
locale: 'en'
|
|
76
77
|
});
|
|
77
78
|
});
|
|
78
79
|
it('hides the action button when insufficient permissions', async ()=>{
|
|
@@ -19,6 +19,7 @@ export function SingleResourceReferenceEditor(props) {
|
|
|
19
19
|
return value ? React.createElement(ResourceCard, {
|
|
20
20
|
onRemove: ()=>props.sdk.field.removeValue(),
|
|
21
21
|
resourceLink: value,
|
|
22
|
+
locale: props.sdk.field.locale,
|
|
22
23
|
isDisabled: disabled,
|
|
23
24
|
getEntryRouteHref: props.getEntryRouteHref
|
|
24
25
|
}) : React.createElement(CombinedLinkEntityActions, {
|
|
@@ -68,7 +68,8 @@ describe('Single resource editor', ()=>{
|
|
|
68
68
|
expect(dialogFn).toHaveBeenCalledTimes(1);
|
|
69
69
|
const options = dialogFn.mock.calls[0][0];
|
|
70
70
|
expect(options).toEqual({
|
|
71
|
-
allowedResources: fieldDefinition.allowedResources
|
|
71
|
+
allowedResources: fieldDefinition.allowedResources,
|
|
72
|
+
locale: 'en'
|
|
72
73
|
});
|
|
73
74
|
});
|
|
74
75
|
it('renders no the action button when permissions insufficient', async ()=>{
|
|
@@ -27,10 +27,12 @@ export function useResourceLinkActions({ parameters, sdk }) {
|
|
|
27
27
|
const multiple = field.type === 'Array';
|
|
28
28
|
const onLinkExisting = useMemo(()=>{
|
|
29
29
|
const promptSelection = multiple ? async ()=>await dialogs.selectMultipleResourceEntities({
|
|
30
|
-
allowedResources: field.allowedResources
|
|
30
|
+
allowedResources: field.allowedResources,
|
|
31
|
+
locale: field.locale
|
|
31
32
|
}) : async ()=>[
|
|
32
33
|
await dialogs.selectSingleResourceEntity({
|
|
33
|
-
allowedResources: field.allowedResources
|
|
34
|
+
allowedResources: field.allowedResources,
|
|
35
|
+
locale: field.locale
|
|
34
36
|
})
|
|
35
37
|
];
|
|
36
38
|
return async ()=>{
|
|
@@ -39,6 +41,7 @@ export function useResourceLinkActions({ parameters, sdk }) {
|
|
|
39
41
|
}, [
|
|
40
42
|
dialogs,
|
|
41
43
|
field.allowedResources,
|
|
44
|
+
field.locale,
|
|
42
45
|
multiple,
|
|
43
46
|
onLinkedExisting
|
|
44
47
|
]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AssetProps, EntryProps } from 'contentful-management/types';
|
|
2
2
|
import * as contentTypes from './content-type';
|
|
3
|
-
import * as entries from './entry';
|
|
4
3
|
import * as locales from './locale';
|
|
5
4
|
import * as spaces from './space';
|
|
6
|
-
export
|
|
5
|
+
export declare const assets: Record<string, AssetProps>;
|
|
6
|
+
export declare const entries: Record<string, EntryProps>;
|
|
7
|
+
export { contentTypes, locales, spaces };
|
|
@@ -31,10 +31,12 @@ type UseEntityOptions = GetEntityOptions & {
|
|
|
31
31
|
type QueryEntityResult<E> = Promise<E>;
|
|
32
32
|
type GetResourceOptions = GetOptions & {
|
|
33
33
|
allowExternal?: boolean;
|
|
34
|
+
locale?: string;
|
|
34
35
|
};
|
|
35
36
|
type QueryResourceResult<R extends Resource = Resource> = QueryEntityResult<ResourceInfo<R>>;
|
|
36
37
|
type UseResourceOptions = GetResourceOptions & {
|
|
37
38
|
enabled?: boolean;
|
|
39
|
+
locale?: string;
|
|
38
40
|
};
|
|
39
41
|
type UseEntityResult<E> = {
|
|
40
42
|
status: 'idle';
|
|
@@ -80,7 +82,7 @@ declare const useEntityLoader: () => {
|
|
|
80
82
|
getResourceProvider: (organizationId: string, appDefinitionId: string) => QueryEntityResult<ResourceProvider>;
|
|
81
83
|
};
|
|
82
84
|
export declare function useEntity<E extends FetchableEntity>(entityType: FetchableEntityType, entityId: string, options?: UseEntityOptions): UseEntityResult<E>;
|
|
83
|
-
export declare function useResource<R extends Resource = Resource>(resourceType: string, urn: string, options?: UseResourceOptions): {
|
|
85
|
+
export declare function useResource<R extends Resource = Resource>(resourceType: string, urn: string, { locale, ...options }?: UseResourceOptions): {
|
|
84
86
|
status: "error" | "success" | "loading";
|
|
85
87
|
data: ResourceInfo<R> | undefined;
|
|
86
88
|
error: unknown;
|
|
@@ -4,6 +4,7 @@ import { CardActionsHandlers, EntryRoute } from './ContentfulEntryCard';
|
|
|
4
4
|
type ResourceCardProps = {
|
|
5
5
|
index?: number;
|
|
6
6
|
resourceLink?: ResourceLink<string>;
|
|
7
|
+
locale?: string;
|
|
7
8
|
isDisabled: boolean;
|
|
8
9
|
renderDragHandle?: RenderDragFn;
|
|
9
10
|
getEntryRouteHref: (entryRoute: EntryRoute) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"@contentful/f36-components": "^4.70.0",
|
|
39
39
|
"@contentful/f36-icons": "^4.29.0",
|
|
40
40
|
"@contentful/f36-tokens": "^4.0.5",
|
|
41
|
-
"@contentful/field-editor-shared": "^2.3.
|
|
41
|
+
"@contentful/field-editor-shared": "^2.3.2",
|
|
42
42
|
"@contentful/mimetype": "^2.2.29",
|
|
43
43
|
"@dnd-kit/core": "^6.0.8",
|
|
44
44
|
"@dnd-kit/modifiers": "^7.0.0",
|
|
45
45
|
"@dnd-kit/sortable": "^8.0.0",
|
|
46
46
|
"@tanstack/react-query": "^4.3.9",
|
|
47
47
|
"constate": "^3.3.2",
|
|
48
|
-
"contentful-management": "^11.
|
|
48
|
+
"contentful-management": "^11.45.1",
|
|
49
49
|
"emotion": "^10.0.17",
|
|
50
50
|
"lodash": "^4.17.15",
|
|
51
51
|
"moment": "^2.20.0",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"registry": "https://npm.pkg.github.com/"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "f40a4a992e37c353214b87da74b1fccdf5559a8b"
|
|
68
68
|
}
|