@contentful/field-editor-reference 6.22.1-canary.3 → 6.22.1-canary.7

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.
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "MultipleReferenceEditor", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- const _fieldeditorshared = require("@contentful/field-editor-shared");
12
+ const _reactquery = require("@contentful/field-editor-shared/react-query");
13
13
  const _sortable = require("@dnd-kit/sortable");
14
14
  const _components = require("../components");
15
15
  const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
@@ -150,7 +150,7 @@ function MultipleReferenceEditor(props) {
150
150
  return /*#__PURE__*/ _react.createElement(_queryClient.SharedQueryClientProvider, null, /*#__PURE__*/ _react.createElement(MultipleReferenceEditorInner, props));
151
151
  }
152
152
  function MultipleReferenceEditorInner(props) {
153
- const { contentTypes: allContentTypes } = (0, _fieldeditorshared.useContentTypes)(props.sdk);
153
+ const { contentTypes: allContentTypes } = (0, _reactquery.useContentTypes)(props.sdk);
154
154
  return /*#__PURE__*/ _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value, disabled, setValue, externalReset })=>{
155
155
  return /*#__PURE__*/ _react.createElement(Editor, {
156
156
  ...props,
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "SingleReferenceEditor", {
9
9
  }
10
10
  });
11
11
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
12
- const _fieldeditorshared = require("@contentful/field-editor-shared");
12
+ const _reactquery = require("@contentful/field-editor-shared/react-query");
13
13
  const _components = require("../components");
14
14
  const _LinkEntityActions = require("../components/LinkActions/LinkEntityActions");
15
15
  const _queryClient = require("./queryClient");
@@ -108,7 +108,7 @@ function SingleReferenceEditor(props) {
108
108
  return /*#__PURE__*/ _react.createElement(_queryClient.SharedQueryClientProvider, null, /*#__PURE__*/ _react.createElement(SingleReferenceEditorInner, props));
109
109
  }
110
110
  function SingleReferenceEditorInner(props) {
111
- const { contentTypes: allContentTypes } = (0, _fieldeditorshared.useContentTypes)(props.sdk);
111
+ const { contentTypes: allContentTypes } = (0, _reactquery.useContentTypes)(props.sdk);
112
112
  return /*#__PURE__*/ _react.createElement(_ReferenceEditor.ReferenceEditor, props, ({ value, setValue, disabled, externalReset })=>{
113
113
  return /*#__PURE__*/ _react.createElement(Editor, {
114
114
  ...props,
@@ -10,13 +10,13 @@ function _export(target, all) {
10
10
  }
11
11
  _export(exports, {
12
12
  SharedQueryClientProvider: function() {
13
- return _fieldeditorshared.SharedQueryClientProvider;
13
+ return _reactquery.SharedQueryClientProvider;
14
14
  },
15
15
  useQuery: function() {
16
- return _fieldeditorshared.useQuery;
16
+ return _reactquery.useQuery;
17
17
  },
18
18
  useQueryClient: function() {
19
- return _fieldeditorshared.useQueryClient;
19
+ return _reactquery.useQueryClient;
20
20
  }
21
21
  });
22
- const _fieldeditorshared = require("@contentful/field-editor-shared");
22
+ const _reactquery = require("@contentful/field-editor-shared/react-query");
@@ -23,16 +23,14 @@ async function filter(arr, predicate) {
23
23
  }
24
24
  function useContentTypePermissions({ entityType, validations, sdk, allContentTypes }) {
25
25
  const availableContentTypes = (0, _react.useMemo)(()=>{
26
- const validationContentTypes = validations.contentTypes ?? [];
27
26
  if (entityType === 'Asset') {
28
27
  return [];
29
28
  }
30
- const hasValidationContentTypes = validationContentTypes.length > 0;
31
- if (hasValidationContentTypes && allContentTypes.length === 0) {
29
+ if (validations.contentTypes && allContentTypes.length === 0) {
32
30
  return [];
33
31
  }
34
- if (hasValidationContentTypes) {
35
- return allContentTypes.filter((ct)=>validationContentTypes.includes(ct.sys.id));
32
+ if (validations.contentTypes) {
33
+ return allContentTypes.filter((ct)=>validations.contentTypes?.includes(ct.sys.id));
36
34
  }
37
35
  return allContentTypes;
38
36
  }, [
@@ -15,14 +15,10 @@ const _useContentTypePermissions = require("./useContentTypePermissions");
15
15
  function useEditorPermissions({ sdk, entityType, parameters, allContentTypes }) {
16
16
  const fieldValidations = sdk.field.validations;
17
17
  const itemsValidations = sdk.field.type === 'Array' ? sdk.field.items?.validations : undefined;
18
- const fieldValidationsKey = JSON.stringify(fieldValidations);
19
- const itemsValidationsKey = JSON.stringify(itemsValidations);
20
- const fieldDefinition = sdk.contentType?.fields?.find((f)=>f.id === sdk.field.id);
21
- const validations = (0, _react.useMemo)(()=>(0, _fromFieldValidations.fromFieldValidations)(sdk.field, fieldDefinition), [
18
+ const validations = (0, _react.useMemo)(()=>(0, _fromFieldValidations.fromFieldValidations)(sdk.field), [
22
19
  sdk.field,
23
- fieldDefinition,
24
- fieldValidationsKey,
25
- itemsValidationsKey
20
+ JSON.stringify(fieldValidations),
21
+ JSON.stringify(itemsValidations)
26
22
  ]);
27
23
  const [canCreateEntity, setCanCreateEntity] = (0, _react.useState)(true);
28
24
  const [canLinkEntity, setCanLinkEntity] = (0, _react.useState)(true);
@@ -178,85 +178,5 @@ describe('useEditorPermissions', ()=>{
178
178
  allContentTypes[1]
179
179
  ]);
180
180
  });
181
- it(`updates availableContentTypes when linkContentType array mutates in place`, async ()=>{
182
- const allContentTypes = [
183
- makeContentType('one'),
184
- makeContentType('two')
185
- ];
186
- const { result, sdk, rerender } = await renderEditorPermissions({
187
- entityType: 'Entry',
188
- allContentTypes,
189
- customizeMock: (field)=>{
190
- const arrayField = field;
191
- arrayField.type = 'Array';
192
- arrayField.items = {
193
- validations: [
194
- {
195
- linkContentType: [
196
- 'one'
197
- ]
198
- }
199
- ]
200
- };
201
- return arrayField;
202
- }
203
- });
204
- expect(result.current.availableContentTypes).toEqual([
205
- allContentTypes[0]
206
- ]);
207
- const validation = sdk.field.items?.validations?.[0];
208
- validation.linkContentType.length = 0;
209
- validation.linkContentType.push('two');
210
- rerender();
211
- expect(result.current.availableContentTypes).toEqual([
212
- allContentTypes[1]
213
- ]);
214
- });
215
- it(`prefers contentType field validations when field validations are empty`, async ()=>{
216
- const allContentTypes = [
217
- makeContentType('one'),
218
- makeContentType('two')
219
- ];
220
- const { result } = await renderEditorPermissions({
221
- entityType: 'Entry',
222
- allContentTypes,
223
- customizeMock: (field)=>{
224
- field.validations = [];
225
- return field;
226
- },
227
- customizeSdk: (sdk)=>{
228
- sdk.contentType = {
229
- sys: {
230
- id: 'ct',
231
- type: 'ContentType',
232
- version: 1
233
- },
234
- name: 'Content Type',
235
- displayField: 'title',
236
- fields: [
237
- {
238
- id: sdk.field.id,
239
- name: 'Field',
240
- type: 'Array',
241
- items: {
242
- type: 'Link',
243
- linkType: 'Entry',
244
- validations: [
245
- {
246
- linkContentType: [
247
- 'two'
248
- ]
249
- }
250
- ]
251
- }
252
- }
253
- ]
254
- };
255
- }
256
- });
257
- expect(result.current.availableContentTypes).toEqual([
258
- allContentTypes[1]
259
- ]);
260
- });
261
181
  });
262
182
  });
@@ -20,10 +20,6 @@ _export(exports, {
20
20
  }
21
21
  });
22
22
  const getContentTypeIds = (contentTypes)=>contentTypes.map((ct)=>ct.sys.id);
23
- const getContentTypeFilter = (editorPermissions)=>{
24
- const validationContentTypes = editorPermissions.validations.contentTypes;
25
- return editorPermissions.availableContentTypes.length > 0 ? getContentTypeIds(editorPermissions.availableContentTypes) : validationContentTypes ?? [];
26
- };
27
23
  async function createEntity(props) {
28
24
  if (props.entityType === 'Entry') {
29
25
  if (!props.contentTypeId) {
@@ -50,7 +46,7 @@ async function selectSingleEntity(props) {
50
46
  if (props.entityType === 'Entry') {
51
47
  return await props.sdk.dialogs.selectSingleEntry({
52
48
  locale: props.sdk.field.locale,
53
- contentTypes: getContentTypeFilter(props.editorPermissions)
49
+ contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes)
54
50
  });
55
51
  } else {
56
52
  return props.sdk.dialogs.selectSingleAsset({
@@ -67,7 +63,7 @@ async function selectMultipleEntities(props) {
67
63
  if (props.entityType === 'Entry') {
68
64
  return await props.sdk.dialogs.selectMultipleEntries({
69
65
  locale: props.sdk.field.locale,
70
- contentTypes: getContentTypeFilter(props.editorPermissions),
66
+ contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes),
71
67
  min,
72
68
  max
73
69
  });
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
6
6
  require("@testing-library/jest-dom");
7
- const _fieldeditorshared = require("@contentful/field-editor-shared");
7
+ const _reactquery = require("@contentful/field-editor-shared/react-query");
8
8
  const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
9
9
  const _react1 = require("@testing-library/react");
10
10
  const _published_content_typejson = /*#__PURE__*/ _interop_require_default(require("../../__fixtures__/content-type/published_content_type.json"));
@@ -226,7 +226,7 @@ describe('ResourceCard', ()=>{
226
226
  resolveEntry = resolve;
227
227
  });
228
228
  sdk.cma.entry.get.mockReturnValueOnce(pendingPromise);
229
- const { getByTestId, queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_fieldeditorshared.SharedQueryClientProvider, {
229
+ const { getByTestId, queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_reactquery.SharedQueryClientProvider, {
230
230
  client: queryClient
231
231
  }, /*#__PURE__*/ _react.createElement(_EntityStore.EntityProvider, {
232
232
  sdk: sdk
@@ -14,12 +14,10 @@ function _interop_require_default(obj) {
14
14
  default: obj
15
15
  };
16
16
  }
17
- function fromFieldValidations(field, fieldDefinition) {
18
- const fieldValidations = fieldDefinition?.validations ?? field.validations;
19
- const itemsValidations = fieldDefinition?.items?.validations ?? (field.type === 'Array' ? field.items?.validations ?? [] : []);
17
+ function fromFieldValidations(field) {
20
18
  const validations = [
21
- ...fieldValidations,
22
- ...itemsValidations
19
+ ...field.validations,
20
+ ...field.type === 'Array' ? field.items?.validations ?? [] : []
23
21
  ];
24
22
  const linkContentTypeValidations = validations.find((v)=>'linkContentType' in v);
25
23
  const linkMimetypeGroupValidations = validations.find((v)=>'linkMimetypeGroup' in v);
@@ -47,15 +45,9 @@ function fromFieldValidations(field, fieldDefinition) {
47
45
  min: undefined
48
46
  };
49
47
  }
50
- const contentTypes = linkContentTypeValidations?.linkContentType ? [
51
- ...linkContentTypeValidations.linkContentType
52
- ] : undefined;
53
- const mimetypeGroups = linkMimetypeGroupValidations?.linkMimetypeGroup ? [
54
- ...linkMimetypeGroupValidations.linkMimetypeGroup
55
- ] : undefined;
56
48
  const result = {
57
- contentTypes,
58
- mimetypeGroups,
49
+ contentTypes: linkContentTypeValidations?.linkContentType ?? undefined,
50
+ mimetypeGroups: linkMimetypeGroupValidations?.linkMimetypeGroup ?? undefined,
59
51
  numberOfLinks
60
52
  };
61
53
  return result;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useCallback } from 'react';
3
- import { useContentTypes } from '@contentful/field-editor-shared';
3
+ import { useContentTypes } from '@contentful/field-editor-shared/react-query';
4
4
  import { arrayMove } from '@dnd-kit/sortable';
5
5
  import { LinkEntityActions } from '../components';
6
6
  import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions';
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useCallback } from 'react';
3
- import { useContentTypes } from '@contentful/field-editor-shared';
3
+ import { useContentTypes } from '@contentful/field-editor-shared/react-query';
4
4
  import { LinkEntityActions } from '../components';
5
5
  import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions';
6
6
  import { SharedQueryClientProvider } from './queryClient';
@@ -1 +1 @@
1
- export { SharedQueryClientProvider, useQueryClient, useQuery } from '@contentful/field-editor-shared';
1
+ export { SharedQueryClientProvider, useQueryClient, useQuery } from '@contentful/field-editor-shared/react-query';
@@ -8,16 +8,14 @@ async function filter(arr, predicate) {
8
8
  }
9
9
  export function useContentTypePermissions({ entityType, validations, sdk, allContentTypes }) {
10
10
  const availableContentTypes = useMemo(()=>{
11
- const validationContentTypes = validations.contentTypes ?? [];
12
11
  if (entityType === 'Asset') {
13
12
  return [];
14
13
  }
15
- const hasValidationContentTypes = validationContentTypes.length > 0;
16
- if (hasValidationContentTypes && allContentTypes.length === 0) {
14
+ if (validations.contentTypes && allContentTypes.length === 0) {
17
15
  return [];
18
16
  }
19
- if (hasValidationContentTypes) {
20
- return allContentTypes.filter((ct)=>validationContentTypes.includes(ct.sys.id));
17
+ if (validations.contentTypes) {
18
+ return allContentTypes.filter((ct)=>validations.contentTypes?.includes(ct.sys.id));
21
19
  }
22
20
  return allContentTypes;
23
21
  }, [
@@ -5,14 +5,10 @@ import { useContentTypePermissions } from './useContentTypePermissions';
5
5
  export function useEditorPermissions({ sdk, entityType, parameters, allContentTypes }) {
6
6
  const fieldValidations = sdk.field.validations;
7
7
  const itemsValidations = sdk.field.type === 'Array' ? sdk.field.items?.validations : undefined;
8
- const fieldValidationsKey = JSON.stringify(fieldValidations);
9
- const itemsValidationsKey = JSON.stringify(itemsValidations);
10
- const fieldDefinition = sdk.contentType?.fields?.find((f)=>f.id === sdk.field.id);
11
- const validations = useMemo(()=>fromFieldValidations(sdk.field, fieldDefinition), [
8
+ const validations = useMemo(()=>fromFieldValidations(sdk.field), [
12
9
  sdk.field,
13
- fieldDefinition,
14
- fieldValidationsKey,
15
- itemsValidationsKey
10
+ JSON.stringify(fieldValidations),
11
+ JSON.stringify(itemsValidations)
16
12
  ]);
17
13
  const [canCreateEntity, setCanCreateEntity] = useState(true);
18
14
  const [canLinkEntity, setCanLinkEntity] = useState(true);
@@ -174,85 +174,5 @@ describe('useEditorPermissions', ()=>{
174
174
  allContentTypes[1]
175
175
  ]);
176
176
  });
177
- it(`updates availableContentTypes when linkContentType array mutates in place`, async ()=>{
178
- const allContentTypes = [
179
- makeContentType('one'),
180
- makeContentType('two')
181
- ];
182
- const { result, sdk, rerender } = await renderEditorPermissions({
183
- entityType: 'Entry',
184
- allContentTypes,
185
- customizeMock: (field)=>{
186
- const arrayField = field;
187
- arrayField.type = 'Array';
188
- arrayField.items = {
189
- validations: [
190
- {
191
- linkContentType: [
192
- 'one'
193
- ]
194
- }
195
- ]
196
- };
197
- return arrayField;
198
- }
199
- });
200
- expect(result.current.availableContentTypes).toEqual([
201
- allContentTypes[0]
202
- ]);
203
- const validation = sdk.field.items?.validations?.[0];
204
- validation.linkContentType.length = 0;
205
- validation.linkContentType.push('two');
206
- rerender();
207
- expect(result.current.availableContentTypes).toEqual([
208
- allContentTypes[1]
209
- ]);
210
- });
211
- it(`prefers contentType field validations when field validations are empty`, async ()=>{
212
- const allContentTypes = [
213
- makeContentType('one'),
214
- makeContentType('two')
215
- ];
216
- const { result } = await renderEditorPermissions({
217
- entityType: 'Entry',
218
- allContentTypes,
219
- customizeMock: (field)=>{
220
- field.validations = [];
221
- return field;
222
- },
223
- customizeSdk: (sdk)=>{
224
- sdk.contentType = {
225
- sys: {
226
- id: 'ct',
227
- type: 'ContentType',
228
- version: 1
229
- },
230
- name: 'Content Type',
231
- displayField: 'title',
232
- fields: [
233
- {
234
- id: sdk.field.id,
235
- name: 'Field',
236
- type: 'Array',
237
- items: {
238
- type: 'Link',
239
- linkType: 'Entry',
240
- validations: [
241
- {
242
- linkContentType: [
243
- 'two'
244
- ]
245
- }
246
- ]
247
- }
248
- }
249
- ]
250
- };
251
- }
252
- });
253
- expect(result.current.availableContentTypes).toEqual([
254
- allContentTypes[1]
255
- ]);
256
- });
257
177
  });
258
178
  });
@@ -1,8 +1,4 @@
1
1
  const getContentTypeIds = (contentTypes)=>contentTypes.map((ct)=>ct.sys.id);
2
- const getContentTypeFilter = (editorPermissions)=>{
3
- const validationContentTypes = editorPermissions.validations.contentTypes;
4
- return editorPermissions.availableContentTypes.length > 0 ? getContentTypeIds(editorPermissions.availableContentTypes) : validationContentTypes ?? [];
5
- };
6
2
  export async function createEntity(props) {
7
3
  if (props.entityType === 'Entry') {
8
4
  if (!props.contentTypeId) {
@@ -29,7 +25,7 @@ export async function selectSingleEntity(props) {
29
25
  if (props.entityType === 'Entry') {
30
26
  return await props.sdk.dialogs.selectSingleEntry({
31
27
  locale: props.sdk.field.locale,
32
- contentTypes: getContentTypeFilter(props.editorPermissions)
28
+ contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes)
33
29
  });
34
30
  } else {
35
31
  return props.sdk.dialogs.selectSingleAsset({
@@ -46,7 +42,7 @@ export async function selectMultipleEntities(props) {
46
42
  if (props.entityType === 'Entry') {
47
43
  return await props.sdk.dialogs.selectMultipleEntries({
48
44
  locale: props.sdk.field.locale,
49
- contentTypes: getContentTypeFilter(props.editorPermissions),
45
+ contentTypes: getContentTypeIds(props.editorPermissions.availableContentTypes),
50
46
  min,
51
47
  max
52
48
  });
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import '@testing-library/jest-dom';
3
- import { SharedQueryClientProvider } from '@contentful/field-editor-shared';
3
+ import { SharedQueryClientProvider } from '@contentful/field-editor-shared/react-query';
4
4
  import { createTestQueryClient } from '@contentful/field-editor-test-utils';
5
5
  import { configure, fireEvent, render, waitFor } from '@testing-library/react';
6
6
  import publishedCT from '../../__fixtures__/content-type/published_content_type.json';
@@ -1,10 +1,8 @@
1
1
  import isNumber from 'lodash/isNumber';
2
- export function fromFieldValidations(field, fieldDefinition) {
3
- const fieldValidations = fieldDefinition?.validations ?? field.validations;
4
- const itemsValidations = fieldDefinition?.items?.validations ?? (field.type === 'Array' ? field.items?.validations ?? [] : []);
2
+ export function fromFieldValidations(field) {
5
3
  const validations = [
6
- ...fieldValidations,
7
- ...itemsValidations
4
+ ...field.validations,
5
+ ...field.type === 'Array' ? field.items?.validations ?? [] : []
8
6
  ];
9
7
  const linkContentTypeValidations = validations.find((v)=>'linkContentType' in v);
10
8
  const linkMimetypeGroupValidations = validations.find((v)=>'linkMimetypeGroup' in v);
@@ -32,15 +30,9 @@ export function fromFieldValidations(field, fieldDefinition) {
32
30
  min: undefined
33
31
  };
34
32
  }
35
- const contentTypes = linkContentTypeValidations?.linkContentType ? [
36
- ...linkContentTypeValidations.linkContentType
37
- ] : undefined;
38
- const mimetypeGroups = linkMimetypeGroupValidations?.linkMimetypeGroup ? [
39
- ...linkMimetypeGroupValidations.linkMimetypeGroup
40
- ] : undefined;
41
33
  const result = {
42
- contentTypes,
43
- mimetypeGroups,
34
+ contentTypes: linkContentTypeValidations?.linkContentType ?? undefined,
35
+ mimetypeGroups: linkMimetypeGroupValidations?.linkMimetypeGroup ?? undefined,
44
36
  numberOfLinks
45
37
  };
46
38
  return result;
@@ -2,4 +2,4 @@
2
2
  * Re-export query client utilities from shared package.
3
3
  * This maintains backwards compatibility while using the shared implementation.
4
4
  */
5
- export { SharedQueryClientProvider, useQueryClient, useQuery, } from '@contentful/field-editor-shared';
5
+ export { SharedQueryClientProvider, useQueryClient, useQuery, } from '@contentful/field-editor-shared/react-query';
@@ -1,4 +1,4 @@
1
- import type { ContentTypeField, FieldAPI } from '@contentful/app-sdk';
1
+ import { FieldAPI } from '@contentful/app-sdk';
2
2
  type NumberOfLinksValidation = {
3
3
  type: 'min-max';
4
4
  min: number;
@@ -17,5 +17,5 @@ export type ReferenceValidations = {
17
17
  mimetypeGroups?: string[];
18
18
  numberOfLinks?: NumberOfLinksValidation;
19
19
  };
20
- export declare function fromFieldValidations(field: FieldAPI, fieldDefinition?: ContentTypeField): ReferenceValidations;
20
+ export declare function fromFieldValidations(field: FieldAPI): ReferenceValidations;
21
21
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-reference",
3
- "version": "6.22.1-canary.3+1daf7e10",
3
+ "version": "6.22.1-canary.7+e61c9c06",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "@contentful/f36-components": "^5.8.1",
40
40
  "@contentful/f36-icons": "^5.8.1",
41
41
  "@contentful/f36-tokens": "^5.1.0",
42
- "@contentful/field-editor-shared": "^2.18.0",
42
+ "@contentful/field-editor-shared": "^2.18.1-canary.19+e61c9c06",
43
43
  "@contentful/mimetype": "^2.2.29",
44
44
  "@dnd-kit/core": "^6.0.8",
45
45
  "@dnd-kit/sortable": "^8.0.0",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "registry": "https://npm.pkg.github.com/"
70
70
  },
71
- "gitHead": "1daf7e105fe9c564afb5e4600321535998f7908a"
71
+ "gitHead": "e61c9c06570d672a3eeef5d455dd0a1dee9cfcd1"
72
72
  }
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _helpers = require("./helpers");
6
- const makeContentType = (id)=>({
7
- sys: {
8
- id
9
- }
10
- });
11
- const makeSdk = ()=>({
12
- field: {
13
- locale: 'en-US',
14
- getValue: jest.fn().mockReturnValue([])
15
- },
16
- dialogs: {
17
- selectSingleEntry: jest.fn(),
18
- selectMultipleEntries: jest.fn()
19
- }
20
- });
21
- describe('LinkActions helpers', ()=>{
22
- it('uses validation content types when availableContentTypes is empty (single)', async ()=>{
23
- const sdk = makeSdk();
24
- await (0, _helpers.selectSingleEntity)({
25
- sdk: sdk,
26
- entityType: 'Entry',
27
- editorPermissions: {
28
- canCreateEntity: true,
29
- canLinkEntity: true,
30
- creatableContentTypes: [],
31
- availableContentTypes: [],
32
- validations: {
33
- contentTypes: [
34
- 'productListing',
35
- 'contextApp'
36
- ]
37
- }
38
- }
39
- });
40
- expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
41
- locale: 'en-US',
42
- contentTypes: [
43
- 'productListing',
44
- 'contextApp'
45
- ]
46
- }));
47
- });
48
- it('uses validation content types when availableContentTypes is empty (multiple)', async ()=>{
49
- const sdk = makeSdk();
50
- await (0, _helpers.selectMultipleEntities)({
51
- sdk: sdk,
52
- entityType: 'Entry',
53
- editorPermissions: {
54
- canCreateEntity: true,
55
- canLinkEntity: true,
56
- creatableContentTypes: [],
57
- availableContentTypes: [],
58
- validations: {
59
- contentTypes: [
60
- 'productListing',
61
- 'contextApp'
62
- ]
63
- }
64
- }
65
- });
66
- expect(sdk.dialogs.selectMultipleEntries).toHaveBeenCalledWith(expect.objectContaining({
67
- locale: 'en-US',
68
- contentTypes: [
69
- 'productListing',
70
- 'contextApp'
71
- ]
72
- }));
73
- });
74
- it('prefers availableContentTypes when present', async ()=>{
75
- const sdk = makeSdk();
76
- await (0, _helpers.selectSingleEntity)({
77
- sdk: sdk,
78
- entityType: 'Entry',
79
- editorPermissions: {
80
- canCreateEntity: true,
81
- canLinkEntity: true,
82
- creatableContentTypes: [],
83
- availableContentTypes: [
84
- makeContentType('one'),
85
- makeContentType('two')
86
- ],
87
- validations: {
88
- contentTypes: [
89
- 'productListing',
90
- 'contextApp'
91
- ]
92
- }
93
- }
94
- });
95
- expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
96
- locale: 'en-US',
97
- contentTypes: [
98
- 'one',
99
- 'two'
100
- ]
101
- }));
102
- });
103
- });
@@ -1,99 +0,0 @@
1
- import { selectMultipleEntities, selectSingleEntity } from './helpers';
2
- const makeContentType = (id)=>({
3
- sys: {
4
- id
5
- }
6
- });
7
- const makeSdk = ()=>({
8
- field: {
9
- locale: 'en-US',
10
- getValue: jest.fn().mockReturnValue([])
11
- },
12
- dialogs: {
13
- selectSingleEntry: jest.fn(),
14
- selectMultipleEntries: jest.fn()
15
- }
16
- });
17
- describe('LinkActions helpers', ()=>{
18
- it('uses validation content types when availableContentTypes is empty (single)', async ()=>{
19
- const sdk = makeSdk();
20
- await selectSingleEntity({
21
- sdk: sdk,
22
- entityType: 'Entry',
23
- editorPermissions: {
24
- canCreateEntity: true,
25
- canLinkEntity: true,
26
- creatableContentTypes: [],
27
- availableContentTypes: [],
28
- validations: {
29
- contentTypes: [
30
- 'productListing',
31
- 'contextApp'
32
- ]
33
- }
34
- }
35
- });
36
- expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
37
- locale: 'en-US',
38
- contentTypes: [
39
- 'productListing',
40
- 'contextApp'
41
- ]
42
- }));
43
- });
44
- it('uses validation content types when availableContentTypes is empty (multiple)', async ()=>{
45
- const sdk = makeSdk();
46
- await selectMultipleEntities({
47
- sdk: sdk,
48
- entityType: 'Entry',
49
- editorPermissions: {
50
- canCreateEntity: true,
51
- canLinkEntity: true,
52
- creatableContentTypes: [],
53
- availableContentTypes: [],
54
- validations: {
55
- contentTypes: [
56
- 'productListing',
57
- 'contextApp'
58
- ]
59
- }
60
- }
61
- });
62
- expect(sdk.dialogs.selectMultipleEntries).toHaveBeenCalledWith(expect.objectContaining({
63
- locale: 'en-US',
64
- contentTypes: [
65
- 'productListing',
66
- 'contextApp'
67
- ]
68
- }));
69
- });
70
- it('prefers availableContentTypes when present', async ()=>{
71
- const sdk = makeSdk();
72
- await selectSingleEntity({
73
- sdk: sdk,
74
- entityType: 'Entry',
75
- editorPermissions: {
76
- canCreateEntity: true,
77
- canLinkEntity: true,
78
- creatableContentTypes: [],
79
- availableContentTypes: [
80
- makeContentType('one'),
81
- makeContentType('two')
82
- ],
83
- validations: {
84
- contentTypes: [
85
- 'productListing',
86
- 'contextApp'
87
- ]
88
- }
89
- }
90
- });
91
- expect(sdk.dialogs.selectSingleEntry).toHaveBeenCalledWith(expect.objectContaining({
92
- locale: 'en-US',
93
- contentTypes: [
94
- 'one',
95
- 'two'
96
- ]
97
- }));
98
- });
99
- });
@@ -1 +0,0 @@
1
- export {};