-
Notifications
You must be signed in to change notification settings - Fork 77
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
Allow 'Open Workspace' to open workspace whenever possible, even if logfile does not exist #1618
Merged
davemfish
merged 8 commits into
natcap:main
from
emilyanndavis:bugfix/1598-improved-error-handling-when-logfile-does-not-exist
Sep 5, 2024
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e9f1e6c
Allows 'Open Workspace' to open workspace whenever possible, even if …
emilyanndavis c182f29
Adds/updates tests
emilyanndavis c505209
Adds "error opening workspace" modal & updates tests
emilyanndavis d824e97
Removes unneeded log messages & updates HISTORY
emilyanndavis 3276d21
Simplifies 'open workspace' behavior, omitting selection of logfile
emilyanndavis 0f7dbcf
Merge branch 'main' of github.com:natcap/invest into bugfix/1598-impr…
emilyanndavis ee148ad
Fixing rst formatting
emilyanndavis 0846c72
Removes openWorkspaceDir helper function
emilyanndavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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 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 |
---|---|---|
|
@@ -7,6 +7,8 @@ import TabContainer from 'react-bootstrap/TabContainer'; | |
import Nav from 'react-bootstrap/Nav'; | ||
import Row from 'react-bootstrap/Row'; | ||
import Col from 'react-bootstrap/Col'; | ||
import Modal from 'react-bootstrap/Modal'; | ||
import Button from 'react-bootstrap/Button'; | ||
import { | ||
MdKeyboardArrowRight, | ||
} from 'react-icons/md'; | ||
|
@@ -45,10 +47,6 @@ async function investGetSpec(modelName) { | |
return undefined; | ||
} | ||
|
||
function handleOpenWorkspace(logfile) { | ||
ipcRenderer.send(ipcMainChannels.SHOW_ITEM_IN_FOLDER, logfile); | ||
} | ||
|
||
/** | ||
* Render an invest model setup form, log display, etc. | ||
* Manage launching of an invest model in a child process. | ||
|
@@ -64,13 +62,17 @@ class InvestTab extends React.Component { | |
uiSpec: null, | ||
userTerminated: false, | ||
executeClicked: false, | ||
showErrorModal: false, | ||
}; | ||
|
||
this.investExecute = this.investExecute.bind(this); | ||
this.switchTabs = this.switchTabs.bind(this); | ||
this.terminateInvestProcess = this.terminateInvestProcess.bind(this); | ||
this.investLogfileCallback = this.investLogfileCallback.bind(this); | ||
this.investExitCallback = this.investExitCallback.bind(this); | ||
this.handleOpenWorkspace = this.handleOpenWorkspace.bind(this); | ||
this.openWorkspaceDir = this.openWorkspaceDir.bind(this); | ||
this.showErrorModal = this.showErrorModal.bind(this); | ||
} | ||
|
||
async componentDidMount() { | ||
|
@@ -154,6 +156,7 @@ class InvestTab extends React.Component { | |
updateJobProperties(tabID, { | ||
argsValues: args, | ||
status: undefined, // in case of re-run, clear an old status | ||
logfile: undefined, // in case of re-run where logfile may no longer exist, clear old logfile path | ||
}); | ||
|
||
ipcRenderer.send( | ||
|
@@ -186,13 +189,34 @@ class InvestTab extends React.Component { | |
); | ||
} | ||
|
||
handleOpenWorkspace(workspace_dir) { | ||
if (workspace_dir) { | ||
this.openWorkspaceDir(workspace_dir); | ||
} | ||
} | ||
|
||
async openWorkspaceDir(workspace_dir) { | ||
const error = await ipcRenderer.invoke(ipcMainChannels.OPEN_PATH, workspace_dir); | ||
if (error) { | ||
logger.error(`Error opening workspace (${workspace_dir}). ${error}`); | ||
this.showErrorModal(true); | ||
} | ||
} | ||
|
||
showErrorModal(shouldShow) { | ||
this.setState({ | ||
showErrorModal: shouldShow, | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
activeTab, | ||
modelSpec, | ||
argsSpec, | ||
uiSpec, | ||
executeClicked, | ||
showErrorModal, | ||
} = this.state; | ||
const { | ||
status, | ||
|
@@ -213,88 +237,99 @@ class InvestTab extends React.Component { | |
const sidebarFooterElementId = `sidebar-footer-${tabID}`; | ||
|
||
return ( | ||
<TabContainer activeKey={activeTab} id="invest-tab"> | ||
<Row className="flex-nowrap"> | ||
<Col | ||
className="invest-sidebar-col" | ||
> | ||
<Nav | ||
className="flex-column" | ||
id="vertical tabs" | ||
variant="pills" | ||
activeKey={activeTab} | ||
onSelect={this.switchTabs} | ||
<> | ||
<TabContainer activeKey={activeTab} id="invest-tab"> | ||
<Row className="flex-nowrap"> | ||
<Col | ||
className="invest-sidebar-col" | ||
> | ||
<Nav.Link eventKey="setup"> | ||
{t('Setup')} | ||
<MdKeyboardArrowRight /> | ||
</Nav.Link> | ||
<Nav.Link eventKey="log" disabled={logDisabled}> | ||
{t('Log')} | ||
<MdKeyboardArrowRight /> | ||
</Nav.Link> | ||
</Nav> | ||
<div | ||
className="sidebar-row sidebar-buttons" | ||
id={sidebarSetupElementId} | ||
/> | ||
<div className="sidebar-row sidebar-links"> | ||
<ResourcesLinks | ||
moduleName={modelRunName} | ||
docs={modelSpec.userguide} | ||
/> | ||
</div> | ||
<div | ||
className="sidebar-row sidebar-footer" | ||
id={sidebarFooterElementId} | ||
> | ||
{ | ||
status | ||
? ( | ||
<ModelStatusAlert | ||
status={status} | ||
handleOpenWorkspace={() => handleOpenWorkspace(logfile)} | ||
terminateInvestProcess={this.terminateInvestProcess} | ||
/> | ||
) | ||
: null | ||
} | ||
</div> | ||
</Col> | ||
<Col className="invest-main-col"> | ||
<TabContent> | ||
<TabPane | ||
eventKey="setup" | ||
aria-label="model setup tab" | ||
<Nav | ||
className="flex-column" | ||
id="vertical tabs" | ||
variant="pills" | ||
activeKey={activeTab} | ||
onSelect={this.switchTabs} | ||
> | ||
<SetupTab | ||
pyModuleName={modelSpec.pyname} | ||
userguide={modelSpec.userguide} | ||
modelName={modelRunName} | ||
argsSpec={argsSpec} | ||
uiSpec={uiSpec} | ||
argsInitValues={argsValues} | ||
investExecute={this.investExecute} | ||
sidebarSetupElementId={sidebarSetupElementId} | ||
sidebarFooterElementId={sidebarFooterElementId} | ||
executeClicked={executeClicked} | ||
switchTabs={this.switchTabs} | ||
<Nav.Link eventKey="setup"> | ||
{t('Setup')} | ||
<MdKeyboardArrowRight /> | ||
</Nav.Link> | ||
<Nav.Link eventKey="log" disabled={logDisabled}> | ||
{t('Log')} | ||
<MdKeyboardArrowRight /> | ||
</Nav.Link> | ||
</Nav> | ||
<div | ||
className="sidebar-row sidebar-buttons" | ||
id={sidebarSetupElementId} | ||
/> | ||
<div className="sidebar-row sidebar-links"> | ||
<ResourcesLinks | ||
moduleName={modelRunName} | ||
docs={modelSpec.userguide} | ||
/> | ||
</TabPane> | ||
<TabPane | ||
eventKey="log" | ||
aria-label="model log tab" | ||
</div> | ||
<div | ||
className="sidebar-row sidebar-footer" | ||
id={sidebarFooterElementId} | ||
> | ||
<LogTab | ||
logfile={logfile} | ||
executeClicked={executeClicked} | ||
tabID={tabID} | ||
/> | ||
</TabPane> | ||
</TabContent> | ||
</Col> | ||
</Row> | ||
</TabContainer> | ||
{ | ||
status | ||
? ( | ||
<ModelStatusAlert | ||
status={status} | ||
handleOpenWorkspace={() => this.handleOpenWorkspace(argsValues?.workspace_dir)} | ||
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. woah I just learned something new! |
||
terminateInvestProcess={this.terminateInvestProcess} | ||
/> | ||
) | ||
: null | ||
} | ||
</div> | ||
</Col> | ||
<Col className="invest-main-col"> | ||
<TabContent> | ||
<TabPane | ||
eventKey="setup" | ||
aria-label="model setup tab" | ||
> | ||
<SetupTab | ||
pyModuleName={modelSpec.pyname} | ||
userguide={modelSpec.userguide} | ||
modelName={modelRunName} | ||
argsSpec={argsSpec} | ||
uiSpec={uiSpec} | ||
argsInitValues={argsValues} | ||
investExecute={this.investExecute} | ||
sidebarSetupElementId={sidebarSetupElementId} | ||
sidebarFooterElementId={sidebarFooterElementId} | ||
executeClicked={executeClicked} | ||
switchTabs={this.switchTabs} | ||
/> | ||
</TabPane> | ||
<TabPane | ||
eventKey="log" | ||
aria-label="model log tab" | ||
> | ||
<LogTab | ||
logfile={logfile} | ||
executeClicked={executeClicked} | ||
tabID={tabID} | ||
/> | ||
</TabPane> | ||
</TabContent> | ||
</Col> | ||
</Row> | ||
</TabContainer> | ||
<Modal show={showErrorModal} onHide={() => this.showErrorModal(false)} aria-labelledby="error-modal-title"> | ||
<Modal.Header closeButton> | ||
<Modal.Title id="error-modal-title">{t('Error opening workspace')}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body>{t('Failed to open workspace directory. Make sure the directory exists and that you have write access to it.')}</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="primary" onClick={() => this.showErrorModal(false)}>{t('OK')}</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
} | ||
|
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 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a benefit to defining both
handleOpenWorkspace
andopenWorkspaceDir
? As opposed to doing all the logic in one function? It's fairly inconsequential so if you prefer it this way feel free to leave it as-is.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.
Probably not. I think this is a holdover from when
handleOpenWorkspace
also calledshell.showItemInFolder
when the logfile was valid. With that complexity gone, it does look a little silly now.