Skip to content

Commit

Permalink
[frontend] Allow update inject without mandatory fields (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 authored Oct 23, 2024
1 parent 00d051a commit 778a7ee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,6 @@ const CreateInjectDetails = ({
};
const validate = (values) => {
const errors = {};
if (openDetails && contractContent && Array.isArray(contractContent.fields)) {
contractContent.fields
.filter(
(f) => !['teams', 'assets', 'assetgroups', 'articles', 'challenges', 'attachments', 'expectations'].includes(
f.key,
),
)
.forEach((field) => {
const value = values[field.key];
if (field.mandatory && (value === undefined || R.isEmpty(value))) {
errors[field.key] = t('This field is required.');
}
if (field.mandatoryGroups) {
const { mandatoryGroups } = field;
const conditionOk = mandatoryGroups?.some((mandatoryKey) => {
const v = values[mandatoryKey];
return v !== undefined && !R.isEmpty(v);
});
// If condition are not filled
if (!conditionOk) {
const labels = mandatoryGroups.map((key) => contractContent.fields.find((f) => f.key === key).label).join(', ');
errors[field.key] = t(`One of this field is required : ${labels}.`);
}
}
});
}
const requiredFields = [
'inject_title',
'inject_depends_duration_days',
Expand Down Expand Up @@ -176,15 +150,9 @@ const CreateInjectDetails = ({
&& data[field.key]
&& data[field.key].length > 0
) {
const regex = /<#list\s+(\w+)\s+as\s+(\w+)>/g;
finalData[field.key] = data[field.key]
.replaceAll(
'<#list challenges as challenge>',
'<#list challenges as challenge>',
)
.replaceAll(
'&lt;#list articles as article&gt;',
'<#list articles as article>',
)
.replace(regex, (_, listName, identifier) => `<#list ${listName} as ${identifier}>`)
.replaceAll('&lt;/#list&gt;', '</#list>');
} else if (data[field.key] && field.type === 'tuple') {
if (field.cardinality && field.cardinality === '1') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,7 @@ const UpdateInjectDetails = ({
};
const validate = (values) => {
const errors = {};
if (openDetails && contractContent && Array.isArray(contractContent.fields)) {
contractContent.fields
.filter(
(f) => !['teams', 'assets', 'assetgroups', 'articles', 'challenges', 'attachments', 'expectations'].includes(
f.key,
),
)
.forEach((field) => {
const value = values[field.key];
if (field.mandatory && (value === undefined || R.isEmpty(value))) {
errors[field.key] = t('This field is required.');
}
if (field.mandatoryGroups) {
const { mandatoryGroups } = field;
const conditionOk = mandatoryGroups?.some((mandatoryKey) => {
const v = values[mandatoryKey];
return v !== undefined && !R.isEmpty(v);
});
// If condition are not filled
if (!conditionOk) {
const labels = mandatoryGroups.map((key) => contractContent.fields.find((f) => f.key === key).label).join(', ');
errors[field.key] = t(`One of this field is required : ${labels}.`);
}
}
});
}

const requiredFields = [
'inject_title',
'inject_depends_duration_days',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static boolean isReady(
if (assets.isEmpty() && assetGroups.isEmpty()) {
ready.set(false);
}
} else if (jsonField.get("type").asText().equals("text") && content.get(key) == null) {
} else if ((jsonField.get("type").asText().equals("text") || jsonField.get("type").asText().equals("textarea")) && content.get(key) == null) {
ready.set(false);
} else if (jsonField.get("type").asText().equals("text") && content.get(key).asText().isEmpty()) {
} else if ((jsonField.get("type").asText().equals("text") || jsonField.get("type").asText().equals("textarea")) && content.get(key).asText().isEmpty()) {
ready.set(false);
}
});
Expand Down

0 comments on commit 778a7ee

Please sign in to comment.