Skip to content

Commit

Permalink
chore: jupyterlab widget factories
Browse files Browse the repository at this point in the history
  • Loading branch information
echarles committed Aug 21, 2023
1 parent a0c5828 commit 327b0ce
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 27 deletions.
30 changes: 15 additions & 15 deletions src/components/tabs/jupyterlab/FileTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class JupyterLabFileType implements DocumentRegistry.IFileType {
constructor(fileType: any) {
this._fileType = fileType;
}
get id() { return this._fileType.name}
get name() { return this._fileType.name}
get displayName() { return this._fileType.displayName}
get fileFormat() { return this._fileType.fileFormat}
get icon() { return this._fileType.icon}
get extensions() { return this._fileType.extensions}
get contentType(): any {return this.contentType()}
get mimeTypes(): any {return this.mimeTypes()}
get pattern():any {return this.pattern()}
get iconClass(): any {return this.iconClass()}
get iconLabel():any {return this.iconLabel()}
get id() { return this._fileType.name }
get name() { return this._fileType.name }
get displayName() { return this._fileType.displayName }
get fileFormat() { return this._fileType.fileFormat }
get icon() { return this._fileType.icon }
get extensions() { return this._fileType.extensions }
get contentType() {return this._fileType.contentType() }
get mimeTypes() { return this._fileType.mimeTypes() }
get pattern() { return this._fileType.pattern() }
get iconClass() { return this._fileType.iconClass() }
get iconLabel() { return this._fileType.iconLabel() }
}

