Skip to content

Commit

Permalink
Improve startup hooks
Browse files Browse the repository at this point in the history
Refactor startup hooks to ensure that non essential services/actions are
dispatched after the intial model load => don't block model loading with
eagerly dispatched actions

Refactor jump-out ui which was using an unnecessary command (If a
command does not edit the local model the logic should be placed in an
action handler instead)
  • Loading branch information
tortmayr committed Oct 1, 2024
1 parent 78b053d commit 6d99086
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 56 deletions.
8 changes: 4 additions & 4 deletions integration/eclipse/src/startup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IVY_TYPES, ToolBar } from '@axonivy/process-editor';
import { IVY_TYPES, ToolBar, JumpOutFeedbackAction } from '@axonivy/process-editor';
import { EnableInscriptionAction } from '@axonivy/process-editor-inscription';
import { EnableViewportAction, SwitchThemeAction, UpdatePaletteItems } from '@axonivy/process-editor-protocol';
import { EnableToolPaletteAction, GLSPActionDispatcher, IDiagramStartup, ShowGridAction, TYPES } from '@eclipse-glsp/client';
Expand All @@ -24,11 +24,11 @@ export class EclipseDiagramStartup implements IDiagramStartup {
this.actionDispatcher.dispatch(SwitchThemeAction.create({ theme: this.options.theme }));
}

async postRequestModel(): Promise<void> {
this.actionDispatcher.dispatch(ShowGridAction.create({ show: this.options.showGrid }));
}
async postRequestModel(): Promise<void> {}

