Skip to content

Commit

Permalink
Add target path for every file input
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc committed Sep 12, 2023
1 parent e917ee9 commit e666585
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 20 deletions.
63 changes: 43 additions & 20 deletions client/src/components/Applications/AppForm/AppForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import { Link } from 'react-router-dom';
import { getSystemName } from 'utils/systems';
import FormSchema from './AppFormSchema';
import {
isTargetPathField,
getInputFieldFromTargetPathField,
getQueueMaxMinutes,
getMaxMinutesValidation,
getNodeCountValidation,
getCoresPerNodeValidation,
getTargetPathFieldName,
updateValuesForQueue,
} from './AppFormUtils';
import DataFilesSelectModal from '../../DataFiles/DataFilesModals/DataFilesSelectModal';
Expand Down Expand Up @@ -459,17 +462,30 @@ export const AppSchemaForm = ({ app }) => {
onSubmit={(values, { setSubmitting, resetForm }) => {
const job = cloneDeep(values);

job.fileInputs = Object.entries(job.fileInputs)
.map(([k, v]) => {
return {
name: k,
sourceUrl: v,
targetPath: app.definition.jobAttributes.fileInputs.find(
(file) => file.name === k
).targetPath,
};
})
.filter((fileInput) => fileInput.sourceUrl); // filter out any empty values
// Tranform input field values into format that jobs service wants
job.fileInputs = Object.values(
Object.entries(job.fileInputs)
.map(([k, v]) => {
return {
name: k,
sourceUrl: !isTargetPathField(k) ? v : null,
targetDir: isTargetPathField(k) ? v : null,
};
})
.filter((fileInput) => fileInput.sourceUrl || fileInput.targetDir) // filter out any empty values
.reduce((acc, entry) => { // merge input field and targetPath fields into one.
const key = getInputFieldFromTargetPathField(entry.name);
if (!acc[key]) {
acc[key] = {};
}
acc[key]['name'] = key;
acc[key]['sourceUrl'] =
acc[key]['sourceUrl'] ?? entry.sourceUrl;
acc[key]['targetPath'] =
acc[key]['targetPath'] ?? entry.targetDir;
return acc;
}, {})
).flat();

job.parameterSet = Object.assign(
{},
Expand Down Expand Up @@ -550,16 +566,23 @@ export const AppSchemaForm = ({ app }) => {
</div>
{Object.entries(appFields.fileInputs).map(
([name, field]) => {
// TODOv3 handle fileInputArrays https://jira.tacc.utexas.edu/browse/TV3-81
// TODOv3 handle fileInputArrays https://jira.tacc.utexas.edu/browse/WP-81
return (
<FormField
{...field}
name={`fileInputs.${name}`}
tapisFile
SelectModal={DataFilesSelectModal}
placeholder="Browse Data Files"
key={`fileInputs.${name}`}
/>
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
26 changes: 26 additions & 0 deletions client/src/components/Applications/AppForm/AppFormSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import * as Yup from 'yup';
import {
getTargetPathFieldName
} from './AppFormUtils';

const FormSchema = (app) => {
const appFields = {
Expand Down Expand Up @@ -131,6 +134,29 @@ 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();
appFields.schema.fileInputs[targetPathName] = appFields.schema.fileInputs[
targetPathName
].matches(
/^tapis:\/\//g,
"Input file Target Directory must be a valid Tapis URI, starting with 'tapis://'"
);

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.',
required: false,
readOnly: false,
type: 'text'
};
appFields.defaults.fileInputs[targetPathName] =
input.targetPath === null || typeof input.targetPath === 'undefined'
? '*'
: input.targetPath;
});
return appFields;
};
Expand Down
35 changes: 35 additions & 0 deletions client/src/components/Applications/AppForm/AppFormUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as Yup from 'yup';
import { getSystemName } from 'utils/systems';

export const TARGET_PATH_FIELD_PREFIX = '_TargetPath_';

export const getQueueMaxMinutes = (app, queueName) => {
return app.exec_sys.batchLogicalQueues.find((q) => q.name === queueName)
.maxMinutes;
Expand Down Expand Up @@ -165,3 +167,36 @@ export const updateValuesForQueue = (app, values) => {

return updatedValues;
};

/**
* Get the field name used for target path in AppForm
*
* @function
* @param {String} inputFieldName
* @returns {String} field Name prefixed with target path
*/
export const getTargetPathFieldName = (inputFieldName) => {
return TARGET_PATH_FIELD_PREFIX + inputFieldName;
};

/**
* Whether a field name is a system defined field for Target Path
*
* @function
* @param {String} inputFieldName
* @returns {String} field Name suffixed with target path
*/
export const isTargetPathField = (inputFieldName) => {
return inputFieldName && inputFieldName.startsWith(TARGET_PATH_FIELD_PREFIX);
};

/**
* From target path field name, derive the original input field name.
*
* @function
* @param {String} targetPathFieldName
* @returns {String} actual field name
*/
export const getInputFieldFromTargetPathField = (targetPathFieldName) => {
return targetPathFieldName.replace(TARGET_PATH_FIELD_PREFIX,'');
};

0 comments on commit e666585

Please sign in to comment.