diff --git a/client/src/components/Applications/AppForm/AppForm.jsx b/client/src/components/Applications/AppForm/AppForm.jsx index 17b794dbf..650307735 100644 --- a/client/src/components/Applications/AppForm/AppForm.jsx +++ b/client/src/components/Applications/AppForm/AppForm.jsx @@ -19,13 +19,13 @@ import { Link } from 'react-router-dom'; import { getSystemName } from 'utils/systems'; import FormSchema from './AppFormSchema'; import { + checkAndSetDefaultTargetPath, isTargetPathField, getInputFieldFromTargetPathField, getQueueMaxMinutes, getMaxMinutesValidation, getNodeCountValidation, getCoresPerNodeValidation, - getTargetPathFieldName, updateValuesForQueue, } from './AppFormUtils'; import DataFilesSelectModal from '../../DataFiles/DataFilesModals/DataFilesSelectModal'; @@ -469,11 +469,14 @@ export const AppSchemaForm = ({ app }) => { return { name: k, sourceUrl: !isTargetPathField(k) ? v : null, - targetDir: isTargetPathField(k) ? v : null, + targetDir: isTargetPathField(k) + ? checkAndSetDefaultTargetPath(v) + : null, }; }) .filter((fileInput) => fileInput.sourceUrl || fileInput.targetDir) // filter out any empty values - .reduce((acc, entry) => { // merge input field and targetPath fields into one. + .reduce((acc, entry) => { + // merge input field and targetPath fields into one. const key = getInputFieldFromTargetPathField(entry.name); if (!acc[key]) { acc[key] = {}; @@ -567,22 +570,22 @@ export const AppSchemaForm = ({ app }) => { {Object.entries(appFields.fileInputs).map( ([name, field]) => { // TODOv3 handle fileInputArrays https://jira.tacc.utexas.edu/browse/WP-81 - return ( - isTargetPathField(name)? - : - + return isTargetPathField(name) ? ( + + ) : ( + ); } )} diff --git a/client/src/components/Applications/AppForm/AppFormSchema.js b/client/src/components/Applications/AppForm/AppFormSchema.js index 310b61c4a..a2e9c53b2 100644 --- a/client/src/components/Applications/AppForm/AppFormSchema.js +++ b/client/src/components/Applications/AppForm/AppFormSchema.js @@ -1,6 +1,7 @@ import * as Yup from 'yup'; import { - getTargetPathFieldName + checkAndSetDefaultTargetPath, + getTargetPathFieldName, } from './AppFormUtils'; const FormSchema = (app) => { @@ -134,7 +135,7 @@ const FormSchema = (app) => { input.sourceUrl === null || typeof input.sourceUrl === 'undefined' ? '' : input.sourceUrl; - + // Add targetDir for all sourceUrl const targetPathName = getTargetPathFieldName(input.name); appFields.schema.fileInputs[targetPathName] = Yup.string(); @@ -148,15 +149,14 @@ const FormSchema = (app) => { appFields.schema.fileInputs[targetPathName] = false; appFields.fileInputs[targetPathName] = { label: 'Target Path for ' + input.name, - description: 'The target path is the location to which data are copied from the input. Empty target path or \'*\' indicates, the simple directory or file name from the input path is automatically assign to the target path.', + description: + "The target path is the location to which data are copied from the input. Empty target path or '*' indicates, the simple directory or file name from the input path is automatically assign to the target path.", required: false, readOnly: false, - type: 'text' + type: 'text', }; appFields.defaults.fileInputs[targetPathName] = - input.targetPath === null || typeof input.targetPath === 'undefined' - ? '*' - : input.targetPath; + checkAndSetDefaultTargetPath(input.targetPath); }); return appFields; }; diff --git a/client/src/components/Applications/AppForm/AppFormUtils.js b/client/src/components/Applications/AppForm/AppFormUtils.js index b0469348d..1b5b30c7e 100644 --- a/client/src/components/Applications/AppForm/AppFormUtils.js +++ b/client/src/components/Applications/AppForm/AppFormUtils.js @@ -195,8 +195,29 @@ export const isTargetPathField = (inputFieldName) => { * * @function * @param {String} targetPathFieldName - * @returns {String} actual field name + * @returns {String} actual field name */ export const getInputFieldFromTargetPathField = (targetPathFieldName) => { - return targetPathFieldName.replace(TARGET_PATH_FIELD_PREFIX,''); + return targetPathFieldName.replace(TARGET_PATH_FIELD_PREFIX, ''); +}; + +/** + * Sets the default value if target path is not set. + * + * @function + * @param {String} targetPathFieldValue + * @returns {String} target path value + */ +export const checkAndSetDefaultTargetPath = (targetPathFieldValue) => { + if (targetPathFieldValue === null || targetPathFieldValue === undefined) { + return '*'; + } + + targetPathFieldValue = targetPathFieldValue.trim(); + + if (targetPathFieldValue.trim() === '') { + return '*'; + } + + return targetPathFieldValue; };