Skip to content

Commit 2800a8c

Browse files
committed
added isShow to page props
1 parent 94ff387 commit 2800a8c

File tree

4 files changed

+82
-79
lines changed

4 files changed

+82
-79
lines changed

src/adminjs-options.interface.ts

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ export interface AdminJSOptions {
5555
* path, under which, AdminJS will be available. Default to `/admin`
5656
*
5757
*/
58-
rootPath?: string;
58+
rootPath?: string
5959
/**
6060
* url to a logout action, default to `/admin/logout`
6161
*/
62-
logoutPath?: string;
62+
logoutPath?: string
6363
/**
6464
* url to a login page, default to `/admin/login`
6565
*/
66-
loginPath?: string;
66+
loginPath?: string
6767
/**
6868
* Array of all Databases which are supported by AdminJS via adapters
6969
*/
70-
databases?: Array<any>;
70+
databases?: Array<any>
7171

7272
/**
7373
* List of custom pages which will be visible below all resources
@@ -88,7 +88,7 @@ export interface AdminJSOptions {
8888
* },
8989
* },
9090
*/
91-
pages?: AdminPages;
91+
pages?: AdminPages
9292
/**
9393
* Array of all Resources which are supported by AdminJS via adapters.
9494
* You can pass either resource or resource with an options and thus modify it.
@@ -98,32 +98,32 @@ export interface AdminJSOptions {
9898
*
9999
* @see ResourceOptions
100100
*/
101-
resources?: Array<ResourceWithOptions | any>;
101+
resources?: Array<ResourceWithOptions | any>
102102
/**
103103
* Option to modify the dashboard
104104
*/
105105
dashboard?: {
106106
/**
107107
* Handler function which can be triggered using {@link ApiClient#getDashboard}.
108108
*/
109-
handler?: PageHandler;
109+
handler?: PageHandler
110110
/**
111111
* Bundled component name which should be rendered when user opens the dashboard
112112
*/
113-
component?: string;
114-
};
113+
component?: string
114+
}
115115
/**
116116
* Flag which indicates if version number should be visible on the UI
117117
*/
118-
version?: VersionSettings;
118+
version?: VersionSettings
119119
/**
120120
* Options which are related to the branding.
121121
*/
122-
branding?: BrandingOptions | BrandingOptionsFunction;
122+
branding?: BrandingOptions | BrandingOptionsFunction
123123
/**
124124
* Custom assets you want to pass to AdminJS
125125
*/
126-
assets?: Assets | AssetsFunction;
126+
assets?: Assets | AssetsFunction
127127
/**
128128
* Indicates is bundled by AdminJS files like:
129129
* - components.bundle.js
@@ -159,7 +159,7 @@ export interface AdminJSOptions {
159159
* with firebase hosting)
160160
* - point {@link AdminJS.assetsCDN} to this domain
161161
*/
162-
assetsCDN?: string;
162+
assetsCDN?: string
163163
/**
164164
* Environmental variables passed to the frontend.
165165
*
@@ -178,7 +178,7 @@ export interface AdminJSOptions {
178178
* AdminJS.env.GOOGLE_MAP_API_TOKEN
179179
* ```
180180
*/
181-
env?: Record<string, string>;
181+
env?: Record<string, string>
182182

183183
/* cspell: disable */
184184

@@ -236,22 +236,22 @@ export interface AdminJSOptions {
236236
* Check out the [i18n tutorial]{@tutorial i18n} to see how
237237
* internationalization in AdminJS works.
238238
*/
239-
locale?: Locale;
239+
locale?: Locale
240240

241241
/**
242242
* rollup bundle options;
243243
*/
244-
bundler?: BundlerOptions;
244+
bundler?: BundlerOptions
245245

246246
/**
247247
* Additional settings.
248248
*/
249-
settings?: Partial<AdminJSSettings>;
249+
settings?: Partial<AdminJSSettings>
250250
}
251251

252252
export type AdminJSSettings = {
253-
defaultPerPage: number;
254-
};
253+
defaultPerPage: number
254+
}
255255

256256
/* cspell: enable */
257257

@@ -268,16 +268,16 @@ export type Assets = {
268268
/**
269269
* List to urls of custom stylesheets. You can pass your font - icons here (as an example)
270270
*/
271-
styles?: Array<string>;
271+
styles?: Array<string>
272272
/**
273273
* List of urls to custom scripts. If you use some particular js
274274
* library - you can pass its url here.
275275
*/
276-
scripts?: Array<string>;
276+
scripts?: Array<string>
277277
/**
278278
* Mapping of core scripts in case you want to version your assets
279279
*/
280-
coreScripts?: CoreScripts;
280+
coreScripts?: CoreScripts
281281
}
282282

283283
/**
@@ -299,17 +299,17 @@ export type VersionSettings = {
299299
/**
300300
* if set to true - current admin version will be visible
301301
*/
302-
admin?: boolean;
302+
admin?: boolean
303303
/**
304304
* Here you can pass any arbitrary version text which will be seen in the US.
305305
* You can pass here your current API version.
306306
*/
307-
app?: string;
307+
app?: string
308308
}
309309

310310
export type VersionProps = {
311-
admin?: string;
312-
app?: string;
311+
admin?: string
312+
app?: string
313313
}
314314

315315
/**
@@ -334,26 +334,26 @@ export type BrandingOptions = {
334334
/**
335335
* URL to a logo, or `false` if you want to hide the default one.
336336
*/
337-
logo?: string | false;
337+
logo?: string | false
338338
/**
339339
* Name of your company, which will replace "AdminJS".
340340
*/
341-
companyName?: string;
341+
companyName?: string
342342
/**
343343
* CSS theme.
344344
*/
345-
theme?: Partial<ThemeOverride>;
345+
theme?: Partial<ThemeOverride>
346346
/**
347347
* Flag indicates if "made with love" tiny heart icon
348348
* should be visible on the bottom sidebar and login page.
349349
* @new since 6.0.0
350350
*/
351-
withMadeWithLove?: boolean;
351+
withMadeWithLove?: boolean
352352

353353
/**
354354
* URL to a favicon
355355
*/
356-
favicon?: string;
356+
favicon?: string
357357
}
358358

359359
/**
@@ -365,9 +365,7 @@ export type BrandingOptions = {
365365
* @memberof AdminJSOptions
366366
* @returns {BrandingOptions | Promise<BrandingOptions>}
367367
*/
368-
export type BrandingOptionsFunction = (
369-
admin?: CurrentAdmin
370-
) => BrandingOptions | Promise<BrandingOptions>
368+
export type BrandingOptionsFunction = (admin?: CurrentAdmin) => BrandingOptions | Promise<BrandingOptions>
371369

372370
/**
373371
* Object describing regular page in AdminJS
@@ -379,16 +377,21 @@ export type AdminPage = {
379377
/**
380378
* Handler function
381379
*/
382-
handler?: PageHandler;
380+
handler?: PageHandler
383381
/**
384382
* Component defined by using {@link AdminJS.bundle}
385383
*/
386-
component: string;
384+
component: string
387385

388386
/**
389387
* Page icon
390388
*/
391-
icon?: string;
389+
icon?: string
390+
391+
/**
392+
* Page visibility
393+
*/
394+
isShown?: boolean
392395
}
393396

394397
/**
@@ -405,9 +408,9 @@ export type AdminPages = Record<string, AdminPage>
405408
* @memberof AdminJSOptions
406409
*/
407410
export type ResourceWithOptions = {
408-
resource: any;
409-
options: ResourceOptions;
410-
features?: Array<FeatureType>;
411+
resource: any
412+
options: ResourceOptions
413+
features?: Array<FeatureType>
411414
}
412415

413416
/**
@@ -431,11 +434,7 @@ export type FeatureType = (
431434
* @alias PageHandler
432435
* @memberof AdminJSOptions
433436
*/
434-
export type PageHandler = (
435-
request: any,
436-
response: any,
437-
context: PageContext,
438-
) => Promise<any>
437+
export type PageHandler = (request: any, response: any, context: PageContext) => Promise<any>
439438

440439
/**
441440
* Bundle options
@@ -453,22 +452,25 @@ export type BundlerOptions = {
453452
/**
454453
* The file path to babel config file or json object of babel config.
455454
*/
456-
babelConfig?: BabelConfig | string;
455+
babelConfig?: BabelConfig | string
457456
}
458457

