diff --git a/src/reducers/index.js b/src/reducers/index.js index 73c62ad150..7949fec13e 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -63,6 +63,7 @@ const combinedReducer = combineReducers({ asyncDataSource: createReducer(false), edge: createReducer({}), id: createReducer(null), + modularPipeline: createReducer({}), // These props have very simple non-nested actions chartSize: createReducer({}, UPDATE_CHART_SIZE, 'chartSize'), zoom: createReducer({}, UPDATE_ZOOM, 'zoom'), diff --git a/src/store/normalize-data.js b/src/store/normalize-data.js index 49347581ed..52b3815126 100644 --- a/src/store/normalize-data.js +++ b/src/store/normalize-data.js @@ -9,6 +9,10 @@ export const createInitialPipelineState = () => ({ ids: [], name: {}, }, + modularPipeline: { + ids: [], + name: {}, + }, node: { ids: [], name: {}, @@ -26,6 +30,7 @@ export const createInitialPipelineState = () => ({ parameters: {}, filepath: {}, datasetType: {}, + modularPipelines: {}, }, nodeType: { ids: ['task', 'data', 'parameters'], @@ -99,6 +104,20 @@ const addPipeline = (state) => (pipeline) => { state.pipeline.name[id] = pipeline.name; }; +/** + * Add a new modular pipeline + * @param {string} modularPipeline.id - Unique namespace of the modular pipeline + * @param {string} modularPipeline.name - modular pipeline name + */ +const addModularPipeline = (state) => (modularPipeline) => { + const { id, name } = modularPipeline; + if (state.modularPipeline.name[id]) { + return; + } + state.modularPipeline.ids.push(id); + state.modularPipeline.name[id] = name; +}; + /** * Add a new node if it doesn't already exist * @param {string} name - Default node name @@ -125,6 +144,7 @@ const addNode = (state) => (node) => { state.node.parameters[id] = node.parameters; state.node.filepath[id] = node.filepath; state.node.datasetType[id] = node.datasetType; + state.node.modularPipelines[id] = node.modular_pipelines; }; /** @@ -188,6 +208,9 @@ const normalizeData = (data) => { state.pipeline.active = state.pipeline.main; } } + if (data.modular_pipelines) { + data.modular_pipelines.forEach(addModularPipeline(state)); + } if (data.tags) { data.tags.forEach(addTag(state)); } diff --git a/src/store/normalize-data.test.js b/src/store/normalize-data.test.js index a15e55e12a..2721314407 100644 --- a/src/store/normalize-data.test.js +++ b/src/store/normalize-data.test.js @@ -47,6 +47,27 @@ describe('normalizeData', () => { expect(normalizeData(data).pipeline.active).toBe(undefined); }); + it('should not add modular pipelines if modular pipelines are not supplied', () => { + const data = Object.assign({}, animals, { modular_pipelines: undefined }); + expect(normalizeData(data).modularPipeline.ids).toHaveLength(0); + }); + + it('should not add duplicate modular pipelines', () => { + const data = Object.assign({}, animals, { + modular_pipelines: [ + { + id: 'pipeline1', + name: 'Pipeline 1', + }, + { + id: 'pipeline1', + name: 'Pipeline 1', + }, + ], + }); + expect(normalizeData(data).modularPipeline.ids).toHaveLength(1); + }); + it('should not add layers if layers are not supplied', () => { const data = Object.assign({}, animals, { layers: undefined }); data.nodes.forEach((node) => {