@firecms/collection_editor 3.0.0-canary.14 → 3.0.0-canary.140

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.
Files changed (62) hide show
  1. package/LICENSE +114 -21
  2. package/dist/ConfigControllerProvider.d.ts +11 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.es.js +4898 -3532
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +6827 -3
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +14 -2
  9. package/dist/types/collection_inference.d.ts +1 -1
  10. package/dist/ui/CollectionViewHeaderAction.d.ts +3 -2
  11. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  12. package/dist/ui/PropertyAddColumnComponent.d.ts +3 -1
  13. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +4 -3
  14. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
  15. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
  16. package/dist/ui/collection_editor/PropertyEditView.d.ts +8 -0
  17. package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
  18. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
  19. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
  20. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  21. package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
  22. package/dist/useCollectionEditorPlugin.d.ts +15 -9
  23. package/dist/utils/collections.d.ts +6 -0
  24. package/package.json +21 -35
  25. package/src/ConfigControllerProvider.tsx +75 -63
  26. package/src/index.ts +1 -0
  27. package/src/types/collection_editor_controller.tsx +14 -4
  28. package/src/types/collection_inference.ts +1 -1
  29. package/src/ui/CollectionViewHeaderAction.tsx +9 -4
  30. package/src/ui/EditorCollectionAction.tsx +10 -63
  31. package/src/ui/EditorCollectionActionStart.tsx +88 -0
  32. package/src/ui/HomePageEditorCollectionAction.tsx +18 -13
  33. package/src/ui/NewCollectionButton.tsx +12 -10
  34. package/src/ui/NewCollectionCard.tsx +3 -3
  35. package/src/ui/PropertyAddColumnComponent.tsx +9 -4
  36. package/src/ui/collection_editor/CollectionDetailsForm.tsx +69 -8
  37. package/src/ui/collection_editor/CollectionEditorDialog.tsx +57 -32
  38. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +6 -5
  39. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +34 -27
  40. package/src/ui/collection_editor/GetCodeDialog.tsx +15 -3
  41. package/src/ui/collection_editor/PropertyEditView.tsx +252 -78
  42. package/src/ui/collection_editor/PropertyFieldPreview.tsx +3 -6
  43. package/src/ui/collection_editor/PropertyTree.tsx +7 -5
  44. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +26 -19
  45. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +25 -9
  46. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +40 -9
  47. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +31 -19
  48. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +50 -47
  49. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +1 -1
  50. package/src/ui/collection_editor/properties/MapPropertyField.tsx +5 -5
  51. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  52. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
  53. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +31 -16
  54. package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -10
  55. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +1 -1
  56. package/src/ui/collection_editor/templates/pages_template.ts +1 -6
  57. package/src/useCollectionEditorPlugin.tsx +37 -27
  58. package/src/utils/collections.ts +30 -0
  59. package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
  60. package/dist/ui/collection_editor/PropertySelectItem.d.ts +0 -8
  61. package/src/ui/RootCollectionSuggestions.tsx +0 -63
  62. package/src/ui/collection_editor/PropertySelectItem.tsx +0 -32
@@ -1,21 +1,33 @@
1
- import { convertDataToEntity, getPropertiesMapping, ImportConfig } from "@firecms/data_import_export";
2
- import { EntityCollectionTable, Properties, useSelectionController } from "@firecms/core";
3
- import { useEffect } from "react";
1
+ import { convertDataToEntity, ImportConfig } from "@firecms/data_import_export";
2
+ import { CircularProgressCenter, EntityCollectionTable, Properties, useSelectionController } from "@firecms/core";
3
+ import { useEffect, useState } from "react";
4
4
  import { Typography } from "@firecms/ui";
5
5
 
