diff --git a/src/adminjs-options.interface.ts b/src/adminjs-options.interface.ts index 33ee9fe86..207bc94ba 100644 --- a/src/adminjs-options.interface.ts +++ b/src/adminjs-options.interface.ts @@ -3,7 +3,7 @@ import { TransformOptions as BabelConfig } from 'babel-core' import BaseResource from './backend/adapters/resource/base-resource' import BaseDatabase from './backend/adapters/database/base-database' -import { PageContext } from './backend/actions/action.interface' +import { IsFunction, PageContext } from './backend/actions/action.interface' import { ResourceOptions } from './backend/decorators/resource/resource-options.interface' import { Locale } from './locale/config' import { CurrentAdmin } from './current-admin.interface' @@ -389,6 +389,11 @@ export type AdminPage = { * Page icon */ icon?: string; + + /** + * Page visibility + */ + isVisible?: boolean | IsFunction } /** diff --git a/src/frontend/components/actions/action.props.ts b/src/frontend/components/actions/action.props.ts index 54cd6421d..73d998136 100644 --- a/src/frontend/components/actions/action.props.ts +++ b/src/frontend/components/actions/action.props.ts @@ -29,4 +29,4 @@ export type ActionProps = { * Sets tag in a header of an action. It is a function taking tag as an argument */ setTag?: Dispatch>; -} +} \ No newline at end of file diff --git a/src/frontend/interfaces/page-json.interface.ts b/src/frontend/interfaces/page-json.interface.ts index 491d81b51..4bf7e9517 100644 --- a/src/frontend/interfaces/page-json.interface.ts +++ b/src/frontend/interfaces/page-json.interface.ts @@ -1,3 +1,6 @@ +import { IsFunction } from 'src/backend' +import { ActionJSON } from './action' + /** * Representing the page in the sidebar * @subcategory Frontend @@ -16,4 +19,9 @@ export interface PageJSON { * Page icon */ icon?: string; + + /** + * Page visibility + */ + isVisible: boolean; } diff --git a/src/frontend/store/pages-to-store.ts b/src/frontend/store/pages-to-store.ts index 844a213a0..7b9be0656 100644 --- a/src/frontend/store/pages-to-store.ts +++ b/src/frontend/store/pages-to-store.ts @@ -2,11 +2,22 @@ import { AdminJSOptions } from '../../adminjs-options.interface' import { PageJSON } from '../interfaces' -const pagesToStore = (pages: AdminJSOptions['pages'] = {}): Array => Object.entries(pages) - .map(([key, adminPage]) => ({ - name: key, - component: adminPage.component, - icon: adminPage.icon, - })) +const pagesToStore = (pages: AdminJSOptions['pages'] = {}): Array => + 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, + } + }); export default pagesToStore