Skip to content

Commit ffea7f4

Browse files
committed
Fixed typescript errors
1 parent 086a7b1 commit ffea7f4

1 file changed

Lines changed: 102 additions & 86 deletions

File tree

src/components/shared/MainNav.tsx

Lines changed: 102 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -63,94 +63,110 @@ const MainNav = ({
6363
}
6464
}
6565

66+
interface linkMapItem {
67+
links: (React.ComponentProps<typeof MainNavLink> & {accessRole: string})[]
68+
}
69+
6670
const linkMap = {
67-
"events": [
68-
{
69-
path: "/events/events",
70-
accessRole: "ROLE_UI_EVENTS_VIEW",
71-
tooltipTitle: "NAV.EVENTS.TITLE",
72-
className: "events"
73-
},
74-
{
75-
path: "/events/series",
76-
accessRole: "ROLE_UI_SERIES_VIEW",
77-
tooltipTitle: "NAV.EVENTS.TITLE",
78-
className: "events",
79-
}
80-
],
81-
"recordings": [
82-
{
83-
path: "/recordings/recordings",
84-
accessRole: "ROLE_UI_LOCATIONS_VIEW",
85-
tooltipTitle: "NAV.CAPTUREAGENTS.TITLE",
86-
className: "recordings",
87-
}
88-
],
89-
"systems": [
90-
{
91-
path: "/systems/jobs",
92-
accessRole: "ROLE_UI_JOBS_VIEW",
93-
tooltipTitle: "NAV.SYSTEMS.TITLE",
94-
className: "systems",
95-
},
96-
{
97-
path: "/systems/servers",
98-
accessRole: "ROLE_UI_SERVERS_VIEW",
99-
tooltipTitle: "NAV.SYSTEMS.TITLE",
100-
className: "systems",
101-
},
102-
{
103-
path: "/systems/services",
104-
accessRole: "ROLE_UI_SERVICES_VIEW",
105-
tooltipTitle: "NAV.SYSTEMS.TITLE",
106-
className: "systems",
107-
}
108-
],
109-
"users": [
110-
{
111-
path: "/users/users",
112-
accessRole: "ROLE_UI_USERS_VIEW",
113-
tooltipTitle: "NAV.USERS.TITLE",
114-
className: "users",
115-
},
116-
{
117-
path: "/users/groups",
118-
accessRole: "ROLE_UI_GROUPS_VIEW",
119-
tooltipTitle: "NAV.USERS.TITLE",
120-
className: "users",
121-
},
122-
{
123-
path: "/users/acls",
124-
accessRole: "ROLE_UI_ACLS_VIEW",
125-
tooltipTitle: "NAV.USERS.TITLE",
126-
className: "users",
127-
}
128-
],
129-
"configuration": [
130-
{
131-
path: "/configuration/themes",
132-
accessRole: "ROLE_UI_THEMES_VIEW",
133-
tooltipTitle: "NAV.CONFIGURATION.TITLE",
134-
className: "configuration",
135-
}
136-
],
137-
"statistics": [
138-
{
139-
path: "/statistics/organization",
140-
accessRole: "ROLE_UI_STATISTICS_ORGANIZATION_VIEW",
141-
tooltipTitle: "NAV.STATISTICS.TITLE",
142-
className: "statistics",
143-
}
144-
]
71+
"events": {
72+
links: [
73+
{
74+
path: "/events/events",
75+
accessRole: "ROLE_UI_EVENTS_VIEW",
76+
tooltipTitle: "NAV.EVENTS.TITLE",
77+
className: "events"
78+
},
79+
{
80+
path: "/events/series",
81+
accessRole: "ROLE_UI_SERIES_VIEW",
82+
tooltipTitle: "NAV.EVENTS.TITLE",
83+
className: "events",
84+
}
85+
]
86+
} as linkMapItem,
87+
"recordings": {
88+
links: [
89+
{
90+
path: "/recordings/recordings",
91+
accessRole: "ROLE_UI_LOCATIONS_VIEW",
92+
tooltipTitle: "NAV.CAPTUREAGENTS.TITLE" as ParseKeys,
93+
className: "recordings",
94+
}
95+
]
96+
} as linkMapItem,
97+
"systems": {
98+
links: [
99+
{
100+
path: "/systems/jobs",
101+
accessRole: "ROLE_UI_JOBS_VIEW",
102+
tooltipTitle: "NAV.SYSTEMS.TITLE" as ParseKeys,
103+
className: "systems"
104+
},
105+
{
106+
path: "/systems/servers",
107+
accessRole: "ROLE_UI_SERVERS_VIEW",
108+
tooltipTitle: "NAV.SYSTEMS.TITLE" as ParseKeys,
109+
className: "systems"
110+
},
111+
{
112+
path: "/systems/services",
113+
accessRole: "ROLE_UI_SERVICES_VIEW",
114+
tooltipTitle: "NAV.SYSTEMS.TITLE" as ParseKeys,
115+
className: "systems"
116+
}
117+
]
118+
} as linkMapItem,
119+
"users": {
120+
links: [
121+
{
122+
path: "/users/users",
123+
accessRole: "ROLE_UI_USERS_VIEW",
124+
tooltipTitle: "NAV.USERS.TITLE" as ParseKeys,
125+
className: "users"
126+
},
127+
{
128+
path: "/users/groups",
129+
accessRole: "ROLE_UI_GROUPS_VIEW",
130+
tooltipTitle: "NAV.USERS.TITLE" as ParseKeys,
131+
className: "users"
132+
},
133+
{
134+
path: "/users/acls",
135+
accessRole: "ROLE_UI_ACLS_VIEW",
136+
tooltipTitle: "NAV.USERS.TITLE" as ParseKeys,
137+
className: "users"
138+
}
139+
]
140+
} as linkMapItem,
141+
"configuration": {
142+
links: [
143+
{
144+
path: "/configuration/themes",
145+
accessRole: "ROLE_UI_THEMES_VIEW",
146+
tooltipTitle: "NAV.CONFIGURATION.TITLE" as ParseKeys,
147+
className: "configuration"
148+
}
149+
]
150+
} as linkMapItem,
151+
"statistics": {
152+
links: [
153+
{
154+
path: "/statistics/organization",
155+
accessRole: "ROLE_UI_STATISTICS_ORGANIZATION_VIEW",
156+
tooltipTitle: "NAV.STATISTICS.TITLE" as ParseKeys,
157+
className: "statistics"
158+
}
159+
]
160+
} as linkMapItem
145161
};
146162

