Skip empty attributes (#1968)
This commit is contained in:
parent
74662a11ac
commit
2de4acb4a8
1 changed files with 47 additions and 60 deletions
|
@ -195,20 +195,6 @@ function getFileInput(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReferenceInput(attribute: AttributeInput) {
|
|
||||||
return {
|
|
||||||
id: attribute.id,
|
|
||||||
references: attribute.value
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRichTextInput(attribute: AttributeInput) {
|
|
||||||
return {
|
|
||||||
id: attribute.id,
|
|
||||||
richText: attribute.value[0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBooleanInput(attribute: AttributeInput) {
|
function getBooleanInput(attribute: AttributeInput) {
|
||||||
return {
|
return {
|
||||||
id: attribute.id,
|
id: attribute.id,
|
||||||
|
@ -216,57 +202,58 @@ function getBooleanInput(attribute: AttributeInput) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDateInput(attribute: AttributeInput) {
|
|
||||||
return {
|
|
||||||
id: attribute.id,
|
|
||||||
date: attribute.value[0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDateTimeInput(attribute: AttributeInput) {
|
|
||||||
return {
|
|
||||||
id: attribute.id,
|
|
||||||
dateTime: attribute.value[0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDefaultInput(attribute: AttributeInput) {
|
|
||||||
return {
|
|
||||||
id: attribute.id,
|
|
||||||
values: ["", undefined, null].includes(attribute.value[0])
|
|
||||||
? []
|
|
||||||
: attribute.value
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const prepareAttributesInput = ({
|
export const prepareAttributesInput = ({
|
||||||
attributes,
|
attributes,
|
||||||
updatedFileAttributes
|
updatedFileAttributes
|
||||||
}: AttributesArgs): AttributeValueInput[] =>
|
}: AttributesArgs): AttributeValueInput[] =>
|
||||||
attributes.map(attribute => {
|
attributes.reduce((attrInput, attr) => {
|
||||||
switch (attribute.data.inputType) {
|
const inputType = attr.data.inputType;
|
||||||
case AttributeInputTypeEnum.FILE:
|
if (inputType === AttributeInputTypeEnum.FILE) {
|
||||||
return getFileInput(attribute, updatedFileAttributes);
|
const fileInput = getFileInput(attr, updatedFileAttributes);
|
||||||
|
if (fileInput.file) {
|
||||||
case AttributeInputTypeEnum.REFERENCE:
|
attrInput.push(fileInput);
|
||||||
return getReferenceInput(attribute);
|
|
||||||
|
|
||||||
case AttributeInputTypeEnum.RICH_TEXT:
|
|
||||||
return getRichTextInput(attribute);
|
|
||||||
|
|
||||||
case AttributeInputTypeEnum.BOOLEAN:
|
|
||||||
return getBooleanInput(attribute);
|
|
||||||
|
|
||||||
case AttributeInputTypeEnum.DATE:
|
|
||||||
return getDateInput(attribute);
|
|
||||||
|
|
||||||
case AttributeInputTypeEnum.DATE_TIME:
|
|
||||||
return getDateTimeInput(attribute);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return getDefaultInput(attribute);
|
|
||||||
}
|
}
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
if (inputType === AttributeInputTypeEnum.BOOLEAN) {
|
||||||
|
const booleanInput = getBooleanInput(attr);
|
||||||
|
attrInput.push(booleanInput);
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
// for cases other than rich text and boolean
|
||||||
|
// we can skip attribute
|
||||||
|
if (!attr.value[0]) {
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
if (inputType === AttributeInputTypeEnum.REFERENCE) {
|
||||||
|
attrInput.push({
|
||||||
|
id: attr.id,
|
||||||
|
references: attr.value
|
||||||
});
|
});
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
if (inputType === AttributeInputTypeEnum.DATE) {
|
||||||
|
attrInput.push({
|
||||||
|
id: attr.id,
|
||||||
|
date: attr.value[0]
|
||||||
|
});
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
if (inputType === AttributeInputTypeEnum.DATE_TIME) {
|
||||||
|
attrInput.push({
|
||||||
|
id: attr.id,
|
||||||
|
dateTime: attr.value[0]
|
||||||
|
});
|
||||||
|
return attrInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrInput.push({
|
||||||
|
id: attr.id,
|
||||||
|
values: attr.value
|
||||||
|
});
|
||||||
|
|
||||||
|
return attrInput;
|
||||||
|
}, []);
|
||||||
|
|
||||||
export const handleUploadMultipleFiles = async (
|
export const handleUploadMultipleFiles = async (
|
||||||
attributesWithNewFileValue: FormsetData<null, File>,
|
attributesWithNewFileValue: FormsetData<null, File>,
|
||||||
|
|
Loading…
Reference in a new issue