Skip to content

Commit

Permalink
to amend
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwiehl committed Jun 14, 2024
1 parent 35b38a6 commit b1ea01b
Show file tree
Hide file tree
Showing 28 changed files with 712 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test.describe('Workbench Layout Migration', () => {
microfrontendSupport: false,
localStorage: {
'scion.workbench.perspective': 'empty',
'scion.workbench.perspectives.empty': 'eyJyZWZlcmVuY2VMYXlvdXQiOnsid29ya2JlbmNoR3JpZCI6ImV5SnliMjkwSWpwN0luUjVjR1VpT2lKTlVHRnlkQ0lzSW1sa0lqb2liV0ZwYmkxaGNtVmhJaXdpYzNSeWRXTjBkWEpoYkNJNmRISjFaU3dpZG1sbGQzTWlPbHRkZlN3aVlXTjBhWFpsVUdGeWRFbGtJam9pYldGcGJpMWhjbVZoSW4wdkx6VT0iLCJ2aWV3T3V0bGV0cyI6Int9In0sInVzZXJMYXlvdXQiOnsid29ya2JlbmNoR3JpZCI6ImV5SnliMjkwSWpwN0luUjVjR1VpT2lKTlZISmxaVTV2WkdVaUxDSmphR2xzWkRFaU9uc2lkSGx3WlNJNklrMVFZWEowSWl3aWFXUWlPaUpzWldaMElpd2ljM1J5ZFdOMGRYSmhiQ0k2ZEhKMVpTd2lkbWxsZDNNaU9sdDdJbWxrSWpvaWRtbGxkeTR5SWl3aVlXeDBaWEp1WVhScGRtVkpaQ0k2SW1WNGNHeHZjbVZ5SWl3aVkzTnpRMnhoYzNNaU9sc2laWGh3Ykc5eVpYSWlYU3dpYm1GMmFXZGhkR2x2YmlJNmV5SnBaQ0k2SWpnek4yTTBZV0ZsTFdKbFpXUXRORFl5WkMwNE56TTRMVGM0WlRkbFpUVmlORFV6WkNKOWZTeDdJbWxrSWpvaWRtbGxkeTR6SWl3aVlXeDBaWEp1WVhScGRtVkpaQ0k2SW01aGRtbG5ZWFJ2Y2lJc0ltTnpjME5zWVhOeklqcGJJbTVoZG1sbllYUnZjaUpkT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DSXNJbTVoZG1sbllYUnBiMjRpT250OWZWMHNJbUZqZEdsMlpWWnBaWGRKWkNJNkluWnBaWGN1TkNKOUxDSmthWEpsWTNScGIyNGlPaUp5YjNjaUxDSnlZWFJwYnlJNk1DNDNOWDBzSW1ScGNtVmpkR2x2YmlJNkluSnZkeUlzSW5KaGRHbHZJam93TGpJMWZTd2lZV04wYVhabFVHRnlkRWxrSWpvaWJHVm1kQ0o5THk4MCIsInZpZXdPdXRsZXRzIjoie1widmlldy4yXCI6W3tcInBhdGhcIjpcInRlc3Qtdmlld1wiLFwicGFyYW1ldGVyc1wiOnt9fV0sXCJ2aWV3LjNcIjpbXSxcInZpZXcuNFwiOlt7XCJwYXRoXCI6XCJ0ZXN0LXZpZXdcIixcInBhcmFtZXRlcnNcIjp7fX1dfSJ9fS8vMg==',
},
});

Expand Down
25 changes: 25 additions & 0 deletions projects/scion/workbench/src/lib/common/uid.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2018-2024 Swiss Federal Railways
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

import {UUID} from '@scion/toolkit/uuid';

/**
* Generates a UID (unique identifier).
*/
export const UID = {
/**
* Generates a UID (unique identifier) with length 8.
*/
randomUID: (): string => {
return UUID.randomUUID().substring(0, 8);
},
};


23 changes: 0 additions & 23 deletions projects/scion/workbench/src/lib/common/uuid.util.ts

This file was deleted.

