Skip to content

Commit

Permalink
GLSP-1071: Rename ServerStatus/ServerMessage action
Browse files Browse the repository at this point in the history
  • Loading branch information
tortmayr committed Sep 14, 2023
1 parent d3ee745 commit f0b33a9
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 92 deletions.
9 changes: 3 additions & 6 deletions examples/workflow-standalone/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
GLSPActionDispatcher,
GLSPClient,
GLSPWebSocketProvider,
ServerMessageAction,
ServerStatusAction
MessageAction,
StatusAction
} from '@eclipse-glsp/client';
import { Container } from 'inversify';
import { join, resolve } from 'path';
Expand Down Expand Up @@ -55,10 +55,7 @@ async function initialize(connectionProvider: MessageConnection, isReconnecting
const message = `Connection to the ${id} glsp server got closed. Connection was successfully re-established.`;
const timeout = 5000;
const severity = 'WARNING';
actionDispatcher.dispatchAll([
ServerStatusAction.create(message, { severity, timeout }),
ServerMessageAction.create(message, { severity })
]);
actionDispatcher.dispatchAll([StatusAction.create(message, { severity, timeout }), MessageAction.create(message, { severity })]);
return;
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/client/src/base/model/diagram-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { SetModelAction } from '@eclipse-glsp/protocol';
import { inject, injectable, multiInject, optional, postConstruct } from 'inversify';
import {
AnyObject,
ApplicationIdProvider,
Args,
EMPTY_ROOT,
GLSPClient,
InitializeParameters,
MaybePromise,
RequestModelAction,
ServerStatusAction,
StatusAction,
TYPES,
hasNumberProp
} from '~glsp-sprotty';
Expand Down Expand Up @@ -171,6 +173,8 @@ export class DiagramLoader {
enableNotifications: options.enableNotifications ?? true
};
await this.actionDispatcher.initialize();
// Set placeholder model until real model from server is available
await this.actionDispatcher.dispatch(SetModelAction.create(EMPTY_ROOT));
await this.invokeStartupHook('preInitialize');
await this.initialize(resolvedOptions);
await this.invokeStartupHook('preRequestModel');
Expand All @@ -191,7 +195,7 @@ export class DiagramLoader {

protected async initialize(options: ResolvedDiagramLoadingOptions): Promise<void> {
if (options.enableNotifications) {
this.actionDispatcher.dispatch(ServerStatusAction.create('Initializing...', { severity: 'INFO' }));
this.actionDispatcher.dispatch(StatusAction.create('Initializing...', { severity: 'INFO' }));
}

const glspClient = await this.options.glspClientProvider();
Expand All @@ -203,7 +207,7 @@ export class DiagramLoader {
}

if (options.enableNotifications) {
this.actionDispatcher.dispatch(ServerStatusAction.create('', { severity: 'NONE' }));
this.actionDispatcher.dispatch(StatusAction.create('', { severity: 'NONE' }));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
MenuItem,
Point,
SModelRoot,
ServerMessageAction,
ServerStatusAction,
MessageAction,
StatusAction,
TYPES,
hasStringProp,
isSelected
Expand Down Expand Up @@ -83,10 +83,7 @@ export class InvokeCopyPasteActionHandler implements IActionHandler {
const message = `Please use the browser's ${operation} command or shortcut.`;
const timeout = 10000;
const severity = 'WARNING';
this.dispatcher.dispatchAll([
ServerStatusAction.create(message, { severity, timeout }),
ServerMessageAction.create(message, { severity })
]);
this.dispatcher.dispatchAll([StatusAction.create(message, { severity, timeout }), MessageAction.create(message, { severity })]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export namespace LabelEditValidation {

export function toEditLabelValidationResult(status: ValidationStatus): EditLabelValidationResult {
const message = status.message;
let severity = 'ok' as Severity;
let severity: Severity = 'ok';
if (ValidationStatus.isError(status)) {
severity = 'error' as Severity;
severity = 'error';
} else if (ValidationStatus.isWarning(status)) {
severity = 'warning' as Severity;
severity = 'warning';
}
return { message, severity };
}
Expand All @@ -61,7 +61,7 @@ export class ServerEditLabelValidator implements IEditLabelValidator {
if (SetEditValidationResultAction.is(action)) {
return LabelEditValidation.toEditLabelValidationResult(action.status);
}
return { severity: 'ok' as Severity };
return { severity: 'ok' };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import {
IActionHandler,
ICommand,
ILogger,
MessageAction,
NavigateToExternalTargetAction,
NavigateToTargetAction,
NavigationTarget,
RequestNavigationTargetsAction,
SelectAction,
SelectAllAction,
ServerMessageAction,
ServerSeverity,
ServerStatusAction,
SetNavigationTargetsAction,
SetResolvedNavigationTargetAction,
SeverityLevel,
StatusAction,
TYPES,
hasObjectProp,
hasStringProp
Expand Down Expand Up @@ -264,11 +264,8 @@ export class NavigationActionHandler implements IActionHandler {
this.notify('WARNING', message);
}

private notify(severity: ServerSeverity, message: string): void {
private notify(severity: SeverityLevel, message: string): void {
const timeout = this.notificationTimeout;
this.dispatcher.dispatchAll([
ServerStatusAction.create(message, { severity, timeout }),
ServerMessageAction.create(message, { severity })
]);
this.dispatcher.dispatchAll([StatusAction.create(message, { severity, timeout }), MessageAction.create(message, { severity })]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
Action,
IActionDispatcher,
IActionHandler,
ServerMessageAction,
ServerStatusAction,
MessageAction,
SourceModelChangedAction,
StatusAction,
TYPES,
ViewerOptions
} from '~glsp-sprotty';
Expand Down Expand Up @@ -68,9 +68,6 @@ export class SourceModelChangedActionHandler implements IActionHandler {
const message = `The source model ${action.sourceModelName} has changed. You might want to consider reloading.`;
const timeout = 0;
const severity = 'WARNING';
this.dispatcher.dispatchAll([
ServerStatusAction.create(message, { severity, timeout }),
ServerMessageAction.create(message, { severity })
]);
this.dispatcher.dispatchAll([StatusAction.create(message, { severity, timeout }), MessageAction.create(message, { severity })]);
}
}
4 changes: 2 additions & 2 deletions packages/client/src/features/status/status-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { FeatureModule, ServerStatusAction, TYPES, bindAsService, configureActionHandler } from '~glsp-sprotty';
import { FeatureModule, StatusAction, TYPES, bindAsService, configureActionHandler } from '~glsp-sprotty';
import '../../../css/status-overlay.css';
import { StatusOverlay } from './status-overlay';

export const statusModule = new FeatureModule((bind, unbind, isBound, rebind) => {
const context = { bind, unbind, isBound, rebind };
bindAsService(context, TYPES.IUIExtension, StatusOverlay);
bind(TYPES.IDiagramStartup).toService(StatusOverlay);
configureActionHandler(context, ServerStatusAction.KIND, StatusOverlay);
configureActionHandler(context, StatusAction.KIND, StatusOverlay);
});
10 changes: 5 additions & 5 deletions packages/client/src/features/status/status-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { inject, injectable } from 'inversify';
import { AbstractUIExtension, IActionHandler, ServerStatusAction, codiconCSSClasses } from '~glsp-sprotty';
import { AbstractUIExtension, IActionHandler, StatusAction, codiconCSSClasses } from '~glsp-sprotty';
import { GLSPActionDispatcher } from '../../base/action-dispatcher';
import { EditorContextService } from '../../base/editor-context-service';
import { IDiagramStartup } from '../../base/model/diagram-loader';

/**
* A reusable status overlay for rendering (icon + message) and handling of {@link ServerStatusAction}'s.
* A reusable status overlay for rendering (icon + message) and handling of {@link StatusAction}'s.
*/
@injectable()
export class StatusOverlay extends AbstractUIExtension implements IActionHandler, IDiagramStartup {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class StatusOverlay extends AbstractUIExtension implements IActionHandler
containerElement.appendChild(this.statusMessageDiv);
}

protected setStatus(status: ServerStatusAction): void {
protected setStatus(status: StatusAction): void {
if (this.statusMessageDiv) {
this.statusMessageDiv.textContent = status.message;
this.removeClasses(this.statusMessageDiv, 1);
Expand Down Expand Up @@ -80,7 +80,7 @@ export class StatusOverlay extends AbstractUIExtension implements IActionHandler
}

protected clearStatus(): void {
this.setStatus(ServerStatusAction.create('', { severity: 'NONE' }));
this.setStatus(StatusAction.create('', { severity: 'NONE' }));
}

protected clearTimeout(): void {
Expand All @@ -100,7 +100,7 @@ export class StatusOverlay extends AbstractUIExtension implements IActionHandler
}
}

handle(action: ServerStatusAction): void {
handle(action: StatusAction): void {
this.clearTimeout();
if (action.severity === 'NONE') {
this.clearStatus();
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/standalone-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ICommand,
ILogger,
ModuleConfiguration,
ServerMessageAction,
MessageAction,
StartProgressAction,
TYPES,
UpdateProgressAction,
Expand All @@ -40,7 +40,7 @@ import { standaloneViewportModule } from './features/viewport/viewport-modules';
export const standaloneFallbackModule = new FeatureModule((bind, unbind, isBound, rebind) => {
const context = { bind, unbind, isBound, rebind };
bind(FallbackActionHandler).toSelf().inSingletonScope();
configureActionHandler(context, ServerMessageAction.KIND, FallbackActionHandler);
configureActionHandler(context, MessageAction.KIND, FallbackActionHandler);
configureActionHandler(context, StartProgressAction.KIND, FallbackActionHandler);
configureActionHandler(context, UpdateProgressAction.KIND, FallbackActionHandler);
configureActionHandler(context, EndProgressAction.KIND, FallbackActionHandler);
Expand Down
48 changes: 21 additions & 27 deletions packages/protocol/src/action-protocol/client-notification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,74 @@
********************************************************************************/
/* eslint-disable max-len */
import { expect } from 'chai';
import {
EndProgressAction,
ServerMessageAction,
ServerStatusAction,
StartProgressAction,
UpdateProgressAction
} from './client-notification';
import { EndProgressAction, MessageAction, StartProgressAction, StatusAction, UpdateProgressAction } from './client-notification';
/**
* Tests for the utility functions declared in the namespaces of the protocol
* action definitions.
*/
describe('Client notification actions', () => {
describe('ServerStatusAction', () => {
describe('StatusAction', () => {
describe('is', () => {
it('should return true for an object having the correct type and a value for all required interface properties', () => {
const statusAction: ServerStatusAction = { kind: 'serverStatus', message: 'Some', severity: 'INFO' };
expect(ServerStatusAction.is(statusAction)).to.be.true;
const statusAction: StatusAction = { kind: StatusAction.KIND, message: 'Some', severity: 'INFO' };
expect(StatusAction.is(statusAction)).to.be.true;
});
it('should return false for `undefined`', () => {
expect(ServerStatusAction.is(undefined)).to.be.false;
expect(StatusAction.is(undefined)).to.be.false;
});
it('should return false for an object that does not have all required interface properties', () => {
expect(ServerStatusAction.is({ kind: 'notTheRightOne' })).to.be.false;
expect(StatusAction.is({ kind: 'notTheRightOne' })).to.be.false;
});
});

describe('create', () => {
it('should return an object conforming to the interface with matching properties for the given required arguments and default values for the optional arguments', () => {
const message = 'someMessage';
const expected: ServerStatusAction = { kind: ServerStatusAction.KIND, message, severity: 'INFO' };
expect(ServerStatusAction.create(message)).to.deep.equals(expected);
const expected: StatusAction = { kind: StatusAction.KIND, message, severity: 'INFO' };
expect(StatusAction.create(message)).to.deep.equals(expected);
});
it('should return an object conforming to the interface with matching properties for the given required and optional arguments', () => {
const expected: ServerStatusAction = {
kind: ServerStatusAction.KIND,
const expected: StatusAction = {
kind: StatusAction.KIND,
message: 'someMessage',
severity: 'ERROR',
timeout: 5
};
const { message, severity, timeout } = expected;
expect(ServerStatusAction.create(message, { severity, timeout })).to.deep.equals(expected);
expect(StatusAction.create(message, { severity, timeout })).to.deep.equals(expected);
});
});
});

describe('ServerMessageAction', () => {
describe('MessageAction', () => {
describe('is', () => {
it('should return true for an object having the correct type and a value for all required interface properties', () => {
const messageAction: ServerMessageAction = { kind: 'serverMessage', message: '', severity: 'INFO' };
expect(ServerMessageAction.is(messageAction)).to.be.true;
const messageAction: MessageAction = { kind: MessageAction.KIND, message: '', severity: 'INFO' };
expect(MessageAction.is(messageAction)).to.be.true;
});
it('should return false for `undefined`', () => {
expect(ServerMessageAction.is(undefined)).to.be.false;
expect(MessageAction.is(undefined)).to.be.false;
});
it('should return false for an object that does not have all required interface properties', () => {
expect(ServerMessageAction.is({ kind: 'notTheRightOne' })).to.be.false;
expect(MessageAction.is({ kind: 'notTheRightOne' })).to.be.false;
});
});

describe('create', () => {
it('should return an object conforming to the interface with matching properties for the given required arguments and default values for the optional arguments', () => {
const message = 'someMessage';
const expected: ServerMessageAction = { kind: ServerMessageAction.KIND, message, severity: 'INFO' };
expect(ServerMessageAction.create(message)).to.deep.equals(expected);
const expected: MessageAction = { kind: MessageAction.KIND, message, severity: 'INFO' };
expect(MessageAction.create(message)).to.deep.equals(expected);
});
it('should return an object conforming to the interface with matching properties for the given required and optional arguments', () => {
const expected: ServerMessageAction = {
kind: ServerMessageAction.KIND,
const expected: MessageAction = {
kind: MessageAction.KIND,
message: 'someMessage',
details: 'details',
severity: 'ERROR'
};
const { message, severity, details } = expected;
expect(ServerMessageAction.create(message, { severity, details })).to.deep.equals(expected);
expect(MessageAction.create(message, { severity, details })).to.deep.equals(expected);
});
});
});
Expand Down
Loading

0 comments on commit f0b33a9

Please sign in to comment.