Cleanup handling of extra_vars in workflow node prompting

This commit is contained in:
mabashian 2020-12-15 13:20:23 -05:00
parent d95373f2b7
commit a345675a97
6 changed files with 54 additions and 48 deletions

View File

@ -51,7 +51,9 @@ function PreviewStep({
mergeExtraVars(initialExtraVars, masked)
);
} else {
overrides.extra_vars = initialExtraVars;
overrides.extra_vars = yaml.safeDump(
mergeExtraVars(initialExtraVars, {})
);
}
}

View File

@ -126,7 +126,7 @@ describe('PreviewStep', () => {
expect(detail).toHaveLength(1);
expect(detail.prop('resource')).toEqual(resource);
expect(detail.prop('overrides')).toEqual({
extra_vars: 'one: 1',
extra_vars: 'one: 1\n',
});
});
test('should remove survey with empty array value', async () => {
@ -152,7 +152,7 @@ describe('PreviewStep', () => {
expect(detail).toHaveLength(1);
expect(detail.prop('resource')).toEqual(resource);
expect(detail.prop('overrides')).toEqual({
extra_vars: 'one: 1',
extra_vars: 'one: 1\n',
});
});
});

View File

@ -93,9 +93,10 @@ function NodeModalForm({
mergeExtraVars(initialExtraVars, surveyValues)
);
} else {
extraVars = initialExtraVars;
extraVars = yaml.safeDump(mergeExtraVars(initialExtraVars, {}));
}
values.extra_data = extraVars && parseVariableField(extraVars);
delete values.extra_vars;
}
onSave(values, launchConfig);

View File

@ -305,7 +305,6 @@ describe('NodeModal', () => {
verbosity: '0',
job_tags: '',
skip_tags: '',
extra_vars: '---',
diff_mode: false,
survey_bar: 'answer',
nodeResource: mockJobTemplate,

View File

@ -134,26 +134,18 @@ const getNodeToEditDefaultValues = (launchConfig, surveyConfig, nodeToEdit) => {
initialValues.diff_mode = sourceOfValues?.diff_mode || false;
}
if (launchConfig.ask_variables_on_launch && launchConfig.survey_enabled) {
if (nodeToEdit?.promptValues?.extra_vars) {
initialValues.extra_vars = nodeToEdit.promptValues.extra_vars;
} else {
const newExtraData = { ...nodeToEdit.originalNodeObject.extra_data };
if (surveyConfig.spec) {
surveyConfig.spec.forEach(question => {
if (
Object.prototype.hasOwnProperty.call(
newExtraData,
question.variable
)
) {
delete newExtraData[question.variable];
}
});
}
initialValues.extra_vars = jsonToYaml(JSON.stringify(newExtraData));
if (launchConfig.ask_variables_on_launch) {
const newExtraData = { ...sourceOfValues.extra_data };
if (launchConfig.survey_enabled && surveyConfig.spec) {
surveyConfig.spec.forEach(question => {
if (
Object.prototype.hasOwnProperty.call(newExtraData, question.variable)
) {
delete newExtraData[question.variable];
}
});
}
initialValues.extra_vars = jsonToYaml(JSON.stringify(newExtraData));
}
if (surveyConfig?.spec) {

View File

@ -79,8 +79,9 @@ function VisualizerToolbar({
<Badge id="visualizer-total-nodes-badge" isRead>
{totalNodes}
</Badge>
<Tooltip content={i18n._(t`Toggle Legend`)} position="bottom">
<Tooltip content={i18n._(t`Toggle legend`)} position="bottom">
<ActionButton
aria-label={i18n._(t`Toggle legend`)}
id="visualizer-toggle-legend"
isActive={totalNodes > 0 && showLegend}
isDisabled={totalNodes === 0}
@ -90,8 +91,9 @@ function VisualizerToolbar({
<CompassIcon />
</ActionButton>
</Tooltip>
<Tooltip content={i18n._(t`Toggle Tools`)} position="bottom">
<Tooltip content={i18n._(t`Toggle tools`)} position="bottom">
<ActionButton
aria-label={i18n._(t`Toggle tools`)}
id="visualizer-toggle-tools"
isActive={totalNodes > 0 && showTools}
isDisabled={totalNodes === 0}
@ -101,33 +103,43 @@ function VisualizerToolbar({
<WrenchIcon />
</ActionButton>
</Tooltip>
<ActionButton
aria-label={i18n._(t`Workflow Documentation`)}
id="visualizer-documentation"
variant="plain"
component="a"
target="_blank"
href={DOCLINK}
<Tooltip
content={i18n._(t`Workflow documentation`)}
position="bottom"
>
<BookIcon />
</ActionButton>
<ActionButton
aria-label={i18n._(t`Workflow documentation`)}
id="visualizer-documentation"
variant="plain"
component="a"
target="_blank"
href={DOCLINK}
>
<BookIcon />
</ActionButton>
</Tooltip>
{template.summary_fields?.user_capabilities?.start && (
<LaunchButton resource={template} aria-label={i18n._(t`Launch`)}>
{({ handleLaunch }) => (
<ActionButton
id="visualizer-launch"
variant="plain"
isDisabled={hasUnsavedChanges || totalNodes === 0}
onClick={handleLaunch}
>
<RocketIcon />
</ActionButton>
)}
</LaunchButton>
<Tooltip content={i18n._(t`Launch workflow`)} position="bottom">
<LaunchButton
resource={template}
aria-label={i18n._(t`Launch workflow`)}
>
{({ handleLaunch }) => (
<ActionButton
id="visualizer-launch"
variant="plain"
isDisabled={hasUnsavedChanges || totalNodes === 0}
onClick={handleLaunch}
>
<RocketIcon />
</ActionButton>
)}
</LaunchButton>
</Tooltip>
)}
{!readOnly && (
<>
<Tooltip content={i18n._(t`Delete All Nodes`)} position="bottom">
<Tooltip content={i18n._(t`Delete all nodes`)} position="bottom">
<ActionButton
id="visualizer-delete-all"
aria-label={i18n._(t`Delete all nodes`)}