Skip to content

Commit 0970e4b

Browse files
committed
fix: fix empty background under Drawer
1 parent 3feebd5 commit 0970e4b

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/frontend/components/app/drawer-portal.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export type DrawerPortalProps = {
2020
width?: number | string | Array<number | string>;
2121
}
2222

23+
export type DrawerWrapperProps = {
24+
onMount: () => void;
25+
}
26+
2327
const DRAWER_PORTAL_ID = 'drawerPortal'
2428
const DRAWER_PORTAL_WRAPPER_ID = 'drawerPortalWrapper'
2529

26-
const DrawerWrapper = ({ onMount }) => {
30+
const DrawerWrapper: React.FC<DrawerWrapperProps> = ({ onMount }) => {
2731
useEffect(() => {
2832
onMount()
2933
}, [])
@@ -34,7 +38,7 @@ const DrawerWrapper = ({ onMount }) => {
3438
)
3539
}
3640

37-
const createPortalContainer = (id: string) => {
41+
const getOrCreatePortalContainer = (id: string) => {
3842
let container = document.getElementById(id)
3943

4044
if (!container) {
@@ -68,7 +72,7 @@ export const DrawerPortal: React.FC<DrawerPortalProps> = ({ children, width }) =
6872
}
6973

7074
useEffect(() => {
71-
const innerWrapperElement = createPortalContainer(DRAWER_PORTAL_WRAPPER_ID)
75+
const innerWrapperElement = getOrCreatePortalContainer(DRAWER_PORTAL_WRAPPER_ID)
7276
if (!drawerElement && window) {
7377
const drawerRoot = createRoot(innerWrapperElement)
7478
drawerRoot.render(<DrawerWrapper onMount={handleDrawerMount} />)

src/frontend/components/application.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,29 @@ const App: React.FC = () => {
4242
const recordId = ':recordId'
4343
const pageName = ':pageName'
4444

45+
const dashboardUrl = h.dashboardUrl()
4546
const recordActionUrl = h.recordActionUrl({ resourceId, recordId, actionName })
4647
const resourceActionUrl = h.resourceActionUrl({ resourceId, actionName })
4748
const bulkActionUrl = h.bulkActionUrl({ resourceId, actionName })
4849
const resourceUrl = h.resourceUrl({ resourceId })
4950
const pageUrl = h.pageUrl(pageName)
5051

52+
/**
53+
* When defining AdminJS routes, we use Routes component twice.
54+
* This results in warnings appearing in console, for example about not being able to locate
55+
* "/admin" route. They can be safely ignored though and should appear only
56+
* in development environment. The warnings originate from the difference between
57+
* "Switch" component that AdminJS had used in "react-router" v5 which was later replaced
58+
* with "Routes" in "react-router" v6. "Switch" would use the first "Route" component
59+
* that matched the provided path, while "Routes" searches for the best matching pattern.
60+
* In AdminJS we use "DrawerPortal" to display actions in a drawer when
61+
* "showInDrawer" option is set to true. The drawer should appear above the currently viewed
62+
* page, but "Routes" broke this behavior because it instead showed a record action route with
63+
* an empty background.
64+
* The current flow is that first "Routes" component includes "Resource" route component
65+
* for drawer-placed actions and the second "Routes" is entered for record actions
66+
* on a separate page.
67+
*/
5168
return (
5269
<>
5370
<Reset />
@@ -60,17 +77,19 @@ const App: React.FC = () => {
6077
) : null}
6178
<Sidebar isVisible={sidebarVisible} />
6279
<Box flex flexGrow={1} flexDirection="column" overflowY="auto" bg="bg">
63-
<TopBar toggleSidebar={(): void => toggleSidebar(!sidebarVisible)} />
80+
<TopBar toggleSidebar={() => toggleSidebar(!sidebarVisible)} />
6481
<Box position="absolute" top={0} zIndex={2000}>
6582
<Notice />
6683
</Box>
6784
<Routes>
68-
<Route path={h.dashboardUrl()} element={<Dashboard />} />
6985
<Route path={`${resourceUrl}/*`} element={<Resource />} />
7086
<Route path={pageUrl} element={<Page />} />
71-
<Route path={`${recordActionUrl}/*`} element={<RecordAction />} />
87+
<Route path={dashboardUrl} element={<Dashboard />} />
88+
</Routes>
89+
<Routes>
7290
<Route path={`${resourceActionUrl}/*`} element={<ResourceAction />} />
7391
<Route path={`${bulkActionUrl}/*`} element={<BulkAction />} />
92+
<Route path={`${recordActionUrl}/*`} element={<RecordAction />} />
7493
</Routes>
7594
</Box>
7695
</Box>

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,9 +3611,9 @@ camelize@^1.0.0:
36113611
integrity sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs=
36123612

36133613
caniuse-lite@^1.0.30001280:
3614-
version "1.0.30001283"
3615-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001283.tgz#8573685bdae4d733ef18f78d44ba0ca5fe9e896b"
3616-
integrity sha512-9RoKo841j1GQFSJz/nCXOj0sD7tHBtlowjYlrqIUS812x9/emfBLBt6IyMz1zIaYc/eRL8Cs6HPUVi2Hzq4sIg==
3614+
version "1.0.30001393"
3615+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001393.tgz"
3616+
integrity sha512-N/od11RX+Gsk+1qY/jbPa0R6zJupEa0lxeBG598EbrtblxVCTJsQwbRBm6+V+rxpc5lHKdsXb9RY83cZIPLseA==
36173617

36183618
capture-stack-trace@^1.0.0:
36193619
version "1.0.1"

0 commit comments

Comments
 (0)