Skip to content

Commit 38af7c3

Browse files
Copilothotlong
andauthored
refactor: address review feedback (dedup expressionUser, drop as-any cast)
Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/9bbb4b9a-dc45-41ea-b03e-55d3172b7dde Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 17cb417 commit 38af7c3

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

packages/app-shell/src/console/AppContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
146146
// `objectName` (set per view) so action buttons mounted inside an
147147
// ObjectView can omit it.
148148
runner.registerHandler('navigate_create', async (action: any) => {
149-
const ctx = (runner as any).context ?? {};
149+
const ctx = runner.getContext?.() ?? {};
150150
const result = resolveNavigateCreateUrl({
151151
action,
152152
context: ctx,
@@ -158,7 +158,7 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
158158
});
159159

160160
runner.registerHandler('navigate_edit', async (action: any) => {
161-
const ctx = (runner as any).context ?? {};
161+
const ctx = runner.getContext?.() ?? {};
162162
const result = resolveNavigateEditUrl({
163163
action,
164164
context: ctx,

packages/app-shell/src/utils/recordFormNavigation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,15 @@ export interface NavigationActionDef {
9393
* Optional context typically supplied by an `ActionRunner` (e.g. when the
9494
* action button is mounted inside an `ObjectView`, the view registers its
9595
* `objectName` and `baseUrl` on the runner so action JSON can omit them).
96+
*
97+
* Tolerant of additional unknown keys because the upstream
98+
* `ActionRunner.getContext()` returns a generic `ActionContext` with an
99+
* open index signature; we only read the two fields we care about.
96100
*/
97101
export interface NavigationActionContext {
98102
objectName?: string;
99103
baseUrl?: string;
104+
[key: string]: unknown;
100105
}
101106

102107
export type NavigationActionResult =

packages/app-shell/src/views/RecordFormPage.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,30 @@ export function RecordFormPage({ mode }: RecordFormPageProps) {
120120
goBack();
121121
}, [goBack]);
122122

123+
// Authenticated-user descriptor — shared by the ExpressionEvaluator (used
124+
// for field-visibility expression evaluation) and the ExpressionProvider
125+
// wrapping the form (which exposes the same descriptor to descendant
126+
// expression consumers). Memoised on the underlying user identity so a
127+
// re-render that doesn't change the user does not invalidate downstream
128+
// memoisations.
129+
const expressionUser = useMemo(
130+
() =>
131+
user
132+
? { name: user.name, email: user.email, role: user.role ?? 'user' }
133+
: { name: 'Anonymous', email: '', role: 'guest' },
134+
[user],
135+
);
136+
123137
// Build expression evaluator for field-visibility expressions, mirroring
124138
// the global ModalForm setup in AppContent.
125139
const expressionEvaluator = useMemo(
126140
() =>
127141
new ExpressionEvaluator({
128-
user: user
129-
? { name: user.name, email: user.email, role: user.role ?? 'user' }
130-
: {},
142+
user: user ? expressionUser : {},
131143
app: { name: appName },
132144
data: {},
133145
}),
134-
[user, appName],
146+
[user, expressionUser, appName],
135147
);
136148

137149
// Resolve the field list using the same visibility-aware logic as the
@@ -182,10 +194,6 @@ export function RecordFormPage({ mode }: RecordFormPageProps) {
182194
);
183195
}
184196

185-
const expressionUser = user
186-
? { name: user.name, email: user.email, role: user.role ?? 'user' }
187-
: { name: 'Anonymous', email: '', role: 'guest' };
188-
189197
return (
190198
<ExpressionProvider user={expressionUser} app={{ name: appName }} data={{}}>
191199
<div

0 commit comments

Comments
 (0)