Skip to content

Commit c4ea3cc

Browse files
committed
Vite update
Multiple fixes in data import, when creating new collections
1 parent cc454ac commit c4ea3cc

File tree

14 files changed

+74
-50
lines changed

14 files changed

+74
-50
lines changed

packages/collection_editor/src/ui/collection_editor/CollectionDetailsForm.tsx

+19-12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export function CollectionDetailsForm({
5252
submitCount
5353
} = useFormex<EntityCollection>();
5454

55+
console.log({
56+
touched,
57+
errors,
58+
})
59+
5560
const [iconDialogOpen, setIconDialogOpen] = useState(false);
5661
const [advancedPanelExpanded, setAdvancedPanelExpanded] = useState(false);
5762

@@ -70,7 +75,7 @@ export function CollectionDetailsForm({
7075

7176
const singularNameTouched = getIn(touched, "singularName");
7277
if (!singularNameTouched && isNewCollection && name) {
73-
setFieldValue("singularName", singular(name))
78+
setFieldValue("singularName", singular(name));
7479
}
7580

7681
};
@@ -107,6 +112,8 @@ export function CollectionDetailsForm({
107112
customIdValue = "optional";
108113
}
109114
}
115+
116+
const showErrors = submitCount > 0;
110117
return (
111118
<div className={"overflow-auto my-auto"}>
112119
<Container maxWidth={"4xl"} className={"flex flex-col gap-4 p-8 m-auto"}>
@@ -141,7 +148,7 @@ export function CollectionDetailsForm({
141148
onChange={(e: any) => updateName(e.target.value)}
142149
label={"Name"}
143150
required
144-
error={touched.name && Boolean(errors.name)}/>
151+
error={showErrors && Boolean(errors.name)}/>
145152
<FieldHelperView error={touched.name && Boolean(errors.name)}>
146153
{touched.name && Boolean(errors.name) ? errors.name : "Name of in this collection, usually a plural name (e.g. Products)"}
147154
</FieldHelperView>
@@ -153,7 +160,7 @@ export function CollectionDetailsForm({
153160
label={"Path"}
154161
disabled={!isNewCollection}
155162
required
156-
error={touched.path && Boolean(errors.path)}/>
163+
error={showErrors && Boolean(errors.path)}/>
157164

158165
<FieldHelperView error={touched.path && Boolean(errors.path)}>
159166
{touched.path && Boolean(errors.path)
@@ -165,7 +172,7 @@ export function CollectionDetailsForm({
165172

166173
{!isSubcollection && <div className={"col-span-12 sm:col-span-4 relative"}>
167174

168-
<TextField error={touched.group && Boolean(errors.group)}
175+
<TextField error={showErrors && Boolean(errors.group)}
169176
disabled={isSubmitting}
170177
value={values.group ?? ""}
171178
autoComplete="off"
@@ -191,7 +198,7 @@ export function CollectionDetailsForm({
191198
})}
192199
</Autocomplete>
193200
<FieldHelperView>
194-
{touched.group && Boolean(errors.group) ? errors.group : "Group of the collection"}
201+
{showErrors && Boolean(errors.group) ? errors.group : "Group of the collection"}
195202
</FieldHelperView>
196203
</div>}
197204

@@ -215,15 +222,15 @@ export function CollectionDetailsForm({
215222
as={DebouncedTextField}
216223
disabled={!isNewCollection}
217224
label={"Collection id"}
218-
error={touched.id && Boolean(errors.id)}/>
225+
error={showErrors && Boolean(errors.id)}/>
219226
<FieldHelperView error={touched.id && Boolean(errors.id)}>
220227
{touched.id && Boolean(errors.id) ? errors.id : "This id identifies this collection"}
221228
</FieldHelperView>
222229
</div>
223230

224231
<div className={"col-span-12"}>
225232
<TextField
226-
error={touched.singularName && Boolean(errors.singularName)}
233+
error={showErrors && Boolean(errors.singularName)}
227234
id={"singularName"}
228235
aria-describedby={"singularName-helper"}
229236
onChange={(e) => {
@@ -232,13 +239,13 @@ export function CollectionDetailsForm({
232239
}}
233240
value={values.singularName ?? ""}
234241
label={"Singular name"}/>
235-
<FieldHelperView error={touched.singularName && Boolean(errors.singularName)}>
236-
{touched.singularName && Boolean(errors.singularName) ? errors.singularName : "Optionally define a singular name for your entities"}
242+
<FieldHelperView error={showErrors && Boolean(errors.singularName)}>
243+
{showErrors && Boolean(errors.singularName) ? errors.singularName : "Optionally define a singular name for your entities"}
237244
</FieldHelperView>
238245
</div>
239246
<div className={"col-span-12"}>
240247
<TextField
241-
error={touched.description && Boolean(errors.description)}
248+
error={showErrors && Boolean(errors.description)}
242249
id="description"
243250
value={values.description ?? ""}
244251
onChange={handleChange}
@@ -247,8 +254,8 @@ export function CollectionDetailsForm({
247254
aria-describedby="description-helper-text"
248255
label="Description"
249256
/>
250-
<FieldHelperView error={touched.description && Boolean(errors.description)}>
251-
{touched.description && Boolean(errors.description) ? errors.description : "Description of the collection, you can use markdown"}
257+
<FieldHelperView error={showErrors && Boolean(errors.description)}>
258+
{showErrors && Boolean(errors.description) ? errors.description : "Description of the collection, you can use markdown"}
252259
</FieldHelperView>
253260
</div>
254261

packages/collection_editor/src/ui/collection_editor/CollectionEditorDialog.tsx

+7-9
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ function CollectionEditorInternal<M extends Record<string, any>>({
261261
const importConfig = useImportConfig();
262262
const navigation = useNavigationController();
263263
const snackbarController = useSnackbarController();
264+
console.log({ importConfig })
264265

265266
// Use this ref to store which properties have errors
266267
const propertyErrorsRef = useRef({});
@@ -374,7 +375,6 @@ function CollectionEditorInternal<M extends Record<string, any>>({
374375
if (!isNewCollection) {
375376
saveCollection(newCollectionState).then(() => {
376377
formexController.resetForm({ values: initialValues });
377-
// setNextMode();
378378
handleClose(newCollectionState);
379379
});
380380
return;
@@ -482,7 +482,6 @@ function CollectionEditorInternal<M extends Record<string, any>>({
482482
const resolvedPath = !pathError ? navigation.resolveAliasesFrom(updatedFullPath) : undefined;
483483
const getDataWithPath = resolvedPath && getData ? () => getData(resolvedPath, parentPaths ?? []) : undefined;
484484

485-
// eslint-disable-next-line react-hooks/rules-of-hooks
486485
useEffect(() => {
487486
setFormDirty(dirty);
488487
}, [dirty]);
@@ -552,9 +551,9 @@ function CollectionEditorInternal<M extends Record<string, any>>({
552551
{currentView === "welcome" &&
553552
<CollectionEditorWelcomeView
554553
path={path}
555-
onContinue={(data) => {
556-
if (data) {
557-
onImportDataSet(data);
554+
onContinue={(importData) => {
555+
if (importData) {
556+
onImportDataSet(importData);
558557
setCurrentView("import_data_mapping");
559558
} else {
560559
setCurrentView("details");
@@ -577,12 +576,13 @@ function CollectionEditorInternal<M extends Record<string, any>>({
577576
{currentView === "import_data_saving" && importConfig &&
578577
<ImportSaveInProgress importConfig={importConfig}
579578
collection={values}
580-
onImportSuccess={(importedCollection) => {
581-
handleClose(importedCollection);
579+
onImportSuccess={async (importedCollection) => {
582580
snackbarController.open({
583581
type: "info",
584582
message: "Data imported successfully"
585583
});
584+
await saveCollection(values);
585+
handleClose(importedCollection);
586586
}}
587587
/>}
588588

@@ -649,7 +649,6 @@ function CollectionEditorInternal<M extends Record<string, any>>({
649649
<Button variant={"text"}
650650
type="button"
651651
onClick={() => {
652-
saveCollection(values);
653652
setCurrentView("import_data_mapping");
654653
}}>
655654
<ArrowBackIcon/>
@@ -718,7 +717,6 @@ function CollectionEditorInternal<M extends Record<string, any>>({
718717
color="primary"
719718
type="submit"
720719
loading={isSubmitting}
721-
// disabled={isSubmitting || !dirty}
722720
>
723721
Update collection
724722
</LoadingButton>}

packages/collection_editor/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function CollectionEditorImportMapping({
140140

141141
return (
142142

143-
<div className={"overflow-auto my-auto bg-gray-50 dark:bg-gray-900"}>
143+
<div className={"overflow-auto my-auto"}>
144144
<Container maxWidth={"6xl"} className={"flex flex-col gap-4 p-8 m-auto"}>
145145

146146
<Typography variant="h6" className={"mt-4"}>Data property mapping</Typography>

packages/data_import_export/src/components/ImportSaveInProgress.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { CenteredView, CircularProgress, Typography, } from "@firecms/ui";
33
import { useEffect, useRef, useState } from "react";
44
import { ImportConfig } from "../types";
55

6-
export function ImportSaveInProgress<M extends { [Key: string]: CMSType }>
6+
export function ImportSaveInProgress<C extends EntityCollection>
77
({
88
importConfig,
99
collection,
1010
onImportSuccess
1111
}:
1212
{
1313
importConfig: ImportConfig,
14-
collection: EntityCollection<any>,
15-
onImportSuccess: (collection: EntityCollection<any>) => void
14+
collection: C,
15+
onImportSuccess: (collection: C) => void
1616
}) {
1717

1818
const dataSource = useDataSource();

packages/firebase_firecms/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"eslint-plugin-promise": "^6.1.1",
3939
"eslint-plugin-react": "^7.33.2",
4040
"eslint-plugin-react-hooks": "^4.6.0",
41-
"typescript": "^5.3.3"
41+
"typescript": "^5.3.3",
42+
"vite": "^5.1.1"
4243
},
4344
"scripts": {
4445
"dev": "vite",

packages/firebase_firecms_pro/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
"@firecms/core": "^3.0.0-beta.2-pre.4",
1313
"@firecms/firebase": "^3.0.0-beta.2-pre.4",
1414
"@firecms/ui": "^3.0.0-beta.2-pre.4",
15-
"@types/node": "^20.11.16",
1615
"firebase": "^10.8.0",
17-
"firecms": "^3.0.0-beta.2-pre.4",
18-
"typescript": "^5.3.3"
16+
"firecms": "^3.0.0-beta.2-pre.4"
17+
},
18+
"devDependencies": {
19+
"@types/node": "^20.11.16",
20+
"typescript": "^5.3.3",
21+
"vite": "^5.1.1"
1922
},
2023
"peerDependencies": {
2124
"react": "^18.2.0",

packages/firecms/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"eslint-plugin-promise": "^6.1.1",
6161
"eslint-plugin-react": "^7.33.2",
6262
"eslint-plugin-react-hooks": "^4.6.0",
63-
"typescript": "^5.3.3"
63+
"typescript": "^5.3.3",
64+
"vite": "^5.1.1"
6465
},
6566
"scripts": {
6667
"dev": "vite",

packages/firecms/src/hooks/useBuildCollectionsConfigController.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export function useBuildCollectionsConfigController<EC extends PersistedCollecti
118118
parentCollectionIds
119119
}: SaveCollectionParams<M>): Promise<void> => {
120120
if (!firestore || !configPath) throw Error("useFirestoreConfigurationPersistence Firestore not initialised");
121+
if (!id)
122+
throw Error("Trying to save a collection with no id");
123+
if (!collectionData.path)
124+
throw Error("Trying to save a collection with no path");
125+
if (!collectionData.name)
126+
throw Error("Trying to save a collection with no name");
121127
const cleanedCollection = prepareCollectionForPersistence(collectionData, propertyConfigsMap);
122128
const strippedPath = buildCollectionId(id, parentCollectionIds);
123129
const previousStrippedId = previousId ? buildCollectionId(previousId, parentCollectionIds) : undefined;
@@ -150,7 +156,7 @@ export function useBuildCollectionsConfigController<EC extends PersistedCollecti
150156
const previousStrippedPath = previousId ? buildCollectionId(previousId, parentCollectionIds) : undefined;
151157
const ref = doc(firestore, configPath, "collections", strippedPath);
152158

153-
console.debug("Saving collection", {
159+
console.debug("Updating collection", {
154160
id,
155161
collectionData,
156162
previousId,

packages/firecms_core/src/core/NavigationRoutes.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22

33
import { Route, Routes, useLocation } from "react-router-dom";
44
import { CMSView } from "../types";
5-
import { DefaultHomePage, EntityCollectionView, NotFoundPage } from "../components";
5+
import { DefaultHomePage, EntityCollectionView, ErrorBoundary, NotFoundPage } from "../components";
66
import { useNavigationController } from "../hooks";
77
import { toArray } from "../util/arrays";
88

@@ -70,13 +70,15 @@ export const NavigationRoutes = React.memo<NavigationRoutesProps>(
7070
return <Route path={urlPath + "/*"}
7171
key={`navigation_${collection.id ?? collection.path}`}
7272
element={
73-
<EntityCollectionView
74-
key={`collection_view_${collection.id ?? collection.path}`}
75-
isSubCollection={false}
76-
parentCollectionIds={[]}
77-
fullPath={collection.id ?? collection.path}
78-
{...collection}
79-
Actions={toArray(collection.Actions)}/>
73+
<ErrorBoundary>
74+
<EntityCollectionView
75+
key={`collection_view_${collection.id ?? collection.path}`}
76+
isSubCollection={false}
77+
parentCollectionIds={[]}
78+
fullPath={collection.id ?? collection.path}
79+
{...collection}
80+
Actions={toArray(collection.Actions)}/>
81+
</ErrorBoundary>
8082
}/>;
8183
}
8284
);

packages/formex/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"eslint-plugin-promise": "^6.1.1",
5050
"eslint-plugin-react": "^7.33.2",
5151
"eslint-plugin-react-hooks": "^4.6.0",
52-
"typescript": "^5.3.3"
52+
"typescript": "^5.3.3",
53+
"vite": "^5.1.1"
5354
},
5455
"scripts": {
5556
"dev": "vite",

packages/formex/src/useCreateFormex.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export function useCreateFormex<T extends object>({ initialValues, initialErrors
106106
}
107107

108108
const resetForm = (props?: FormexResetProps<T>) => {
109-
console.log("resetForm", props);
110109
const {
111110
submitCount: submitCountProp,
112111
values: valuesProp,

packages/schema_inference/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"module": "./dist/index.es.js",
99
"types": "dist/index.d.ts",
1010
"source": "src/index.ts",
11-
"dependencies": {
11+
"devDependencies": {
1212
"@firecms/core": "^3.0.0-beta.2-pre.4",
1313
"@types/node": "^20.11.16",
14-
"typescript": "^5.3.3"
14+
"typescript": "^5.3.3",
15+
"vite": "^5.1.1"
1516
},
1617
"files": [
1718
"dist",

packages/ui/src/components/Table.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Table = ({
1313
className,
1414
style
1515
}: TableProps) => (
16-
<table className={cn("w-full text-left text-slate-800 dark:text-slate-200 rounded-md overflow-x-auto",
16+
<table className={cn("w-full text-left text-gray-800 dark:text-slate-200 rounded-md overflow-x-auto",
1717
className)}
1818
style={style}>
1919
{children}
@@ -29,7 +29,7 @@ export const TableBody = ({
2929
className
3030
}: TableBodyProps) => (
3131
<tbody
32-
className={cn("bg-white text-sm dark:bg-slate-800 divide-y divide-slate-200 dark:divide-slate-700", className)}>
32+
className={cn("bg-white text-sm dark:bg-gray-800 divide-y divide-slate-200 dark:divide-gray-700", className)}>
3333
{children}
3434
</tbody>
3535
);
@@ -46,8 +46,8 @@ export const TableHeader = ({
4646
<thead>
4747
<tr className={cn(
4848
defaultBorderMixin,
49-
"text-sm font-medium text-slate-700 dark:text-slate-300",
50-
"bg-slate-50 border-b dark:bg-slate-900", className)}>
49+
"text-sm font-medium text-gray-700 dark:text-slate-300",
50+
"bg-slate-50 border-b dark:bg-gray-900", className)}>
5151
{children}
5252
</tr>
5353
</thead>
@@ -70,9 +70,9 @@ export const TableRow = ({
7070
onClick={onClick}
7171
style={style}
7272
className={cn(
73-
"divide-slate-100 dark:divide-slate-800",
74-
"bg-white dark:bg-slate-950",
75-
onClick ? "hover:bg-slate-100 dark:hover:bg-slate-800 cursor-pointer" : "",
73+
"divide-slate-100 dark:divide-gray-800",
74+
"bg-white dark:bg-gray-950",
75+
onClick ? "hover:bg-slate-100 dark:hover:bg-gray-800 cursor-pointer" : "",
7676
className)}
7777
>
7878
{children}

0 commit comments

Comments
 (0)