@firecms/collection_editor 3.0.0-beta.5 → 3.0.0-beta.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.
- package/LICENSE +113 -21
- package/dist/ConfigControllerProvider.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +1814 -1772
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/collection_editor_controller.d.ts +1 -1
- package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
- package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +1 -1
- package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
- package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
- package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
- package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
- package/dist/useCollectionEditorPlugin.d.ts +6 -9
- package/dist/utils/collections.d.ts +6 -0
- package/package.json +21 -21
- package/src/ConfigControllerProvider.tsx +52 -58
- package/src/index.ts +1 -0
- package/src/types/collection_editor_controller.tsx +1 -1
- package/src/ui/EditorCollectionAction.tsx +0 -51
- package/src/ui/EditorCollectionActionStart.tsx +87 -0
- package/src/ui/HomePageEditorCollectionAction.tsx +5 -5
- package/src/ui/NewCollectionCard.tsx +3 -3
- package/src/ui/collection_editor/CollectionDetailsForm.tsx +34 -4
- package/src/ui/collection_editor/CollectionEditorDialog.tsx +39 -24
- package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +4 -4
- package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +21 -19
- package/src/ui/collection_editor/PropertyEditView.tsx +5 -4
- package/src/ui/collection_editor/PropertyFieldPreview.tsx +3 -6
- package/src/ui/collection_editor/PropertySelectItem.tsx +2 -2
- package/src/ui/collection_editor/PropertyTree.tsx +3 -3
- package/src/ui/collection_editor/SubcollectionsEditTab.tsx +1 -1
- package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +25 -9
- package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +9 -7
- package/src/ui/collection_editor/properties/BlockPropertyField.tsx +14 -8
- package/src/ui/collection_editor/properties/MapPropertyField.tsx +5 -5
- package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
- package/src/useCollectionEditorPlugin.tsx +27 -26
- package/src/utils/collections.ts +30 -0
- package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
- package/src/ui/RootCollectionSuggestions.tsx +0 -63
|
@@ -25,7 +25,7 @@ export interface CollectionEditorDialogProps {
|
|
|
25
25
|
icon: React.ReactNode;
|
|
26
26
|
};
|
|
27
27
|
pathSuggestions?: (path?: string) => Promise<string[]>;
|
|
28
|
-
getUser
|
|
28
|
+
getUser?: (uid: string) => User | null;
|
|
29
29
|
getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
|
|
30
30
|
parentCollection?: PersistedCollection;
|
|
31
31
|
}
|
|
@@ -4,7 +4,7 @@ export declare function CollectionEditorWelcomeView({ path, pathSuggestions, par
|
|
|
4
4
|
path: string;
|
|
5
5
|
pathSuggestions?: (path: string) => Promise<string[]>;
|
|
6
6
|
parentCollection?: EntityCollection;
|
|
7
|
-
onContinue: (importData?: object[]) => void;
|
|
7
|
+
onContinue: (importData?: object[], propertiesOrder?: string[]) => void;
|
|
8
8
|
existingCollectionPaths?: string[];
|
|
9
9
|
}): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
export declare function TemplateButton({ title, subtitle, icon, onClick }: {
|
|
@@ -9,7 +9,7 @@ type CollectionEditorFormProps = {
|
|
|
9
9
|
setDirty?: (dirty: boolean) => void;
|
|
10
10
|
reservedGroups?: string[];
|
|
11
11
|
extraIcon: React.ReactNode;
|
|
12
|
-
getUser
|
|
12
|
+
getUser?: (uid: string) => User | null;
|
|
13
13
|
getData?: () => Promise<object[]>;
|
|
14
14
|
doCollectionInference: (collection: PersistedCollection) => Promise<Partial<EntityCollection> | null> | undefined;
|
|
15
15
|
propertyConfigs: Record<string, PropertyConfig>;
|
|
@@ -4,17 +4,17 @@ import { DraggableProvided } from "@hello-pangea/dnd";
|
|
|
4
4
|
export declare const PropertyTree: React.MemoExoticComponent<(<M extends {
|
|
5
5
|
[Key: string]: CMSType;
|
|
6
6
|
}>({ namespace, selectedPropertyKey, onPropertyClick, properties, propertiesOrder: propertiesOrderProp, additionalFields, errors, onPropertyMove, onPropertyRemove, className, inferredPropertyKeys, collectionEditable }: {
|
|
7
|
-
namespace?: string
|
|
8
|
-
selectedPropertyKey?: string
|
|
9
|
-
onPropertyClick?: (
|
|
7
|
+
namespace?: string;
|
|
8
|
+
selectedPropertyKey?: string;
|
|
9
|
+
onPropertyClick?: (propertyKey: string, namespace?: string) => void;
|
|
10
10
|
properties: PropertiesOrBuilders<M>;
|
|
11
|
-
propertiesOrder?: string[]
|
|
12
|
-
additionalFields?: AdditionalFieldDelegate<M
|
|
11
|
+
propertiesOrder?: string[];
|
|
12
|
+
additionalFields?: AdditionalFieldDelegate<M>[];
|
|
13
13
|
errors: Record<string, any>;
|
|
14
|
-
onPropertyMove?: (
|
|
15
|
-
onPropertyRemove?: (
|
|
16
|
-
className?: string
|
|
17
|
-
inferredPropertyKeys?: string[]
|
|
14
|
+
onPropertyMove?: (propertiesOrder: string[], namespace?: string) => void;
|
|
15
|
+
onPropertyRemove?: (propertyKey: string, namespace?: string) => void;
|
|
16
|
+
className?: string;
|
|
17
|
+
inferredPropertyKeys?: string[];
|
|
18
18
|
collectionEditable: boolean;
|
|
19
19
|
}) => import("react/jsx-runtime").JSX.Element)>;
|
|
20
20
|
export declare function PropertyTreeEntry({ propertyKey, namespace, propertyOrBuilder, additionalField, provided, selectedPropertyKey, errors, onPropertyClick, onPropertyMove, onPropertyRemove, inferredPropertyKeys, collectionEditable }: {
|
|
@@ -7,6 +7,6 @@ export declare function SubcollectionsEditTab({ collection, parentCollection, co
|
|
|
7
7
|
parentCollection?: EntityCollection;
|
|
8
8
|
configController: CollectionsConfigController;
|
|
9
9
|
collectionInference?: CollectionInference;
|
|
10
|
-
getUser
|
|
10
|
+
getUser?: (uid: string) => User | null;
|
|
11
11
|
parentCollectionIds?: string[];
|
|
12
12
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -18,19 +18,18 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
|
|
|
18
18
|
* names when creating collections.
|
|
19
19
|
* e.g. ["admin"]
|
|
20
20
|
*/
|
|
21
|
-
reservedGroups
|
|
21
|
+
reservedGroups?: string[];
|
|
22
22
|
extraView?: {
|
|
23
23
|
View: React.ComponentType<{
|
|
24
24
|
path: string;
|
|
25
25
|
}>;
|
|
26
26
|
icon: React.ReactNode;
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
getPathSuggestions?: (path?: string) => Promise<string[]>;
|
|
29
29
|
collectionInference?: CollectionInference;
|
|
30
30
|
getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
|
|
31
|
-
getUser
|
|
31
|
+
getUser?: (uid: string) => UserType | null;
|
|
32
32
|
onAnalyticsEvent?: (event: string, params?: object) => void;
|
|
33
|
-
introMode?: "new_project" | "existing_project";
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
35
|
* Use this hook to initialise the Collection Editor plugin.
|
|
@@ -39,11 +38,9 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
|
|
|
39
38
|
* @param configPermissions
|
|
40
39
|
* @param reservedGroups
|
|
41
40
|
* @param extraView
|
|
42
|
-
* @param
|
|
41
|
+
* @param getPathsSuggestions
|
|
43
42
|
* @param getUser
|
|
44
43
|
* @param collectionInference
|
|
45
44
|
*/
|
|
46
|
-
export declare function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>({ collectionConfigController,
|
|
47
|
-
export declare function IntroWidget({
|
|
48
|
-
introMode?: "new_project" | "existing_project";
|
|
49
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
45
|
+
export declare function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>({ collectionConfigController, configPermissions, reservedGroups, extraView, getPathSuggestions, getUser, collectionInference, getData, onAnalyticsEvent }: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection>;
|
|
46
|
+
export declare function IntroWidget({}: {}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EntityCollection, ModifyCollectionProps } from "@firecms/core";
|
|
2
|
+
import { PersistedCollection } from "../types/persisted_collection";
|
|
3
|
+
/**
|
|
4
|
+
* Function in charge of merging collections defined in code with those stored in the backend.
|
|
5
|
+
*/
|
|
6
|
+
export declare const mergeCollections: (baseCollections: EntityCollection[], backendCollections: PersistedCollection[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void) => EntityCollection<any, any>[];
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firecms/collection_editor",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.7",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"source": "src/index.ts",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@firecms/data_import_export": "^3.0.0-beta.
|
|
11
|
-
"@firecms/formex": "^3.0.0-beta.
|
|
12
|
-
"@firecms/schema_inference": "^3.0.0-beta.
|
|
13
|
-
"@firecms/ui": "^3.0.0-beta.
|
|
10
|
+
"@firecms/data_import_export": "^3.0.0-beta.7",
|
|
11
|
+
"@firecms/formex": "^3.0.0-beta.7",
|
|
12
|
+
"@firecms/schema_inference": "^3.0.0-beta.7",
|
|
13
|
+
"@firecms/ui": "^3.0.0-beta.7",
|
|
14
14
|
"json5": "^2.2.3",
|
|
15
15
|
"prism-react-renderer": "^2.3.1"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"react": "^18.
|
|
19
|
-
"react-dom": "^18.
|
|
18
|
+
"react": "^18.3.1",
|
|
19
|
+
"react-dom": "^18.3.1",
|
|
20
20
|
"react-router": "^6.22.0",
|
|
21
21
|
"react-router-dom": "^6.22.0"
|
|
22
22
|
},
|
|
@@ -54,24 +54,24 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@jest/globals": "^29.7.0",
|
|
57
|
-
"@types/react": "^18.
|
|
58
|
-
"@types/react-dom": "^18.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
60
|
-
"@typescript-eslint/parser": "^7.
|
|
61
|
-
"@vitejs/plugin-react": "^4.
|
|
57
|
+
"@types/react": "^18.3.3",
|
|
58
|
+
"@types/react-dom": "^18.3.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
|
60
|
+
"@typescript-eslint/parser": "^7.11.0",
|
|
61
|
+
"@vitejs/plugin-react": "^4.3.0",
|
|
62
62
|
"eslint": "^8.57.0",
|
|
63
63
|
"eslint-config-standard": "^17.1.0",
|
|
64
64
|
"eslint-plugin-import": "^2.29.1",
|
|
65
65
|
"eslint-plugin-n": "^16.6.2",
|
|
66
|
-
"eslint-plugin-promise": "^6.
|
|
67
|
-
"eslint-plugin-react": "^7.34.
|
|
68
|
-
"eslint-plugin-react-hooks": "^4.6.
|
|
66
|
+
"eslint-plugin-promise": "^6.2.0",
|
|
67
|
+
"eslint-plugin-react": "^7.34.2",
|
|
68
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
69
69
|
"jest": "^29.7.0",
|
|
70
|
-
"react-router": "^6.
|
|
71
|
-
"react-router-dom": "^6.
|
|
72
|
-
"ts-jest": "^29.1.
|
|
73
|
-
"typescript": "^5.4.
|
|
74
|
-
"vite": "^5.2.
|
|
70
|
+
"react-router": "^6.23.1",
|
|
71
|
+
"react-router-dom": "^6.23.1",
|
|
72
|
+
"ts-jest": "^29.1.4",
|
|
73
|
+
"typescript": "^5.4.5",
|
|
74
|
+
"vite": "^5.2.12",
|
|
75
75
|
"vite-plugin-fonts": "^0.7.0"
|
|
76
76
|
},
|
|
77
77
|
"files": [
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "b1f5dbd89d66bd75e8d214a4a6c40e07e371a1d1"
|
|
85
85
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { PropsWithChildren, useCallback
|
|
1
|
+
import React, { PropsWithChildren, useCallback } from "react";
|
|
2
2
|
import equal from "react-fast-compare"
|
|
3
3
|
|
|
4
4
|
import { CollectionsConfigController } from "./types/config_controller";
|
|
@@ -48,9 +48,9 @@ export interface ConfigControllerProviderProps {
|
|
|
48
48
|
icon: React.ReactNode
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
getPathSuggestions?: (path?: string) => Promise<string[]>;
|
|
52
52
|
|
|
53
|
-
getUser
|
|
53
|
+
getUser?: (uid: string) => User | null
|
|
54
54
|
|
|
55
55
|
getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
|
|
56
56
|
|
|
@@ -66,7 +66,7 @@ export const ConfigControllerProvider = React.memo(
|
|
|
66
66
|
reservedGroups,
|
|
67
67
|
collectionInference,
|
|
68
68
|
extraView,
|
|
69
|
-
|
|
69
|
+
getPathSuggestions,
|
|
70
70
|
getUser,
|
|
71
71
|
getData,
|
|
72
72
|
onAnalyticsEvent
|
|
@@ -77,20 +77,6 @@ export const ConfigControllerProvider = React.memo(
|
|
|
77
77
|
const snackbarController = useSnackbarController();
|
|
78
78
|
const { propertyConfigs } = useCustomizationController();
|
|
79
79
|
|
|
80
|
-
const {
|
|
81
|
-
collections
|
|
82
|
-
} = navigation;
|
|
83
|
-
const existingPaths = (collections ?? []).map(col => col.path.trim().toLowerCase());
|
|
84
|
-
|
|
85
|
-
const [rootPathSuggestions, setRootPathSuggestions] = React.useState<string[] | undefined>();
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (pathSuggestions) {
|
|
88
|
-
pathSuggestions().then((paths) => {
|
|
89
|
-
setRootPathSuggestions(paths.filter(p => !existingPaths.includes(p.trim().toLowerCase())));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}, [pathSuggestions]);
|
|
93
|
-
|
|
94
80
|
const [currentDialog, setCurrentDialog] = React.useState<{
|
|
95
81
|
isNewCollection: boolean,
|
|
96
82
|
parentCollection?: PersistedCollection,
|
|
@@ -123,19 +109,22 @@ export const ConfigControllerProvider = React.memo(
|
|
|
123
109
|
deleteCollections: true
|
|
124
110
|
}), []);
|
|
125
111
|
|
|
126
|
-
const editCollection =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
112
|
+
const editCollection = ({
|
|
113
|
+
id,
|
|
114
|
+
fullPath,
|
|
115
|
+
parentCollectionIds,
|
|
116
|
+
parentCollection
|
|
117
|
+
}: {
|
|
132
118
|
id?: string,
|
|
133
119
|
fullPath?: string,
|
|
134
120
|
parentCollectionIds: string[],
|
|
135
121
|
parentCollection?: PersistedCollection
|
|
136
122
|
}) => {
|
|
137
123
|
console.debug("Edit collection", id, fullPath, parentCollectionIds, parentCollection);
|
|
138
|
-
onAnalyticsEvent?.("edit_collection", {
|
|
124
|
+
onAnalyticsEvent?.("edit_collection", {
|
|
125
|
+
id,
|
|
126
|
+
fullPath
|
|
127
|
+
});
|
|
139
128
|
setCurrentDialog({
|
|
140
129
|
editedCollectionId: id,
|
|
141
130
|
fullPath,
|
|
@@ -144,16 +133,16 @@ export const ConfigControllerProvider = React.memo(
|
|
|
144
133
|
parentCollection,
|
|
145
134
|
redirect: false
|
|
146
135
|
});
|
|
147
|
-
}
|
|
136
|
+
};
|
|
148
137
|
|
|
149
|
-
const editProperty =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
138
|
+
const editProperty = ({
|
|
139
|
+
propertyKey,
|
|
140
|
+
property,
|
|
141
|
+
editedCollectionId,
|
|
142
|
+
currentPropertiesOrder,
|
|
143
|
+
parentCollectionIds,
|
|
144
|
+
collection
|
|
145
|
+
}: {
|
|
157
146
|
propertyKey?: string,
|
|
158
147
|
property?: Property,
|
|
159
148
|
currentPropertiesOrder?: string[],
|
|
@@ -162,7 +151,10 @@ export const ConfigControllerProvider = React.memo(
|
|
|
162
151
|
collection: PersistedCollection,
|
|
163
152
|
}) => {
|
|
164
153
|
console.debug("Edit property", propertyKey, property, editedCollectionId, currentPropertiesOrder, parentCollectionIds, collection);
|
|
165
|
-
onAnalyticsEvent?.("edit_property", {
|
|
154
|
+
onAnalyticsEvent?.("edit_property", {
|
|
155
|
+
propertyKey,
|
|
156
|
+
editedCollectionId
|
|
157
|
+
});
|
|
166
158
|
// namespace is all the path until the last dot
|
|
167
159
|
const namespace = propertyKey && propertyKey.includes(".")
|
|
168
160
|
? propertyKey.substring(0, propertyKey.lastIndexOf("."))
|
|
@@ -175,19 +167,19 @@ export const ConfigControllerProvider = React.memo(
|
|
|
175
167
|
property,
|
|
176
168
|
namespace,
|
|
177
169
|
currentPropertiesOrder,
|
|
178
|
-
editedCollectionId
|
|
170
|
+
editedCollectionId,
|
|
179
171
|
parentCollectionIds,
|
|
180
172
|
collectionEditable: collection?.editable ?? false
|
|
181
173
|
});
|
|
182
|
-
}
|
|
174
|
+
};
|
|
183
175
|
|
|
184
|
-
const createCollection =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
176
|
+
const createCollection = ({
|
|
177
|
+
parentCollectionIds,
|
|
178
|
+
parentCollection,
|
|
179
|
+
initialValues,
|
|
180
|
+
redirect,
|
|
181
|
+
sourceClick
|
|
182
|
+
}: {
|
|
191
183
|
parentCollectionIds: string[],
|
|
192
184
|
parentCollection?: PersistedCollection
|
|
193
185
|
initialValues?: {
|
|
@@ -198,8 +190,20 @@ export const ConfigControllerProvider = React.memo(
|
|
|
198
190
|
redirect: boolean,
|
|
199
191
|
sourceClick?: string
|
|
200
192
|
}) => {
|
|
201
|
-
console.debug("Create collection", {
|
|
202
|
-
|
|
193
|
+
console.debug("Create collection", {
|
|
194
|
+
parentCollectionIds,
|
|
195
|
+
parentCollection,
|
|
196
|
+
initialValues,
|
|
197
|
+
redirect,
|
|
198
|
+
sourceClick
|
|
199
|
+
});
|
|
200
|
+
onAnalyticsEvent?.("create_collection", {
|
|
201
|
+
parentCollectionIds,
|
|
202
|
+
parentCollection,
|
|
203
|
+
initialValues,
|
|
204
|
+
redirect,
|
|
205
|
+
sourceClick
|
|
206
|
+
});
|
|
203
207
|
setCurrentDialog({
|
|
204
208
|
isNewCollection: true,
|
|
205
209
|
parentCollectionIds,
|
|
@@ -207,17 +211,7 @@ export const ConfigControllerProvider = React.memo(
|
|
|
207
211
|
initialValues,
|
|
208
212
|
redirect
|
|
209
213
|
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const getPathSuggestions = !pathSuggestions
|
|
213
|
-
? undefined
|
|
214
|
-
: (path?: string) => {
|
|
215
|
-
if (!path && rootPathSuggestions)
|
|
216
|
-
return Promise.resolve(rootPathSuggestions);
|
|
217
|
-
else {
|
|
218
|
-
return pathSuggestions?.(path);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
214
|
+
};
|
|
221
215
|
|
|
222
216
|
return (
|
|
223
217
|
<ConfigControllerContext.Provider value={collectionConfigController}>
|
|
@@ -227,7 +221,7 @@ export const ConfigControllerProvider = React.memo(
|
|
|
227
221
|
createCollection,
|
|
228
222
|
editProperty,
|
|
229
223
|
configPermissions: configPermissions ?? defaultConfigPermissions,
|
|
230
|
-
|
|
224
|
+
getPathSuggestions
|
|
231
225
|
}}>
|
|
232
226
|
|
|
233
227
|
{children}
|
package/src/index.ts
CHANGED
|
@@ -23,8 +23,6 @@ export function EditorCollectionAction({
|
|
|
23
23
|
const authController = useAuthController();
|
|
24
24
|
const navigationController = useNavigationController();
|
|
25
25
|
const collectionEditorController = useCollectionEditorController();
|
|
26
|
-
const configController = useCollectionsConfigController();
|
|
27
|
-
const snackbarController = useSnackbarController();
|
|
28
26
|
|
|
29
27
|
const parentCollection = navigationController.getCollectionFromIds(parentCollectionIds);
|
|
30
28
|
|
|
@@ -35,54 +33,6 @@ export function EditorCollectionAction({
|
|
|
35
33
|
}).editCollections
|
|
36
34
|
: true;
|
|
37
35
|
|
|
38
|
-
let saveDefaultFilterButton = null;
|
|
39
|
-
if (!equal(getObjectOrNull(tableController.filterValues), getObjectOrNull(collection.initialFilter)) ||
|
|
40
|
-
!equal(getObjectOrNull(tableController.sortBy), getObjectOrNull(collection.initialSort))) {
|
|
41
|
-
saveDefaultFilterButton = <>
|
|
42
|
-
{(collection.initialFilter || collection.initialSort) && <Tooltip
|
|
43
|
-
title={"Reset to default filter and sort"}>
|
|
44
|
-
<Button
|
|
45
|
-
color={"primary"}
|
|
46
|
-
size={"small"}
|
|
47
|
-
variant={"text"}
|
|
48
|
-
onClick={() => {
|
|
49
|
-
tableController.clearFilter?.();
|
|
50
|
-
if (collection?.initialFilter)
|
|
51
|
-
tableController.setFilterValues?.(collection?.initialFilter);
|
|
52
|
-
if (collection?.initialSort)
|
|
53
|
-
tableController.setSortBy?.(collection?.initialSort);
|
|
54
|
-
}}>
|
|
55
|
-
<UndoIcon/>
|
|
56
|
-
</Button>
|
|
57
|
-
</Tooltip>}
|
|
58
|
-
|
|
59
|
-
<Tooltip
|
|
60
|
-
title={tableController.sortBy || tableController.filterValues ? "Save default filter and sort" : "Clear default filter and sort"}>
|
|
61
|
-
<Button
|
|
62
|
-
color={"primary"}
|
|
63
|
-
size={"small"}
|
|
64
|
-
variant={"outlined"}
|
|
65
|
-
onClick={() => configController
|
|
66
|
-
?.saveCollection({
|
|
67
|
-
id: collection.id,
|
|
68
|
-
parentCollectionIds,
|
|
69
|
-
collectionData: mergeDeep(collection as PersistedCollection,
|
|
70
|
-
{
|
|
71
|
-
initialFilter: tableController.filterValues ?? null,
|
|
72
|
-
initialSort: tableController.sortBy ?? null
|
|
73
|
-
})
|
|
74
|
-
}).then(() => {
|
|
75
|
-
snackbarController.open({
|
|
76
|
-
type: "success",
|
|
77
|
-
message: "Default config saved"
|
|
78
|
-
});
|
|
79
|
-
})}>
|
|
80
|
-
<SaveIcon/>
|
|
81
|
-
</Button>
|
|
82
|
-
</Tooltip>
|
|
83
|
-
</>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
36
|
const editorButton = <Tooltip
|
|
87
37
|
title={canEditCollection ? "Edit collection" : "You don't have permissions to edit this collection"}>
|
|
88
38
|
<IconButton
|
|
@@ -96,7 +46,6 @@ export function EditorCollectionAction({
|
|
|
96
46
|
</Tooltip>;
|
|
97
47
|
|
|
98
48
|
return <>
|
|
99
|
-
{canEditCollection && saveDefaultFilterButton}
|
|
100
49
|
{editorButton}
|
|
101
50
|
</>
|
|
102
51
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import equal from "react-fast-compare"
|
|
2
|
+
|
|
3
|
+
import { CollectionActionsProps, mergeDeep, useAuthController, useSnackbarController } from "@firecms/core";
|
|
4
|
+
import { Button, SaveIcon, Tooltip, UndoIcon, } from "@firecms/ui";
|
|
5
|
+
|
|
6
|
+
import { useCollectionEditorController } from "../useCollectionEditorController";
|
|
7
|
+
import { useCollectionsConfigController } from "../useCollectionsConfigController";
|
|
8
|
+
import { PersistedCollection } from "../types/persisted_collection";
|
|
9
|
+
|
|
10
|
+
export function EditorCollectionActionStart({
|
|
11
|
+
path: fullPath,
|
|
12
|
+
parentCollectionIds,
|
|
13
|
+
collection,
|
|
14
|
+
tableController
|
|
15
|
+
}: CollectionActionsProps) {
|
|
16
|
+
|
|
17
|
+
const authController = useAuthController();
|
|
18
|
+
const collectionEditorController = useCollectionEditorController();
|
|
19
|
+
const configController = useCollectionsConfigController();
|
|
20
|
+
const snackbarController = useSnackbarController();
|
|
21
|
+
|
|
22
|
+
const canEditCollection = collectionEditorController.configPermissions
|
|
23
|
+
? collectionEditorController.configPermissions({
|
|
24
|
+
user: authController.user,
|
|
25
|
+
collection
|
|
26
|
+
}).editCollections
|
|
27
|
+
: true;
|
|
28
|
+
|
|
29
|
+
let saveDefaultFilterButton = null;
|
|
30
|
+
if (!equal(getObjectOrNull(tableController.filterValues), getObjectOrNull(collection.initialFilter)) ||
|
|
31
|
+
!equal(getObjectOrNull(tableController.sortBy), getObjectOrNull(collection.initialSort))) {
|
|
32
|
+
saveDefaultFilterButton = <>
|
|
33
|
+
<Tooltip
|
|
34
|
+
title={tableController.sortBy || tableController.filterValues ? "Save default filter and sort" : "Clear default filter and sort"}>
|
|
35
|
+
<Button
|
|
36
|
+
color={"primary"}
|
|
37
|
+
size={"small"}
|
|
38
|
+
variant={"outlined"}
|
|
39
|
+
onClick={() => configController
|
|
40
|
+
?.saveCollection({
|
|
41
|
+
id: collection.id,
|
|
42
|
+
parentCollectionIds,
|
|
43
|
+
collectionData: mergeDeep(collection as PersistedCollection,
|
|
44
|
+
{
|
|
45
|
+
initialFilter: tableController.filterValues ?? null,
|
|
46
|
+
initialSort: tableController.sortBy ?? null
|
|
47
|
+
})
|
|
48
|
+
}).then(() => {
|
|
49
|
+
snackbarController.open({
|
|
50
|
+
type: "success",
|
|
51
|
+
message: "Default config saved"
|
|
52
|
+
});
|
|
53
|
+
})}>
|
|
54
|
+
<SaveIcon/>
|
|
55
|
+
</Button>
|
|
56
|
+
</Tooltip>
|
|
57
|
+
|
|
58
|
+
{(collection.initialFilter || collection.initialSort) && <Tooltip
|
|
59
|
+
title={"Reset to default filter and sort"}>
|
|
60
|
+
<Button
|
|
61
|
+
color={"primary"}
|
|
62
|
+
size={"small"}
|
|
63
|
+
variant={"text"}
|
|
64
|
+
onClick={() => {
|
|
65
|
+
tableController.clearFilter?.();
|
|
66
|
+
if (collection?.initialFilter)
|
|
67
|
+
tableController.setFilterValues?.(collection?.initialFilter);
|
|
68
|
+
if (collection?.initialSort)
|
|
69
|
+
tableController.setSortBy?.(collection?.initialSort);
|
|
70
|
+
}}>
|
|
71
|
+
<UndoIcon/>
|
|
72
|
+
</Button>
|
|
73
|
+
</Tooltip>}
|
|
74
|
+
</>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return <>
|
|
78
|
+
{canEditCollection && saveDefaultFilterButton}
|
|
79
|
+
</>
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getObjectOrNull(o?: object): object | null {
|
|
84
|
+
if (o && Object.keys(o).length === 0)
|
|
85
|
+
return o
|
|
86
|
+
return o ?? null;
|
|
87
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "@firecms/core";
|
|
7
7
|
import { DeleteIcon, IconButton, Menu, MenuItem, MoreVertIcon, SettingsIcon, } from "@firecms/ui";
|
|
8
8
|
import { useCollectionEditorController } from "../useCollectionEditorController";
|
|
9
|
-
import {
|
|
9
|
+
import { useState } from "react";
|
|
10
10
|
import { useCollectionsConfigController } from "../useCollectionsConfigController";
|
|
11
11
|
|
|
12
12
|
export function HomePageEditorCollectionAction({
|
|
@@ -24,13 +24,13 @@ export function HomePageEditorCollectionAction({
|
|
|
24
24
|
collection
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
const onEditCollectionClicked =
|
|
27
|
+
const onEditCollectionClicked = () => {
|
|
28
28
|
collectionEditorController?.editCollection({ id: collection.id, parentCollectionIds: [] });
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
|
|
31
31
|
const [deleteRequested, setDeleteRequested] = useState(false);
|
|
32
32
|
|
|
33
|
-
const deleteCollection =
|
|
33
|
+
const deleteCollection = () => {
|
|
34
34
|
configController?.deleteCollection({ id: collection.id }).then(() => {
|
|
35
35
|
setDeleteRequested(false);
|
|
36
36
|
snackbarController.open({
|
|
@@ -38,7 +38,7 @@ export function HomePageEditorCollectionAction({
|
|
|
38
38
|
type: "success"
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
42
|
|
|
43
43
|
return <>
|
|
44
44
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PluginHomePageAdditionalCardsProps, useAuthController } from "@firecms/core";
|
|
2
|
-
import { AddIcon, Card,
|
|
2
|
+
import { AddIcon, Card, cls, Typography } from "@firecms/ui";
|
|
3
3
|
import { useCollectionEditorController } from "../useCollectionEditorController";
|
|
4
4
|
|
|
5
5
|
export function NewCollectionCard({
|
|
@@ -20,7 +20,7 @@ export function NewCollectionCard({
|
|
|
20
20
|
: true;
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<Card className={
|
|
23
|
+
<Card className={cls("h-full p-4 min-h-[124px]")}
|
|
24
24
|
onClick={collectionEditorController && canCreateCollections
|
|
25
25
|
? () => collectionEditorController.createCollection({
|
|
26
26
|
initialValues: group ? { group } : undefined,
|
|
@@ -31,7 +31,7 @@ export function NewCollectionCard({
|
|
|
31
31
|
: undefined}>
|
|
32
32
|
|
|
33
33
|
<div
|
|
34
|
-
className="flex
|
|
34
|
+
className="flex items-center justify-center h-full w-full flex-grow flex-col">
|
|
35
35
|
<AddIcon color="primary" size={"large"}/>
|
|
36
36
|
<Typography color="primary"
|
|
37
37
|
variant={"caption"}
|