slice-machine-ui 2.16.2-alpha.jp-cr-ui-types-internal-version.2 → 2.16.2-alpha.jp-cr-ui-base.1
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/out/404.html +1 -1
- package/out/_next/static/chunks/157-54b8336d20b41933.js +3 -0
- package/out/_next/static/chunks/{183-85de38d65a85dc2c.js → 183-4ea255b867ff171b.js} +1 -1
- package/out/_next/static/chunks/248-03446cd9e9f13730.js +1 -0
- package/out/_next/static/chunks/{630-db2634510e265e9a.js → 630-a9927675acae2970.js} +1 -1
- package/out/_next/static/chunks/{867-bb2db4d365ee7e40.js → 647-7b9b5aa9468f9e4b.js} +1 -1
- package/out/_next/static/chunks/{882-636039ab926dbc22.js → 882-53d88aa0b7e3ffeb.js} +1 -1
- package/out/_next/static/chunks/{main-1c0e53194ff2e726.js → main-c46f4dcf6e3174bd.js} +1 -1
- package/out/_next/static/chunks/pages/{_app-f7875dc5387317e5.js → _app-53a42c901b57c0e8.js} +60 -60
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-389d1b7a492fb3e7.js → [customTypeId]-a408f5a660e096a6.js} +1 -1
- package/out/_next/static/chunks/pages/{custom-types-2a5fd94ee42ba593.js → custom-types-5acd56959b60346f.js} +1 -1
- package/out/_next/static/chunks/pages/{index-02dd147957c8b40f.js → index-0d8cb369de720a35.js} +1 -1
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-3589bd1f9138a97b.js → [pageTypeId]-f5e851ebe35049a8.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/{simulator-e78d6a6078714a03.js → simulator-5008e29008aa04f4.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-94c9cad9da2c3089.js +1 -0
- package/out/_next/static/{D2HaNBRmqpwrvztn78FNp → v6DDS8Zqx4NR8CqxDBGqT}/_buildManifest.js +1 -1
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/settings.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +9 -9
- package/src/features/{customTypes → builder}/fields/ContentRelationshipFieldPicker.tsx +91 -79
- package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +2 -4
- package/src/features/customTypes/customTypesTable/{useCustomTypes.ts → useCustomTypesAutoRevalidation.tsx} +1 -34
- package/src/features/customTypes/useCustomTypes.ts +48 -0
- package/src/legacy/lib/models/common/widgets/ContentRelationship/Form.tsx +1 -1
- package/out/_next/static/chunks/493-455020ccdddebf32.js +0 -5
- package/out/_next/static/chunks/895-e5bf82a4d5d7c3e1.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-85ab73c10f8322e1.js +0 -1
- /package/out/_next/static/{D2HaNBRmqpwrvztn78FNp → v6DDS8Zqx4NR8CqxDBGqT}/_ssgManifest.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pluralize } from "@prismicio/editor-support/String";
|
|
2
|
-
import { revalidateData, useRequest } from "@prismicio/editor-support/Suspense";
|
|
3
2
|
import {
|
|
3
|
+
Alert,
|
|
4
4
|
AnimatedSuspense,
|
|
5
5
|
Badge,
|
|
6
6
|
Box,
|
|
@@ -27,11 +27,14 @@ import {
|
|
|
27
27
|
LinkConfig,
|
|
28
28
|
NestableWidget,
|
|
29
29
|
} from "@prismicio/types-internal/lib/customtypes";
|
|
30
|
+
import { useEffect } from "react";
|
|
30
31
|
|
|
31
32
|
import { ErrorBoundary } from "@/ErrorBoundary";
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
revalidateGetCustomTypes,
|
|
35
|
+
useCustomTypes as useCustomTypesRequest,
|
|
36
|
+
} from "@/features/customTypes/useCustomTypes";
|
|
33
37
|
import { isValidObject } from "@/utils/isValidObject";
|
|
34
|
-
import { useEffect, useState } from "react";
|
|
35
38
|
|
|
36
39
|
type NonReadonly<T> = { -readonly [P in keyof T]: T[P] };
|
|
37
40
|
|
|
@@ -258,10 +261,7 @@ function ContentRelationshipFieldPickerContent(
|
|
|
258
261
|
props: ContentRelationshipFieldPickerProps,
|
|
259
262
|
) {
|
|
260
263
|
const { value, onChange } = props;
|
|
261
|
-
const { allCustomTypes,
|
|
262
|
-
useCustomTypes(value);
|
|
263
|
-
|
|
264
|
-
const [isNewType, setIsNewType] = useState(false);
|
|
264
|
+
const { allCustomTypes, pickedCustomTypes } = useCustomTypes(value);
|
|
265
265
|
|
|
266
266
|
const fieldCheckMap = value
|
|
267
267
|
? convertLinkCustomtypesToFieldCheckMap(value)
|
|
@@ -283,8 +283,8 @@ function ContentRelationshipFieldPickerContent(
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
function addCustomType(id: string) {
|
|
286
|
-
|
|
287
|
-
onChange(
|
|
286
|
+
const newFields = value ? [...value, id] : [id];
|
|
287
|
+
onChange(newFields);
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
function removeCustomType(id: string) {
|
|
@@ -311,15 +311,54 @@ function ContentRelationshipFieldPickerContent(
|
|
|
311
311
|
<>
|
|
312
312
|
<Box flexDirection="column">
|
|
313
313
|
<Text variant="h4" color="grey12">
|
|
314
|
-
Allowed
|
|
314
|
+
Allowed type
|
|
315
315
|
</Text>
|
|
316
316
|
<Text color="grey11">
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
Select a single type that editors can link to in the Page
|
|
318
|
+
Builder.
|
|
319
319
|
<br />
|
|
320
|
-
For
|
|
320
|
+
For the selected type, choose which fields to include in the API
|
|
321
321
|
response.
|
|
322
322
|
</Text>
|
|
323
|
+
{pickedCustomTypes.length > 1 && (
|
|
324
|
+
<Box margin={{ block: 12 }}>
|
|
325
|
+
<Alert
|
|
326
|
+
color="warn"
|
|
327
|
+
icon="alert"
|
|
328
|
+
subtitle={
|
|
329
|
+
<>
|
|
330
|
+
<Text color="inherit" variant="bold">
|
|
331
|
+
Legacy mode. Keep only one type to enable the improved
|
|
332
|
+
Content Relationship feature.
|
|
333
|
+
</Text>
|
|
334
|
+
<br />
|
|
335
|
+
<a
|
|
336
|
+
href="https://prismic.io/docs/fields/content-relationship"
|
|
337
|
+
target="_blank"
|
|
338
|
+
rel="noopener noreferrer"
|
|
339
|
+
style={{
|
|
340
|
+
color: "inherit",
|
|
341
|
+
textDecoration: "none",
|
|
342
|
+
fontWeight: "bold",
|
|
343
|
+
display: "flex",
|
|
344
|
+
alignItems: "center",
|
|
345
|
+
gap: 4,
|
|
346
|
+
}}
|
|
347
|
+
>
|
|
348
|
+
<Text color="inherit" variant="bold">
|
|
349
|
+
See documentation
|
|
350
|
+
</Text>
|
|
351
|
+
<Icon
|
|
352
|
+
name="arrowForward"
|
|
353
|
+
size="small"
|
|
354
|
+
color="inherit"
|
|
355
|
+
/>
|
|
356
|
+
</a>
|
|
357
|
+
</>
|
|
358
|
+
}
|
|
359
|
+
/>
|
|
360
|
+
</Box>
|
|
361
|
+
)}
|
|
323
362
|
</Box>
|
|
324
363
|
{pickedCustomTypes.map((customType) => (
|
|
325
364
|
<Box
|
|
@@ -332,17 +371,21 @@ function ContentRelationshipFieldPickerContent(
|
|
|
332
371
|
backgroundColor="white"
|
|
333
372
|
justifyContent="space-between"
|
|
334
373
|
>
|
|
335
|
-
|
|
336
|
-
<
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
374
|
+
{pickedCustomTypes.length > 1 ? (
|
|
375
|
+
<Text>{customType.id}</Text>
|
|
376
|
+
) : (
|
|
377
|
+
<TreeView>
|
|
378
|
+
<TreeViewCustomType
|
|
379
|
+
customType={customType}
|
|
380
|
+
onChange={(value) =>
|
|
381
|
+
onCustomTypesChange(customType.id, value)
|
|
382
|
+
}
|
|
383
|
+
fieldCheckMap={fieldCheckMap[customType.id] ?? {}}
|
|
384
|
+
allCustomTypes={allCustomTypes}
|
|
385
|
+
/>
|
|
386
|
+
</TreeView>
|
|
387
|
+
)}
|
|
388
|
+
|
|
346
389
|
<IconButton
|
|
347
390
|
icon="close"
|
|
348
391
|
size="small"
|
|
@@ -352,17 +395,9 @@ function ContentRelationshipFieldPickerContent(
|
|
|
352
395
|
/>
|
|
353
396
|
</Box>
|
|
354
397
|
))}
|
|
355
|
-
<AddTypeButton
|
|
356
|
-
onSelect={addCustomType}
|
|
357
|
-
pickedCustomTypes={pickedCustomTypes}
|
|
358
|
-
availableCustomTypes={availableCustomTypes}
|
|
359
|
-
/>
|
|
360
398
|
</>
|
|
361
399
|
) : (
|
|
362
|
-
<EmptyView
|
|
363
|
-
onSelect={addCustomType}
|
|
364
|
-
availableCustomTypes={availableCustomTypes}
|
|
365
|
-
/>
|
|
400
|
+
<EmptyView onSelect={addCustomType} allCustomTypes={allCustomTypes} />
|
|
366
401
|
)}
|
|
367
402
|
</Box>
|
|
368
403
|
<Box backgroundColor="white" flexDirection="column" padding={12}>
|
|
@@ -385,11 +420,11 @@ function ContentRelationshipFieldPickerContent(
|
|
|
385
420
|
|
|
386
421
|
type EmptyViewProps = {
|
|
387
422
|
onSelect: (customTypeId: string) => void;
|
|
388
|
-
|
|
423
|
+
allCustomTypes: CustomType[];
|
|
389
424
|
};
|
|
390
425
|
|
|
391
426
|
function EmptyView(props: EmptyViewProps) {
|
|
392
|
-
const {
|
|
427
|
+
const { allCustomTypes, onSelect } = props;
|
|
393
428
|
|
|
394
429
|
return (
|
|
395
430
|
<Box
|
|
@@ -400,20 +435,16 @@ function EmptyView(props: EmptyViewProps) {
|
|
|
400
435
|
>
|
|
401
436
|
<Box flexDirection="column" alignItems="center" gap={4}>
|
|
402
437
|
<Text variant="h5" color="grey12">
|
|
403
|
-
No
|
|
438
|
+
No type selected
|
|
404
439
|
</Text>
|
|
405
440
|
<Text color="grey11" component="p" align="center">
|
|
406
|
-
|
|
441
|
+
Select the type editors can link to.
|
|
407
442
|
<br />
|
|
408
|
-
|
|
409
|
-
in your frontend queries).
|
|
443
|
+
Then, choose which fields to return in the API.
|
|
410
444
|
</Text>
|
|
411
445
|
</Box>
|
|
412
446
|
<Box>
|
|
413
|
-
<AddTypeButton
|
|
414
|
-
availableCustomTypes={availableCustomTypes}
|
|
415
|
-
onSelect={onSelect}
|
|
416
|
-
/>
|
|
447
|
+
<AddTypeButton allCustomTypes={allCustomTypes} onSelect={onSelect} />
|
|
417
448
|
</Box>
|
|
418
449
|
</Box>
|
|
419
450
|
);
|
|
@@ -421,28 +452,22 @@ function EmptyView(props: EmptyViewProps) {
|
|
|
421
452
|
|
|
422
453
|
type AddTypeButtonProps = {
|
|
423
454
|
onSelect: (customTypeId: string) => void;
|
|
424
|
-
|
|
425
|
-
availableCustomTypes: CustomType[];
|
|
426
|
-
pickedCustomTypes?: CustomType[];
|
|
455
|
+
allCustomTypes: CustomType[];
|
|
427
456
|
};
|
|
428
457
|
|
|
429
458
|
function AddTypeButton(props: AddTypeButtonProps) {
|
|
430
|
-
const {
|
|
459
|
+
const { allCustomTypes, onSelect } = props;
|
|
431
460
|
|
|
432
461
|
const triggerButton = (
|
|
433
|
-
<Button
|
|
434
|
-
|
|
435
|
-
color="grey"
|
|
436
|
-
disabled={availableCustomTypes.length === 0}
|
|
437
|
-
>
|
|
438
|
-
{pickedCustomTypes.length > 0 ? "Add another type" : "Add type"}
|
|
462
|
+
<Button startIcon="add" color="grey" disabled={allCustomTypes.length === 0}>
|
|
463
|
+
Add type
|
|
439
464
|
</Button>
|
|
440
465
|
);
|
|
441
466
|
|
|
442
467
|
const disabledButton = (
|
|
443
468
|
<Box>
|
|
444
469
|
<Tooltip
|
|
445
|
-
content="
|
|
470
|
+
content="No type available"
|
|
446
471
|
side="bottom"
|
|
447
472
|
align="start"
|
|
448
473
|
disableHoverableContent
|
|
@@ -452,21 +477,17 @@ function AddTypeButton(props: AddTypeButtonProps) {
|
|
|
452
477
|
</Box>
|
|
453
478
|
);
|
|
454
479
|
|
|
455
|
-
if (
|
|
480
|
+
if (allCustomTypes.length === 0) return disabledButton;
|
|
456
481
|
|
|
457
482
|
return (
|
|
458
483
|
<Box>
|
|
459
484
|
<DropdownMenu>
|
|
460
485
|
<DropdownMenuTrigger>{triggerButton}</DropdownMenuTrigger>
|
|
461
|
-
<DropdownMenuContent
|
|
462
|
-
maxHeight={400}
|
|
463
|
-
minWidth={256}
|
|
464
|
-
align={pickedCustomTypes.length > 0 ? "start" : "center"}
|
|
465
|
-
>
|
|
486
|
+
<DropdownMenuContent maxHeight={400} minWidth={256} align="center">
|
|
466
487
|
<DropdownMenuLabel>
|
|
467
488
|
<Text color="grey11">Types</Text>
|
|
468
489
|
</DropdownMenuLabel>
|
|
469
|
-
{
|
|
490
|
+
{allCustomTypes.map((customType) => (
|
|
470
491
|
<DropdownMenuItem
|
|
471
492
|
key={customType.id}
|
|
472
493
|
onSelect={() => onSelect(customType.id)}
|
|
@@ -498,7 +519,6 @@ interface TreeViewCustomTypeProps {
|
|
|
498
519
|
fieldCheckMap: PickerCustomType;
|
|
499
520
|
onChange: (newValue: PickerCustomType) => void;
|
|
500
521
|
allCustomTypes: CustomType[];
|
|
501
|
-
isNewType: boolean;
|
|
502
522
|
}
|
|
503
523
|
|
|
504
524
|
function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
@@ -507,7 +527,6 @@ function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
|
507
527
|
fieldCheckMap: customTypeFieldsCheckMap,
|
|
508
528
|
onChange: onCustomTypeChange,
|
|
509
529
|
allCustomTypes,
|
|
510
|
-
isNewType,
|
|
511
530
|
} = props;
|
|
512
531
|
|
|
513
532
|
const renderedFields = getCustomTypeStaticFields(customType).map(
|
|
@@ -606,7 +625,7 @@ function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
|
606
625
|
: "(No fields returned in the API)"
|
|
607
626
|
}
|
|
608
627
|
badge={getTypeFormatLabel(customType.format)}
|
|
609
|
-
defaultOpen
|
|
628
|
+
defaultOpen
|
|
610
629
|
>
|
|
611
630
|
{renderedFields.length > 0 ? (
|
|
612
631
|
renderedFields
|
|
@@ -877,17 +896,21 @@ function getTypeFormatLabel(format: CustomType["format"]) {
|
|
|
877
896
|
}
|
|
878
897
|
|
|
879
898
|
/** Retrieves all existing page & custom types. */
|
|
880
|
-
function useCustomTypes(value: LinkCustomtypes | undefined) {
|
|
881
|
-
|
|
899
|
+
function useCustomTypes(value: LinkCustomtypes | undefined): {
|
|
900
|
+
/** Every existing custom type, used to discover nested custom types down the tree and the add type dropdown. */
|
|
901
|
+
allCustomTypes: CustomType[];
|
|
902
|
+
/** The custom types that are already picked. */
|
|
903
|
+
pickedCustomTypes: CustomType[];
|
|
904
|
+
} {
|
|
905
|
+
const { customTypes: allCustomTypes } = useCustomTypesRequest();
|
|
882
906
|
|
|
883
907
|
useEffect(() => {
|
|
884
|
-
void
|
|
908
|
+
void revalidateGetCustomTypes();
|
|
885
909
|
}, []);
|
|
886
910
|
|
|
887
911
|
if (!value) {
|
|
888
912
|
return {
|
|
889
913
|
allCustomTypes,
|
|
890
|
-
availableCustomTypes: allCustomTypes,
|
|
891
914
|
pickedCustomTypes: [],
|
|
892
915
|
};
|
|
893
916
|
}
|
|
@@ -899,20 +922,9 @@ function useCustomTypes(value: LinkCustomtypes | undefined) {
|
|
|
899
922
|
return {
|
|
900
923
|
allCustomTypes,
|
|
901
924
|
pickedCustomTypes,
|
|
902
|
-
availableCustomTypes: allCustomTypes.filter(
|
|
903
|
-
(ct) => pickedCustomTypes.some((pct) => pct.id === ct.id) === false,
|
|
904
|
-
),
|
|
905
925
|
};
|
|
906
926
|
}
|
|
907
927
|
|
|
908
|
-
async function getCustomTypes(): Promise<CustomType[]> {
|
|
909
|
-
const { errors, models } =
|
|
910
|
-
await managerClient.customTypes.readAllCustomTypes();
|
|
911
|
-
|
|
912
|
-
if (errors.length > 0) throw errors;
|
|
913
|
-
return models.map(({ model }) => model);
|
|
914
|
-
}
|
|
915
|
-
|
|
916
928
|
function resolveContentRelationshipCustomTypes(
|
|
917
929
|
customTypes: LinkCustomtypes,
|
|
918
930
|
localCustomTypes: CustomType[],
|
|
@@ -29,10 +29,8 @@ import { SingleIcon } from "@/icons/SingleIcon";
|
|
|
29
29
|
|
|
30
30
|
import { CUSTOM_TYPES_CONFIG } from "../customTypesConfig";
|
|
31
31
|
import { EditDropdown } from "../EditDropdown";
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
useCustomTypesAutoRevalidation,
|
|
35
|
-
} from "./useCustomTypes";
|
|
32
|
+
import { useCustomTypes } from "../useCustomTypes";
|
|
33
|
+
import { useCustomTypesAutoRevalidation } from "./useCustomTypesAutoRevalidation";
|
|
36
34
|
|
|
37
35
|
type CustomTypesTableProps = {
|
|
38
36
|
format: CustomTypeFormat;
|
|
@@ -1,46 +1,13 @@
|
|
|
1
|
-
import { updateData, useRequest } from "@prismicio/editor-support/Suspense";
|
|
2
1
|
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
3
2
|
import type { CustomTypeFormat } from "@slicemachine/manager";
|
|
4
|
-
import {
|
|
3
|
+
import { useEffect } from "react";
|
|
5
4
|
import { useSelector } from "react-redux";
|
|
6
5
|
|
|
7
6
|
import { CustomTypes } from "@/legacy/lib/models/common/CustomType";
|
|
8
7
|
import { hasLocal } from "@/legacy/lib/models/common/ModelData";
|
|
9
|
-
import { managerClient } from "@/managerClient";
|
|
10
8
|
import { selectAllCustomTypes } from "@/modules/availableCustomTypes";
|
|
11
9
|
import type { SliceMachineStoreType } from "@/redux/type";
|
|
12
10
|
|
|
13
|
-
type UseCustomTypesReturnType = {
|
|
14
|
-
customTypes: CustomType[];
|
|
15
|
-
updateCustomTypes: (customTypes: CustomType[]) => void;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function useCustomTypes(
|
|
19
|
-
format: CustomTypeFormat,
|
|
20
|
-
): UseCustomTypesReturnType {
|
|
21
|
-
const updateCustomTypes = useCallback(
|
|
22
|
-
(data: CustomType[]) => updateData(getCustomTypes, [format], data),
|
|
23
|
-
[format],
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
customTypes: useRequest(getCustomTypes, [format]),
|
|
28
|
-
updateCustomTypes,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function getCustomTypes(format: CustomTypeFormat): Promise<CustomType[]> {
|
|
33
|
-
const { errors, models } = await managerClient.customTypes.readAllCustomTypes(
|
|
34
|
-
{ format },
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (errors.length > 0) {
|
|
38
|
-
throw errors;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return models.map(({ model }) => model);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
11
|
/**
|
|
45
12
|
* TODO: DT-1363 - Update the way to have new data without Redux by revalidating
|
|
46
13
|
* Suspense
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
revalidateData,
|
|
3
|
+
updateData,
|
|
4
|
+
useRequest,
|
|
5
|
+
} from "@prismicio/editor-support/Suspense";
|
|
6
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
7
|
+
import type { CustomTypeFormat } from "@slicemachine/manager";
|
|
8
|
+
import { useCallback } from "react";
|
|
9
|
+
|
|
10
|
+
import { managerClient } from "@/managerClient";
|
|
11
|
+
|
|
12
|
+
type UseCustomTypesReturnType = {
|
|
13
|
+
customTypes: CustomType[];
|
|
14
|
+
updateCustomTypes: (customTypes: CustomType[]) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function useCustomTypes(
|
|
18
|
+
format?: CustomTypeFormat,
|
|
19
|
+
): UseCustomTypesReturnType {
|
|
20
|
+
const updateCustomTypes = useCallback(
|
|
21
|
+
(data: CustomType[]) => updateData(getCustomTypes, [format], data),
|
|
22
|
+
[format],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
customTypes: useRequest(getCustomTypes, [format]),
|
|
27
|
+
updateCustomTypes,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function getCustomTypes(
|
|
32
|
+
format?: CustomTypeFormat,
|
|
33
|
+
): Promise<CustomType[]> {
|
|
34
|
+
const { errors, models } = await managerClient.customTypes.readAllCustomTypes(
|
|
35
|
+
format ? { format } : undefined,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (errors.length > 0) {
|
|
39
|
+
throw errors;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return models.map(({ model }) => model);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function revalidateGetCustomTypes(format?: CustomTypeFormat) {
|
|
46
|
+
void revalidateData(getCustomTypes, []);
|
|
47
|
+
void revalidateData(getCustomTypes, [format]);
|
|
48
|
+
}
|
|
@@ -3,7 +3,7 @@ import { FormikProps } from "formik";
|
|
|
3
3
|
import { Box } from "theme-ui";
|
|
4
4
|
import * as yup from "yup";
|
|
5
5
|
|
|
6
|
-
import { ContentRelationshipFieldPicker } from "@/features/
|
|
6
|
+
import { ContentRelationshipFieldPicker } from "@/features/builder/fields/ContentRelationshipFieldPicker";
|
|
7
7
|
import { Col, Flex as FlexGrid } from "@/legacy/components/Flex";
|
|
8
8
|
import WidgetFormField from "@/legacy/lib/builders/common/EditModal/Field";
|
|
9
9
|
import { createFieldNameFromKey } from "@/legacy/lib/forms";
|