Skip to content
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

[KED-2492] Update store functions for new modular pipeline data #391

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
23 changes: 23 additions & 0 deletions src/store/normalize-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const createInitialPipelineState = () => ({
ids: [],
name: {},
},
modularPipeline: {
ids: [],
name: {},
},
node: {
ids: [],
name: {},
Expand All @@ -26,6 +30,7 @@ export const createInitialPipelineState = () => ({
parameters: {},
filepath: {},
datasetType: {},
modularPipelines: {},
},
nodeType: {
ids: ['task', 'data', 'parameters'],
Expand Down Expand Up @@ -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
Expand All @@ -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;
};

/**
Expand Down Expand Up @@ -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));
}
Expand Down
21 changes: 21 additions & 0 deletions src/store/normalize-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down