Skip to content

Commit

Permalink
Handle empty targetPath input and linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc committed Sep 13, 2023
1 parent e666585 commit 1043498
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
41 changes: 22 additions & 19 deletions client/src/components/Applications/AppForm/AppForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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] = {};
Expand Down Expand Up @@ -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)?
<FormField
{...field}
name={`fileInputs.${name}`}
placeholder="Target Path Name"
key={`fileInputs.${name}`}
/>:
<FormField
{...field}
name={`fileInputs.${name}`}
tapisFile
SelectModal={DataFilesSelectModal}
placeholder="Browse Data Files"
key={`fileInputs.${name}`}
/>
return isTargetPathField(name) ? (
<FormField
{...field}
name={`fileInputs.${name}`}
placeholder="Target Path Name"
key={`fileInputs.${name}`}
/>
) : (
<FormField
{...field}
name={`fileInputs.${name}`}
tapisFile
SelectModal={DataFilesSelectModal}
placeholder="Browse Data Files"
key={`fileInputs.${name}`}
/>
);
}
)}
Expand Down
14 changes: 7 additions & 7 deletions client/src/components/Applications/AppForm/AppFormSchema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Yup from 'yup';
import {
getTargetPathFieldName
checkAndSetDefaultTargetPath,
getTargetPathFieldName,
} from './AppFormUtils';

const FormSchema = (app) => {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
};
Expand Down
25 changes: 23 additions & 2 deletions client/src/components/Applications/AppForm/AppFormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 1043498

Please sign in to comment.