Feat/added isVisible to page props#1262
Feat/added isVisible to page props#1262acamara2016 wants to merge 3 commits intoSoftwareBrothers:masterfrom
Conversation
src/adminjs-options.interface.ts
Outdated
| * | ||
| */ | ||
| rootPath?: string; | ||
| rootPath?: string |
src/adminjs-options.interface.ts
Outdated
| /** | ||
| * Page visibility | ||
| */ | ||
| isShown?: boolean |
There was a problem hiding this comment.
Why not isVisible? That's what we use in other configs, this could also be boolean | IsFunction
There was a problem hiding this comment.
I changed isShown to isVisible in the latest commit with type either boolean | IsFunction
| const { translateLabel } = useTranslation() | ||
| const location = useLocation() | ||
| const navigate = useNavigate() | ||
| const history = useHistory() |
There was a problem hiding this comment.
we've updated to react-router v6 which doesn't export useHistory, it has useNavigate instead
|
|
||
| if (!pages || !pages.length) { | ||
| return null | ||
| return <></> |
There was a problem hiding this comment.
returning an empty fragment is slower than returning null as it creates a DOM element, I don't see a reason for this change
2800a8c to
ad6b8f0
Compare
ad6b8f0 to
df2a541
Compare
df2a541 to
daea8d6
Compare
| /** | ||
| * Page visibility | ||
| */ | ||
| isVisible: boolean | IsFunction; |
There was a problem hiding this comment.
PageJSON is something returned to the frontend from the backend so it cannot be a function (IsFunction) and has to be pre-evaluated.
pagesToStore would have to do something like:
Object.entries(pages).map(([key, adminPage]) => {
let isVisible = true;
if (adminPage.isVisible) {
if (typeof adminPage.isVisible === 'function') {
isVisible = adminPage.isVisible({ currentAdmin })
} else {
isVisible = adminPage.isVisible
}
}
return {
name: key,
component: adminPage.component,
icon: adminPage.icon,
isVisible,
}
})
dziraf
left a comment
There was a problem hiding this comment.
One last thing, have you tested if this actually hides the page from the sidebar?
I'm not sure if any changes here are required: https://github.com/SoftwareBrothers/adminjs/blob/5145c48b7eb0758a603a4ee5435aa3883193ddd5/src/frontend/components/app/sidebar/sidebar-pages.tsx
| @@ -1,3 +1,6 @@ | |||
| import { IsFunction } from 'src/backend' | |||
There was a problem hiding this comment.
Sorry I haven't noticed this earlier. Can you change the import path to be relative (not start with src/)?
This PR is to allow hiding/reveal for custom components nav from the dashboard. Unlike the resources, custom components cannot be hidden from the dashboard