Skip to content

Commit

Permalink
Fix [Batch run] Show function's inputs on re-run and mark mandatory i…
Browse files Browse the repository at this point in the history
…tems
  • Loading branch information
mavdryk committed Oct 5, 2023
1 parent 7089025 commit 483d626
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 58 deletions.
122 changes: 79 additions & 43 deletions src/components/JobWizard/JobWizard.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
isFinite,
isNil,
keyBy,
map,
merge,
omit,
set,
Expand Down Expand Up @@ -277,7 +276,10 @@ export const generateJobWizardDefaultData = (
}

if (!isEmpty(defaultData.task.spec.inputs)) {
jobFormData.dataInputs.dataInputsTable = parseDefaultDataInputs(defaultData.task.spec.inputs)
jobFormData.dataInputs.dataInputsTable = parseDefaultDataInputs(
functionParameters,
defaultData.task.spec.inputs
)
}

return [jobFormData, jobAdditionalData]
Expand Down Expand Up @@ -571,62 +573,93 @@ export const getCategoryName = categoryId => {
return categoriesNames[categoryId] ?? categoryId
}

const getDataInputData = (dataInputName, dataInputValue) => {
return {
name: dataInputName,
path: dataInputValue ?? '',
fieldInfo: {
pathType: dataInputValue?.replace(/:\/\/.*$/g, '://') ?? '',
value: dataInputValue?.replace(/.*:\/\//g, '') ?? ''
}
}
}

const sortParameters = (parameter, nextParameter) => nextParameter.isRequired - parameter.isRequired

export const parseDataInputs = functionParameters => {
return functionParameters
.filter(dataInputs => dataInputs.type?.includes('DataItem'))
.map(input => {
.map(dataInput => {
return {
doc: input.doc,
data: getDataInputData(dataInput.name, dataInput.default),
doc: dataInput.doc,
isRequired: !has(dataInput, 'default'),
isDefault: true,
data: {
name: input.name,
path: input.path ?? '',
fieldInfo: {
pathType: input.path?.replace(/:\/\/.*$/g, '://') ?? '',
value: input.path?.replace(/.*:\/\//g, '') ?? ''
}
}
isPredefined: true
}
})
.sort(sortParameters)
}

export const parseDefaultDataInputs = dataInputs => {
return map(dataInputs, (value, key) => {
export const parseDefaultDataInputs = (funcParams, runDataInputs) => {
const predefinedDataInputs = chain(funcParams)
.filter(dataInput => dataInput.type?.includes('DataItem'))
.map(dataInput => {
const dataInputValue = runDataInputs[dataInput.name] ?? dataInput.default ?? ''

return {
data: getDataInputData(dataInput.name, dataInputValue),
doc: dataInput.doc ?? '',
isRequired: !has(dataInput, 'default'),
isDefault: true,
isPredefined: true
}
})
.sort(sortParameters)
.value()

const customDataInputsNames = difference(Object.keys(runDataInputs), Object.keys(funcParams))

const customDataInputs = customDataInputsNames.map(dataInputName => {
const dataInputValue = runDataInputs[dataInputName] ?? ''

return {
data: getDataInputData(dataInputName, dataInputValue),
isRequired: false,
isDefault: true,
data: {
name: key,
path: value ?? '',
fieldInfo: {
pathType: value?.replace(/:\/\/.*$/g, '://') ?? '',
value: value?.replace(/.*:\/\//g, '') ?? ''
}
}
isPredefined: false
}
})

return predefinedDataInputs.concat(customDataInputs)
}

export const parsePredefinedParameters = funcParams => {
return funcParams
.filter(parameter => !parameter.type?.includes('DataItem'))
.map(parameter => {
const parsedValue = parseParameterValue(parameter.default)

return {
data: {
name: parameter.name ?? '',
type: parameter.type ?? '',
value: parsedValue,
isChecked: !has(parameter, 'default'),
isHyper: false
},
doc: parameter.doc,
isHidden: parameter.name === 'context',
isUnsupportedType: !parameterTypeValueMap[parameter.type],
isDefault: true,
isPredefined: true
}
})
return (
funcParams
.filter(parameter => !parameter.type?.includes('DataItem'))
.map(parameter => {
const parsedValue = parseParameterValue(parameter.default)
const parameterIsRequired = !has(parameter, 'default')

return {
data: {
name: parameter.name ?? '',
type: parameter.type ?? '',
value: parsedValue,
isChecked: parameterIsRequired,
isHyper: false
},
doc: parameter.doc,
isHidden: parameter.name === 'context',
isUnsupportedType: !parameterTypeValueMap[parameter.type],
isRequired: parameterIsRequired,
isDefault: true,
isPredefined: true
}
})
.sort(sortParameters)
)
}

export const parseDefaultParameters = (funcParams = {}, runParams = {}, runHyperParams = {}) => {
Expand All @@ -641,6 +674,7 @@ export const parseDefaultParameters = (funcParams = {}, runParams = {}, runHyper
)
const predefinedParameterIsModified =
parameter.name in runParams || parameter.name in runHyperParams
const parametersIsRequired = !has(parameter, 'default')

return {
data: {
Expand All @@ -652,16 +686,18 @@ export const parseDefaultParameters = (funcParams = {}, runParams = {}, runHyper
)
: parameter.type ?? '',
value: parsedValue,
isChecked: (parsedValue && predefinedParameterIsModified) || !has(parameter, 'default'),
isChecked: (parsedValue && predefinedParameterIsModified) || parametersIsRequired,
isHyper: parameter.name in runHyperParams
},
doc: parameter.doc ?? '',
isHidden: parameter.name === 'context',
isUnsupportedType: !parameterTypeValueMap[parameter.type],
isRequired: parametersIsRequired,
isDefault: true,
isPredefined: true
}
})
.sort(sortParameters)
.value()

const customParametersNames = difference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const FormDataInputsRow = ({
)}
>
<Tooltip template={<TextTooltipTemplate text={fieldData.data.name} />}>
{fieldData.data.name}
{fieldData.data?.name}
{fieldData.isRequired && <span className="asterisk"> *</span>}
</Tooltip>
{fields.value[index].doc && <Tip text={fields.value[index].doc} />}
</div>
Expand All @@ -136,6 +137,7 @@ const FormDataInputsRow = ({
</div>
<FormRowActions
applyChanges={applyChanges}
deleteIsDisabled={fieldData.isRequired}
deleteRow={deleteRow}
discardOrDelete={discardOrDelete}
editingItem={editingItem}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ const FormParametersRow = ({
!disabled ? (
<div className={tableRowClassNames} key={index}>
<div className="form-table__cell form-table__cell_min">
<FormCheckBox
name={`${rowPath}.data.isChecked`}
onClick={event => event.stopPropagation()}
/>
{!fieldData.isRequired && (
<FormCheckBox
name={`${rowPath}.data.isChecked`}
onClick={event => event.stopPropagation()}
/>
)}
</div>
{withHyperparameters && (
<div className="form-table__cell form-table__cell_hyper">
Expand Down Expand Up @@ -346,10 +348,12 @@ const FormParametersRow = ({
}
>
<div className="form-table__cell form-table__cell_min">
<FormCheckBox
name={`${rowPath}.data.isChecked`}
onClick={event => event.stopPropagation()}
/>
{!fieldData.isRequired && (
<FormCheckBox
name={`${rowPath}.data.isChecked`}
onClick={event => event.stopPropagation()}
/>
)}
</div>
{withHyperparameters && (
<div className="form-table__cell form-table__cell_hyper">
Expand All @@ -359,6 +363,7 @@ const FormParametersRow = ({
<div className="form-table__cell form-table__cell_2 form-table__name-cell">
<Tooltip template={<TextTooltipTemplate text={fieldData.data.name} />}>
{fieldData.data.name}
{fieldData.isRequired && <span className="asterisk"> *</span>}
</Tooltip>
{!fieldData.isPredefined && (
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@
.form-table__volume-cell {
width: 33.3%;
}

&.excluded {
.form-table__cell {
color: $spunPearl;
}
}
}
}
4 changes: 4 additions & 0 deletions src/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ iframe {
}
}

.asterisk {
color: $amaranth
}

//TODO: Delete after removing Textarea and Input and using DRC components
@mixin fieldWrapperOld {
position: relative;
Expand Down

0 comments on commit 483d626

Please sign in to comment.