Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 2f31406

Browse files
feat(app-shell): refine studio package scope (#1483)
Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com>
1 parent b3e6d9e commit 2f31406

14 files changed

Lines changed: 315 additions & 61 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
Refine Studio package-scoped navigation and home overview.
7+
8+
Studio now treats the selected package as the home overview scope, flattens the root Overview sidebar group, hides the duplicate all-metadata sidebar entry, redirects the invalid package metadata route to package management, preserves the selected package across package-management navigation, and adds a localized package-management sidebar label.

‎content/docs/guide/console.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The console opens at **http://localhost:5175** with MSW (Mock Service Worker) pr
2828
| **Expression Visibility** | Show/hide navigation items using `visible: "${data.role === 'admin'}"`. |
2929
| **Branding** | Per-app colors, favicons, and logos via `AppShell` branding. |
3030
| **Command Palette** | `⌘+K` opens a searchable command bar for quick navigation. |
31+
| **Studio Package Scope** | Studio home, metadata counts, quick-create links, and diagnostics follow the selected package. |
3132
| **App Creation Wizard** | 4-step wizard (Basic Info → Objects → Navigation → Branding) to create or edit apps. |
3233
| **Error Boundary** | Graceful error handling with a retry button. |
3334

‎packages/app-shell/README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ for each metadata type. Every type has a pure-renderer **preview** that doubles
147147
as its **designer** when given `editing` + `onPatch` props — no backend round
148148
trip is required to edit a draft.
149149

150+
### Studio package scope
151+
152+
Studio treats the selected package as the authoring scope. The package selector
153+
is mandatory, and Studio repairs missing `?package=` query parameters from the
154+
last selected package or the first project package so scoped pages do not drift
155+
out of sync with the sidebar. The Studio home overview, quick-create links,
156+
metadata counts, and diagnostics all follow that active package. The dedicated
157+
package-management page remains the global place to create, import, publish,
158+
enable, or disable packages; direct `/metadata/package` links redirect there.
159+
The Studio sidebar also flattens the root Overview group so Home and package
160+
navigation sit directly under the package selector.
161+
150162
### Visual flow canvas
151163

152164
The `flow` designer (`FlowPreview` → `FlowCanvas`) renders an automation as an

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
173173
launcherApps.find((a: any) => a.isDefault === true) ||
174174
launcherApps[0];
175175

176+
useEffect(() => {
177+
if (!activeApp?.name) return;
178+
const packageMetadataPath = `/apps/${activeApp.name}/metadata/package`;
179+
if (
180+
location.pathname === packageMetadataPath ||
181+
location.pathname.startsWith(`${packageMetadataPath}/`)
182+
) {
183+
navigate(`/apps/${activeApp.name}/component/developer/packages`, { replace: true });
184+
}
185+
}, [activeApp?.name, location.pathname, navigate]);
186+
176187
const [isDialogOpen, setIsDialogOpen] = useState(false);
177188
const [editingRecord, setEditingRecord] = useState<any>(null);
178189
const [refreshKey, setRefreshKey] = useState(0);
@@ -415,6 +426,10 @@ export function AppContent({ extraRoutes, extraRoutesNoApp }: AppContentProps =
415426
wins React Router's score tiebreaker (both
416427
`metadata/:type/:name` and `:objectName/view/:viewId`
417428
score 16; declaration order breaks the tie). */}
429+
<Route
430+
path="metadata/package/*"
431+
element={<Navigate to={`/apps/${activeApp.name}/component/developer/packages`} replace />}
432+
/>
418433
<Route path="metadata">
419434
<Route index element={<MetadataDirectoryPage />} />
420435
<Route path="_diagnostics" element={<MetadataDiagnosticsPage />} />
@@ -670,4 +685,3 @@ function RouteNotFound() {
670685
</div>
671686
);
672687
}
673-
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
2+
import { SidebarProvider, useSidebar } from '@object-ui/components';
3+
import { describe, expect, it } from 'vitest';
4+
import { useResponsiveSidebar } from '../useResponsiveSidebar';
5+
6+
function setViewportWidth(width: number) {
7+
Object.defineProperty(window, 'innerWidth', {
8+
configurable: true,
9+
writable: true,
10+
value: width,
11+
});
12+
}
13+
14+
function Harness() {
15+
useResponsiveSidebar();
16+
const { open, setOpen } = useSidebar();
17+
18+
return (
19+
<>
20+
<div data-testid="sidebar-open">{String(open)}</div>
21+
<button type="button" onClick={() => setOpen(true)}>
22+
Expand sidebar
23+
</button>
24+
</>
25+
);
26+
}
27+
28+
describe('useResponsiveSidebar', () => {
29+
it('auto-collapses at tablet width without overriding a manual expand', async () => {
30+
setViewportWidth(970);
31+
32+
render(
33+
<SidebarProvider defaultOpen>
34+
<Harness />
35+
</SidebarProvider>,
36+
);
37+
38+
await waitFor(() => {
39+
expect(screen.getByTestId('sidebar-open')).toHaveTextContent('false');
40+
});
41+
42+
fireEvent.click(screen.getByRole('button', { name: 'Expand sidebar' }));
43+
44+
await waitFor(() => {
45+
expect(screen.getByTestId('sidebar-open')).toHaveTextContent('true');
46+
});
47+
});
48+
});

‎packages/app-shell/src/hooks/useResponsiveSidebar.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @module
77
*/
88

9-
import { useEffect } from 'react';
9+
import { useEffect, useRef } from 'react';
1010
import { useSidebar } from '@object-ui/components';
1111

1212
/** Tablet breakpoint range: 768px <= width < 1024px */
@@ -15,20 +15,31 @@ const TABLET_MAX = 1024;
1515

1616
export function useResponsiveSidebar() {
1717
const { setOpen, isMobile } = useSidebar();
18+
const setOpenRef = useRef(setOpen);
1819

1920
useEffect(() => {
21+
setOpenRef.current = setOpen;
22+
}, [setOpen]);
23+
24+
useEffect(() => {
25+
if (isMobile) return undefined;
26+
27+
let wasTablet = false;
28+
2029
function handleResize() {
2130
const width = window.innerWidth;
22-
if (width >= TABLET_MIN && width < TABLET_MAX) {
23-
// Tablet: auto-collapse sidebar
24-
setOpen(false);
31+
const isTablet = width >= TABLET_MIN && width < TABLET_MAX;
32+
if (isTablet && !wasTablet) {
33+
// Auto-collapse once when entering tablet width, then preserve manual toggles.
34+
setOpenRef.current(false);
2535
}
36+
wasTablet = isTablet;
2637
}
2738

2839
// Run on mount to set initial state
2940
handleResize();
3041

3142
window.addEventListener('resize', handleResize);
3243
return () => window.removeEventListener('resize', handleResize);
33-
}, [setOpen, isMobile]);
44+
}, [isMobile]);
3445
}

