Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/445 and more #553

Merged
merged 11 commits into from
May 7, 2024
Merged

Issue/445 and more #553

merged 11 commits into from
May 7, 2024

Conversation

danielwiehl
Copy link
Collaborator

@danielwiehl danielwiehl commented May 7, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added
  • Docs have been added or updated

PR Type

What kind of change does this PR introduce?

  • Fix
  • Feature
  • Documentation
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Performance (changes that improve performance)
  • Test (adding missing tests, refactoring tests; no production code change)
  • Chore (other changes like formatting, updating the license, removal of deprecations, etc)
  • Deps (changes related to updating dependencies)
  • CI (changes to our CI configuration files and scripts)
  • Revert (revert of a previous commit)
  • Release (publish a new release)
  • Other... Please describe:

Issue

Issue Number: #445, #479, #27, #344

Does this PR introduce a breaking change?

  • Yes

  • No

  • SCION Workbench requires Angular version 17.0.6 or later to fix fix(router): Ensure canMatch guards run on wildcard routes angular/angular#53239

  • Views in the initial layout (or perspective) must now be navigated.

  • Removed the option to close a view via the wbRouterLink directive.

  • Changed type of view id from string to ViewId

  • Property blankPartId in WorkbenchNavigationExtras has been renamed.

  • Property blankInsertionIndex in WorkbenchNavigationExtras has been renamed.

  • Interface and method for preventing closing of a view have changed.

danielwiehl and others added 11 commits May 7, 2024 06:51
…ngular#53239

BREAKING CHANGE: SCION Workbench requires Angular version 17.0.6 or later to fix angular/angular#53239
…uter link

The router link behaves differently depending on whether it is used inside or outside a view and whether the user presses the CTRL key (Mac: ⌘, Windows: ⊞). Closing a view should be an explicit action, regardless of the environment. We have, therefore, removed the option to close a view using the router link.

BREAKING CHANGE: Removed the option to close a view via the `wbRouterLink` directive.

The router link can no longer be used to close a view. To close a view, use the `WorkbenchView`, the `WorkbenchRouter`, or the `WorkbenchService` instead.

Examples:
```ts
// Closing a view via `WorkbenchView` handle
inject(WorkbenchView).close();

// Closing view(s) via `WorkbenchRouter`
inject(WorkbenchRouter).navigate(['path/*/view'], {close: true});

// Closing view(s) via `WorkbenchService`
inject(WorkbenchService).closeViews('view.1', 'view.2');
```
…r perspective)

Previously, views in the initial layout (or perspective) were limited to only supporting empty-path routes and could not be navigated or opened multiple times.

Authors: marcarrian <[email protected]>, danielwiehl <[email protected]>

closes #445

BREAKING CHANGE: Views in the initial layout (or perspective) must now be navigated.

Previously, no explicit navigation was required because views and routes were coupled via route outlet and view id.

**Migrate the layout as follows:**

Explicitly navigate views, passing an empty array of commands and the view id as navigation hint.

```ts
// Before Migration
provideWorkbench({
  layout: (factory: WorkbenchLayoutFactory) => factory
    .addPart(MAIN_AREA)
    .addPart('left', {relativeTo: MAIN_AREA, align: 'left'})
    .addView('navigator', {partId: 'left', activateView: true}),
});

// After Migration
provideWorkbench({
  layout: (factory: WorkbenchLayoutFactory) => factory
    .addPart(MAIN_AREA)
    .addPart('left', {relativeTo: MAIN_AREA, align: 'left'})
    .addView('navigator', {partId: 'left', activateView: true})
    // Navigate view, passing hint to match route.
    .navigateView('navigator', [], {hint: 'navigator'}),
});
```

**Migrate the routes as follows:**
- Remove the `outlet` property;
- Add `canMatchWorkbenchView` guard and initialize it with the hint passed to the navigation;

```ts
// Before Migration
provideRouter([
  {
    path: '',
    outlet: 'navigator',
    loadComponent: () => ...,
  },
]);

// After Migration
provideRouter([
  {
    path: '',
    // Match route only if navigated with specified hint.
    canMatch: [canMatchWorkbenchView('navigator')],
    loadComponent: () => ...,
  },
]);
```

BREAKING CHANGE: Changed type of view id from `string` to `ViewId`

