@@ -13,7 +13,11 @@ import {
1313 SubNavSection ,
1414 SubNavLink ,
1515} from '@strapi/design-system' ;
16- import { Page , useStrapiApp , Layouts } from '@strapi/strapi/admin' ;
16+ import {
17+ useStrapiApp ,
18+ Layouts ,
19+ useRBAC ,
20+ } from '@strapi/strapi/admin' ;
1721
1822import pluginPermissions from '../../permissions' ;
1923import pluginId from '../../helpers/pluginId' ;
@@ -27,6 +31,9 @@ import { InjectedRoute } from '../../types/injection-zones';
2731
2832const App = ( ) => {
2933 const getPlugin = useStrapiApp ( 'MyComponent' , ( state ) => state . getPlugin ) ;
34+ const {
35+ allowedActions : { canList, canPatterns, canOverview } ,
36+ } = useRBAC ( pluginPermissions ) ;
3037
3138 const plugin = getPlugin ( pluginId ) ;
3239
@@ -36,48 +43,54 @@ const App = () => {
3643 const currentPath = location . pathname ;
3744
3845 return (
39- < Page . Protect permissions = { pluginPermissions [ 'settings.patterns' ] } >
40- < Layouts . Root
41- sideNav = { (
42- < SubNav >
43- < SubNavHeader value = "" label = "Webtools" / >
44- < SubNavSections >
45- < SubNavSection label = "Core" >
46+ < Layouts . Root
47+ sideNav = { (
48+ < SubNav >
49+ < SubNavHeader value = "" label = "Webtools" / >
50+ < SubNavSections >
51+ < SubNavSection label = "Core" >
52+ { canOverview && (
4653 < SubNavLink tag = { Link } to = "/plugins/webtools" key = "test" className = { currentPath === '/plugins/webtools' ? 'active' : '' } >
4754 Overview
4855 </ SubNavLink >
56+ ) }
57+ { canList && (
4958 < SubNavLink tag = { Link } to = "/plugins/webtools/urls" key = "test" className = { currentPath . startsWith ( '/plugins/webtools/urls' ) ? 'active' : '' } >
5059 All URLs
5160 </ SubNavLink >
61+ ) }
62+ { canPatterns && (
5263 < SubNavLink tag = { Link } to = "/plugins/webtools/patterns" key = "test" className = { currentPath . startsWith ( '/plugins/webtools/patterns' ) ? 'active' : '' } >
5364 Url Patterns
5465 </ SubNavLink >
55- </ SubNavSection >
66+ ) }
67+ </ SubNavSection >
68+ { routerComponents . length > 0 && (
5669 < SubNavSection label = "Addons" >
5770 { routerComponents . map ( ( { path, label } ) => (
5871 < SubNavLink tag = { Link } to = { `/plugins/webtools${ path } ` } key = { path } className = { currentPath . startsWith ( `/plugins/webtools${ path } ` ) ? 'active' : '' } >
5972 { label }
6073 </ SubNavLink >
6174 ) ) }
6275 </ SubNavSection >
63- </ SubNavSections >
64- </ SubNav >
65- ) }
66- >
67- < Routes >
68- < Route path = "/" element = { < Overview /> } />
69- < Route path = "/urls" element = { < List /> } />
70- < Route path = "/patterns" element = { < PatternsListPage /> } />
71- < Route path = "/patterns/new" element = { < PatternsCreatePage /> } />
72- < Route path = "/patterns/:id" element = { < PatternsEditPage /> } />
73- { routerComponents . map ( ( { path, Component } ) => (
74- < Route path = { path } element = { < Component /> } />
75- ) ) }
76+ ) }
77+ </ SubNavSections >
78+ </ SubNav >
79+ ) }
80+ >
81+ < Routes >
82+ < Route path = "/" element = { < Overview /> } />
83+ < Route path = "/urls" element = { < List /> } />
84+ < Route path = "/patterns" element = { < PatternsListPage /> } />
85+ < Route path = "/patterns/new" element = { < PatternsCreatePage /> } />
86+ < Route path = "/patterns/:id" element = { < PatternsEditPage /> } />
87+ { routerComponents . map ( ( { path, Component } ) => (
88+ < Route path = { path } element = { < Component /> } />
89+ ) ) }
7690
77- < Route path = "*" element = { < PageNotFound /> } />
78- </ Routes >
79- </ Layouts . Root >
80- </ Page . Protect >
91+ < Route path = "*" element = { < PageNotFound /> } />
92+ </ Routes >
93+ </ Layouts . Root >
8194 ) ;
8295} ;
8396
0 commit comments