459458
export interface AdminJSOptionsWithDefault extends AdminJSOptions {
460-
rootPath: string;
461-
logoutPath: string;
462-
loginPath: string;
463-
databases?: Array<BaseDatabase>;
464-
resources?: Array<BaseResource | {
465-
resource: BaseResource;
466-
options: ResourceOptions;
467-
}>;
459+
rootPath: string
460+
logoutPath: string
461+
loginPath: string
462+
databases?: Array<BaseDatabase>
463+
resources?: Array<
464+
| BaseResource
465+
| {
466+
resource: BaseResource
467+
options: ResourceOptions
468+
}
469+
>
468470
dashboard: {
469-
handler?: PageHandler;
470-
component?: string;
471-
};
472-
bundler: BundlerOptions;
473-
pages: AdminJSOptions['pages'];
471+
handler?: PageHandler
472+
component?: string
473+
}
474+
bundler: BundlerOptions
475+
pages: AdminJSOptions['pages']
474476
}
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react'
22
import { Navigation, NavigationElementProps } from '@adminjs/design-system'
33

4-
import { useNavigate, useLocation } from 'react-router'
4+
import { useHistory, useLocation } from 'react-router'
55
import ViewHelpers from '../../../../backend/utils/view-helpers/view-helpers'
66
import { useTranslation } from '../../../hooks/use-translation'
77
import { ReduxState } from '../../../store/store'
88

99
type Props = {
10-
pages?: ReduxState['pages'];
10+
pages?: ReduxState['pages']
1111
}
1212

1313
const h = new ViewHelpers()
@@ -17,36 +17,29 @@ const SidebarPages: React.FC<Props> = (props) => {
1717

1818
const { translateLabel } = useTranslation()
1919
const location = useLocation()
20-
const navigate = useNavigate()
20+
const history = useHistory()
2121

2222
if (!pages || !pages.length) {
23-
return null
23+
return <></>
2424
}
2525

26-
const isActive = (page): boolean => (
27-
!!location.pathname.match(`/pages/${page.name}`)
28-
)
26+
const isActive = (page): boolean => !!location.pathname.match(`/pages/${page.name}`)
2927

3028
const elements: Array<NavigationElementProps> = pages.map((page) => ({
3129
id: page.name,
3230
label: page.name,
3331
isSelected: isActive(page),
32+
isShown: page.isShown,
3433
icon: page.icon,
3534
href: h.pageUrl(page.name),
3635
onClick: (event, element): void => {
3736
event.preventDefault()
3837
if (element.href) {
39-
navigate(element.href)
38+
history.push(element.href)
4039
}
4140
},
4241
}))
43-
44-
return (
45-
<Navigation
46-
label={translateLabel('pages')}
47-
elements={elements}
48-
/>
49-
)
42+
return <Navigation label={translateLabel('pages')} elements={elements} />
5043
}
5144

5245
export default SidebarPages
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ActionJSON } from './action'
2+
13
/**
24
* Representing the page in the sidebar
35
* @subcategory Frontend
@@ -6,14 +8,19 @@ export interface PageJSON {
68
/**
79
* Page name
810
*/
9-
name: string;
11+
name: string
1012
/**
1113
* Page component. Bundled with {@link AdminJS.bundle}
1214
*/
13-
component: string;
15+
component: string
1416

1517
/**
1618
* Page icon
1719
*/
18-
icon?: string;
20+
icon?: string
21+
22+
/**
23+
* Page visibility
24+
*/
25+
isShown: boolean
1926
}

src/frontend/store/pages-to-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { AdminJSOptions } from '../../adminjs-options.interface'
22

33
import { PageJSON } from '../interfaces'
44

5-
const pagesToStore = (pages: AdminJSOptions['pages'] = {}): Array<PageJSON> => Object.entries(pages)
6-
.map(([key, adminPage]) => ({
5+
const pagesToStore = (pages: AdminJSOptions['pages'] = {}): Array<PageJSON> =>
6+
Object.entries(pages).map(([key, adminPage]) => ({
77
name: key,
88
component: adminPage.component,
99
icon: adminPage.icon,
10+
isShown: adminPage.isShown,
1011
}))
1112

1213
export default pagesToStore

0 commit comments

Comments
 (0)