Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
changes corresponding to CCI-Tools/cate#270
Browse files Browse the repository at this point in the history
  • Loading branch information
forman committed Jul 10, 2017
1 parent a0061a6 commit c000e14
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 134 deletions.
17 changes: 17 additions & 0 deletions src/renderer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,23 @@ export function setWorkspaceResource(resName: string, opName: string, opArgs: Op
}
}

export function setWorkspaceResourcePersistence(resName: string, persistent: boolean): ThunkAction {
return (dispatch: Dispatch, getState: GetState) => {
const baseDir = selectors.workspaceBaseDirSelector(getState());
assert.ok(baseDir);

function call(onProgress) {
return selectors.workspaceAPISelector(getState()).setWorkspaceResourcePersistence(baseDir, resName, persistent);
}

function action(workspace: WorkspaceState) {
dispatch(setCurrentWorkspace(workspace));
}

callAPI(dispatch, "Changing resource persistence", call, action);
}
}

export function renameWorkspaceResource(resName: string, newResName: string): ThunkAction {
return (dispatch: Dispatch, getState: GetState) => {
const baseDir = selectors.workspaceBaseDirSelector(getState());
Expand Down
106 changes: 0 additions & 106 deletions src/renderer/containers/ResourceRenameDialog.tsx

This file was deleted.

134 changes: 134 additions & 0 deletions src/renderer/containers/WorkflowStepPropertiesDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import * as React from 'react';
import {State, ResourceState, DialogState, WorkflowStepState} from "../state";
import {connect, DispatchProp} from "react-redux";
import * as actions from "../actions";
import * as selectors from "../selectors";
import * as assert from "../../common/assert";
import {ModalDialog} from "../components/ModalDialog";
import {Checkbox} from "@blueprintjs/core";

const DIALOG_ID = 'workflowStepPropertiesDialog';
const DIALOG_TITLE = 'Workflow Step & Resource Properties';

interface IResourcePropertiesDialogOwnProps {
selectedWorkflowStep: WorkflowStepState;
}

interface IWorkflowStepPropertiesDialogProps extends IResourcePropertiesDialogOwnProps, DialogState {
resources: ResourceState[];
}

interface IWorkflowStepPropertiesDialogState {
stepId: string;
stepPersistent: boolean;
}

function mapStateToProps(state: State, ownProps: IResourcePropertiesDialogOwnProps): IWorkflowStepPropertiesDialogProps {
return {
selectedWorkflowStep: ownProps.selectedWorkflowStep,
isOpen: selectors.dialogStateSelector(DIALOG_ID)(state).isOpen,
resources: selectors.resourcesSelector(state),
};
}

class WorkflowStepPropertiesDialog extends React.Component<IWorkflowStepPropertiesDialogProps & DispatchProp<State>, IWorkflowStepPropertiesDialogState> {

constructor(props: IWorkflowStepPropertiesDialogProps & DispatchProp<State>) {
super(props);
this.onCancel = this.onCancel.bind(this);
this.onConfirm = this.onConfirm.bind(this);
this.canConfirm = this.canConfirm.bind(this);
this.renderBody = this.renderBody.bind(this);
this.state = WorkflowStepPropertiesDialog.mapPropsToState(props);
}

private static mapPropsToState(props: IWorkflowStepPropertiesDialogProps) {
const step = props.selectedWorkflowStep;
assert.ok(step);
return {
stepId: step.id || '',
stepPersistent: step.persistent || false,
};
}

componentWillReceiveProps(nextProps: IWorkflowStepPropertiesDialogProps): void {
this.setState(WorkflowStepPropertiesDialog.mapPropsToState(nextProps));
}

private onConfirm() {
this.props.dispatch(actions.hideDialog(DIALOG_ID));

const oldStepId = this.props.selectedWorkflowStep.id || '';
const newStepId = this.state.stepId ? this.state.stepId.trim() : '';
const oldStepPersistent = this.props.selectedWorkflowStep.persistent || false;
const newStepPersistent = this.state.stepPersistent || false;

if (oldStepPersistent !== newStepPersistent) {
this.props.dispatch(actions.setWorkspaceResourcePersistence(oldStepId, newStepPersistent));
}
if (oldStepId !== newStepId) {
this.props.dispatch(actions.renameWorkspaceResource(oldStepId, newStepId));
}
}

private onCancel() {
this.props.dispatch(actions.hideDialog(DIALOG_ID));
}

private canConfirm(): boolean {
const oldStepId = this.props.selectedWorkflowStep.id || '';
const newStepId = this.state.stepId ? this.state.stepId.trim() : '';
const oldStepPersistent = this.props.selectedWorkflowStep.persistent || false;
const newStepPersistent = this.state.stepPersistent || false;
return newStepId !== '' && (newStepId !== oldStepId || newStepPersistent !== oldStepPersistent);
}

render() {
if (!this.props.isOpen) {
return null;
}
return (
<ModalDialog
isOpen={this.props.isOpen}
title={DIALOG_TITLE}
iconName="edit"
onCancel={this.onCancel}
onConfirm={this.onConfirm}
canConfirm={this.canConfirm}
renderBody={this.renderBody}
/>
);
}

private renderBody() {
if (!this.props.isOpen) {
return null;
}

return (
<div style={{width: '100%', padding: 6}}>
<label className="pt-label">
Resource name
<span className="pt-text-muted"> (must be unique within the workspace)</span>
<input className="pt-input"
style={{width: '100%'}}
type="text"
value={this.state.stepId}
onChange={(ev: any) => this.setState({stepId: ev.target.value})}/>
</label>

<div style={{paddingTop: 10}}>
<Checkbox checked={this.state.stepPersistent}
onChange={(ev: any) => this.setState({stepPersistent: ev.target.checked})}
label="Persist resulting resource"
/>
<span className="pt-text-muted">If checked, the resource will be read from a file in the workspac next time the workspace is opened.
This usually speeds up the loading of workspace, but requires extra disk space.</span>
</div>
</div>
);
}
}

export default connect(mapStateToProps)(WorkflowStepPropertiesDialog);

53 changes: 25 additions & 28 deletions src/renderer/containers/WorkspacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {AnchorButton, Tabs2, Tab2, Tooltip, Position, Popover, Menu, MenuItem} f
import {Table, Column, Cell, TruncatedFormat} from "@blueprintjs/table";
import {ListBox} from "../components/ListBox";
import {LabelWithType} from "../components/LabelWithType";
import ResourceRenameDialog from "./ResourceRenameDialog";
import WorkflowStepPropertiesDialog from "./WorkflowStepPropertiesDialog";
import OperationStepDialog from "./OperationStepDialog";
import {ContentWithDetailsPanel} from "../components/ContentWithDetailsPanel";
import * as assert from "../../common/assert";
Expand Down Expand Up @@ -78,7 +78,7 @@ class WorkspacePanel extends React.PureComponent<IWorkspacePanelProps & Dispatch
this.handleShowWorkflowStepDetailsChanged = this.handleShowWorkflowStepDetailsChanged.bind(this);
this.handleWorkflowStepIdSelected = this.handleWorkflowStepIdSelected.bind(this);
this.handleShowFigureButtonClicked = this.handleShowFigureButtonClicked.bind(this);
this.handleRenameResourceButtonClicked = this.handleRenameResourceButtonClicked.bind(this);
this.handleWorkflowStepPropertiesButtonClicked = this.handleWorkflowStepPropertiesButtonClicked.bind(this);
this.handleOpenWorkspaceDirectoryClicked = this.handleOpenWorkspaceDirectoryClicked.bind(this);
this.handleEditOperationStepButtonClicked = this.handleEditOperationStepButtonClicked.bind(this);
this.renderStepItem = this.renderStepItem.bind(this);
Expand Down Expand Up @@ -129,8 +129,8 @@ class WorkspacePanel extends React.PureComponent<IWorkspacePanelProps & Dispatch
this.props.dispatch(actions.showTableView(this.getEffectiveResource().name, null, this.props.activeViewId));
}

private handleRenameResourceButtonClicked() {
this.props.dispatch(actions.showDialog('resourceRenameDialog'));
private handleWorkflowStepPropertiesButtonClicked() {
this.props.dispatch(actions.showDialog('workflowStepPropertiesDialog'));
}

private handleOpenWorkspaceDirectoryClicked() {
Expand Down Expand Up @@ -284,11 +284,11 @@ class WorkspacePanel extends React.PureComponent<IWorkspacePanelProps & Dispatch
onClick={this.handleShowResourceTableView}
/>
</Tooltip>
<Tooltip content="Rename resource" position={Position.LEFT}>
<Tooltip content="Resource/step properties" position={Position.LEFT}>
<AnchorButton
disabled={!resource}
iconName="label"
onClick={this.handleRenameResourceButtonClicked}/>
onClick={this.handleWorkflowStepPropertiesButtonClicked}/>
</Tooltip>
<Tooltip content="Edit workflow step" position={Position.LEFT}>
<AnchorButton
Expand All @@ -309,7 +309,7 @@ class WorkspacePanel extends React.PureComponent<IWorkspacePanelProps & Dispatch
iconName="delete"
onClick={this.handleCleanWorkflowButtonClicked}/>
</Tooltip>
{resource ? <ResourceRenameDialog selectedResource={resource}/> : null}
{workflowStep ? <WorkflowStepPropertiesDialog selectedWorkflowStep={workflowStep}/> : null}
{isOperationStepSelected ?
<OperationStepDialog id="editOperationStepDialog" operationStep={workflowStep}/> : null}
</div>
Expand Down Expand Up @@ -506,44 +506,41 @@ class WorkspacePanel extends React.PureComponent<IWorkspacePanelProps & Dispatch

//noinspection JSMethodCanBeStatic
private getWorkflowStepLabel(step: WorkflowStepState) {
let opName;

const items = [];

if (step && step.op) {
opName = step.op;
let opName = step.op;
const index = opName.lastIndexOf('.');
if (index > 0) {
opName = opName.slice(index + 1);
}
}
const resource = this.props.resourcesMap[step.id];

let opNameLabel;
if (opName) {
opNameLabel = <code>{opName}()</code>;
items.push(<code key={0}>{opName}()</code>);
} else {
items.push(<code key={0}>?()</code>);
}

let resourceLabel;
const resource = this.props.resourcesMap[step.id];
if (resource) {
resourceLabel = <LabelWithType label={resource.name}
dataType={resource.dataType}/>;
items.push(<span key={1}> &rarr; </span>);
items.push(<LabelWithType key={2} label={resource.name}
dataType={resource.dataType}/>);
}

if (opNameLabel && resourceLabel) {
return <span>{opNameLabel} &rarr; {resourceLabel}</span>;
} else if (resourceLabel) {
return <span>? &rarr; {resourceLabel}</span>;
} else if (opNameLabel) {
return <span>{opNameLabel}</span>;
} else {
return <span>?</span>;
let persistenceLabel;
if (step && step.persistent) {
items.push(<span key={3}> </span>);
items.push(<span key={4} className="pt-icon-database"/>);
}

return <span>{items}</span>;
}
}

export default connect(mapStateToProps)(WorkspacePanel);



function convertSteps(operations: OperationState[], steps: WorkflowStepState[], target: 'python'|'shell'): string {
function convertSteps(operations: OperationState[], steps: WorkflowStepState[], target: 'python' | 'shell'): string {
// TODO (forman): move this to backend, as this is best done in Python
let lines = [];
if (target === 'python') {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ export interface WorkflowStepState {
*/
op: string;

/**
* Whether the step stores resource files for faster opening of workspaces.
*/
persistent?: boolean;

input: { [name: string]: WorkflowPortState };
output: { [name: string]: WorkflowPortState };
}
Expand Down
Loading

0 comments on commit c000e14

Please sign in to comment.