-
Notifications
You must be signed in to change notification settings - Fork 347
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
Update node properties to allow changing file #867
Changes from 3 commits
cadd6ab
d9c78c1
c77d5a2
abab7e7
9d843ad
44794a1
24ec481
359796e
4dfe3be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,6 +30,7 @@ import { | |||||||||||||||||
pipelineIcon, | ||||||||||||||||||
savePipelineIcon, | ||||||||||||||||||
runtimesIcon, | ||||||||||||||||||
showBrowseFileDialog, | ||||||||||||||||||
showFormDialog, | ||||||||||||||||||
errorIcon | ||||||||||||||||||
} from '@elyra/ui-components'; | ||||||||||||||||||
|
@@ -200,6 +201,7 @@ export class PipelineEditor extends React.Component< | |||||||||||||||||
position = 10; | ||||||||||||||||||
node: React.RefObject<HTMLDivElement>; | ||||||||||||||||||
propertiesInfo: any; | ||||||||||||||||||
propertiesController: any; | ||||||||||||||||||
|
||||||||||||||||||
constructor(props: any) { | ||||||||||||||||||
super(props); | ||||||||||||||||||
|
@@ -233,6 +235,10 @@ export class PipelineEditor extends React.Component< | |||||||||||||||||
this.applyPropertyChanges = this.applyPropertyChanges.bind(this); | ||||||||||||||||||
this.closePropertiesDialog = this.closePropertiesDialog.bind(this); | ||||||||||||||||||
this.openPropertiesDialog = this.openPropertiesDialog.bind(this); | ||||||||||||||||||
this.propertiesActionHandler = this.propertiesActionHandler.bind(this); | ||||||||||||||||||
this.propertiesControllerHandler = this.propertiesControllerHandler.bind( | ||||||||||||||||||
this | ||||||||||||||||||
); | ||||||||||||||||||
|
||||||||||||||||||
this.node = React.createRef(); | ||||||||||||||||||
this.handleEvent = this.handleEvent.bind(this); | ||||||||||||||||||
|
@@ -342,6 +348,8 @@ export class PipelineEditor extends React.Component< | |||||||||||||||||
]; | ||||||||||||||||||
|
||||||||||||||||||
const propertiesCallbacks = { | ||||||||||||||||||
actionHandler: this.propertiesActionHandler, | ||||||||||||||||||
controllerHandler: this.propertiesControllerHandler, | ||||||||||||||||||
applyPropertyChanges: this.applyPropertyChanges, | ||||||||||||||||||
closePropertiesDialog: this.closePropertiesDialog | ||||||||||||||||||
}; | ||||||||||||||||||
|
@@ -456,6 +464,13 @@ export class PipelineEditor extends React.Component< | |||||||||||||||||
} | ||||||||||||||||||
const app_data = node.app_data; | ||||||||||||||||||
|
||||||||||||||||||
if (app_data.filename !== propertySet.filename) { | ||||||||||||||||||
app_data.filename = propertySet.filename; | ||||||||||||||||||
Comment on lines
+467
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this would specifically need to be updated to the following once #861 is merged or in #861 once this is merged.
Suggested change
|
||||||||||||||||||
node.label = propertySet.filename | ||||||||||||||||||
.replace(/^.*[\\/]/, '') | ||||||||||||||||||
.replace(/\.[^/.]+$/, ''); | ||||||||||||||||||
kevin-bates marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
app_data.runtime_image = propertySet.runtime_image; | ||||||||||||||||||
app_data.outputs = propertySet.outputs; | ||||||||||||||||||
app_data.env_vars = propertySet.env_vars; | ||||||||||||||||||
|
@@ -471,6 +486,28 @@ export class PipelineEditor extends React.Component< | |||||||||||||||||
this.setState({ showPropertiesDialog: false, propertiesInfo: propsInfo }); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
propertiesControllerHandler(propertiesController: any): void { | ||||||||||||||||||
this.propertiesController = propertiesController; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
propertiesActionHandler(id: string, appData: any, data: any): void { | ||||||||||||||||||
if (id === 'browse_file') { | ||||||||||||||||||
const propertyId = { name: data.parameter_ref }; | ||||||||||||||||||
showBrowseFileDialog(this.browserFactory.defaultBrowser.model.manager, { | ||||||||||||||||||
filter: (model: any): boolean => { | ||||||||||||||||||
return model.type == 'notebook'; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the intension here that we would update this when we add support for other file types? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the filter is so you only show files that should be selectable. in this case, we only want to show |
||||||||||||||||||
} | ||||||||||||||||||
}).then((result: any) => { | ||||||||||||||||||
if (result.button.accept && result.value.length) { | ||||||||||||||||||
this.propertiesController.updatePropertyValue( | ||||||||||||||||||
propertyId, | ||||||||||||||||||
result.value[0].path | ||||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
}); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/* | ||||||||||||||||||
* Add options to the node context menu | ||||||||||||||||||
* Pipeline specific context menu items are: | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright 2018-2020 IBM Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Dialog } from '@jupyterlab/apputils'; | ||
import { IDocumentManager } from '@jupyterlab/docmanager'; | ||
import { | ||
BreadCrumbs, | ||
DirListing, | ||
FilterFileBrowserModel | ||
} from '@jupyterlab/filebrowser'; | ||
import { Widget, PanelLayout } from '@lumino/widgets'; | ||
|
||
const BROWSE_FILE_CLASS = 'elyra-browseFileDialog'; | ||
|
||
export interface IBrowseFileDialogOptions { | ||
filter?: (model: any) => boolean; | ||
multiselect?: boolean; | ||
includeDir?: boolean; | ||
} | ||
|
||
/** | ||
* Browse file widget for dialog body | ||
*/ | ||
export class BrowseFileDialog extends Widget | ||
implements Dialog.IBodyWidget<IBrowseFileDialogOptions> { | ||
directoryListing: DirListing; | ||
breadCrumbs: BreadCrumbs; | ||
dirListingHandleEvent: (event: Event) => void; | ||
multiselect: boolean; | ||
includeDir: boolean; | ||
|
||
constructor(props: any) { | ||
super(props); | ||
|
||
const model = new FilterFileBrowserModel({ | ||
manager: props.manager, | ||
filter: props.filter | ||
}); | ||
|
||
const layout = (this.layout = new PanelLayout()); | ||
|
||
this.directoryListing = new DirListing({ | ||
model: model | ||
}); | ||
|
||
this.multiselect = props.multiselect; | ||
this.includeDir = props.includeDir; | ||
this.dirListingHandleEvent = this.directoryListing.handleEvent; | ||
this.directoryListing.handleEvent = (event: Event): void => { | ||
this.handleEvent(event); | ||
}; | ||
|
||
this.breadCrumbs = new BreadCrumbs({ | ||
model: model | ||
}); | ||
|
||
layout.addWidget(this.breadCrumbs); | ||
layout.addWidget(this.directoryListing); | ||
} | ||
|
||
getValue(): any { | ||
const itemsIter = this.directoryListing.selectedItems(); | ||
const selected = []; | ||
let item = null; | ||
|
||
while ((item = itemsIter.next()) !== undefined) { | ||
if (this.includeDir || item.type !== 'directory') { | ||
selected.push(item); | ||
} | ||
} | ||
|
||
return selected; | ||
} | ||
|
||
handleEvent(event: Event): void { | ||
let modifierKey = false; | ||
if (event instanceof MouseEvent) { | ||
modifierKey = | ||
(event as MouseEvent).shiftKey || (event as MouseEvent).metaKey; | ||
} else if (event instanceof KeyboardEvent) { | ||
modifierKey = | ||
(event as KeyboardEvent).shiftKey || (event as KeyboardEvent).metaKey; | ||
} | ||
|
||
switch (event.type) { | ||
case 'keydown': | ||
case 'keyup': | ||
case 'mousedown': | ||
case 'mouseup': | ||
case 'click': | ||
if (this.multiselect || !modifierKey) { | ||
this.dirListingHandleEvent.call(this.directoryListing, event); | ||
} | ||
break; | ||
case 'dblclick': { | ||
const clickedItem = this.directoryListing.modelForClick( | ||
event as MouseEvent | ||
); | ||
if (clickedItem.type === 'directory') { | ||
this.dirListingHandleEvent.call(this.directoryListing, event); | ||
} else { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
break; | ||
} | ||
default: | ||
this.dirListingHandleEvent.call(this.directoryListing, event); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
export const showBrowseFileDialog = ( | ||
manager: IDocumentManager, | ||
options: IBrowseFileDialogOptions | ||
): Promise<Dialog.IResult<any>> => { | ||
const dialog = new Dialog({ | ||
title: 'Select a file', | ||
body: new BrowseFileDialog({ | ||
manager: manager, | ||
filter: options.filter, | ||
multiselect: options.multiselect, | ||
includeDir: options.includeDir | ||
}), | ||
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: 'Select' })] | ||
}); | ||
|
||
dialog.addClass(BROWSE_FILE_CLASS); | ||
|
||
return dialog.launch(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note: this line will need to be updated to work with #861 is merged (in whichever PR is merged last)