Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 2.69 KB

how-to-perspective.md

File metadata and controls

73 lines (54 loc) · 2.69 KB

SCION Workbench

SCION Workbench Projects Overview Changelog Contributing Sponsoring

This chapter requires a perspective to be registered. See Providing a Perspective to learn how to provide a perspective.

How to query perspectives

Query perspectives using the WorkbenchService.perspectives signal.

How to switch a perspective

Switch perspectives using the WorkbenchService.switchPerspective method.

How to reset a perspectives

Reset the active perspective to its initial layout using the WorkbenchService.resetPerspective method.

How to test if a perspective is active

Check if a perspective is active using the WorkbenchPerspective.active signal, or read the active perspective from the WorkbenchService.activePerspective signal.

// Read the active perspective.
const activePerspective = inject(WorkbenchService).activePerspective();

// Check if a perspective is active.
const perspective = inject(WorkbenchService).getPerspective('perspective');
const isActive = perspective.active()

How to configure the initial perspective

Set the initial perspective in the workbench configuration by defining the initialPerspective property. Provide either a perspective id or a function to select from available perspectives.

Setting the developer perspective as the initial perspective.

import {provideWorkbench} from '@scion/workbench';

provideWorkbench({
  layout: {
    initialPerspective: 'developer',
  },
});

Selecting the developer perspective based on the user's roles and available perspectives.

import {provideWorkbench, WorkbenchPerspective} from '@scion/workbench';
import {inject} from '@angular/core';

provideWorkbench({
  layout: {
    initialPerspective: async (perspectives: WorkbenchPerspective[]) => {
      if (await inject(AuthService).hasRole('developer') && perspectives.some(perspective => perspective.id === 'developer')) {
        return 'developer';
      }
      return undefined;
    },
  },
});

The AuthService is illustrative and not part of the Workbench API.