147163
// Link arrays containing more than one link must be sorted so that the
148164
// current view is always the first element. Otherwise, NavLink will not
149165
// recognize the current view as active.
150166
if (firstPathFragment.length > 0) {
151-
let arrToSort = linkMap[firstPathFragment];
167+
let arrToSort = linkMap[firstPathFragment as keyof typeof linkMap].links;
152168
if (arrToSort != undefined && arrToSort.length > 1) {
153-
arrToSort.forEach((item) => {
169+
arrToSort.forEach((item : any) => {
154170
if (item.path === pathname) { item.tmpIndex = 0 } else { item.tmpIndex = 1 }
155171
});
156172
arrToSort.sort((a: any, b: any) => a.tmpIndex - b.tmpIndex);
@@ -170,30 +186,30 @@ const MainNav = ({
170186
{/* todo: more than one href? how? roles? (see MainNav admin-ui-frontend)*/}
171187
<MainNavButton
172188
accessRole="ROLE_UI_NAV_RECORDINGS_VIEW"
173-
links={linkMap["events"]}
189+
links={linkMap["events"].links}
174190
/>
175191
<MainNavButton
176192
accessRole="ROLE_UI_NAV_CAPTURE_VIEW"
177-
links={linkMap["recordings"]}
193+
links={linkMap["recordings"].links}
178194
/>
179195
<MainNavButton
180196
accessRole="ROLE_UI_NAV_SYSTEMS_VIEW"
181-
links={linkMap["systems"]}
197+
links={linkMap["systems"].links}
182198
/>
183199
<MainNavButton
184200
accessRole="ROLE_UI_NAV_ORGANIZATION_VIEW"
185-
links={linkMap["users"]}
201+
links={linkMap["users"].links}
186202
/>
187203
{themesEnabled &&
188204
<MainNavButton
189205
accessRole="ROLE_UI_NAV_CONFIGURATION_VIEW"
190-
links={linkMap["configuration"]}
206+
links={linkMap["configuration"].links}
191207
/>
192208
}
193209
{statisticsEnabled &&
194210
<MainNavButton
195211
accessRole="ROLE_UI_NAV_STATISTICS_VIEW"
196-
links={linkMap["statistics"]}
212+
links={linkMap["statistics"].links}
197213
/>
198214
}
199215
</div>

0 commit comments

Comments
 (0)