Skip to content

Commit

Permalink
Merge pull request #187 from Arnei/add-datetimelocal-field
Browse files Browse the repository at this point in the history
Add datetime-local field to workflow config
  • Loading branch information
Arnei authored Jul 24, 2023
2 parents 17bdd40 + 63c17b4 commit 3a7ea47
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 93 deletions.
143 changes: 59 additions & 84 deletions app/src/components/events/partials/wizards/RenderWorkflowConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,73 +84,31 @@ const renderInputByType = (field, key, formik) => {
return <RenderNumber field={field} key={key} formik={formik} />;
case "text":
return <RenderText field={field} key={key} formik={formik} />;
case "datetime-local":
return <RenderDatetimeLocal field={field} key={key} formik={formik} />;
default:
return "";
}
};

const RenderDatetimeLocal = ({ field, key, formik }) => {
field.value = undefined;

return <RenderField field={field} key={key} formik={formik} />;
};

const RenderCheckbox = ({ field, key, formik }) => {
// id used for Field and label
const uuid = uuidv4();
const disabled = !!field.disabled ? field.disabled : false;
field.defaultValue = field.value;
field.value = undefined;

return (
<li key={key}>
<Field
id={uuid}
className="configField"
name={"configuration." + field.name}
defaultValue={field.value}
disabled={disabled}
type={field.type}
/>
<label htmlFor={uuid}>{field.label}</label>
{/* if input has an additional fieldset or further configuration inputs
then render again by input type*/}
{!!field.fieldset && !!formik.values.configuration[field.name] && (
<ul className="workflow-configuration-subpanel">
{field.fieldset?.map((f, keys) => renderInputByType(f, keys, formik))}
</ul>
)}
</li>
);
return <RenderField field={field} key={key} formik={formik} />;
};

const RenderRadio = ({ field, key, formik }) => {
// id used for Field and label
const uuid = uuidv4();
const disabled = !!field.disabled ? field.disabled : false;

return (
<li key={key}>
<Field
id={uuid}
className="configField"
name={"configuration." + field.name}
value={field.value}
disabled={disabled}
type={field.type}
/>
<label htmlFor={uuid}>{field.label}</label>
{/* if input has an additional fieldset or further configuration inputs
then render again by input type*/}
{!!field.fieldset &&
formik.values.configuration[field.name] === field.value && (
<ul className="workflow-configuration-subpanel">
{field.fieldset?.map((f, keys) =>
renderInputByType(f, keys, formik)
)}
</ul>
)}
</li>
);
return <RenderField field={field} key={key} formik={formik} />;
};

const RenderNumber = ({ field, key, formik }) => {
// id used for Field and label
const uuid = uuidv4();
const disabled = !!field.disabled ? field.disabled : false;

// validate that value of number is between max and min
const validate = (value) => {
let error;
Expand All @@ -160,44 +118,61 @@ const RenderNumber = ({ field, key, formik }) => {
return error;
};

return (
<li key={key}>
<Field
id={uuid}
validate={validate}
className="configField"
name={"configuration." + field.name}
disabled={disabled}
type={field.type}
min={field.min}
max={field.max}
/>
<label htmlFor={uuid}>{field.label}</label>
{/* if input has an additional fieldset or further configuration inputs
then render again by input type*/}
{!!field.fieldset && !!formik.values.configuration[field.name] && (
<ul className="workflow-configuration-subpanel">
{field.fieldset?.map((f, keys) => renderInputByType(f, keys, formik))}
</ul>
)}
</li>
);
field.defaultValue = field.value;
field.value = undefined;

return <RenderField field={field} key={key} formik={formik} validate={validate}/>;
};

const RenderText = ({ field, key, formik }) => {
field.value = undefined;

return <RenderField field={field} key={key} formik={formik} />;
};

const RenderField = ({field, key, formik, validate = undefined }) => {
// id used for Field and label
const uuid = uuidv4();
const disabled = !!field.disabled ? field.disabled : false;

// Only set value to *anything* if there is actually a value to be had
// Otherwise it empties the displayed value when switching between tabs
const renderField = () => {
if (field.value) {
return(
<Field
id={uuid}
defaultValue={field.defaultValue}
value={field.value}
validate={validate}
className="configField"
name={"configuration." + field.name}
disabled={disabled}
type={field.type}
min={field.min}
max={field.max}
/>
)
} else {
return(
<Field
id={uuid}
defaultValue={field.defaultValue}
validate={validate}
className="configField"
name={"configuration." + field.name}
disabled={disabled}
type={field.type}
min={field.min}
max={field.max}
/>
)
}
}

return (
<li key={key}>
<Field
id={uuid}
className="configField"
name={"configuration." + field.name}
disabled={disabled}
type={field.type}
/>
{renderField()}
<label htmlFor={uuid}>{field.label}</label>
{/* if input has an additional fieldset or further configuration inputs
then render again by input type*/}
Expand All @@ -208,7 +183,7 @@ const RenderText = ({ field, key, formik }) => {
)}
</li>
);
};
}

// Getting state data out of redux store
const mapStateToProps = () => {
Expand Down
23 changes: 14 additions & 9 deletions app/src/utils/workflowPanelUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ export const setDefaultConfig = (workflowDefinitions, workflowId) => {
const fillDefaultConfig = (fieldset, defaultConfiguration) => {
// iteration through each input field
fieldset.forEach((field) => {
// set value in default configuration
if (field.type !== "radio") {
defaultConfiguration[field.name] = field.value;
} else {
// set only the checked input of radio button as default value
if (field.type === "radio" && field.checked) {
defaultConfiguration[field.name] = field.value;
}
}

// set only the checked input of radio button as default value
if (field.type === "radio" && field.checked) {
defaultConfiguration[field.name] = field.value;
}
else if (field.type === "datetime-local") {
const date = new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('.')[0];
defaultConfiguration[field.name] = date;
field.defaultValue = date;
}
// set value in default configuration
else {
defaultConfiguration[field.name] = field.value;
}

// if an input has further configuration then go through fillDefaultConfig again
if (field.fieldset) {
Expand Down

0 comments on commit 3a7ea47

Please sign in to comment.