Skip to content

Commit

Permalink
Merge pull request #136 from uselagoon/task-default-values
Browse files Browse the repository at this point in the history
feat: default task variables values
  • Loading branch information
DaveDarsa authored Sep 3, 2023
2 parents 1fc1b5b + 68b4b32 commit 72d959a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/components/AddTask/components/InvokeRegisteredTask.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect} from 'react';
import { Mutation } from 'react-apollo';
import ReactSelect from 'react-select';

Expand Down Expand Up @@ -44,13 +44,26 @@ const InvokeRegisteredTask = ({
isConfirmOpen,
setIsConfirmOpen,
}) => {
useEffect(() => {
let defaultArgValues = {};
selectedTask.arguments.forEach(item => {
if (item.defaultValue) {
defaultArgValues[item.name] = item.defaultValue;
}
});
setAdvancedTaskArguments(defaultArgValues)
}, []);

let taskArgumentsExist = false;
let argumentVariablesHaveValues = true;

if (selectedTask.arguments) {
taskArgumentsExist = true;
argumentVariablesHaveValues = selectedTask.arguments.reduce((p, c) => {
let hasArg = advancedTaskArguments[c['name']];
if (!advancedTaskArguments[c['optional']]) {
hasArg = !advancedTaskArguments[c['optional']];
}
return hasArg && p;
}, true);
}
Expand Down Expand Up @@ -91,8 +104,8 @@ const InvokeRegisteredTask = ({
<div key={`env-text-${index}`} className="envSelect">
<label id="source-env">{d.displayName || d.name} :</label>
<ReactSelect
aria-labelledby="{d.name}"
name="{d.name}"
aria-labelledby={d.name}
name={d.name}
placeholder="Select environment..."
value={{
label: R.prop(d.name, advancedTaskArguments),
Expand All @@ -116,8 +129,8 @@ const InvokeRegisteredTask = ({
<label id="source-env">{d.displayName || d.name} :</label>
<input
type="text"
name="{d.name}"
value={R.prop(d.name, advancedTaskArguments)}
name={d.name}
value={advancedTaskArguments[d.name] }
onChange={event => {
setAdvancedTaskArguments({
...advancedTaskArguments,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/query/EnvironmentWithTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default gql`
displayName
type
range
defaultValue
optional
}
}
... on AdvancedTaskDefinitionImage {
Expand All @@ -51,6 +53,8 @@ export default gql`
displayName
type
range
defaultValue
optional
}
}
}
Expand Down

0 comments on commit 72d959a

Please sign in to comment.