-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] add a new React-based dialog type
ReactDialog
This makes it easy to make react-based dialogs, by introducing an abstract class called `ReactDialog` that extends `AbstractDialog` for making dialogs with React, similar to how `ReactWidget` extends `BaseWidget`. Signed-off-by: Samuel Frylmark <samuel.frylmark@ericsson.com>
- Loading branch information
1 parent
0c01098
commit 5034fbe
Showing
5 changed files
with
138 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as React from 'react'; | ||
import { inject, injectable, postConstruct } from 'inversify'; | ||
import { DialogProps } from './dialogs'; | ||
import { ReactDialog } from './dialogs/react-dialog'; | ||
import { ApplicationServer, ApplicationInfo, ExtensionInfo } from '../common/application-protocol'; | ||
|
||
export const ABOUT_CONTENT_CLASS = 'theia-aboutDialog'; | ||
export const ABOUT_EXTENSIONS_CLASS = 'theia-aboutExtensions'; | ||
|
||
@injectable() | ||
export class AboutDialogProps extends DialogProps { | ||
} | ||
|
||
@injectable() | ||
export class AboutDialog extends ReactDialog<void> { | ||
protected applicationInfo: ApplicationInfo | undefined; | ||
protected extensionsInfos: ExtensionInfo[] = []; | ||
protected readonly okButton: HTMLButtonElement; | ||
|
||
@inject(ApplicationServer) | ||
protected readonly appServer: ApplicationServer; | ||
|
||
constructor( | ||
@inject(AboutDialogProps) protected readonly props: AboutDialogProps | ||
) { | ||
super({ | ||
title: props.title | ||
}); | ||
this.appendAcceptButton('Ok'); | ||
} | ||
|
||
@postConstruct() | ||
protected async init(): Promise<void> { | ||
this.applicationInfo = await this.appServer.getApplicationInfo(); | ||
this.extensionsInfos = await this.appServer.getExtensionsInfos(); | ||
this.update(); | ||
} | ||
|
||
protected renderHeader(): React.ReactNode { | ||
const applicationInfo = this.applicationInfo; | ||
return applicationInfo && <h3>{applicationInfo.name} {applicationInfo.version}</h3>; | ||
} | ||
|
||
protected renderExtensions(): React.ReactNode { | ||
const extensionsInfos = this.extensionsInfos; | ||
return <> | ||
<h3>List of extensions</h3> | ||
|
||
<ul className={ABOUT_EXTENSIONS_CLASS}> | ||
{ | ||
extensionsInfos | ||
.sort((a: ExtensionInfo, b: ExtensionInfo) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())) | ||
.map((extension: ExtensionInfo) => <li key={extension.name}>{extension.name} {extension.version}</li>) | ||
} | ||
</ul> | ||
</>; | ||
} | ||
|
||
protected render(): React.ReactNode { | ||
return <div className={ABOUT_CONTENT_CLASS}> | ||
{this.renderHeader()} | ||
{this.renderExtensions()} | ||
</div>; | ||
} | ||
|
||
get value(): undefined { return undefined; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { injectable, inject } from 'inversify'; | ||
import { Disposable, DisposableCollection } from '../../common'; | ||
import { Message } from '../widgets'; | ||
import { AbstractDialog, DialogProps } from '../dialogs'; | ||
|
||
@injectable() | ||
export abstract class ReactDialog<T> extends AbstractDialog<T> { | ||
protected readonly onRender = new DisposableCollection(); | ||
|
||
constructor( | ||
@inject(DialogProps) protected readonly props: DialogProps | ||
) { | ||
super(props); | ||
this.toDispose.push(Disposable.create(() => { | ||
ReactDOM.unmountComponentAtNode(this.contentNode); | ||
})); | ||
} | ||
|
||
protected onUpdateRequest(msg: Message): void { | ||
super.onUpdateRequest(msg); | ||
ReactDOM.render(<>{this.render()}</>, this.contentNode, () => this.onRender.dispose()); | ||
} | ||
|
||
/** | ||
* Render the React widget in the DOM. | ||
* - If the widget has been previously rendered, | ||
* any subsequent calls will perform an update and only | ||
* change the DOM if absolutely necessary. | ||
*/ | ||
protected abstract render(): React.ReactNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters