Remove Workflow.js and related functions
authorFrank Bessou <frank.bessou@logilab.fr>
Wed, 10 May 2017 13:31:56 +0200
changeset 190 bc61eaa9d97a
parent 189 c6d48aca5190
child 191 a532f96e0050
Remove Workflow.js and related functions
src/components/Entity.js
src/components/Workflow.js
--- a/src/components/Entity.js	Wed May 10 14:53:10 2017 +0200
+++ b/src/components/Entity.js	Wed May 10 13:31:56 2017 +0200
@@ -10,7 +10,6 @@
 import {PropTypesEntityModel} from '../model';
 import {buildFormData, appendPath} from '../utils';
 import {ActionsDropDown, CollectionView} from './BaseViews';
-import {WorkflowActions} from './Workflow';
 import {AttributeValue} from './Attribute';
 
 export function EntityAttributes(props) {
@@ -309,34 +308,6 @@
     entity: PropTypesEntityModel.isRequired,
 };
 
-export class WorkflowableEntityView extends EntityView {
-
-    renderTitle() {
-        const wfProps = {
-            etype: this.props.entity.cw_etype,
-            eid: this.props.entity.eid,
-            workflowState: this.props.entity.workflow_state,
-        };
-        const other = {className: 'pull-right'};
-        return (
-            <div>
-                { super.renderTitle() }
-                <WorkflowActions {...other} {...wfProps} />
-            </div>
-        );
-    }
-}
-
-WorkflowableEntityView.propTypes = {
-    // XXX Copy from EntityView.propTypes
-    entity: PropTypes.shape({
-        cw_etype: PropTypes.string.isRequired,
-        eid: PropTypes.number.isRequired,
-        workflow_state: PropTypes.string.isRequired,
-        dc_title: PropTypes.string.isRequired,
-    }).isRequired,
-};
-
 const uiSchema = {
     description: {
         'ui:widget': 'textarea',
--- a/src/components/Workflow.js	Wed May 10 14:53:10 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-import {PropTypes} from 'prop-types';
-import {isEmpty} from 'lodash/lang';
-import {zip} from 'lodash/array';
-import {get, omit} from 'lodash/object';
-import React from 'react';
-import Api from '../Api';
-
-export class WorkflowActions extends React.Component {
-
-    constructor(props, context) {
-        super(props, context);
-        this.state = {
-            schema: null,
-            // the initial workflow state, passed from parent component.
-            workflowState: props.workflowState,
-            possibleTransitions: null,
-        };
-        this.fireTransition = this.fireTransition.bind(this);
-    }
-
-    componentDidMount() {
-        this.getTransitionsSchema()
-            .then(schema => {
-                const possibleTransitions = this.getPossibleTransitions(schema);
-                this.setState({schema: schema, possibleTransitions: possibleTransitions});
-            });
-    }
-
-    getPossibleTransitions(schema) {
-        const eschema = schema.definitions['TrInfo'];
-        const names = get(
-                eschema, ['properties', 'name', 'enum'], []);
-        const titles = get(
-                eschema, ['properties', 'name', 'options', 'enum_titles'], []);
-        return zip(names, titles);
-    }
-
-    getTransitionsSchema() {
-        const {etype, eid} = this.props;
-        return Api.getTransitionsSchema(etype, eid);
-    }
-
-    fireTransition(trname) {
-        const {etype, eid} = this.props;
-        const path = `/${etype}/${eid}`;
-        Api.addTransition(etype, eid, {name: trname})
-            .then(trinfo => {
-                this.getTransitionsSchema()
-                    .then(schema => {
-                        const possibleTransitions = this.getPossibleTransitions(schema);
-                        this.setState({
-                            schema: schema,
-                            possibleTransitions: possibleTransitions,
-                            workflowState: trinfo.to_state,
-                        });
-                        this.context.router.history.push(path);
-                    });
-            });
-    }
-
-    render() {
-        if (this.state.schema === null) {
-            return <div>loading...</div>;
-        }
-        const viewProps = omit(this.state, ['schema']);
-        viewProps.fireTransition = this.fireTransition;
-        return <WorkflowActionsView {...this.props} {...viewProps} />;
-    }
-}
-
-WorkflowActions.contextTypes = {
-    router: PropTypes.object,
-};
-
-WorkflowActions.propTypes = {
-    etype: PropTypes.string.isRequired,
-    eid: PropTypes.number.isRequired,
-    workflowState: PropTypes.string.isRequired,
-};
-
-function WorkflowActionsView(props) {
-    const className = (defaultValue) => [
-        get(props, ['className'], ''), defaultValue].join(' ');
-    const {fireTransition} = props;
-    const buildLink = ([name, title]) => {
-        const onClick = () => fireTransition(name);
-        const link = <a href="#" onClick={onClick}>{title}</a>;
-        return <li key={name}>{link}</li>;
-    };
-    if (!isEmpty(props.possibleTransitions)) {
-        return (
-            <div className={className('btn btn-group')}>
-                <button className="btn btn-primary">
-                    {props.workflowState}
-                </button>
-                <button className="btn btn-primary dropdown-toggle"
-                    data-toggle="dropdown"
-                >
-                    <span className="caret" />
-                </button>
-                <ul className="pull-left dropdown-menu">
-                    { props.possibleTransitions.map(buildLink) }
-                </ul>
-            </div>
-        );
-    }
-    return (
-        <button className={className('btn btn-default')}>
-            {props.workflowState}
-        </button>
-    );
-}
-
-WorkflowActionsView.propTypes = {
-    workflowState: PropTypes.string.isRequired,
-    fireTransition: PropTypes.func.isRequired,
-    possibleTransitions: PropTypes.arrayOf(
-            PropTypes.arrayOf(PropTypes.string)).isRequired,
-    className: PropTypes.string,
-};