Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHOAIENG-13688: Infinite loading after renaming a new txt file to pipeline extension #72

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/pipeline-editor/src/PipelineEditorWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class PipelineEditorWidget extends ReactWidget {
refreshPaletteSignal: Signal<this, any>;
context: Context;
settings: ISettingRegistry.ISettings;
defaultRuntimeType: string;

constructor(options: any) {
super();
Expand All @@ -171,6 +172,7 @@ class PipelineEditorWidget extends ReactWidget {
this.refreshPaletteSignal = options.refreshPaletteSignal;
this.context = options.context;
this.settings = options.settings;
this.defaultRuntimeType = options.defaultRuntimeType;
let nullPipeline = this.context.model.toJSON() === null;

this.context.model.contentChanged.connect(() => {
Expand All @@ -181,7 +183,7 @@ class PipelineEditorWidget extends ReactWidget {
});
this.context.fileChanged.connect(() => {
if (this.context.model.toJSON() === null) {
const pipelineJson = getEmptyPipelineJson(undefined);
const pipelineJson = getEmptyPipelineJson(this.defaultRuntimeType);
this.context.model.fromString(JSON.stringify(pipelineJson));
}
});
Expand Down Expand Up @@ -1210,6 +1212,7 @@ export class PipelineEditorFactory extends ABCWidgetFactory<DocumentWidget> {
addFileToPipelineSignal: Signal<this, any>;
refreshPaletteSignal: Signal<this, any>;
settings: ISettingRegistry.ISettings;
defaultRuntimeType: string;

constructor(options: any) {
super(options);
Expand All @@ -1219,6 +1222,7 @@ export class PipelineEditorFactory extends ABCWidgetFactory<DocumentWidget> {
this.addFileToPipelineSignal = new Signal<this, any>(this);
this.refreshPaletteSignal = new Signal<this, any>(this);
this.settings = options.settings;
this.defaultRuntimeType = options.defaultRuntimeType;
}

protected createNewWidget(context: DocumentRegistry.Context): DocumentWidget {
Expand All @@ -1230,7 +1234,8 @@ export class PipelineEditorFactory extends ABCWidgetFactory<DocumentWidget> {
context: context,
addFileToPipelineSignal: this.addFileToPipelineSignal,
refreshPaletteSignal: this.refreshPaletteSignal,
settings: this.settings
settings: this.settings,
defaultRuntimeType: this.defaultRuntimeType
};
const content = new PipelineEditorWidget(props);

Expand Down
309 changes: 155 additions & 154 deletions packages/pipeline-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,160 +132,6 @@ const extension: JupyterFrontEndPlugin<void> = {
.load(PLUGIN_ID)
.catch((error) => console.log(error));

// Set up new widget Factory for .pipeline files
const pipelineEditorFactory = new PipelineEditorFactory({
name: PIPELINE_EDITOR,
fileTypes: [PIPELINE],
defaultFor: [PIPELINE],
shell: app.shell,
commands: app.commands,
browserFactory: browserFactory,
serviceManager: app.serviceManager,
settings: settings
});

// Add the default behavior of opening the widget for .pipeline files
app.docRegistry.addFileType(
{
name: PIPELINE,
displayName: 'Pipeline',
extensions: ['.pipeline'],
icon: pipelineIcon
},
['JSON']
);
app.docRegistry.addWidgetFactory(pipelineEditorFactory);

const tracker = new WidgetTracker<DocumentWidget>({
namespace: PIPELINE_EDITOR_NAMESPACE
});

pipelineEditorFactory.widgetCreated.connect((sender, widget) => {
void tracker.add(widget);

// Notify the widget tracker if restore data needs to update
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
});

// Handle state restoration
void restorer.restore(tracker, {
command: commandIDs.openDocManager,
args: (widget) => ({
path: widget.context.path,
factory: PIPELINE_EDITOR
}),
name: (widget) => widget.context.path
});

// Add command to add file to pipeline
const addFileToPipelineCommand: string = commandIDs.addFileToPipeline;
app.commands.addCommand(addFileToPipelineCommand, {
label: 'Add File to Pipeline',
icon: addIcon,
execute: (args) => {
pipelineEditorFactory.addFileToPipelineSignal.emit(args);
}
});
const refreshPaletteCommand: string = commandIDs.refreshPalette;
app.commands.addCommand(refreshPaletteCommand, {
label: 'Refresh Pipeline Palette',
icon: refreshIcon,
execute: (args) => {
pipelineEditorFactory.refreshPaletteSignal.emit(args);
}
});
app.contextMenu.addItem({
selector: '[data-file-type="notebook"]',
command: addFileToPipelineCommand
});
app.contextMenu.addItem({
selector: '[data-file-type="python"]',
command: addFileToPipelineCommand
});
app.contextMenu.addItem({
selector: '[data-file-type="r"]',
command: addFileToPipelineCommand
});

// Add an application command
const openPipelineEditorCommand: string = commandIDs.openPipelineEditor;
app.commands.addCommand(openPipelineEditorCommand, {
label: (args: any) => {
if (args.isPalette) {
return `New ${PIPELINE_EDITOR}`;
}
if (args.runtimeType?.id === 'LOCAL') {
const contextMenuPrefix = args.isContextMenu ? 'New ' : '';
return `${contextMenuPrefix}Generic ${PIPELINE_EDITOR}`;
}
if (args.isMenu) {
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
}
if (args.isContextMenu) {
return `New ${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
}
return PIPELINE_EDITOR;
},
caption: (args: any) => {
if (args.runtimeType?.id === 'LOCAL') {
return `Generic ${PIPELINE_EDITOR}`;
}
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
},
iconLabel: (args: any) => {
if (args.isPalette) {
return '';
}
if (args.runtimeType?.id === 'LOCAL') {
return `Generic ${PIPELINE_EDITOR}`;
}
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
},
icon: (args: any) => {
if (args.isPalette) {
return undefined;
}
return args.runtimeType?.icon;
},
execute: (args: any) => {
// Creates blank file, then opens it in a new window
app.commands
.execute(commandIDs.newDocManager, {
type: 'file',
path: browserFactory.model.path,
ext: '.pipeline'
})
.then(async (model) => {
const platformId = args.runtimeType?.id;
const runtime_type =
platformId === 'LOCAL' ? undefined : platformId;

const pipelineJson = getEmptyPipelineJson(runtime_type);
const newWidget = await app.commands.execute(
commandIDs.openDocManager,
{
path: model.path,
factory: PIPELINE_EDITOR
}
);
newWidget.context.ready.then(() => {
newWidget.context.model.fromJSON(pipelineJson);
app.commands.execute(commandIDs.saveDocManager, {
path: model.path
});
});
});
}
});
// Add the command to the palette.
palette.addItem({
command: openPipelineEditorCommand,
args: { isPalette: true },
category: 'Elyra'
});

PipelineService.getRuntimeTypes()
.then(async (types) => {
const filteredTypes = types.filter((t) => t.runtime_enabled);
Expand All @@ -301,6 +147,161 @@ const extension: JupyterFrontEndPlugin<void> = {

const resolvedTypes = await Promise.all(promises);

// Set up new widget Factory for .pipeline files
const pipelineEditorFactory = new PipelineEditorFactory({
name: PIPELINE_EDITOR,
fileTypes: [PIPELINE],
defaultFor: [PIPELINE],
shell: app.shell,
commands: app.commands,
browserFactory: browserFactory,
serviceManager: app.serviceManager,
settings: settings,
defaultRuntimeType: resolvedTypes[0]?.id
});

// Add the default behavior of opening the widget for .pipeline files
app.docRegistry.addFileType(
{
name: PIPELINE,
displayName: 'Pipeline',
extensions: ['.pipeline'],
icon: pipelineIcon
},
['JSON']
);
app.docRegistry.addWidgetFactory(pipelineEditorFactory);

const tracker = new WidgetTracker<DocumentWidget>({
namespace: PIPELINE_EDITOR_NAMESPACE
});

pipelineEditorFactory.widgetCreated.connect((sender, widget) => {
void tracker.add(widget);

// Notify the widget tracker if restore data needs to update
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
});

// Handle state restoration
void restorer.restore(tracker, {
command: commandIDs.openDocManager,
args: (widget) => ({
path: widget.context.path,
factory: PIPELINE_EDITOR
}),
name: (widget) => widget.context.path
});

// Add command to add file to pipeline
const addFileToPipelineCommand: string = commandIDs.addFileToPipeline;
app.commands.addCommand(addFileToPipelineCommand, {
label: 'Add File to Pipeline',
icon: addIcon,
execute: (args) => {
pipelineEditorFactory.addFileToPipelineSignal.emit(args);
}
});
const refreshPaletteCommand: string = commandIDs.refreshPalette;
app.commands.addCommand(refreshPaletteCommand, {
label: 'Refresh Pipeline Palette',
icon: refreshIcon,
execute: (args) => {
pipelineEditorFactory.refreshPaletteSignal.emit(args);
}
});
app.contextMenu.addItem({
selector: '[data-file-type="notebook"]',
command: addFileToPipelineCommand
});
app.contextMenu.addItem({
selector: '[data-file-type="python"]',
command: addFileToPipelineCommand
});
app.contextMenu.addItem({
selector: '[data-file-type="r"]',
command: addFileToPipelineCommand
});

// Add an application command
const openPipelineEditorCommand: string = commandIDs.openPipelineEditor;
app.commands.addCommand(openPipelineEditorCommand, {
label: (args: any) => {
if (args.isPalette) {
return `New ${PIPELINE_EDITOR}`;
}
if (args.runtimeType?.id === 'LOCAL') {
const contextMenuPrefix = args.isContextMenu ? 'New ' : '';
return `${contextMenuPrefix}Generic ${PIPELINE_EDITOR}`;
}
if (args.isMenu) {
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
}
if (args.isContextMenu) {
return `New ${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
}
return PIPELINE_EDITOR;
},
caption: (args: any) => {
if (args.runtimeType?.id === 'LOCAL') {
return `Generic ${PIPELINE_EDITOR}`;
}
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
},
iconLabel: (args: any) => {
if (args.isPalette) {
return '';
}
if (args.runtimeType?.id === 'LOCAL') {
return `Generic ${PIPELINE_EDITOR}`;
}
return `${args.runtimeType?.display_name} ${PIPELINE_EDITOR}`;
},
icon: (args: any) => {
if (args.isPalette) {
return undefined;
}
return args.runtimeType?.icon;
},
execute: (args: any) => {
// Creates blank file, then opens it in a new window
app.commands
.execute(commandIDs.newDocManager, {
type: 'file',
path: browserFactory.model.path,
ext: '.pipeline'
})
.then(async (model) => {
const platformId = args.runtimeType?.id;
const runtime_type =
platformId === 'LOCAL' ? undefined : platformId;

const pipelineJson = getEmptyPipelineJson(runtime_type);
const newWidget = await app.commands.execute(
commandIDs.openDocManager,
{
path: model.path,
factory: PIPELINE_EDITOR
}
);
newWidget.context.ready.then(() => {
newWidget.context.model.fromJSON(pipelineJson);
app.commands.execute(commandIDs.saveDocManager, {
path: model.path
});
});
});
}
});
// Add the command to the palette.
palette.addItem({
command: openPipelineEditorCommand,
args: { isPalette: true },
category: 'Elyra'
});

// Add the command to the launcher
if (launcher) {
const fileMenuItems: IRankedMenu.IItemOptions[] = [];
Expand Down