const FileTypes = (props: JupyterFrontEndProps) => {
Expand All @@ -36,10 +36,10 @@ const FileTypes = (props: JupyterFrontEndProps) => {
<>
{ fileTypes &&
<Table.Container>
<Table.Title as="h2" id="repositories">
<Table.Title as="h2" id="file-types">
File types
</Table.Title>
<Table.Subtitle as="p" id="repositories-subtitle">
<Table.Subtitle as="p" id="file-types-subtitle">
List of registered file types.
</Table.Subtitle>
<DataTable
Expand Down Expand Up @@ -69,7 +69,7 @@ const FileTypes = (props: JupyterFrontEndProps) => {
header: 'Display Name',
field: 'displayName',
renderCell: row => {
return <Text>{String(row.displayName)}</Text>;
return <Text>{String(row.displayName)}</Text>
}
},
{
Expand All @@ -87,7 +87,7 @@ const FileTypes = (props: JupyterFrontEndProps) => {
header: 'File Format',
field: 'fileFormat',
renderCell: row => {
return <Label variant="primary">{String(row.fileFormat)}</Label>;
return <Label variant="primary">{String(row.fileFormat)}</Label>
}
},
]
Expand Down
22 changes: 11 additions & 11 deletions src/components/tabs/jupyterlab/Models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class JupyterLabModelFactory implements DocumentRegistry.IModelFactory<any> {
constructor(modelFactory: DocumentRegistry.IModelFactory<any>) {
this._modelFactory = modelFactory;
}
get id() { return this._modelFactory.name}
get name() { return this._modelFactory.name}
get contentType() {return this._modelFactory.contentType}
get collaborative() {return this._modelFactory.collaborative}
get isDisposed() {return this._modelFactory.isDisposed};
get fileFormat() {return this._modelFactory.fileFormat};
get id() { return this._modelFactory.name }
get name() { return this._modelFactory.name }
get contentType() { return this._modelFactory.contentType }
get collaborative() { return this._modelFactory.collaborative }
get isDisposed() { return this._modelFactory.isDisposed }
get fileFormat() { return this._modelFactory.fileFormat }
createNew(options?: DocumentRegistry.IModelOptions<ISharedDocument> | undefined) {
throw new Error('Method not implemented.');
}
Expand All @@ -33,18 +33,18 @@ const Models = (props: JupyterFrontEndProps) => {
useEffect(() => {
if (app) {
const modelFactories = Array.from(app?.docRegistry.modelFactories());
const jupyterlabFileTypes = modelFactories.map(modelFactory => new JupyterLabModelFactory(modelFactory));
setModelFactories(jupyterlabFileTypes);
const jupyterlabModelFactories = modelFactories.map(modelFactory => new JupyterLabModelFactory(modelFactory));
setModelFactories(jupyterlabModelFactories);
}
}, [app]);
return (
<>
{ modelFactories &&
<Table.Container>
<Table.Title as="h2" id="repositories">
<Table.Title as="h2" id="model-factories">
Model Factories
</Table.Title>
<Table.Subtitle as="p" id="repositories-subtitle">
<Table.Subtitle as="p" id="model-factories-subtitle">
List of registered model factories.
</Table.Subtitle>
<DataTable
Expand All @@ -71,7 +71,7 @@ const Models = (props: JupyterFrontEndProps) => {
header: 'File Format',
field: 'fileFormat',
renderCell: row => {
return <Label variant="primary">{String(row.fileFormat)}</Label>;
return <Label variant="primary">{String(row.fileFormat)}</Label>
}
},
]
Expand Down
95 changes: 94 additions & 1 deletion src/components/tabs/jupyterlab/Widgets.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,100 @@
import { useState, useEffect } from 'react';
import { Widget } from '@lumino/widgets';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { IObservableList } from '@jupyterlab/observables';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
import { Text, LabelGroup, Label } from '@primer/react';
import { Table, DataTable } from '@primer/react/drafts';
import { JupyterFrontEndProps } from '../../Datalayer';

class JupyterLabWidgetFactory implements DocumentRegistry.IWidgetFactory<any, any> {
private _widgetFactory: DocumentRegistry.IWidgetFactory<any, any> ;
constructor(widgetFactory: DocumentRegistry.IWidgetFactory<any, any>) {
this._widgetFactory = widgetFactory;
}
get id() { return this._widgetFactory.name }
get name() { return this._widgetFactory.name }
get modelName() { return this._widgetFactory.modelName }
get label() { return this._widgetFactory.label }
get fileTypes() { return this._widgetFactory.fileTypes }
get isDisposed() { return this._widgetFactory.isDisposed }
get widgetCreated() { return this._widgetFactory.widgetCreated }
autoStartDefault?: boolean | undefined;
readOnly?: boolean | undefined;
preferKernel?: boolean | undefined;
canStartKernel?: boolean | undefined;
shutdownOnClose?: boolean | undefined;
defaultFor?: readonly string[] | undefined;
defaultRendered?: readonly string[] | undefined;
translator?: IRenderMime.ITranslator | undefined;
toolbarFactory?: ((widget: Widget) => DocumentRegistry.IToolbarItem[] | IObservableList<DocumentRegistry.IToolbarItem>) | undefined;
createNew(context: DocumentRegistry.IContext<any>, source?: any) {
throw new Error('Method not implemented.');
}
preferredLanguage(path: string): string {
throw new Error('Method not implemented.');
}
dispose(): void {
throw new Error('Method not implemented.');
}
}

const Widgets = (props: JupyterFrontEndProps) => {
return <></>
const { app } = props;
const [modelFactories, setWidgetFactories] = useState<JupyterLabWidgetFactory[]>();
useEffect(() => {
if (app) {
const widgetFactories = Array.from(app?.docRegistry.widgetFactories());
const jupyterlabFileTypes = widgetFactories.map(widgetFactory => new JupyterLabWidgetFactory(widgetFactory));
setWidgetFactories(jupyterlabFileTypes);
}
}, [app]);
return (
<>
{ modelFactories &&
<Table.Container>
<Table.Title as="h2" id="widget-factories">
Widget Factories
</Table.Title>
<Table.Subtitle as="p" id="widget-factories-subtitle">
List of registered widgets factories.
</Table.Subtitle>
<DataTable
aria-labelledby="file-types"
aria-describedby="file-types-subtitle"
data={modelFactories}
columns={[
{
header: 'Name',
field: 'name',
renderCell: row => <Text>{row.name}</Text>
},
{
header: 'Label',
field: 'label',
renderCell: row => {
return <Text>{row.label}</Text>
}
},
{
header: 'Model Name',
field: 'modelName',
renderCell: row => <Label>{row.modelName}</Label>
},
{
header: 'File Types',
field: 'fileTypes',
renderCell: row => {
return <LabelGroup>{row.fileTypes.map(fileType => <Label variant="primary">{fileType}</Label>)}</LabelGroup>
}
},
]
}
/>
</Table.Container>
}
</>
)
}

export default Widgets;

0 comments on commit 327b0ce

Please sign in to comment.