Skip to content

Commit 4998143

Browse files
committed
Secondary form fixes, and they preserve the form width when in side panel mode
1 parent b3a2a79 commit 4998143

File tree

6 files changed

+215
-256
lines changed

6 files changed

+215
-256
lines changed

packages/firecms_core/src/core/EntityEditView.tsx

+17-69
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React, { useEffect, useMemo, useState } from "react";
2-
import { Entity, EntityCollection, EntityCustomView, EntityStatus, FireCMSPlugin, FormContext, User } from "../types";
2+
import { Entity, EntityCollection, EntityStatus, FireCMSPlugin, FormContext, User } from "../types";
33

44
import { CircularProgressCenter, EntityCollectionView, EntityView, ErrorBoundary } from "../components";
5-
import { canEditEntity, removeInitialAndTrailingSlashes, resolveDefaultSelectedView, resolveEntityView } from "../util";
5+
import {
6+
canEditEntity,
7+
removeInitialAndTrailingSlashes,
8+
resolveDefaultSelectedView,
9+
resolvedSelectedEntityView
10+
} from "../util";
611

712
import {
813
useAuthController,
@@ -13,7 +18,7 @@ import {
1318
} from "../hooks";
1419
import { CircularProgress, cls, defaultBorderMixin, Tab, Tabs, Typography } from "@firecms/ui";
1520
import { getEntityFromCache } from "../util/entity_cache";
16-
import { EntityForm, EntityFormProps, FormLayoutInner } from "../form";
21+
import { EntityForm, EntityFormProps } from "../form";
1722
import { EntityEditViewFormActions } from "./EntityEditViewFormActions";
1823

1924
const MAIN_TAB_VALUE = "main_##Q$SC^#S6";
@@ -120,43 +125,6 @@ export function EntityEditView<M extends Record<string, any>, USER extends User>
120125
/>;
121126
}
122127

123-
function SecondaryForm<M extends object>({
124-
collection,
125-
className,
126-
customView,
127-
entity,
128-
formContext,
129-
forceActionsAtTheBottom,
130-
}: {
131-
className?: string,
132-
customView: EntityCustomView,
133-
formContext: FormContext<M>,
134-
collection: EntityCollection<M>,
135-
forceActionsAtTheBottom?: boolean,
136-
entity: Entity<M> | undefined,
137-
}) {
138-
139-
if (!customView.Builder) {
140-
console.error("customView.Builder is not defined");
141-
return null;
142-
}
143-
144-
return <FormLayoutInner
145-
className={className}
146-
forceActionsAtTheBottom={forceActionsAtTheBottom}
147-
formContext={formContext}
148-
EntityFormActionsComponent={EntityEditViewFormActions}>
149-
<ErrorBoundary>
150-
{formContext && <customView.Builder
151-
collection={collection}
152-
entity={entity}
153-
modifiedValues={formContext.formex.values ?? entity?.values}
154-
formContext={formContext}
155-
/>}
156-
</ErrorBoundary>
157-
</FormLayoutInner>;
158-
}
159-
160128
export function EntityEditViewInner<M extends Record<string, any>>({
161129
path,
162130
entityId,
@@ -214,42 +182,21 @@ export function EntityEditViewInner<M extends Record<string, any>>({
214182
}
215183
}, [selectedTabProp]);
216184

217-
const mainViewVisible = selectedTab === MAIN_TAB_VALUE;
218-
219185
const subcollections = (collection.subcollections ?? []).filter(c => !c.hideFromNavigation);
220186
const subcollectionsCount = subcollections?.length ?? 0;
221187
const customViews = collection.entityViews;
222188
const customViewsCount = customViews?.length ?? 0;
223189
const hasAdditionalViews = customViewsCount > 0 || subcollectionsCount > 0;
224190

225-
const resolvedEntityViews = customViews ? customViews
226-
.map(e => resolveEntityView(e, customizationController.entityViews))
227-
.filter(Boolean) as EntityCustomView[]
228-
: [];
191+
const {
192+
resolvedEntityViews,
193+
selectedEntityView,
194+
selectedSecondaryForm
195+
} = resolvedSelectedEntityView(customViews, customizationController, selectedTab);
229196

230-
const selectedEntityView = resolvedEntityViews.find(e => e.key === selectedTab);
231197
const actionsAtTheBottom = !largeLayout || layout === "side_panel" || selectedEntityView?.includeActions === "bottom";
232198

233-
const secondaryForms: React.ReactNode[] | undefined = formContext && customViews && resolvedEntityViews
234-
.filter(e => e.includeActions)
235-
.map((customView) => {
236-
if (!customView || !formContext)
237-
return null;
238-
239-
if (!customView.Builder) {
240-
console.error("customView.Builder is not defined");
241-
return null;
242-
}
243-
244-
return <SecondaryForm key={`custom_view_${customView.key}`}
245-
className={selectedTab !== customView.key ? "hidden" : ""}
246-
customView={customView}
247-
formContext={formContext}
248-
collection={collection}
249-
forceActionsAtTheBottom={!largeLayout || layout === "side_panel" || customView.includeActions === "bottom"}
250-
entity={usedEntity}/>;
251-
252-
}).filter(Boolean);
199+
const mainViewVisible = selectedTab === MAIN_TAB_VALUE || Boolean(selectedSecondaryForm);
253200

254201
const customViewsView: React.ReactNode[] | undefined = customViews && resolvedEntityViews
255202
.filter(e => !e.includeActions)
@@ -322,7 +269,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
322269
path,
323270
entityId,
324271
selectedTab: value === MAIN_TAB_VALUE ? undefined : value,
325-
collection
272+
collection,
326273
});
327274
}
328275
};
@@ -361,6 +308,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
361308
onSaved?.(res);
362309
formProps?.onSaved?.(res);
363310
}}
311+
Builder={selectedSecondaryForm?.Builder}
364312
/>;
365313

366314
const subcollectionTabs = subcollections && subcollections.map((subcollection) =>
@@ -421,7 +369,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
421369
</div>
422370
: entityView}
423371

424-
{secondaryForms}
372+
{/*{secondaryForms}*/}
425373

426374
{customViewsView}
427375

packages/firecms_core/src/core/EntitySidePanel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ export function EntitySidePanel(props: EntitySidePanelProps) {
141141
path,
142142
entityId,
143143
selectedTab,
144-
collection
144+
collection,
145145
}) => {
146146
sideEntityController.replace({
147147
path,
148148
entityId,
149149
selectedTab,
150150
updateUrl: true,
151-
collection
151+
collection,
152152
});
153153
}}
154154
formProps={props.formProps}

0 commit comments

Comments
 (0)