If storing the view id in a variable, change its type from `string` to `ViewId`.
…rkbench Router API

Page objects for the Workbench API should closely mimic the underlying API, i.e., provide a method similar to the actual API to make tests more readable and concise.

Relates to #479
The navigator can now specify the part in which to navigate views.

The following rules apply:
- If target is `blank`, opens the view in the specified part;
- If target is `auto`, navigates matching views in the specified part, or opens a new view in that part otherwise;
- If the specified part is not in the layout, opens the view in the active part, with the active part of the main area taking precedence;

BREAKING CHANGE: Property `blankPartId` in `WorkbenchNavigationExtras` has been renamed.

To migrate, use `WorkbenchNavigationExtras.partId` instead of `WorkbenchNavigationExtras.blankPartId`.
The workbench router provides a new API for modifying the workbench layout. Instead of an array of commands, a function can be passed to the `navigate` method. The router will invoke this function with the current layout. The layout has methods for modification, with each modification creating a new layout instance. Use the new instance for further modifications and finally return it.

The following example adds a part to the left of the main area, inserts a view and navigates it.

```ts
import {inject} from '@angular/core';
import {MAIN_AREA, WorkbenchRouter} from '@scion/workbench';

inject(WorkbenchRouter).navigate(layout => layout
  .addPart('left', {relativeTo: MAIN_AREA, align: 'left'})
  .addView('navigator', {partId: 'left'})
  .navigateView('navigator', ['path/to/view'])
  .activateView('navigator')
);
```
The SCION Workbench can now be set up using the `provideWorkbench` function. Instead of importing the `WorkbenchModule`, use `provideWorkbench` function to register workbench providers.

**Before:**
```ts
@NgModule({
  imports: [WorkbenchModule.forRoot()],
  bootstrap: [AppComponent],
})
export class AppModule {
}
```

**After:**
```ts
bootstrapApplication(AppComponent, {
  providers: [provideWorkbench()],
});
```

Or for `NgModule` based applications:

```ts
@NgModule({
  providers: [provideWorkbench()],
  bootstrap: [AppComponent],
})
export class AppModule {
}
```
To have a consistent API, we have renamed the `blankInsertionIndex` property in `WorkbenchNavigationExtras` to `position`.

BREAKING CHANGE: Property `blankInsertionIndex` in `WorkbenchNavigationExtras` has been renamed.

To migrate, update to the latest version of `@scion/workbench-client` and use `WorkbenchNavigationExtras.position` instead of `WorkbenchNavigationExtras.blankInsertionIndex`.
Previously, when navigating an open view, its properties may not have been updated with data configured on the route (or its parent routes). The problem only existed when navigating to a child route having the same route root as the previous navigation.
The following issues have been fixed:
- `CanClose` guard now also works on child routes;
- multiple views can be closed simultaneously, even if some views prevent closing; previously, Angular navigation was canceled, causing no views to be closed;
- `CanClose` guard can now perform an Angular navigation, e.g., to display a dialog with routed content;

closes #27, closes #344

BREAKING CHANGE: Interface and method for preventing closing of a view have changed.

To migrate, implement the `CanClose` instead of the `WorkbenchViewPreDestroy` interface.

**Before migration:**
```ts
class YourComponent implements WorkbenchViewPreDestroy {
  public async onWorkbenchViewPreDestroy(): Promise<boolean> {
    // return `true` to close the view, otherwise `false`.
  }
}
```

**After migration:**

```ts
class YourComponent implements CanClose {
  public async canClose(): Promise<boolean> {
    // return `true` to close the view, otherwise `false`.
  }
}
```
…ath route

Previously, views could not be navigated to child routes of the top-level empty path route. This limitation has now been removed, enabling the registration of route guards at a single place.

```ts
{
  path: '',
  canActivate: [authGuard()],
  children: [
    {
      path: 'view-1',
      loadComponent: () => import('./view/view-1.component'),
    },
    {
      path: 'view-2',
      loadComponent: () => import('./view/view-2.component'),
    },
  ]
},
```

closes #487
@Marcarrian Marcarrian merged commit da578a9 into master May 7, 2024
64 checks passed
@Marcarrian Marcarrian deleted the issue/445 branch May 7, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants