Skip to content

Commit 96df185

Browse files
committed
Logs cleanup
1 parent c6606dd commit 96df185

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

packages/firecms_core/src/core/EntityEditView.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ export function EntityEditView<M extends Record<string, any>, USER extends User>
109109
? getEntityFromMemoryCache(props.path + "/" + entityId)
110110
: getEntityFromMemoryCache(props.path + "#new");
111111

112-
console.log("EntityEditView initialDirtyValues:", initialDirtyValues);
113-
114112
const authController = useAuthController();
115113

116114
const initialStatus = props.copy ? "copy" : (entityId ? "existing" : "new");

packages/firecms_core/src/form/EntityForm.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ export function EntityForm<M extends Record<string, any>>({
285285
}, [localChangesDataRaw, initialValues]);
286286

287287
const hasLocalChanges = !localChangesCleared && localChangesData && Object.keys(localChangesData).length > 0;
288-
console.log("222 Local changes data", { localChangesDataRaw, localChangesData, hasLocalChanges });
289288

290289
const formex: FormexController<M> = formexProp ?? useCreateFormex<M>({
291290
initialValues: initialValues as M,
@@ -798,10 +797,12 @@ export function EntityForm<M extends Record<string, any>>({
798797
className={"flex flex-row gap-4 self-end sticky top-4 z-10"}>
799798

800799
{manualApplyLocalChanges && hasLocalChanges &&
801-
<LocalChangesMenu localChangesData={localChangesData as Partial<M>}
802-
formex={formex}
803-
onClearLocalChanges={() => setLocalChangesCleared(true)}
804-
cacheKey={(status === "new" || status === "copy") ? path + "#new" : path + "/" + entityId}
800+
<LocalChangesMenu
801+
cacheKey={status === "new" || status === "copy" ? path + "#new" : path + "/" + entityId}
802+
properties={resolvedCollection.properties}
803+
localChangesData={localChangesData as Partial<M>}
804+
formex={formex}
805+
onClearLocalChanges={() => setLocalChangesCleared(true)}
805806
/>}
806807

807808
{formex.dirty

packages/firecms_core/src/form/components/LocalChangesMenu.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@ import {
1111
Typography, VisibilityIcon,
1212
WarningIcon
1313
} from "@firecms/ui";
14-
import { flattenKeys, FormexController } from "@firecms/formex";
14+
import { flattenKeys, FormexController, getIn } from "@firecms/formex";
1515
import { useSnackbarController } from "../../hooks";
1616
import { mergeDeep } from "../../util";
1717
import { removeEntityFromCache } from "../../util/entity_cache";
18+
import { getPropertyInPath } from "../../util";
19+
import { PropertyPreview } from "../../preview";
20+
import { ResolvedProperties, ResolvedProperty } from "../../types";
1821

1922
interface LocalChangesMenuProps<M extends object> {
2023
cacheKey: string;
2124
localChangesData: Partial<M>;
2225
formex: FormexController<M>;
2326
onClearLocalChanges?: () => void;
27+
properties: ResolvedProperties<M>;
2428
}
2529

2630
export function LocalChangesMenu<M extends object>({
2731
localChangesData,
2832
formex,
2933
onClearLocalChanges,
30-
cacheKey
34+
cacheKey,
35+
properties
3136
}: LocalChangesMenuProps<M>) {
3237

3338
const snackbarController = useSnackbarController();
@@ -111,25 +116,30 @@ export function LocalChangesMenu<M extends object>({
111116
</p>
112117
<div
113118
className={`border rounded-lg divide-y divide-surface-200 divide-surface-opacity-40 dark:divide-surface-700 dark:divide-opacity-40 ${defaultBorderMixin}`}>
114-
{Object.entries(localChangesData).map(([key, value]) => (
115-
<div key={key}
116-
className="grid grid-cols-12 gap-x-4 px-4 py-3 items-center">
117-
<div
118-
className="col-span-3">
119-
<Typography variant="caption"
120-
className="text-gray-500 dark:text-gray-400 break-words">{key}</Typography>
119+
{flattenKeys(localChangesData).map((key) => {
120+
const value = getIn(localChangesData, key);
121+
const property = getPropertyInPath(properties, key) as ResolvedProperty;
122+
if (!property) {
123+
return null;
124+
}
125+
return (
126+
<div key={key}
127+
className="grid grid-cols-12 gap-x-4 px-4 py-3 items-center">
128+
<div
129+
className="col-span-3 text-right">
130+
<Typography variant="caption"
131+
className="text-gray-500 dark:text-gray-400 break-words">{property.name || key}</Typography>
132+
</div>
133+
<div className="col-span-9">
134+
<PropertyPreview
135+
propertyKey={key}
136+
value={value}
137+
property={property}
138+
size={"small"}/>
139+
</div>
121140
</div>
122-
<div className="col-span-9">
123-
<Typography component="div" variant="body2"
124-
className="text-gray-800 dark:text-gray-200">
125-
<div
126-
className="whitespace-pre-wrap break-words text-sm">
127-
{typeof value === "object" && value !== null ? JSON.stringify(value, null, 2) : String(value)}
128-
</div>
129-
</Typography>
130-
</div>
131-
</div>
132-
))}
141+
);
142+
})}
133143
</div>
134144
</DialogContent>
135145
<DialogActions>

packages/firecms_core/src/util/createFormexStub.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export function createFormexStub<T extends object>(values: T): FormexController<
44
const errorMessage = "You are in a read-only context. You cannot modify the formex controller.";
55

66
return {
7+
debugId: "",
78
values,
89
initialValues: values,
910
touched: {} as Record<string, boolean>,
@@ -19,6 +20,9 @@ export function createFormexStub<T extends object>(values: T): FormexController<
1920
setValues: () => {
2021
throw new Error(errorMessage);
2122
},
23+
setTouched(touched: Record<string, boolean>): void {
24+
throw new Error(errorMessage);
25+
},
2226
setFieldValue: () => {
2327
throw new Error(errorMessage);
2428
},

packages/firecms_core/src/util/entity_cache.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export function removeEntityFromMemoryCache(path: string): void {
102102
}
103103

104104
export function saveEntityToMemoryCache(path: string, data: object): void {
105-
console.log("!!! Saving entity to memory cache", path, data);
106105
entityCache.set(path, data);
107106
}
108107

@@ -149,10 +148,6 @@ export function getEntityFromCache(path: string): object | undefined {
149148
* @param path - The unique path/key for the entity to remove.
150149
*/
151150
export function removeEntityFromCache(path: string): void {
152-
153-
console.log("Removing entity from cache", path);
154-
155-
// Remove from localStorage
156151
if (isLocalStorageAvailable) {
157152
try {
158153
const key = LOCAL_STORAGE_PREFIX + path;

0 commit comments

Comments
 (0)