MCPcopy Create free account
hub / github.com/dfinity/orbit / Navigation

Class Navigation

apps/wallet/src/plugins/navigation.plugin.ts:217–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217class Navigation {
218 constructor(
219 public sections: () => NavigationSections,
220 public routes: RouteRecordRaw[] = [],
221 ) {}
222
223 withSections(sections: NavigationSections): Navigation {
224 this.sections = () => sections;
225 return this;
226 }
227
228 withRoutes(routes: RouteRecordRaw[]): Navigation {
229 this.routes = routes;
230 return this;
231 }
232
233 install(app: App): void {
234 const { sections } = this;
235
236 const navigation = ref<NavigationSections>(sections());
237 const session = useSessionStore();
238 const store = useStationStore();
239 const userState = computed(() => ({
240 user: store.$state.user,
241 privileges: store.$state.privileges,
242 selectedStation: session.data.selected,
243 }));
244
245 watch(
246 () => userState.value,
247 () => {
248 const full = sections();
249 navigation.value = {
250 main: this.retainAuthorizedNavigation(full.main),
251 };
252 },
253 { deep: true, immediate: true },
254 );
255
256 app.config.globalProperties.$navigation = navigation;
257 }
258
259 private retainAuthorizedNavigation = (items: NavigationItem[]): NavigationItem[] => {
260 return items.filter(item => {
261 item.items = this.retainAuthorizedNavigation(item.items || []);
262
263 if (item.auth.type === NavigastionAuthType.Route) {
264 const route = this.findRouteByName(item.auth.route, this.routes);
265
266 if (!route) {
267 logger.warn(`Route '${item.auth.route}' not found for navigation item`);
268 return false;
269 }
270
271 if (!route.meta) {
272 logger.warn(`Route '${item.auth.route}' has no meta with the auth configuration`);
273 return false;
274 }

Callers

nothing calls this directly

Calls 2

hasRequiredSessionFunction · 0.90
hasRequiredPrivilegeFunction · 0.90

Tested by

no test coverage detected