4 changes: 2 additions & 2 deletions projects/scion/workbench/src/lib/dialog/ɵworkbench-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {WorkbenchDialogHeaderDirective} from './dialog-header/workbench-dialog-h
import {Disposable} from '../common/disposable';
import {Blockable} from '../glass-pane/blockable';
import {Blocking} from '../glass-pane/blocking';
import {randomUUID} from '../common/uuid.util';
import {UUID} from '@scion/toolkit/uuid';

/** @inheritDoc */
export class ɵWorkbenchDialog<R = unknown> implements WorkbenchDialog<R>, Blockable, Blocking {
Expand All @@ -57,7 +57,7 @@ export class ɵWorkbenchDialog<R = unknown> implements WorkbenchDialog<R>, Block
/**
* Unique identity of this dialog.
*/
public readonly id = randomUUID();
public readonly id = UUID.randomUUID();
/**
* Indicates whether this dialog is blocked by other dialog(s) that overlay this dialog.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {noop} from 'rxjs';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {FocusMonitor, FocusOrigin} from '@angular/cdk/a11y';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {randomUUID} from '../common/uuid.util';
import {UUID} from '@scion/toolkit/uuid';

/**
* Provides a filter control.
Expand All @@ -35,7 +35,7 @@ export class FilterFieldComponent implements ControlValueAccessor, OnDestroy {
private _cvaChangeFn: (value: any) => void = noop;
private _cvaTouchedFn: () => void = noop;

public readonly id = randomUUID();
public readonly id = UUID.randomUUID();

/**
* Sets focus order in sequential keyboard navigation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<!-- MPart (leaf) -->
<ng-container *ngIf="element | wbInstanceof:MPart as part" [cdkPortalOutlet]="part.id | wbPartPortal"></ng-container>
@if (element | wbInstanceof:MPart; as part) {
<ng-container [cdkPortalOutlet]="part.id | wbPartPortal"/>
}

<!-- MTreeNode -->
<ng-container *ngIf="element | wbInstanceof:MTreeNode as treeNode">
<!-- Node with a single visible child. -->
<wb-grid-element *ngIf="children.length === 1" [element]="children[0].element"></wb-grid-element>

<!-- Node with multiple visible children. -->
<sci-sashbox *ngIf="children.length > 1"
[direction]="treeNode.direction"
[attr.data-nodeid]="treeNode.nodeId"
(sashStart)="onSashStart()"
(sashEnd)="onSashEnd(treeNode, $event)">
<ng-template *ngFor="let child of children; index as i; trackBy: indexTrackByFn" sciSash [size]="child.size">
<wb-grid-element [element]="child.element" [class]="'sash-' + (i + 1)"></wb-grid-element>
</ng-template>
</sci-sashbox>
</ng-container>
@if (element | wbInstanceof:MTreeNode; as treeNode) {
@if (children.length === 1) {
<!-- Node with a single visible child. -->
<wb-grid-element [element]="children[0].element"/>
}
@if (children.length > 1) {
<!-- Node with multiple visible children. -->
<sci-sashbox [direction]="treeNode.direction"
[attr.data-nodeid]="treeNode.id"
(sashStart)="onSashStart()"
(sashEnd)="onSashEnd(treeNode, $event)">
@for (child of children; track child.element.id) {
<ng-template sciSash [size]="child.size">
<wb-grid-element [element]="child.element" [class]="'sash-' + ($index + 1)"/>
</ng-template>
}
</sci-sashbox>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
* SPDX-License-Identifier: EPL-2.0
*/

import {Component, HostBinding, Input, OnChanges, SimpleChanges, TrackByFunction} from '@angular/core';
import {Component, HostBinding, Input, OnChanges, SimpleChanges} from '@angular/core';
import {MPart, MTreeNode} from '../workbench-layout.model';
import {ɵWorkbenchRouter} from '../../routing/ɵworkbench-router.service';
import {WorkbenchLayoutService} from '../workbench-layout.service';
import {InstanceofPipe} from '../../common/instanceof.pipe';
import {PortalModule} from '@angular/cdk/portal';
import {PartPortalPipe} from '../../part/part-portal.pipe';
import {NgFor, NgIf} from '@angular/common';
import {SciSashboxComponent, SciSashDirective} from '@scion/components/sashbox';
import {WorkbenchLayouts} from '../workbench-layouts.util';

Expand All @@ -37,8 +36,6 @@ import {WorkbenchLayouts} from '../workbench-layouts.util';
styleUrls: ['./grid-element.component.scss'],
standalone: true,
imports: [
NgIf,
NgFor,
InstanceofPipe,
PortalModule,
PartPortalPipe,
Expand Down Expand Up @@ -70,8 +67,8 @@ export class GridElementComponent implements OnChanges {

public ngOnChanges(changes: SimpleChanges): void {
this.children = this.element instanceof MTreeNode ? this.computeChildren(this.element) : [];
this.parentNodeId = this.element.parent?.nodeId;
this.nodeId = this.element instanceof MTreeNode ? this.element.nodeId : undefined;
this.parentNodeId = this.element.parent?.id;
this.nodeId = this.element instanceof MTreeNode ? this.element.id : undefined;
this.partId = this.element instanceof MPart ? this.element.id : undefined;
}

Expand All @@ -82,7 +79,7 @@ export class GridElementComponent implements OnChanges {
public onSashEnd(treeNode: MTreeNode, [sashSize1, sashSize2]: number[]): void {
const ratio = sashSize1 / (sashSize1 + sashSize2);
this._workbenchLayoutService.notifyDragEnding();
this._workbenchRouter.navigate(layout => layout.setSplitRatio(treeNode.nodeId, ratio)).then();
this._workbenchRouter.navigate(layout => layout.setSplitRatio(treeNode.id, ratio)).then();
}

private computeChildren(treeNode: MTreeNode): ChildElement[] {
Expand All @@ -104,14 +101,6 @@ export class GridElementComponent implements OnChanges {
}
return [];
}

/**
* Each layout change creates new model object instances since the layout is deserialized from the URL.
* Therefore, the "correct" track-by function is critical to help Angular identify DOM elements for reuse, which significantly can
* improve performance. Note that we use the index instead of the object identity because a different identity may be computed for
* nodes when re-arranging parts. Using the index is like not using *ngFor at all.
*/
public indexTrackByFn: TrackByFunction<ChildElement> = (index: number): number => index;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface MPartV5 {

export interface MTreeNodeV5 {
type: 'MTreeNode';
nodeId: string;
id: string;
child1: MTreeNodeV5 | MPartV5;
child2: MTreeNodeV5 | MPartV5;
ratio: number;
Expand All @@ -44,4 +44,3 @@ export interface MViewV5 {
}

export type ViewIdV5 = `view.${number}`;

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Injectable} from '@angular/core';
import {MPartGridV4, MPartV4, MTreeNodeV4, MViewV4} from './model/workbench-layout-migration-v4.model';
import {WorkbenchMigration} from '../../migration/workbench-migration';
import {MPartGridV5, MPartV5, MTreeNodeV5, MViewV5} from './model/workbench-layout-migration-v5.model';
import {randomUUID} from '../../common/uuid.util';
import {UID} from '../../common/uid.util';

/**
* Migrates the workbench layout from version 4 to version 5.
Expand Down Expand Up @@ -46,6 +46,7 @@ export class WorkbenchLayoutMigrationV5 implements WorkbenchMigration {
function migrateNode(nodeV4: MTreeNodeV4): MTreeNodeV5 {
return {
...nodeV4,
id: UID.randomUID(),
child1: migrateGridElement(nodeV4.child1),
child2: migrateGridElement(nodeV4.child2),
};
Expand All @@ -58,7 +59,8 @@ export class WorkbenchLayoutMigrationV5 implements WorkbenchMigration {
function migrateView(viewV4: MViewV4): MViewV5 {
const viewV5: MViewV5 = {
...viewV4,
navigation: viewV4.navigation ? {...viewV4.navigation, id: randomUUID()} : undefined,
uid: UID.randomUID(),
navigation: viewV4.navigation ? {...viewV4.navigation, id: UID.randomUID()} : undefined,
};
if (!viewV5.navigation) {
delete viewV5.navigation;
Expand Down
Loading

0 comments on commit b1ea01b

Please sign in to comment.