‎packages/app-shell/src/layout/AppHeader.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ export function AppHeader({
574574

575575
{isApp && (
576576
<>
577-
{/* Mobile sidebar trigger */}
578-
<SidebarTrigger className="md:hidden shrink-0 ml-1" aria-label={t('common.toggleSidebar') || 'Toggle sidebar'} />
577+
{/* Keep the sidebar trigger visible through narrow desktop widths,
578+
where the sidebar may already be collapsed into icon mode. */}
579+
<SidebarTrigger className="lg:hidden shrink-0 ml-1" aria-label={t('common.toggleSidebar') || 'Toggle sidebar'} />
579580

580581
{/* App dropdown — desktop/tablet only. On mobile the sidebar
581582
already shows the active app at its top, so a second app

‎packages/app-shell/src/layout/ContextSelectors.tsx‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,10 @@ export function useAppContextSelectors(
148148
// more "sidebar says A while the list shows B" drift.
149149
const params = new URLSearchParams(location.search);
150150

151-
// Re-apply a remembered scope once, on first mount, so a selection
152-
// survives a full page reload (when the URL comes back without the
153-
// query param). Subsequent navigation is driven purely by the URL.
154-
const seededRef = React.useRef(false);
151+
// Re-apply a remembered scope whenever navigation drops the query param.
152+
// The selector is mandatory for Studio: package-scoped pages should never
153+
// sit at a blank package value just because a nav link omitted `?package=`.
155154
React.useEffect(() => {
156-
if (seededRef.current) return;
157-
seededRef.current = true;
158155
const p = new URLSearchParams(location.search);
159156
let changed = false;
160157
for (const sel of list) {
@@ -168,8 +165,7 @@ export function useAppContextSelectors(
168165
if (changed) {
169166
navigate({ pathname: location.pathname, search: p.toString() }, { replace: true });
170167
}
171-
// eslint-disable-next-line react-hooks/exhaustive-deps
172-
}, []);
168+
}, [appName, list, location.pathname, location.search, navigate]);
173169

174170
const setValue = React.useCallback((sel: ContextSelectorDef, raw: string) => {
175171
const value = raw === ALL_SENTINEL ? (sel.allValue ?? '') : raw;
@@ -190,7 +186,11 @@ export function useAppContextSelectors(
190186

191187
const contextValues: Record<string, string> = {};
192188
for (const sel of list) {
193-
contextValues[sel.id] = params.get('package') ?? (sel.allValue ?? '');
189+
let saved = '';
190+
try {
191+
saved = sessionStorage.getItem(`objectui-ctx-${appName}-${sel.id}`) ?? '';
192+
} catch { /* storage disabled */ }
193+
contextValues[sel.id] = (params.get('package') ?? saved) || (sel.allValue ?? '');
194194
}
195195

196196
const element = list.length === 0 ? null : (
@@ -238,34 +238,31 @@ function SelectorControl({
238238
// `includeAll`, never render an "All" row, and auto-select the first option
239239
// as soon as the list resolves when nothing concrete is selected yet.
240240
const hasConcrete = !!value && value !== (def.allValue ?? '');
241-
const seededRef = React.useRef(false);
242241
React.useEffect(() => {
243-
if (seededRef.current) return;
244242
if (hasConcrete) {
245-
seededRef.current = true;
246243
return;
247244
}
248245
if (options.length > 0) {
249-
seededRef.current = true;
250246
onChange(options[0].value);
251247
}
252-
// eslint-disable-next-line react-hooks/exhaustive-deps
253-
}, [options, hasConcrete]);
248+
}, [hasConcrete, onChange, options]);
254249

255250
const current = hasConcrete ? value : '';
256251

257252
return (
258253
<Select value={current} onValueChange={onChange}>
259254
<SelectTrigger
260255
aria-label={label}
261-
className="h-8 w-full gap-1.5 rounded-md border-sidebar-border/60 bg-sidebar-accent/40 px-2 text-xs font-medium text-sidebar-foreground shadow-none hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent"
256+
className="h-9 w-full gap-2 rounded-md border-sidebar-border/70 bg-sidebar/80 px-2 text-xs font-medium text-sidebar-foreground shadow-none transition-colors hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:shrink-0"
262257
>
263-
<span className="flex min-w-0 items-center gap-1.5 truncate">
264-
<Icon className="h-3.5 w-3.5 shrink-0 opacity-60" />
265-
<SelectValue placeholder={placeholder} />
266-
</span>
258+
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden">
259+
<span className="flex h-5 w-5 shrink-0 items-center justify-center rounded border border-sidebar-border/70 bg-sidebar-accent text-sidebar-foreground/70">
260+
<Icon className="h-3 w-3" />
261+
</span>
262+
<SelectValue placeholder={placeholder} className="truncate" />
263+
</div>
267264
</SelectTrigger>
268-
<SelectContent>
265+
<SelectContent className="w-[var(--radix-select-trigger-width)]">
269266
{options.map((opt) => (
270267
<SelectItem key={opt.value} value={opt.value}>
271268
{opt.label}

0 commit comments

Comments
 (0)