@firecms/collection_editor 3.0.0-alpha.9 → 3.0.0-beta.10
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/LICENSE +114 -21
- package/dist/ConfigControllerProvider.d.ts +13 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.es.js +5587 -4976
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +6829 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +36 -8
- package/dist/types/collection_inference.d.ts +1 -1
- package/dist/types/config_controller.d.ts +33 -6
- package/dist/types/persisted_collection.d.ts +4 -2
- package/dist/ui/CollectionViewHeaderAction.d.ts +11 -0
- package/dist/{components → ui}/EditorCollectionAction.d.ts +1 -1
- package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
- package/dist/ui/MissingReferenceWidget.d.ts +3 -0
- package/dist/ui/NewCollectionButton.d.ts +1 -0
- package/dist/ui/PropertyAddColumnComponent.d.ts +8 -0
- package/dist/{components → ui}/collection_editor/CollectionDetailsForm.d.ts +3 -2
- package/dist/{components → ui}/collection_editor/CollectionEditorDialog.d.ts +15 -11
- package/dist/{components → ui}/collection_editor/CollectionEditorWelcomeView.d.ts +3 -3
- package/dist/{components → ui}/collection_editor/CollectionPropertiesEditorForm.d.ts +8 -6
- package/dist/{components → ui}/collection_editor/CollectionYupValidation.d.ts +3 -0
- package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
- package/dist/{components → ui}/collection_editor/EnumForm.d.ts +1 -2
- package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
- package/dist/{components → ui}/collection_editor/PropertyEditView.d.ts +21 -11
- package/dist/{components → ui}/collection_editor/PropertyFieldPreview.d.ts +4 -3
- package/dist/{components → ui}/collection_editor/PropertyTree.d.ts +11 -7
- package/dist/{components → ui}/collection_editor/SubcollectionsEditTab.d.ts +3 -3
- package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
- package/dist/{components → ui}/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +14 -0
- package/dist/{components → ui}/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/{components → ui}/collection_editor/properties/BlockPropertyField.d.ts +4 -1
- package/dist/{components → ui}/collection_editor/properties/CommonPropertyFields.d.ts +1 -1
- package/dist/{components → ui}/collection_editor/properties/MapPropertyField.d.ts +4 -1
- package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
- package/dist/{components → ui}/collection_editor/properties/RepeatPropertyField.d.ts +4 -1
- package/dist/{components → ui}/collection_editor/properties/StringPropertyField.d.ts +1 -1
- package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
- package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
- package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
- package/dist/{components → ui}/collection_editor/util.d.ts +1 -0
- package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
- package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
- package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
- package/dist/useCollectionEditorPlugin.d.ts +17 -6
- package/dist/utils/collections.d.ts +6 -0
- package/dist/utils/entities.d.ts +3 -4
- package/package.json +35 -37
- package/src/ConfigControllerProvider.tsx +350 -0
- package/src/index.ts +36 -0
- package/src/types/collection_editor_controller.tsx +53 -0
- package/src/types/collection_inference.ts +3 -0
- package/src/types/config_controller.tsx +60 -0
- package/src/types/config_permissions.ts +20 -0
- package/src/types/persisted_collection.ts +9 -0
- package/src/ui/CollectionViewHeaderAction.tsx +48 -0
- package/src/ui/EditorCollectionAction.tsx +56 -0
- package/src/ui/EditorCollectionActionStart.tsx +88 -0
- package/src/ui/HomePageEditorCollectionAction.tsx +89 -0
- package/src/ui/MissingReferenceWidget.tsx +37 -0
- package/src/ui/NewCollectionButton.tsx +18 -0
- package/src/ui/NewCollectionCard.tsx +48 -0
- package/src/ui/PropertyAddColumnComponent.tsx +47 -0
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +426 -0
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +826 -0
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +214 -0
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +513 -0
- package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
- package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
- package/src/ui/collection_editor/EnumForm.tsx +357 -0
- package/src/ui/collection_editor/GetCodeDialog.tsx +122 -0
- package/src/ui/collection_editor/PropertyEditView.tsx +789 -0
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +204 -0
- package/src/ui/collection_editor/PropertyTree.tsx +254 -0
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +269 -0
- package/src/ui/collection_editor/SwitchControl.tsx +39 -0
- package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
- package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +53 -0
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +299 -0
- package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +144 -0
- package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +40 -0
- package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +110 -0
- package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +89 -0
- package/src/ui/collection_editor/properties/EnumPropertyField.tsx +114 -0
- package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +150 -0
- package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
- package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
- package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +160 -0
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +108 -0
- package/src/ui/collection_editor/properties/StoragePropertyField.tsx +215 -0
- package/src/ui/collection_editor/properties/StringPropertyField.tsx +70 -0
- package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
- package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +45 -0
- package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
- package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +61 -0
- package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +115 -0
- package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +150 -0
- package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
- package/src/ui/collection_editor/templates/blog_template.ts +115 -0
- package/src/ui/collection_editor/templates/pages_template.ts +183 -0
- package/src/ui/collection_editor/templates/products_template.ts +88 -0
- package/src/ui/collection_editor/templates/users_template.ts +42 -0
- package/src/ui/collection_editor/util.ts +28 -0
- package/src/ui/collection_editor/utils/strings.ts +9 -0
- package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
- package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
- package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
- package/src/useCollectionEditorController.tsx +9 -0
- package/src/useCollectionEditorPlugin.tsx +164 -0
- package/src/useCollectionsConfigController.tsx +9 -0
- package/src/utils/arrays.ts +3 -0
- package/src/utils/collections.ts +30 -0
- package/src/utils/entities.ts +38 -0
- package/src/vite-env.d.ts +1 -0
- package/dist/components/collection_editor/PropertySelectItem.d.ts +0 -8
- package/dist/components/collection_editor/SelectIcons.d.ts +0 -6
- package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +0 -4
- package/dist/components/collection_editor/properties/FieldHelperView.d.ts +0 -4
- package/dist/components/collection_editor/templates/blog_template.d.ts +0 -10
- package/dist/components/collection_editor/templates/products_template.d.ts +0 -12
- package/dist/components/collection_editor/templates/users_template.d.ts +0 -7
- package/dist/components/collection_editor/utils/supported_fields.d.ts +0 -3
- package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +0 -3
- package/dist/types/editable_properties.d.ts +0 -10
- package/dist/utils/icons.d.ts +0 -2
- package/dist/utils/synonyms.d.ts +0 -1951
- /package/dist/{components → ui}/HomePageEditorCollectionAction.d.ts +0 -0
- /package/dist/{components → ui}/NewCollectionCard.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/UnsavedChangesDialog.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/BooleanPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/DateTimePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/EnumPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/KeyValuePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/NumberPropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/ReferencePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/StoragePropertyField.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/NumberPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/StringPropertyValidation.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/properties/validation/ValidationPanel.d.ts +0 -0
- /package/dist/{components → ui}/collection_editor/utils/useTraceUpdate.d.ts +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { Field, FormexFieldProps } from "@firecms/formex";
|
|
4
|
+
import { SwitchControl } from "../../SwitchControl";
|
|
5
|
+
|
|
6
|
+
export function AdvancedPropertyValidation({ disabled }: {
|
|
7
|
+
disabled: boolean
|
|
8
|
+
}) {
|
|
9
|
+
|
|
10
|
+
const columnWidth = "columnWidth";
|
|
11
|
+
const hideFromCollection = "hideFromCollection";
|
|
12
|
+
const readOnly = "readOnly";
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
|
|
16
|
+
<div className={"grid grid-cols-12 gap-2"}>
|
|
17
|
+
<div className={"col-span-12"}>
|
|
18
|
+
<Field type="checkbox" name={hideFromCollection}>
|
|
19
|
+
{({ field, form }: FormexFieldProps) => {
|
|
20
|
+
return <SwitchControl
|
|
21
|
+
label={"Hide from collection"}
|
|
22
|
+
disabled={disabled}
|
|
23
|
+
form={form}
|
|
24
|
+
tooltip={"Hide this field from the collection view. It will still be visible in the form view"}
|
|
25
|
+
field={field}/>
|
|
26
|
+
}}
|
|
27
|
+
</Field>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<div className={"col-span-12"}>
|
|
31
|
+
<Field name={readOnly}
|
|
32
|
+
type="checkbox">
|
|
33
|
+
{({ field, form }: FormexFieldProps) => {
|
|
34
|
+
return <SwitchControl
|
|
35
|
+
label={"Read only"}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
tooltip={"Is this a read only field. Display only as a preview"}
|
|
38
|
+
form={form}
|
|
39
|
+
field={field}/>
|
|
40
|
+
}}
|
|
41
|
+
</Field>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { getIn, useFormex } from "@firecms/formex";
|
|
4
|
+
import { DebouncedTextField } from "@firecms/ui";
|
|
5
|
+
import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
|
|
6
|
+
|
|
7
|
+
export function ArrayPropertyValidation({
|
|
8
|
+
max = true,
|
|
9
|
+
min = true,
|
|
10
|
+
disabled
|
|
11
|
+
}: {
|
|
12
|
+
min?: boolean;
|
|
13
|
+
max?: boolean;
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
}) {
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
values,
|
|
19
|
+
handleChange
|
|
20
|
+
} = useFormex();
|
|
21
|
+
|
|
22
|
+
const validationMin = "validation.min";
|
|
23
|
+
const validationMax = "validation.max";
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className={"grid grid-cols-12 gap-2"}>
|
|
27
|
+
|
|
28
|
+
<GeneralPropertyValidation disabled={disabled}/>
|
|
29
|
+
|
|
30
|
+
{min && <div className={"col-span-6"}>
|
|
31
|
+
<DebouncedTextField value={getIn(values, validationMin)}
|
|
32
|
+
disabled={disabled}
|
|
33
|
+
label={"Min length"}
|
|
34
|
+
name={validationMin}
|
|
35
|
+
type="number"
|
|
36
|
+
size="small"
|
|
37
|
+
onChange={handleChange}/>
|
|
38
|
+
</div>}
|
|
39
|
+
{max && <div className={"col-span-6"}>
|
|
40
|
+
<DebouncedTextField value={getIn(values, validationMax)}
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
label={"Max length"}
|
|
43
|
+
name={validationMax}
|
|
44
|
+
type="number"
|
|
45
|
+
size="small"
|
|
46
|
+
onChange={handleChange}/>
|
|
47
|
+
</div>}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
|
|
4
|
+
import { DebouncedTextField } from "@firecms/ui";
|
|
5
|
+
import { SwitchControl } from "../../SwitchControl";
|
|
6
|
+
|
|
7
|
+
export function GeneralPropertyValidation({ disabled }: {
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}) {
|
|
11
|
+
|
|
12
|
+
const { values, handleChange } = useFormex();
|
|
13
|
+
|
|
14
|
+
const validationRequired = "validation.required";
|
|
15
|
+
const validationRequiredMessage = "validation.requiredMessage";
|
|
16
|
+
const validationUnique = "validation.unique";
|
|
17
|
+
const validationUniqueInArray = "validation.uniqueInArray";
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<div className={"col-span-6"}>
|
|
22
|
+
<Field name={validationRequired}
|
|
23
|
+
type="checkbox">
|
|
24
|
+
{({ field, form }: FormexFieldProps) => {
|
|
25
|
+
return <SwitchControl
|
|
26
|
+
disabled={disabled}
|
|
27
|
+
label={"Required"}
|
|
28
|
+
tooltip={"You won't be able to save this entity if this value is not set"}
|
|
29
|
+
form={form}
|
|
30
|
+
field={field}/>
|
|
31
|
+
}}
|
|
32
|
+
</Field>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div className={"col-span-6"}>
|
|
36
|
+
|
|
37
|
+
<Field name={validationUnique}
|
|
38
|
+
type="checkbox">
|
|
39
|
+
{({ field, form }: FormexFieldProps) => {
|
|
40
|
+
return <SwitchControl
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
label={"Unique"}
|
|
43
|
+
tooltip={"There cannot be multiple entities with the same value"}
|
|
44
|
+
form={form}
|
|
45
|
+
field={field}/>
|
|
46
|
+
}}
|
|
47
|
+
</Field>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
{getIn(values, validationRequired) && <div className={"col-span-12"}>
|
|
51
|
+
<DebouncedTextField
|
|
52
|
+
disabled={disabled}
|
|
53
|
+
value={getIn(values, validationRequiredMessage)}
|
|
54
|
+
label={"Required message"}
|
|
55
|
+
name={validationRequiredMessage}
|
|
56
|
+
size="small"
|
|
57
|
+
onChange={handleChange}/>
|
|
58
|
+
</div>}
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
|
|
4
|
+
import { DebouncedTextField } from "@firecms/ui";
|
|
5
|
+
import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
|
|
6
|
+
import { SwitchControl } from "../../SwitchControl";
|
|
7
|
+
|
|
8
|
+
export function NumberPropertyValidation({ disabled }: {
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}) {
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
values,
|
|
14
|
+
handleChange
|
|
15
|
+
} = useFormex();
|
|
16
|
+
|
|
17
|
+
const validationMin = "validation.min";
|
|
18
|
+
const validationMax = "validation.max";
|
|
19
|
+
const validationLessThan = "validation.lessThan";
|
|
20
|
+
const validationMoreThan = "validation.moreThan";
|
|
21
|
+
const validationPositive = "validation.positive";
|
|
22
|
+
const validationNegative = "validation.negative";
|
|
23
|
+
const validationInteger = "validation.integer";
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
|
|
27
|
+
<div className={"grid grid-cols-12 gap-2"}>
|
|
28
|
+
<GeneralPropertyValidation disabled={disabled}/>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<div className={"col-span-6"}>
|
|
32
|
+
<DebouncedTextField value={getIn(values, validationMin)}
|
|
33
|
+
label={"Min value"}
|
|
34
|
+
name={validationMin}
|
|
35
|
+
type="number"
|
|
36
|
+
size="small"
|
|
37
|
+
disabled={disabled}
|
|
38
|
+
onChange={handleChange}/>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div className={"col-span-6"}>
|
|
42
|
+
<DebouncedTextField value={getIn(values, validationMax)}
|
|
43
|
+
label={"Max value"}
|
|
44
|
+
name={validationMax}
|
|
45
|
+
type="number"
|
|
46
|
+
size="small"
|
|
47
|
+
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
onChange={handleChange}/>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
<div className={"col-span-6"}>
|
|
54
|
+
<DebouncedTextField
|
|
55
|
+
value={getIn(values, validationLessThan)}
|
|
56
|
+
label={"Less than"}
|
|
57
|
+
name={validationLessThan}
|
|
58
|
+
type="number"
|
|
59
|
+
size="small"
|
|
60
|
+
|
|
61
|
+
disabled={disabled}
|
|
62
|
+
onChange={handleChange}/>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div className={"col-span-6"}>
|
|
66
|
+
<DebouncedTextField
|
|
67
|
+
value={getIn(values, validationMoreThan)}
|
|
68
|
+
label={"More than"}
|
|
69
|
+
name={validationMoreThan}
|
|
70
|
+
type="number"
|
|
71
|
+
size="small"
|
|
72
|
+
|
|
73
|
+
disabled={disabled}
|
|
74
|
+
onChange={handleChange}/>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div className={"col-span-4"}>
|
|
78
|
+
<Field name={validationPositive}
|
|
79
|
+
type="checkbox">
|
|
80
|
+
{({ field, form }: FormexFieldProps) => {
|
|
81
|
+
return <SwitchControl
|
|
82
|
+
label={"Positive value"}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
form={form}
|
|
85
|
+
field={field}/>
|
|
86
|
+
}}
|
|
87
|
+
</Field>
|
|
88
|
+
</div>
|
|
89
|
+
<div className={"col-span-4"}>
|
|
90
|
+
<Field name={validationNegative}
|
|
91
|
+
type="checkbox">
|
|
92
|
+
{({ field, form }: FormexFieldProps) => {
|
|
93
|
+
return <SwitchControl
|
|
94
|
+
label={"Negative value"}
|
|
95
|
+
disabled={disabled}
|
|
96
|
+
form={form}
|
|
97
|
+
field={field}/>
|
|
98
|
+
}}
|
|
99
|
+
</Field>
|
|
100
|
+
</div>
|
|
101
|
+
<div className={"col-span-4"}>
|
|
102
|
+
<Field name={validationInteger}
|
|
103
|
+
type="checkbox">
|
|
104
|
+
{({ field, form }: FormexFieldProps) => {
|
|
105
|
+
return <SwitchControl
|
|
106
|
+
label={"Integer value"}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
form={form}
|
|
109
|
+
field={field}/>
|
|
110
|
+
}}
|
|
111
|
+
</Field>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { Field, FormexFieldProps, getIn, useFormex } from "@firecms/formex";
|
|
4
|
+
import { FieldCaption, serializeRegExp } from "@firecms/core";
|
|
5
|
+
import { DebouncedTextField, } from "@firecms/ui";
|
|
6
|
+
import { GeneralPropertyValidation } from "./GeneralPropertyValidation";
|
|
7
|
+
import { SwitchControl } from "../../SwitchControl";
|
|
8
|
+
|
|
9
|
+
export function StringPropertyValidation({
|
|
10
|
+
length,
|
|
11
|
+
lowercase,
|
|
12
|
+
matches,
|
|
13
|
+
max,
|
|
14
|
+
min,
|
|
15
|
+
trim,
|
|
16
|
+
uppercase,
|
|
17
|
+
disabled,
|
|
18
|
+
showErrors
|
|
19
|
+
}: {
|
|
20
|
+
length?: boolean;
|
|
21
|
+
min?: boolean;
|
|
22
|
+
max?: boolean;
|
|
23
|
+
trim?: boolean;
|
|
24
|
+
matches?: boolean;
|
|
25
|
+
lowercase?: boolean;
|
|
26
|
+
uppercase?: boolean;
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
showErrors: boolean;
|
|
29
|
+
}) {
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
values,
|
|
33
|
+
handleChange,
|
|
34
|
+
errors
|
|
35
|
+
} = useFormex();
|
|
36
|
+
|
|
37
|
+
const validationLength = "validation.length";
|
|
38
|
+
const validationMin = "validation.min";
|
|
39
|
+
const validationMax = "validation.max";
|
|
40
|
+
const validationTrim = "validation.trim";
|
|
41
|
+
const validationMatches = "validation.matches";
|
|
42
|
+
const validationLowercase = "validation.lowercase";
|
|
43
|
+
const validationUppercase = "validation.uppercase";
|
|
44
|
+
|
|
45
|
+
const matchesError = getIn(errors, validationMatches);
|
|
46
|
+
|
|
47
|
+
const matchesValue = getIn(values, validationMatches);
|
|
48
|
+
const matchesStringValue = typeof matchesValue === "string" ? matchesValue : serializeRegExp(matchesValue);
|
|
49
|
+
return (
|
|
50
|
+
<div className={"grid grid-cols-12 gap-2"}>
|
|
51
|
+
|
|
52
|
+
<GeneralPropertyValidation disabled={disabled}/>
|
|
53
|
+
|
|
54
|
+
<div className={"grid grid-cols-12 gap-2 col-span-12"}>
|
|
55
|
+
|
|
56
|
+
{lowercase && <div className={"col-span-4"}>
|
|
57
|
+
<Field name={validationLowercase}
|
|
58
|
+
type="checkbox">
|
|
59
|
+
{({ field, form }: FormexFieldProps) => {
|
|
60
|
+
return <SwitchControl
|
|
61
|
+
label={"Lowercase"}
|
|
62
|
+
disabled={disabled}
|
|
63
|
+
form={form}
|
|
64
|
+
field={field}/>
|
|
65
|
+
}}
|
|
66
|
+
</Field>
|
|
67
|
+
</div>}
|
|
68
|
+
|
|
69
|
+
{uppercase && <div className={"col-span-4"}>
|
|
70
|
+
<Field name={validationUppercase}
|
|
71
|
+
type="checkbox">
|
|
72
|
+
{({ field, form }: FormexFieldProps) => {
|
|
73
|
+
return <SwitchControl
|
|
74
|
+
label={"Uppercase"}
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
form={form}
|
|
77
|
+
field={field}/>
|
|
78
|
+
}}
|
|
79
|
+
</Field>
|
|
80
|
+
</div>}
|
|
81
|
+
|
|
82
|
+
{trim && <div className={"col-span-4"}>
|
|
83
|
+
<Field name={validationTrim}
|
|
84
|
+
type="checkbox">
|
|
85
|
+
{({ field, form }: FormexFieldProps) => {
|
|
86
|
+
return <SwitchControl
|
|
87
|
+
label={"Trim"}
|
|
88
|
+
disabled={disabled}
|
|
89
|
+
form={form}
|
|
90
|
+
field={field}/>
|
|
91
|
+
}}
|
|
92
|
+
</Field>
|
|
93
|
+
</div>}
|
|
94
|
+
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div className={"grid grid-cols-12 gap-2 col-span-12"}>
|
|
98
|
+
{length && <div className={"col-span-4"}>
|
|
99
|
+
<DebouncedTextField
|
|
100
|
+
value={getIn(values, validationLength)}
|
|
101
|
+
label={"Exact length"}
|
|
102
|
+
name={validationLength}
|
|
103
|
+
type="number"
|
|
104
|
+
size="small"
|
|
105
|
+
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
onChange={handleChange}/>
|
|
108
|
+
</div>}
|
|
109
|
+
|
|
110
|
+
{min && <div className={"col-span-4"}>
|
|
111
|
+
<DebouncedTextField value={getIn(values, validationMin)}
|
|
112
|
+
label={"Min length"}
|
|
113
|
+
name={validationMin}
|
|
114
|
+
type="number"
|
|
115
|
+
size="small"
|
|
116
|
+
|
|
117
|
+
disabled={disabled}
|
|
118
|
+
onChange={handleChange}/>
|
|
119
|
+
</div>}
|
|
120
|
+
|
|
121
|
+
{max && <div className={"col-span-4"}>
|
|
122
|
+
<DebouncedTextField value={getIn(values, validationMax)}
|
|
123
|
+
label={"Max length"}
|
|
124
|
+
name={validationMax}
|
|
125
|
+
type="number"
|
|
126
|
+
size="small"
|
|
127
|
+
|
|
128
|
+
disabled={disabled}
|
|
129
|
+
onChange={handleChange}/>
|
|
130
|
+
</div>}
|
|
131
|
+
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
{matches && <div className={"col-span-12"}>
|
|
135
|
+
<Field name={validationMatches}
|
|
136
|
+
as={DebouncedTextField}
|
|
137
|
+
label={"Matches regex"}
|
|
138
|
+
size="small"
|
|
139
|
+
disabled={disabled}
|
|
140
|
+
value={matchesStringValue}
|
|
141
|
+
error={Boolean(matchesError)}/>
|
|
142
|
+
<FieldCaption error={Boolean(matchesError)}>
|
|
143
|
+
{matchesError ? "Not a valid regexp" : "e.g. /^\\d+$/ for digits only"}
|
|
144
|
+
</FieldCaption>
|
|
145
|
+
</div>}
|
|
146
|
+
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
|
|
3
|
+
import { ExpandablePanel, RuleIcon, Typography } from "@firecms/ui";
|
|
4
|
+
|
|
5
|
+
export function ValidationPanel({
|
|
6
|
+
children
|
|
7
|
+
}: PropsWithChildren<{}>) {
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<ExpandablePanel
|
|
11
|
+
initiallyExpanded={false}
|
|
12
|
+
asField={true}
|
|
13
|
+
innerClassName="p-4"
|
|
14
|
+
title={
|
|
15
|
+
<div className="flex flex-row text-gray-500">
|
|
16
|
+
<RuleIcon/>
|
|
17
|
+
<Typography variant={"subtitle2"}
|
|
18
|
+
className="ml-2">
|
|
19
|
+
Validation
|
|
20
|
+
</Typography>
|
|
21
|
+
</div>
|
|
22
|
+
}>
|
|
23
|
+
|
|
24
|
+
{children}
|
|
25
|
+
|
|
26
|
+
</ExpandablePanel>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { EntityCollection, makePropertiesEditable } from "@firecms/core";
|
|
2
|
+
|
|
3
|
+
export const blogCollectionTemplate:EntityCollection = {
|
|
4
|
+
id: "blog",
|
|
5
|
+
path: "blog",
|
|
6
|
+
name: "Blog",
|
|
7
|
+
singularName: "Blog entry",
|
|
8
|
+
icon: "article",
|
|
9
|
+
description: "A collection of blog entries",
|
|
10
|
+
defaultSize: "l",
|
|
11
|
+
properties: makePropertiesEditable({
|
|
12
|
+
name: {
|
|
13
|
+
name: "Name",
|
|
14
|
+
validation: { required: true },
|
|
15
|
+
dataType: "string"
|
|
16
|
+
},
|
|
17
|
+
header_image: {
|
|
18
|
+
name: "Header image",
|
|
19
|
+
dataType: "string",
|
|
20
|
+
storage: {
|
|
21
|
+
storagePath: "images",
|
|
22
|
+
acceptedFiles: ["image/*"],
|
|
23
|
+
metadata: {
|
|
24
|
+
cacheControl: "max-age=1000000"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
content: {
|
|
29
|
+
name: "Content",
|
|
30
|
+
description: "Content blocks for the blog entry",
|
|
31
|
+
validation: { required: true },
|
|
32
|
+
dataType: "array",
|
|
33
|
+
oneOf: {
|
|
34
|
+
typeField: "type",
|
|
35
|
+
valueField: "value",
|
|
36
|
+
properties: {
|
|
37
|
+
text: {
|
|
38
|
+
dataType: "string",
|
|
39
|
+
name: "Text",
|
|
40
|
+
markdown: true
|
|
41
|
+
},
|
|
42
|
+
quote: {
|
|
43
|
+
dataType: "string",
|
|
44
|
+
name: "Quote",
|
|
45
|
+
multiline: true
|
|
46
|
+
},
|
|
47
|
+
images: {
|
|
48
|
+
name: "Images",
|
|
49
|
+
dataType: "array",
|
|
50
|
+
of: {
|
|
51
|
+
dataType: "string",
|
|
52
|
+
storage: {
|
|
53
|
+
storagePath: "images",
|
|
54
|
+
acceptedFiles: ["image/*"],
|
|
55
|
+
metadata: {
|
|
56
|
+
cacheControl: "max-age=1000000"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
description: "This fields allows uploading multiple images at once and reordering"
|
|
61
|
+
},
|
|
62
|
+
products: {
|
|
63
|
+
name: "Products",
|
|
64
|
+
dataType: "array",
|
|
65
|
+
of: {
|
|
66
|
+
dataType: "reference",
|
|
67
|
+
path: "products",
|
|
68
|
+
previewProperties: ["name", "main_image"]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
propertiesOrder: ["text", "quote", "images", "products"]
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
created_on: {
|
|
76
|
+
name: "Created on",
|
|
77
|
+
dataType: "date",
|
|
78
|
+
autoValue: "on_create"
|
|
79
|
+
},
|
|
80
|
+
status: {
|
|
81
|
+
name: "Status",
|
|
82
|
+
validation: { required: true },
|
|
83
|
+
dataType: "string",
|
|
84
|
+
enumValues: {
|
|
85
|
+
published: {
|
|
86
|
+
id: "published",
|
|
87
|
+
label: "Published",
|
|
88
|
+
},
|
|
89
|
+
draft: "Draft"
|
|
90
|
+
},
|
|
91
|
+
defaultValue: "draft"
|
|
92
|
+
},
|
|
93
|
+
publish_date: {
|
|
94
|
+
name: "Publish date",
|
|
95
|
+
dataType: "date",
|
|
96
|
+
clearable: true
|
|
97
|
+
},
|
|
98
|
+
reviewed: {
|
|
99
|
+
name: "Reviewed",
|
|
100
|
+
dataType: "boolean"
|
|
101
|
+
},
|
|
102
|
+
tags: {
|
|
103
|
+
name: "Tags",
|
|
104
|
+
description: "Example of generic array",
|
|
105
|
+
dataType: "array",
|
|
106
|
+
of: {
|
|
107
|
+
dataType: "string",
|
|
108
|
+
previewAsTag: true
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}),
|
|
112
|
+
initialFilter: {
|
|
113
|
+
status: ["==", "published"]
|
|
114
|
+
}
|
|
115
|
+
};
|