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

Bug 1875440: Make pipeline task parameter editable (if it was only defined in the pipeline, not in the task) #6520

Merged
merged 1 commit into from
Sep 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { PipelineTask } from '../../../../utils/pipeline-augment';
import { applyParamsUpdate } from '../update-utils';
import { UpdateTaskParamData } from '../types';

describe('applyParamsUpdate', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for these tests... My refactor PR has a few as well, but it has missed 2 releases. It needs to be done for 4.7, so I'll start rebasing and aligning next sprint to merge as Master opens.

it('change an existing task param', () => {
const inputTask: PipelineTask = {
name: 'pipeline-task',
taskRef: {
name: 'task',
},
params: [
{ name: 'EXISTING_TASK_PARAM', value: 'old value' },
{ name: 'ANOTHER_EXISTING_TASK_PARAM', value: 'ignored value' },
],
};
const params: UpdateTaskParamData = {
newValue: 'new value',
taskParamName: 'EXISTING_TASK_PARAM',
};
const updatedTask = applyParamsUpdate(inputTask, params);
expect(updatedTask).not.toBe(inputTask);
expect(updatedTask.params).not.toBe(inputTask.params);
expect(updatedTask).toEqual({
name: 'pipeline-task',
taskRef: {
name: 'task',
},
params: [
{ name: 'EXISTING_TASK_PARAM', value: 'new value' },
{ name: 'ANOTHER_EXISTING_TASK_PARAM', value: 'ignored value' },
],
});
});

it('change a non-existing task param', () => {
const inputTask: PipelineTask = {
name: 'pipeline-task',
taskRef: {
name: 'task',
},
params: [{ name: 'ANOTHER_EXISTING_TASK_PARAM', value: 'ignored value' }],
};
const params: UpdateTaskParamData = {
newValue: 'new value',
taskParamName: 'NEW_TASK_PARAM',
};
const updatedTask = applyParamsUpdate(inputTask, params);
expect(updatedTask).not.toBe(inputTask);
expect(updatedTask.params).not.toBe(inputTask.params);
expect(updatedTask).toEqual({
name: 'pipeline-task',
taskRef: {
name: 'task',
},
params: [
{ name: 'ANOTHER_EXISTING_TASK_PARAM', value: 'ignored value' },
{ name: 'NEW_TASK_PARAM', value: 'new value' },
],
});
});

it('change a non-existing task param in a task without any param', () => {
const inputTask: PipelineTask = {
name: 'pipeline-task',
taskRef: {
name: 'task',
},
};
const params: UpdateTaskParamData = {
newValue: 'new value',
taskParamName: 'NEW_TASK_PARAM',
};
const updatedTask = applyParamsUpdate(inputTask, params);
expect(updatedTask).not.toBe(inputTask);
expect(updatedTask).toEqual({
name: 'pipeline-task',
taskRef: {
name: 'task',
},
params: [{ name: 'NEW_TASK_PARAM', value: 'new value' }],
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
import { getRandomChars } from '@console/shared/src/utils';
import { getRandomChars } from '@console/shared';
import {
PipelineResourceTask,
PipelineTask,
Expand Down Expand Up @@ -306,26 +306,37 @@ const applyResourceUpdate = (
};
};

const applyParamsUpdate = (
export const applyParamsUpdate = (
pipelineTask: PipelineTask,
params: UpdateTaskParamData,
): PipelineTask => {
const { newValue, taskParamName } = params;

return {
...pipelineTask,
params: pipelineTask.params.map(
let foundParam = false;
const changedParams =
pipelineTask.params?.map(
(param): PipelineTaskParam => {
if (param.name !== taskParamName) {
return param;
}

foundParam = true;
return {
...param,
value: newValue,
};
},
),
) || [];

if (!foundParam) {
changedParams.push({
name: taskParamName,
value: newValue,
});
}

return {
...pipelineTask,
params: changedParams,
};
};

Expand Down