Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
feat: bulk creation modes (#12)
Browse files Browse the repository at this point in the history
add flow loading api, flow batching element creation api, flow reset api
  • Loading branch information
acateland committed Sep 15, 2016
1 parent d8a3d81 commit bb98996
Show file tree
Hide file tree
Showing 38 changed files with 1,815 additions and 1,494 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
npm-debug.log
jsconfig.json
node_modules/
coverage/
lib/
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-flow-designer",
"version": "0.0.7",
"version": "0.0.8",
"description": "Flow designer for react and redux",
"main": "lib/react-flow-designer.js",
"scripts": {
Expand Down Expand Up @@ -53,7 +53,6 @@
"eslint-plugin-react": "^6.0.0",
"extract-text-webpack-plugin": "2.0.0-beta.3",
"immutable": "3.8.1",
"jasmine-immutable-matchers": "1.0.1",
"jest-cli": "15.1.1",
"node-sass": "3.9.3",
"react": "15.3.0",
Expand Down Expand Up @@ -83,7 +82,7 @@
"d3-drag": "1.0.0",
"d3-interpolate": "1.1.1",
"d3-scale": "1.0.2",
"d3-selection": "1.0.1",
"d3-selection": "1.0.2",
"d3-shape": "1.0.3",
"d3-zoom": "1.0.2",
"invariant": "2.2.1",
Expand Down
31 changes: 31 additions & 0 deletions src/actions/flow.actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
FLOWDESIGNER_FLOW_ADD_ELEMENTS,
FLOWDESIGNER_FLOW_RESET,
FLOWDESIGNER_FLOW_LOAD,
} from '../constants/flowdesigner.constants';

/**
* Ask to sequentially add elements to the flow, each creation should be checked against store,
* then applied via current reducers
*
* @params {array} listOfActionCreation
*/
export const addFlowElements = listOfActionCreation => ({
type: FLOWDESIGNER_FLOW_ADD_ELEMENTS,
listOfActionCreation,
});

/**
* ask for flow reset, emptying, nodes, links, ports collections
*/
export const resetFlow = () => ({
type: FLOWDESIGNER_FLOW_RESET,
});

/**
* reset old flow, load elements for the new flow
*/
export const loadFlow = listOfActionCreation => ({
type: FLOWDESIGNER_FLOW_LOAD,
listOfActionCreation,
});
10 changes: 10 additions & 0 deletions src/actions/flow.actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as flowActions from './flow.actions';

describe('Check that flowActions generate proper action objects', () => {
it('addFlowElements generate proper action object', () => {
expect(flowActions.addFlowElements([])).toEqual({
type: 'FLOWDESIGNER.FLOW_ADD_ELEMENTS',
listOfActionCreation: [],
});
});
});
193 changes: 38 additions & 155 deletions src/actions/link.actions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import invariant from 'invariant';

import {
FLOWDESIGNER_LINK_ADD,
FLOWDESIGNER_LINK_SET_TARGET,
FLOWDESIGNER_LINK_SET_SOURCE,
FLOWDESIGNER_LINK_REMOVE,
FLOWDESIGNER_LINK_SET_ATTR,
FLOWDESIGNER_LINK_REMOVE_ATTR,
FLOWDESIGNER_LINK_ADD,
FLOWDESIGNER_LINK_SET_TARGET,
FLOWDESIGNER_LINK_SET_SOURCE,
FLOWDESIGNER_LINK_REMOVE,
FLOWDESIGNER_LINK_SET_ATTR,
FLOWDESIGNER_LINK_REMOVE_ATTR,
} from '../constants/flowdesigner.constants';

/**
Expand All @@ -17,180 +15,65 @@ import {
* @param {string} linkType
* @param {Object} attr
*/
export const addLink = (linkId, sourceId, targetId, linkType, attr) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (state.flowDesigner.links[linkId]) {
error = true;
invariant(
false,
`can't set a target ${targetId} on non existing link with id ${linkId}`);
}
if (state.flowDesigner.ports[targetId]) {
error = true;
invariant(
false,
`can't set a non existing target with id ${targetId} on link ${linkId}`
);
}
if (state.flowDesigner.ports[sourceId]) {
error = true;
invariant(
false,
`can't set a non existing source with id ${sourceId} on link ${linkId}`
);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_ADD,
linkId,
sourceId,
targetId,
linkType,
attr,
});
}
}


);
export const addLink = (linkId, sourceId, targetId, linkType, attr) => ({
type: FLOWDESIGNER_LINK_ADD,
linkId,
sourceId,
targetId,
linkType,
attr,
});

/**
* Ask for change of link target
* @param {string} linkId
* @param {string} targetId - the target port identifier
*/
export const setLinkTarget = (linkId, targetId) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (state.flowDesigner.links[linkId]) {
error = true;
invariant(
false,
`can't set a target ${targetId} on non existing link with id ${linkId}`);
}
if (state.flowDesigner.ports[targetId]) {
error = true;
invariant(
false,
`can't set a non existing target with id ${targetId} on link ${linkId}`
);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_SET_TARGET,
linkId,
targetId,
});
}
}
);
export const setLinkTarget = (linkId, targetId) => ({
type: FLOWDESIGNER_LINK_SET_TARGET,
linkId,
targetId,
});

/**
* Ask for change of link source
* @param {string} linkId
* @param {string} sourceId - the source port identifier
*/
export const setLinkSource = (linkId, sourceId) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (state.flowDesigner.links[linkId]) {
error = true;
invariant(
false,
`can't set a source ${sourceId} on non existing link with id ${linkId}`
);
}
if (state.flowDesigner.ports[sourceId]) {
error = true;
invariant(
false,
`can't set a non existing target with id ${sourceId} on link ${linkId}`
);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_SET_SOURCE,
linkId,
sourceId,
});
}
}
);
export const setLinkSource = (linkId, sourceId) => ({
type: FLOWDESIGNER_LINK_SET_SOURCE,
linkId,
sourceId,
});

/**
* Ask to set attributes on link
* @param {string} linkId
* @param {Object} attr
*/
export const setLinkAttribute = (linkId, attr) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (!state.flowDesigner.links.get(linkId)) {
error = true;
invariant(
false,
`Can't set an attribute on non existing link ${linkId}`);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_SET_ATTR,
linkId,
attr,
});
}
}
);
export const setLinkAttribute = (linkId, attr) => ({
type: FLOWDESIGNER_LINK_SET_ATTR,
linkId,
attr,
});

/**
* Ask to remove an attribute on target link
* @param {string} linkId
* @param {string} attrKey - the key of the attribute to be removed
*/
export const removeLinkAttribute = (linkId, attrKey) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (!state.flowDesigner.links.get(linkId)) {
error = true;
invariant(
false,
`Can't remove an attribute on non existing link ${linkId}`);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_REMOVE_ATTR,
linkId,
attrKey,
});
}
}
);
export const removeLinkAttribute = (linkId, attrKey) => ({
type: FLOWDESIGNER_LINK_REMOVE_ATTR,
linkId,
attrKey,
});

/**
* Ask for link removal
* @param {string} linkId
* @return {Object}
*/
export const removeLink = (linkId) => (
(dispatch, getState) => {
const state = getState();
let error = false;
if (!state.flowDesigner.links.get(linkId)) {
error = true;
invariant(
false,
`can't remove non existing link ${linkId}`);
}
if (!error) {
dispatch({
type: FLOWDESIGNER_LINK_REMOVE,
linkId,
});
}
}
);
export const removeLink = (linkId) => ({
type: FLOWDESIGNER_LINK_REMOVE,
linkId,
});

0 comments on commit bb98996

Please sign in to comment.