diff --git a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/FileBrowserApp.tsx b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/FileBrowserApp.tsx index d84356c7..e4392a25 100644 --- a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/FileBrowserApp.tsx +++ b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/FileBrowserApp.tsx @@ -13,6 +13,13 @@ type FileBrowserAppProps = { rootOverride?: string; /** What the root crumb is called. Defaults to the base folder's own name. */ rootLabel?: string; + /** + * Keep the current folder in this query param, on the route you are already on. + * + * For an embedded browser that wants a reloadable, shareable location. NOT `urlPath`, which owns the + * pathname and navigates to `/files` — passing that from a panel takes the whole app with it. + */ + pathParam?: string; /** Put the current folder in `?path=`. Opt-in — only the /files screen is guaranteed one browser. */ urlPath?: boolean; /** @@ -22,8 +29,15 @@ type FileBrowserAppProps = { panelId?: string; }; -export const FileBrowserApp = ({ basePath = '/', rootOverride, rootLabel, urlPath, panelId }: FileBrowserAppProps) => { - const fileBrowserManager = useFileBrowserApp(basePath, rootOverride, urlPath, panelId); +export const FileBrowserApp = ({ + basePath = '/', + rootOverride, + rootLabel, + urlPath, + panelId, + pathParam, +}: FileBrowserAppProps) => { + const fileBrowserManager = useFileBrowserApp(basePath, rootOverride, urlPath, panelId, pathParam); const { handleNavigate } = fileBrowserManager; return ( diff --git a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts index b209a597..616bb5a6 100644 --- a/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts +++ b/src/workspaces/officerdev/src/apps/FileBrowser/FileBrowserApp/useFileBrowserApp.ts @@ -24,7 +24,25 @@ import { useTranslation } from '../../../locales'; */ export const FILES_PATH_PARAM = 'path'; -export const useFileBrowserApp = (basePath: string, rootOverride?: string, urlPath = false, panelId?: string) => { +/** + * `pathParam` — keep the current folder in a QUERY PARAM, on whatever route we are already on. + * + * This is not `urlPath` and must not be confused with it. `urlPath` owns the URL's PATHNAME: it reads + * the folder out of `location.pathname` and navigates to `/files/`. That is correct for the + * Files screen, which IS that route, and catastrophic inside a panel — a plugin passing `urlPath` + * navigated the whole app to /files the moment anybody opened a folder. + * + * So an embedder gets its own mechanism: a named search param, written with `replace` so browsing does + * not fill the back stack, and no pathname involved at all. A reload lands where you were and the link + * can be sent to somebody, which is what was actually wanted. + */ +export const useFileBrowserApp = ( + basePath: string, + rootOverride?: string, + urlPath = false, + panelId?: string, + pathParam?: string, +) => { const { t } = useTranslation(); const { user } = useAuth(); const navigate = useNavigate();