diff --git a/packages/messages/src/browser/messages-frontend-module.ts b/packages/messages/src/browser/messages-frontend-module.ts index 1deeb358cf9c4..6dd5c577f1525 100644 --- a/packages/messages/src/browser/messages-frontend-module.ts +++ b/packages/messages/src/browser/messages-frontend-module.ts @@ -18,7 +18,7 @@ import '../../src/browser/style/index.css'; import { ContainerModule } from 'inversify'; import { MessageClient } from '@theia/core/lib/common'; -import { NotificationManager, NotificationManagerImpl } from './notifications-manager'; +import { NotificationManager } from './notifications-manager'; import { bindNotificationPreferences } from './notification-preferences'; import { NotificationCenter } from './notification-center'; import { StatusBarProgress } from './status-bar-progress'; @@ -35,8 +35,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { bind(KeybindingContribution).toService(NotificationsContribution); bind(NotificationsKeybindingContext).toSelf().inSingletonScope(); bind(KeybindingContext).toService(NotificationsKeybindingContext); - bind(NotificationManagerImpl).toSelf().inSingletonScope(); - bind(NotificationManager).toService(NotificationManagerImpl); - rebind(MessageClient).toService(NotificationManagerImpl); + bind(NotificationManager).toSelf().inSingletonScope(); + rebind(MessageClient).toService(NotificationManager); bindNotificationPreferences(bind); }); diff --git a/packages/messages/src/browser/notification-center-component.tsx b/packages/messages/src/browser/notification-center-component.tsx index e2320c51591d0..741bddd744021 100644 --- a/packages/messages/src/browser/notification-center-component.tsx +++ b/packages/messages/src/browser/notification-center-component.tsx @@ -16,7 +16,7 @@ import * as React from 'react'; import { DisposableCollection } from '@theia/core'; -import { NotificationManager, Notification } from './notifications-manager'; +import { NotificationManager, Notification, NotificationUpdateEvent } from './notifications-manager'; const PerfectScrollbar = require('react-perfect-scrollbar'); @@ -24,7 +24,7 @@ export interface NotificationCenterComponentProps { readonly manager: NotificationManager; } -interface NotificationCenterComponentState extends NotificationManager.UpdateEvent { } +interface NotificationCenterComponentState extends NotificationUpdateEvent { } export class NotificationCenterComponent extends React.Component { @@ -62,8 +62,8 @@ export class NotificationCenterComponent extends React.Component{title}
    -
  • -
  • +
  • +
@@ -76,27 +76,44 @@ export class NotificationCenterComponent extends React.Component { this.props.manager.hide(); } - protected onClearAll(): void { + protected onClearAll = () => { this.props.manager.clearAll(); } - protected onClear(messageId: string): void { - this.props.manager.clear(messageId); + protected onClear = (event: React.MouseEvent) => { + if (event.target instanceof HTMLElement) { + const messageId = event.target.dataset.messageId; + if (messageId) { + this.props.manager.clear(messageId); + } + } } - protected onToggleExpansion(messageId: string): void { - this.props.manager.toggleExpansion(messageId); + protected onToggleExpansion = (event: React.MouseEvent) => { + if (event.target instanceof HTMLElement) { + const messageId = event.target.dataset.messageId; + if (messageId) { + this.props.manager.toggleExpansion(messageId); + } + } } - protected onAction(messageId: string, action: string): void { - this.props.manager.accept(messageId, action); + protected onAction = (event: React.MouseEvent) => { + if (event.target instanceof HTMLElement) { + const messageId = event.target.dataset.messageId; + const action = event.target.dataset.action; + if (messageId && action) { + this.props.manager.accept(messageId, action); + this.props.manager.toggleExpansion(messageId); + } + } } - protected messageClickeHandler(event: React.MouseEvent): void { + protected messageClickeHandler = (event: React.MouseEvent) => { if (event.target instanceof HTMLAnchorElement) { event.stopPropagation(); event.preventDefault(); @@ -112,13 +129,14 @@ export class NotificationCenterComponent extends React.Component
- +
    {expandable && ( -
  • this.onToggleExpansion(messageId)} /> +
  • )} -
  • this.onClear(messageId)} /> +
@@ -128,7 +146,8 @@ export class NotificationCenterComponent extends React.Component {notification.actions && notification.actions.map((action, index) => ( ))} diff --git a/packages/messages/src/browser/notifications-manager.ts b/packages/messages/src/browser/notifications-manager.ts index 098acc5141ac2..addfc10d520fb 100644 --- a/packages/messages/src/browser/notifications-manager.ts +++ b/packages/messages/src/browser/notifications-manager.ts @@ -17,7 +17,7 @@ import { injectable, inject, postConstruct } from 'inversify'; import { MessageClient, MessageType, Message as PlainMessage, ProgressMessage, ProgressUpdate, CancellationToken } from '@theia/core/lib/common'; import { deepClone } from '@theia/core/lib/common/objects'; -import { Event, Emitter } from '@theia/core'; +import { Emitter } from '@theia/core'; import { Deferred } from '@theia/core/lib/common/promise-util'; import { Md5 } from 'ts-md5'; import * as markdownit from 'markdown-it'; @@ -27,23 +27,9 @@ import { ContextKeyService, ContextKey } from '@theia/core/lib/browser/context-k import { OpenerService } from '@theia/core/lib/browser'; import URI from '@theia/core/lib/common/uri'; -export const NotificationManager = Symbol('NotificationManager'); -export interface NotificationManager { +export interface NotificationUpdateEvent { + readonly notifications: Notification[]; readonly open: boolean; - readonly onUpdate: Event; - accept(notification: Notification | string, action: string): void; - hide(): void; - toggle(): void; - clear(notification: Notification | string): void; - clearAll(): void; - toggleExpansion(notification: string): void; - openLink(link: string): Promise; -} -export namespace NotificationManager { - export interface UpdateEvent { - readonly notifications: Notification[]; - readonly open: boolean; - } } export interface Notification { @@ -63,7 +49,7 @@ export namespace Notification { } @injectable() -export class NotificationManagerImpl extends MessageClient implements NotificationManager { +export class NotificationManager extends MessageClient { @inject(NotificationPreferences) protected readonly preferences: NotificationPreferences; @@ -74,7 +60,7 @@ export class NotificationManagerImpl extends MessageClient implements Notificati @inject(OpenerService) protected readonly openerService: OpenerService; - protected readonly onUpdateEmitter = new Emitter(); + protected readonly onUpdateEmitter = new Emitter(); protected readonly fireUpdateEvent = throttle(() => { const notifications = deepClone(Array.from(this.notifications.values())); this.onUpdateEmitter.fire({ notifications, open: this.open });