6
- export function CollectionEditorImportDataPreview({ importConfig, properties, propertiesOrder }: {
6
+ export function CollectionEditorImportDataPreview({
7
+ importConfig,
8
+ properties,
9
+ propertiesOrder
10
+ }: {
7
11
  importConfig: ImportConfig,
8
12
  properties: Properties,
9
13
  propertiesOrder: string[]
10
14
  }) {
11
15
 
12
- useEffect(() => {
13
- const propertiesMapping = getPropertiesMapping(importConfig.originProperties, properties);
14
- const mappedData = importConfig.importData.map(d => convertDataToEntity(d, importConfig.idColumn, importConfig.headersMapping, properties, propertiesMapping, "TEMP_PATH"));
16
+ const [loading, setLoading] = useState<boolean>(false);
17
+
18
+ async function loadEntities() {
19
+ // const propertiesMapping = getPropertiesMapping(importConfig.originProperties, properties, importConfig.headersMapping);
20
+ const mappedData = importConfig.importData.map(d => convertDataToEntity(d, importConfig.idColumn, importConfig.headersMapping, properties, "TEMP_PATH", importConfig.defaultValues));
15
21
  importConfig.setEntities(mappedData);
22
+ }
23
+
24
+ useEffect(() => {
25
+ loadEntities().finally(() => setLoading(false));
16
26
  }, []);
17
27
 
18
28
  const selectionController = useSelectionController();
29
+ if (loading)
30
+ return <CircularProgressCenter/>
19
31
 
20
32
  return <EntityCollectionTable
21
33
  title={<div>
@@ -31,7 +43,11 @@ export function CollectionEditorImportDataPreview({ importConfig, properties, pr
31
43
  filterable={false}
32
44
  sortable={false}
33
45
  selectionController={selectionController}
34
- displayedColumnIds={propertiesOrder.map(p => ({ key: p, disabled: false }))}
35
- properties={properties}/>
46
+ displayedColumnIds={propertiesOrder.map(p => ({
47
+ key: p,
48
+ disabled: false
49
+ }))}
50
+ properties={properties}
51
+ enablePopupIcon={false}/>
36
52
 
37
53
  }
@@ -6,14 +6,13 @@ import {
6
6
  } from "@firecms/data_import_export";
7
7
  import { getIn, useFormex } from "@firecms/formex";
8
8
 
9
- import { PropertyConfigBadge, getFieldConfig, getFieldId, Properties, Property, PropertyConfig, } from "@firecms/core";
10
- import { Container, Select, Tooltip, Typography } from "@firecms/ui";
9
+ import { getFieldConfig, getFieldId, Properties, Property, PropertyConfig, PropertyConfigBadge, } from "@firecms/core";
10
+ import { cls, Container, Select, SelectItem, Tooltip, Typography } from "@firecms/ui";
11
11
  import React, { useState } from "react";
12
12
  import { OnPropertyChangedParams, PropertyFormDialog, PropertyWithId } from "../PropertyEditView";
13
13
  import { getFullId, idToPropertiesPath, namespaceToPropertiesOrderPath } from "../util";
14
14
  import { PersistedCollection } from "../../../types/persisted_collection";
15
15
  import { updatePropertyFromWidget } from "../utils/update_property_for_widget";
16
- import { PropertySelectItem } from "../PropertySelectItem";
17
16
  import { supportedFields } from "../utils/supported_fields";
18
17
  import { buildPropertyFromData } from "@firecms/schema_inference";
19
18
 
@@ -143,18 +142,20 @@ export function CollectionEditorImportMapping({
143
142
  <div className={"overflow-auto my-auto"}>
144
143
  <Container maxWidth={"6xl"} className={"flex flex-col gap-4 p-8 m-auto"}>
145
144
 
146
- <Typography variant="h6" className={"mt-4"}>Data property mapping</Typography>
145
+ <Typography variant="h6" className={"my-4 ml-3.5"}>Data property mapping</Typography>
147
146
 
148
- <DataNewPropertiesMapping headersMapping={importConfig.headersMapping}
149
- idColumn={importConfig.idColumn}
150
- originProperties={importConfig.originProperties}
147
+ <DataNewPropertiesMapping importConfig={importConfig}
151
148
  destinationProperties={values.properties as Properties}
152
- onIdPropertyChanged={(value) => importConfig.setIdColumn(value ?? undefined)}
153
149
  buildPropertyView={({
154
150
  property,
155
151
  propertyKey,
156
- importKey
152
+ importKey,
153
+ isIdColumn
157
154
  }) => {
155
+ if (isIdColumn) {
156
+ return <Typography> This column will be used as ID</Typography>
157
+ }
158
+
158
159
  return <ImportNewPropertyFieldPreview
159
160
  property={property}
160
161
  propertyKey={propertyKey}
@@ -266,3 +267,33 @@ function PropertySelect({
266
267
  </Select>
267
268
  </Tooltip>;
268
269
  }
270
+
271
+ export interface PropertySelectItemProps {
272
+ value: string;
273
+ optionDisabled: boolean;
274
+ propertyConfig: PropertyConfig;
275
+ existing: boolean;
276
+ }
277
+
278
+ export function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps) {
279
+ return <SelectItem value={value}
280
+ disabled={optionDisabled}
281
+ className={"flex flex-row items-center"}>
282
+ <div
283
+ className={cls(
284
+ "flex flex-row items-center text-base min-h-[48px]",
285
+ optionDisabled ? "w-full" : "")}>
286
+ <div className={"mr-8"}>
287
+ <PropertyConfigBadge propertyConfig={propertyConfig}/>
288
+ </div>
289
+ <div>
290
+ <div>{propertyConfig.name}</div>
291
+ <Typography variant={"caption"}
292
+ color={"disabled"}
293
+ className={"max-w-sm"}>
294
+ {existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description}
295
+ </Typography>
296
+ </div>
297
+ </div>
298
+ </SelectItem>
299
+ }
@@ -1,12 +1,24 @@
1
- import React, { useCallback, useState } from "react";
1
+ import React, { useState } from "react";
2
2
  import { AddIcon, Button, Paper, Typography } from "@firecms/ui";
3
3
  import { getIn, useFormex } from "@firecms/formex";
4
- import { PropertyFormDialog } from "../PropertyEditView";
5
- import { getFullId, idToPropertiesPath, namespaceToPropertiesOrderPath } from "../util";
4
+ import { OnPropertyChangedParams, PropertyFormDialog } from "../PropertyEditView";
5
+ import {
6
+ getFullId,
7
+ getFullIdPath,
8
+ idToPropertiesPath,
9
+ namespaceToPropertiesOrderPath,
10
+ namespaceToPropertiesPath
11
+ } from "../util";
6
12
  import { PropertyTree } from "../PropertyTree";
7
- import { ArrayProperty, Property, PropertyConfig } from "@firecms/core";
8
-
9
- export function BlockPropertyField({ disabled, getData, allowDataInference, propertyConfigs, collectionEditable }: {
13
+ import { ArrayProperty, PropertyConfig } from "@firecms/core";
14
+
15
+ export function BlockPropertyField({
16
+ disabled,
17
+ getData,
18
+ allowDataInference,
19
+ propertyConfigs,
20
+ collectionEditable
21
+ }: {
10
22
  disabled: boolean;
11
23
  getData?: () => Promise<object[]>;
12
24
  allowDataInference: boolean;
@@ -25,38 +37,37 @@ export function BlockPropertyField({ disabled, getData, allowDataInference, prop
25
37
 
26
38
  const onPropertyChanged = ({
27
39
  id,
40
+ namespace,
28
41
  property
29
- }: { id?: string, property: Property }) => {
42
+ }: OnPropertyChangedParams) => {
30
43
  if (!id)
31
44
  throw Error();
32
45
 
33
- setFieldValue("oneOf.properties", {
34
- ...(values.oneOf?.properties ?? {}),
35
- [id]: property
36
- }, false);
46
+ setFieldValue("oneOf." + getFullIdPath(id, namespace), property, false);
47
+
37
48
  const currentPropertiesOrder = values.oneOf?.propertiesOrder ?? Object.keys(values.oneOf?.properties ?? {});
38
49
  const newPropertiesOrder = currentPropertiesOrder.includes(id) ? currentPropertiesOrder : [...currentPropertiesOrder, id];
39
- setFieldValue("oneOf.propertiesOrder", newPropertiesOrder, false);
50
+ setFieldValue("oneOf." + namespaceToPropertiesOrderPath(namespace), newPropertiesOrder, false);
40
51
  setPropertyDialogOpen(false);
41
52
  };
42
53
 
43
54
  const selectedPropertyFullId = selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : undefined;
44
55
  const selectedProperty = selectedPropertyFullId ? getIn(values.oneOf?.properties, selectedPropertyFullId.replaceAll(".", ".properties.")) : undefined;
45
56
 
46
- const deleteProperty = useCallback((propertyKey?: string, namespace?: string) => {
57
+ const deleteProperty = (propertyKey?: string, namespace?: string) => {
47
58
  const fullId = propertyKey ? getFullId(propertyKey, namespace) : undefined;
48
59
  if (!fullId)
49
60
  throw Error("collection editor miss config");
50
61
 
51
62
  setFieldValue(`oneOf.${idToPropertiesPath(fullId)}`, undefined, false);
52
63
  const propertiesOrderPath = `oneOf.${namespaceToPropertiesOrderPath(namespace)}`;
53
- const currentPropertiesOrder: string[] = getIn(values, propertiesOrderPath);
64
+ const currentPropertiesOrder: string[] = getIn(values, propertiesOrderPath) ?? Object.keys(getIn(values, namespaceToPropertiesPath(namespace)));
54
65
  setFieldValue(propertiesOrderPath, currentPropertiesOrder.filter((p) => p !== propertyKey), false);
55
66
 
56
67
  setPropertyDialogOpen(false);
57
68
  setSelectedPropertyKey(undefined);
58
69
  setSelectedPropertyNamespace(undefined);
59
- }, [setFieldValue, values]);
70
+ };
60
71
 
61
72
  const addChildButton = <Button
62
73
  autoFocus
@@ -68,16 +79,17 @@ export function BlockPropertyField({ disabled, getData, allowDataInference, prop
68
79
  Add property to {values.name ?? "this block"}
69
80
  </Button>;
70
81
 
71
- const onPropertyMove = useCallback((propertiesOrder: string[], namespace?: string) => {
82
+ const onPropertyMove = (propertiesOrder: string[], namespace?: string) => {
72
83
  setFieldValue(`oneOf.${namespaceToPropertiesOrderPath(namespace)}`, propertiesOrder, false);
73
- }, []);
84
+ };
74
85
 
75
86
  return (
76
87
  <>
77
88
  <div className={"col-span-12"}>
78
89
  <div className={"flex justify-between items-end mt-8 mb-4"}>
79
- <Typography variant={"subtitle2"}>Properties in this
80
- block</Typography>
90
+ <Typography variant={"subtitle2"}>
91
+ Properties in this block
92
+ </Typography>
81
93
  {addChildButton}
82
94
  </div>
83
95
  <Paper className="p-2 pl-8">
@@ -26,53 +26,56 @@ export function DateTimePropertyField({ disabled }: {
26
26
 
27
27
  return (
28
28
  <>
29
- <div className={"flex flex-col col-span-12"}>
30
- <Select name={modePath}
31
- value={modeValue ?? "date"}
32
- error={Boolean(modeError)}
33
- onValueChange={(v) => setFieldValue(modePath, v)}
34
- label={"Mode"}
35
- renderValue={(v) => {
36
- switch (v) {
37
- case "date_time":
38
- return "Date/Time";
39
- case "date":
40
- return "Date";
41
- default:
42
- return "";
43
- }
44
- }}
45
- disabled={disabled}>
46
- <SelectItem value={"date_time"}> Date/Time </SelectItem>
47
- <SelectItem value={"date"}> Date </SelectItem>
48
- </Select>
49
- <FieldCaption error={Boolean(modeError)}>
50
- {modeError}
51
- </FieldCaption>
52
-
53
- <Select name={autoValuePath}
54
- disabled={disabled}
55
- value={autoValueValue ?? ""}
56
- onValueChange={(v) => setFieldValue(autoValuePath, v === "none" ? null : v)}
57
- renderValue={(v) => {
58
- switch (v) {
59
- case "on_create":
60
- return "On create";
61
- case "on_update":
62
- return "On any update";
63
- default:
64
- return "None";
65
- }
66
- }}
67
- error={Boolean(autoValueError)}
68
- label={"Automatic value"}>
69
- <SelectItem value={"none"}> None </SelectItem>
70
- <SelectItem value={"on_create"}> On create </SelectItem>
71
- <SelectItem value={"on_update"}> On any update </SelectItem>
72
- </Select>
73
- <FieldCaption error={Boolean(autoValueError)}>
74
- {autoValueError ?? "Update this field automatically when creating or updating the entity"}
75
- </FieldCaption>
29
+ <div className={"flex flex-col col-span-12 gap-2"}>
30
+ <div>
31
+ <Select name={modePath}
32
+ value={modeValue ?? "date"}
33
+ error={Boolean(modeError)}
34
+ onValueChange={(v) => setFieldValue(modePath, v)}
35
+ label={"Mode"}
36
+ renderValue={(v) => {
37
+ switch (v) {
38
+ case "date_time":
39
+ return "Date/Time";
40
+ case "date":
41
+ return "Date";
42
+ default:
43
+ return "";
44
+ }
45
+ }}
46
+ disabled={disabled}>
47
+ <SelectItem value={"date_time"}> Date/Time </SelectItem>
48
+ <SelectItem value={"date"}> Date </SelectItem>
49
+ </Select>
50
+ <FieldCaption error={Boolean(modeError)}>
51
+ {modeError}
52
+ </FieldCaption>
53
+ </div>
54
+ <div>
55
+ <Select name={autoValuePath}
56
+ disabled={disabled}
57
+ value={autoValueValue ?? ""}
58
+ onValueChange={(v) => setFieldValue(autoValuePath, v === "none" ? null : v)}
59
+ renderValue={(v) => {
60
+ switch (v) {
61
+ case "on_create":
62
+ return "On create";
63
+ case "on_update":
64
+ return "On any update";
65
+ default:
66
+ return "None";
67
+ }
68
+ }}
69
+ error={Boolean(autoValueError)}
70
+ label={"Automatic value"}>
71
+ <SelectItem value={"none"}> None </SelectItem>
72
+ <SelectItem value={"on_create"}> On create </SelectItem>
73
+ <SelectItem value={"on_update"}> On any update </SelectItem>
74
+ </Select>
75
+ <FieldCaption error={Boolean(autoValueError)}>
76
+ {autoValueError ?? "Update this field automatically when creating or updating the entity"}
77
+ </FieldCaption>
78
+ </div>
76
79
 
77
80
  </div>
78
81
 
@@ -71,7 +71,7 @@ export function EnumPropertyField({
71
71
  }}
72
72
  getData={getData
73
73
  ? () => getData()
74
- .then(res => res.map(d => values.id && getIn(d, values.id)).filter(Boolean))
74
+ .then(res => res.map(entry => values.id && getIn(entry, values.id)).filter(Boolean))
75
75
  : undefined}
76
76
  onValuesChanged={onValuesChanged}/>
77
77
  </div>
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useState } from "react";
1
+ import React, { useState } from "react";
2
2
  import { FieldCaption, MapProperty, Property, PropertyConfig, } from "@firecms/core";
3
3
  import { AddIcon, BooleanSwitchWithLabel, Button, Paper, Typography } from "@firecms/ui";
4
4
  import { PropertyFormDialog } from "../PropertyEditView";
@@ -42,7 +42,7 @@ export function MapPropertyField({ disabled, getData, allowDataInference, proper
42
42
  setPropertyDialogOpen(false);
43
43
  };
44
44
 
45
- const deleteProperty = useCallback((propertyKey?: string, namespace?: string) => {
45
+ const deleteProperty = (propertyKey?: string, namespace?: string) => {
46
46
  const fullId = propertyKey ? getFullId(propertyKey, namespace) : undefined;
47
47
  if (!fullId)
48
48
  throw Error("collection editor miss config");
@@ -58,16 +58,16 @@ export function MapPropertyField({ disabled, getData, allowDataInference, proper
58
58
  setPropertyDialogOpen(false);
59
59
  setSelectedPropertyKey(undefined);
60
60
  setSelectedPropertyNamespace(undefined);
61
- }, [setFieldValue, values]);
61
+ };
62
62
 
63
63
  const selectedPropertyFullId = selectedPropertyKey ? getFullId(selectedPropertyKey, selectedPropertyNamespace) : undefined;
64
64
  const selectedProperty = selectedPropertyFullId ? getIn(values.properties, selectedPropertyFullId.replaceAll(".", ".properties.")) : undefined;
65
65
 
66
66
  const empty = !propertiesOrder || propertiesOrder.length < 1;
67
67
 
68
- const onPropertyMove = useCallback((propertiesOrder: string[], namespace?: string) => {
68
+ const onPropertyMove = (propertiesOrder: string[], namespace?: string) => {
69
69
  setFieldValue(namespaceToPropertiesOrderPath(namespace), propertiesOrder, false);
70
- }, []);
70
+ };
71
71
 
72
72
  return (
73
73
  <>
@@ -0,0 +1,139 @@
1
+ import React from "react";
2
+ import { StringPropertyValidation } from "./validation/StringPropertyValidation";
3
+ import { ValidationPanel } from "./validation/ValidationPanel";
4
+ import { Field, getIn, useFormex } from "@firecms/formex";
5
+
6
+ import { DebouncedTextField, ExpandablePanel, FileUploadIcon, TextField, Typography } from "@firecms/ui";
7
+
8
+ export function MarkdownPropertyField({
9
+ disabled,
10
+ showErrors
11
+ }: {
12
+ disabled: boolean;
13
+ showErrors: boolean;
14
+ }) {
15
+
16
+ const {
17
+ values,
18
+ setFieldValue
19
+ } = useFormex();
20
+
21
+ const baseStoragePath = "storage";
22
+
23
+ const metadata = `${baseStoragePath}.metadata`;
24
+ const fileName = `${baseStoragePath}.fileName`;
25
+ const maxSize = `${baseStoragePath}.maxSize`;
26
+ const storagePath = `${baseStoragePath}.storagePath`;
27
+
28
+ const fileNameValue = getIn(values, fileName) ?? "{rand}_{file}";
29
+ const storagePathValue = getIn(values, storagePath) ?? "/";
30
+ const maxSizeValue = getIn(values, maxSize);
31
+
32
+ const hasFilenameCallback = typeof fileNameValue === "function";
33
+ const hasStoragePathCallback = typeof storagePathValue === "function";
34
+
35
+ return (
36
+ <>
37
+ <div className={"col-span-12"}>
38
+
39
+ <ValidationPanel>
40
+
41
+ <StringPropertyValidation disabled={disabled}
42
+ length={true}
43
+ lowercase={true}
44
+ max={true}
45
+ min={true}
46
+ trim={true}
47
+ uppercase={true}
48
+ showErrors={showErrors}/>
49
+
50
+ </ValidationPanel>
51
+
52
+ </div>
53
+
54
+ <div className={"col-span-12"}>
55
+ <ExpandablePanel
56
+ title={
57
+ <div className="flex flex-row text-gray-500">
58
+ <FileUploadIcon/>
59
+ <Typography variant={"subtitle2"}
60
+ className="ml-2">
61
+ File upload config
62
+ </Typography>
63
+ </div>
64
+ }>
65
+
66
+ <div className={"grid grid-cols-12 gap-2 p-4"}>
67
+
68
+
69
+ <div className={"col-span-12"}>
70
+ <Field name={fileName}
71
+ as={DebouncedTextField}
72
+ label={"File name"}
73
+ size={"small"}
74
+ disabled={hasFilenameCallback || disabled}
75
+ value={hasFilenameCallback ? "-" : fileNameValue}
76
+ />
77
+ </div>
78
+ <div className={"col-span-12"}>
79
+ <Field name={storagePath}
80
+ as={DebouncedTextField}
81
+ label={"Storage path"}
82
+ disabled={hasStoragePathCallback || disabled}
83
+ size={"small"}
84
+ value={hasStoragePathCallback ? "-" : storagePathValue}
85
+ />
86
+ <Typography variant={"caption"} className={"ml-3.5 mt-1 mb-2"}>
87
+ <p>You can use the following placeholders in
88
+ the file name
89
+ and storage path values:</p>
90
+ <ul>
91
+ <li>{"{file} - Full name of the uploaded file"}</li>
92
+ <li>{"{file.name} - Name of the uploaded file without extension"}</li>
93
+ <li>{"{file.ext} - Extension of the uploaded file"}</li>
94
+ <li>{"{entityId} - ID of the entity"}</li>
95
+ <li>{"{propertyKey} - ID of this field"}</li>
96
+ <li>{"{path} - Path of this entity"}</li>
97
+ <li>{"{rand} - Random value used to avoid name collisions"}</li>
98
+ </ul>
99
+ </Typography>
100
+
101
+ <Typography variant={"caption"} className={"ml-3.5 mt-1 mb-2"}>
102
+ When using Markdown, the URL of the uploaded files are always saved in the text value
103
+ (not
104
+ the path).
105
+ </Typography>
106
+ </div>
107
+
108
+ <div className={"col-span-12"}>
109
+ <DebouncedTextField name={maxSize}
110
+ type={"number"}
111
+ label={"Max size (in bytes)"}
112
+ size={"small"}
113
+ value={maxSizeValue !== undefined && maxSizeValue !== null ? maxSizeValue.toString() : ""}
114
+ onChange={(e) => {
115
+ const value = e.target.value;
116
+ if (value === "") setFieldValue(maxSize, undefined);
117
+ else setFieldValue(maxSize, parseInt(value));
118
+ }}
119
+ />
120
+ </div>
121
+
122
+ </div>
123
+ </ExpandablePanel>
124
+ </div>
125
+
126
+ <div className={"col-span-12"}>
127
+
128
+ <TextField name={"defaultValue"}
129
+ disabled={disabled}
130
+ onChange={(e: any) => {
131
+ setFieldValue("defaultValue", e.target.value === "" ? undefined : e.target.value);
132
+ }}
133
+ label={"Default value"}
134
+ value={getIn(values, "defaultValue") ?? ""}/>
135
+
136
+ </div>
137
+ </>
138
+ );
139
+ }
@@ -39,7 +39,6 @@ export function RepeatPropertyField({
39
39
 
40
40
  const onPropertyChanged = ({ id, property, namespace }:
41
41
  { id?: string, property: Property, namespace?: string }) => {
42
- console.log("onPropertyChanged", id, property, namespace);
43
42
  setFieldValue("of", property);
44
43
  };
45
44
 
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
2
  import {
3
3
  Button,
4
- Checkbox,
5
4
  DebouncedTextField,
6
5
  ExpandablePanel,
7
6
  FileUploadIcon,
@@ -44,11 +43,13 @@ export function StoragePropertyField({
44
43
 
45
44
  const metadata = `${baseStoragePath}.metadata`;
46
45
  const fileName = `${baseStoragePath}.fileName`;
46
+ const maxSize = `${baseStoragePath}.maxSize`;
47
47
  const storagePath = `${baseStoragePath}.storagePath`;
48
48
  const storeUrl = `${baseStoragePath}.storeUrl`;
49
49
 
50
50
  const fileNameValue = getIn(values, fileName) ?? "{rand}_{file}";
51
51
  const storagePathValue = getIn(values, storagePath) ?? "/";
52
+ const maxSizeValue = getIn(values, maxSize);
52
53
 
53
54
  const storedValue = getIn(values, acceptedFiles);
54
55
  const fileTypesValue: string[] | undefined = Array.isArray(storedValue) ? storedValue : undefined;
@@ -56,10 +57,10 @@ export function StoragePropertyField({
56
57
 
57
58
  const handleTypesChange = (value: string[]) => {
58
59
  if (!value) setFieldValue(acceptedFiles, undefined);
59
- else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
60
- else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
61
- else if (allFileTypesSelected)
62
- setFieldValue(acceptedFiles, Object.keys(fileTypes).filter((v) => !value.includes(v)));
60
+ // else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
61
+ // else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
62
+ // else if (allFileTypesSelected)
63
+ // setFieldValue(acceptedFiles, Object.keys(fileTypes).filter((v) => !value.includes(v)));
63
64
  else setFieldValue(acceptedFiles, value);
64
65
  };
65
66
 
@@ -87,10 +88,12 @@ export function StoragePropertyField({
87
88
  <div className={"col-span-12"}>
88
89
 
89
90
  <MultiSelect
91
+ className={"w-full"}
92
+ placeholder={"All file types allowed"}
90
93
  disabled={disabled}
91
94
  name={acceptedFiles}
92
95
  value={fileTypesValue ?? []}
93
- onMultiValueChange={handleTypesChange}
96
+ onValueChange={handleTypesChange}
94
97
  label={allFileTypesSelected ? undefined : "Allowed file types"}
95
98
  renderValues={(selected) => {
96
99
  if (!selected || selected.length === 0) return "All file types allowed";
@@ -99,21 +102,15 @@ export function StoragePropertyField({
99
102
  .join(", ");
100
103
  }}>
101
104
 
102
- <MultiSelectItem key={"all"} value={"all"} className={"flex items-center gap-2"}>
103
- <Checkbox
104
- checked={!fileTypesValue}/>
105
- All
106
- </MultiSelectItem>
107
-
108
105
  {Object.entries(fileTypes).map(([value, label]) => (
109
106
  <MultiSelectItem key={value} value={value} className={"flex items-center gap-2"}>
110
- <Checkbox
111
- checked={allFileTypesSelected || fileTypesValue.indexOf(value) > -1}/>
107
+ {/*<Checkbox*/}
108
+ {/* checked={allFileTypesSelected || fileTypesValue.indexOf(value) > -1}/>*/}
112
109
  <div className={"flex-grow"}>
113
110
  {label}
114
111
  </div>
115
112
  <Button size={"small"}
116
- variant={"outlined"}
113
+ variant={"text"}
117
114
  onClick={(e) => {
118
115
  e.preventDefault();
119
116
  e.stopPropagation();
@@ -161,7 +158,10 @@ export function StoragePropertyField({
161
158
 
162
159
  <Field name={storeUrl}
163
160
  type="checkbox">
164
- {({ field, form }: FormexFieldProps) => {
161
+ {({
162
+ field,
163
+ form
164
+ }: FormexFieldProps) => {
165
165
  return <SwitchControl
166
166
  label={"Save URL instead of storage path"}
167
167
  disabled={existing || disabled}
@@ -178,6 +178,21 @@ export function StoragePropertyField({
178
178
  You can only change this prop upon creation.
179
179
  </Typography>
180
180
  </div>
181
+
182
+ <div className={"col-span-12"}>
183
+ <DebouncedTextField name={maxSize}
184
+ type={"number"}
185
+ label={"Max size (in bytes)"}
186
+ size={"small"}
187
+ value={maxSizeValue !== undefined && maxSizeValue !== null ? maxSizeValue.toString() : ""}
188
+ onChange={(e) => {
189
+ const value = e.target.value;
190
+ if (value === "") setFieldValue(maxSize, undefined);
191
+ else setFieldValue(maxSize, parseInt(value));
192
+ }}
193
+ />
194
+ </div>
195
+
181
196
  </div>
182
197
  </ExpandablePanel>
183
198