async postModelInitialization(): Promise<void> {
this.actionDispatcher.dispatch(JumpOutFeedbackAction.create());
this.actionDispatcher.dispatch(ShowGridAction.create({ show: this.options.showGrid }));
this.actionDispatcher.dispatch(UpdatePaletteItems.create());
this.actionDispatcher.dispatch(EnableInscriptionAction.create({}));
}
Expand Down
9 changes: 4 additions & 5 deletions integration/standalone/src/startup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JumpOutFeedbackAction } from '@axonivy/process-editor';
import { EnableInscriptionAction } from '@axonivy/process-editor-inscription';
import { EnableViewportAction, SwitchThemeAction, UpdatePaletteItems } from '@axonivy/process-editor-protocol';
import {
Expand All @@ -10,7 +11,6 @@ import {
} from '@eclipse-glsp/client';
import { ContainerModule, inject, injectable } from 'inversify';
import { IvyDiagramOptions } from './di.config';

import './index.css';

@injectable()
Expand All @@ -27,17 +27,16 @@ export class StandaloneDiagramStartup implements IDiagramStartup {
this.actionDispatcher.dispatch(SwitchThemeAction.create({ theme: this.options.theme }));
}

async postRequestModel(): Promise<void> {
this.actionDispatcher.dispatch(UpdatePaletteItems.create());
}

async postModelInitialization(): Promise<void> {
this.actionDispatcher.dispatch(UpdatePaletteItems.create());
this.actionDispatcher.dispatch(
EnableInscriptionAction.create({
connection: { server: this.options.inscriptionContext.server },
inscriptionContext: this.options.inscriptionContext
})
);
this.actionDispatcher.dispatch(JumpOutFeedbackAction.create());

if (this.options.select) {
const elementIds = this.options.select.split(NavigationTarget.ELEMENT_IDS_SEPARATOR);
this.actionDispatcher.dispatch(SelectAction.create({ selectedElementsIDs: elementIds }));
Expand Down
2 changes: 2 additions & 0 deletions integration/viewer/src/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Action, CenterAction, GLSPActionDispatcher, IDiagramStartup, Navigation
import { ContainerModule, inject, injectable, interfaces } from 'inversify';
import { IvyDiagramOptions } from './di.config';
import { isInPreviewMode } from './url-helper';
import { JumpOutFeedbackAction } from '@axonivy/process-editor/';

const ContainerSymbol = Symbol('ContainerSymbol');

Expand All @@ -26,6 +27,7 @@ export class ViewerDiagramStartup implements IDiagramStartup {

protected async dispatchAfterModelInitialized(): Promise<void> {
const actions: Action[] = [];
actions.push(JumpOutFeedbackAction.create());
if (this.isNumeric(this.options.zoom)) {
actions.push(SetViewportZoomAction.create({ zoom: +this.options.zoom / 100 }));
actions.push(...this.showElement((ids: string[]) => CenterAction.create(ids, { animate: false, retainZoom: true })));
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export { ivyChangeBoundsToolModule, ivyExportModule } from './tools/di.config';
/* Features */
export * from './jump/action';
export * from './jump/model';
export * from './jump/jump-out-ui';
export * from './ui-tools/quick-action/model';
export * from './ui-tools/quick-action/quick-action';
export * from './ui-tools/quick-action/quick-action-ui';
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/jump/di.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import './jump-out.css';

import { configureActionHandler, configureCommand, FeatureModule, TYPES } from '@eclipse-glsp/client';
import { configureActionHandler, FeatureModule, TYPES } from '@eclipse-glsp/client';

import { JumpAction } from '@axonivy/process-editor-protocol';
import { IVY_TYPES } from '../types';
import { JumpActionHandler, JumpQuickActionProvider } from './action';
import { JumpOutFeedbackCommand, JumpOutUi } from './jump-out-ui';
import { JumpOutFeedbackAction, JumpOutUi } from './jump-out-ui';

const ivyJumpModule = new FeatureModule((bind, _unbind, isBound) => {
bind(JumpOutUi).toSelf().inSingletonScope();
bind(TYPES.IUIExtension).toService(JumpOutUi);
configureCommand({ bind, isBound }, JumpOutFeedbackCommand);
configureActionHandler({ bind, isBound }, JumpOutFeedbackAction.KIND, JumpOutUi);
bind(IVY_TYPES.QuickActionProvider).to(JumpQuickActionProvider);
configureActionHandler({ bind, isBound }, JumpAction.KIND, JumpActionHandler);
});
Expand Down
19 changes: 10 additions & 9 deletions packages/editor/src/jump/jump-out-ui.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
/* eslint-disable no-unused-expressions */
import {
Action,
ActionDispatcher,
ArgsAware,
Bounds,
CommandExecutionContext,
CommandReturn,
GGraph,
GModelFactory,
GModelRoot,
IActionHandler,
ICommand,
InitializeCanvasBoundsAction,
TYPES,
configureCommand,
configureActionHandler,
selectModule
} from '@eclipse-glsp/client';
import { Container, injectable } from 'inversify';
import { beforeEach, describe, expect, test } from 'vitest';

import { createTestContainer } from '../utils/test-utils';
import { JumpOutFeedbackAction, JumpOutFeedbackCommand } from './jump-out-ui';
import { JumpOutFeedbackAction, JumpOutUi } from './jump-out-ui';

let root: GModelRoot & ArgsAware;
let jumpOutBtn = false;

@injectable()
class JumpOutFeedbackCommandMock extends JumpOutFeedbackCommand {
execute(context: CommandExecutionContext): CommandReturn {
jumpOutBtn = this.showJumpOutBtn(root);
return root;
class JumpOutActionHandlerMock implements IActionHandler {
handle(action: Action): ICommand | Action | void {
const outUi = new JumpOutUi();
jumpOutBtn = outUi.showJumpOutBtn(root);
}
}

function createContainer(): Container {
const container = createTestContainer(selectModule);
configureCommand(container, JumpOutFeedbackCommandMock);
configureActionHandler(container, JumpOutFeedbackAction.KIND, JumpOutActionHandlerMock);

return container;
}
Expand Down
59 changes: 24 additions & 35 deletions packages/editor/src/jump/jump-out-ui.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { JumpAction } from '@axonivy/process-editor-protocol';
import { IvyIcons } from '@axonivy/ui-icons';
import {
Action,
CommandExecutionContext,
CommandReturn,
EditorContextService,
FeedbackCommand,
GLSPAbstractUIExtension,
GModelRoot,
IActionDispatcher,
IActionHandler,
IFeedbackActionDispatcher,
SetUIExtensionVisibilityAction,
GModelRoot,
TYPES,
SelectionService,
GLSPAbstractUIExtension
SetUIExtensionVisibilityAction,
TYPES
} from '@eclipse-glsp/client';
import { inject, injectable, postConstruct } from 'inversify';
import { IvyIcons } from '@axonivy/ui-icons';
import { createElement, createIcon } from '../utils/ui-utils';
import { JumpAction } from '@axonivy/process-editor-protocol';

@injectable()
export class JumpOutUi extends GLSPAbstractUIExtension {
export class JumpOutUi extends GLSPAbstractUIExtension implements IActionHandler {
static readonly ID = 'jumpOutUi';

@inject(TYPES.IActionDispatcher) protected readonly actionDispatcher: IActionDispatcher;
Expand All @@ -34,11 +32,6 @@ export class JumpOutUi extends GLSPAbstractUIExtension {
return 'jump-out-container';
}

@postConstruct()
protected postConstruct(): void {
this.feedbackDispatcher.registerFeedback(this, [JumpOutFeedbackAction.create()]);
}

protected initializeContents(containerElement: HTMLElement): void {
containerElement.style.position = 'absolute';
}
Expand All @@ -51,36 +44,32 @@ export class JumpOutUi extends GLSPAbstractUIExtension {
button.onclick = _ev => this.actionDispatcher.dispatch(JumpAction.create({ elementId: '' }));
containerElement.appendChild(button);
}

handle(action: Action): void {
if (action.kind === JumpOutFeedbackAction.KIND) {
this.feedbackDispatcher.registerFeedback(this, [
SetUIExtensionVisibilityAction.create({ extensionId: JumpOutUi.ID, visible: this.showJumpOutBtn(this.editorContext.modelRoot) })
]);
}
}

showJumpOutBtn(root: GModelRoot): boolean {
return root.id.includes('-');
}
}

export interface JumpOutFeedbackAction extends Action {
kind: typeof JumpOutFeedbackCommand.KIND;
kind: typeof JumpOutFeedbackAction.KIND;
elementId?: string;
}

export namespace JumpOutFeedbackAction {
export const KIND = 'jumpOutFeedback';

export function create(elementId?: string): JumpOutFeedbackAction {
return {
kind: JumpOutFeedbackCommand.KIND,
kind: JumpOutFeedbackAction.KIND,
elementId
};
}
}

@injectable()
export class JumpOutFeedbackCommand extends FeedbackCommand {
static readonly KIND = 'toolPaletteFeedback';
@inject(TYPES.Action) protected action: JumpOutFeedbackAction;
@inject(TYPES.IActionDispatcher) protected readonly actionDispatcher: IActionDispatcher;

execute(context: CommandExecutionContext): CommandReturn {
this.actionDispatcher.dispatch(
SetUIExtensionVisibilityAction.create({ extensionId: JumpOutUi.ID, visible: this.showJumpOutBtn(context.root) })
);
return context.root;
}

showJumpOutBtn(root: GModelRoot): boolean {
return root.id.includes('-');
}
}

0 comments on commit 6d99086

Please sign in to comment.