Fix empty field handling
This commit is contained in:
parent
0383950c8e
commit
a7fb22e3b7
@ -23,6 +23,7 @@ const ENABLE_REVIEW = true;
|
||||
|
||||
// Import the styles
|
||||
import '@react-pdf-viewer/core/lib/styles/index.css';
|
||||
import { normalizeData } from 'utils/field-value-process';
|
||||
|
||||
|
||||
const siderStyle: React.CSSProperties = {
|
||||
@ -355,6 +356,7 @@ const InferencePage = () => {
|
||||
setDataSource(newData);
|
||||
const newRevisedData = {};
|
||||
for (let i = 0; i < newData.length; i++) {
|
||||
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
|
||||
newRevisedData[newData[i].key] = newData[i].revised;
|
||||
}
|
||||
updateRevisedData(newRevisedData).then(() => {
|
||||
@ -370,30 +372,7 @@ const InferencePage = () => {
|
||||
const newData = [...dataSource];
|
||||
const newRevisedData = {};
|
||||
for (let i = 0; i < newData.length; i++) {
|
||||
if (newData[i].revised === "<empty>") {
|
||||
newData[i].revised = null;
|
||||
}
|
||||
if (typeof(newData[i].revised) === "string") {
|
||||
newData[i].revised = newData[i].revised.trim();
|
||||
}
|
||||
if (newData[i].revised === "" || newData[i].revised === null || newData[i].revised === undefined) {
|
||||
newData[i].revised = null;
|
||||
}
|
||||
if ((newData[i].key === "imei_number" || newData[i].key === "purchase_date") && typeof(newData[i].revised) === "string") {
|
||||
// Convert to list
|
||||
newData[i].revised = new Array(newData[i].revised.split(","));
|
||||
}
|
||||
if (Array.isArray(newData[i].revised)) {
|
||||
// Trim all empty strings
|
||||
for (let j = 0; j < newData[i].revised.length; j++) {
|
||||
if (typeof(newData[i].revised[j]) === "string") {
|
||||
newData[i].revised[j] = newData[i].revised[j].trim();
|
||||
}
|
||||
if (newData[i].revised[j] === "<empty>") {
|
||||
newData[i].revised[j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
|
||||
newRevisedData[newData[i].key] = newData[i].revised;
|
||||
}
|
||||
updateRevisedData(newRevisedData).then(() => {
|
||||
|
@ -21,6 +21,8 @@ import { Viewer } from '@react-pdf-viewer/core';
|
||||
// Import the styles
|
||||
import '@react-pdf-viewer/core/lib/styles/index.css';
|
||||
|
||||
import { normalizeData } from 'utils/field-value-process';
|
||||
|
||||
|
||||
const siderStyle: React.CSSProperties = {
|
||||
backgroundColor: '#fafafa',
|
||||
@ -415,6 +417,7 @@ const ReviewPage = () => {
|
||||
setDataSource(newData);
|
||||
const newRevisedData = {};
|
||||
for (let i = 0; i < newData.length; i++) {
|
||||
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
|
||||
newRevisedData[newData[i].key] = newData[i].revised;
|
||||
}
|
||||
updateRevisedData(newRevisedData).then(() => {
|
||||
@ -430,30 +433,7 @@ const ReviewPage = () => {
|
||||
const newData = [...dataSource];
|
||||
const newRevisedData = {};
|
||||
for (let i = 0; i < newData.length; i++) {
|
||||
if (newData[i].revised === "<empty>") {
|
||||
newData[i].revised = null;
|
||||
}
|
||||
if (typeof(newData[i].revised) === "string") {
|
||||
newData[i].revised = newData[i].revised.trim();
|
||||
}
|
||||
if (newData[i].revised === "" || newData[i].revised === null || newData[i].revised === undefined) {
|
||||
newData[i].revised = null;
|
||||
}
|
||||
if ((newData[i].key === "imei_number" || newData[i].key === "purchase_date") && typeof(newData[i].revised) === "string") {
|
||||
// Convert to list
|
||||
newData[i].revised = new Array(newData[i].revised.split(","));
|
||||
}
|
||||
if (Array.isArray(newData[i].revised)) {
|
||||
// Trim all empty strings
|
||||
for (let j = 0; j < newData[i].revised.length; j++) {
|
||||
if (typeof(newData[i].revised[j]) === "string") {
|
||||
newData[i].revised[j] = newData[i].revised[j].trim();
|
||||
}
|
||||
if (newData[i].revised[j] === "<empty>") {
|
||||
newData[i].revised[j] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
|
||||
newRevisedData[newData[i].key] = newData[i].revised;
|
||||
}
|
||||
updateRevisedData(newRevisedData).then(() => {
|
||||
|
32
cope2n-fe/src/utils/field-value-process.ts
Normal file
32
cope2n-fe/src/utils/field-value-process.ts
Normal file
@ -0,0 +1,32 @@
|
||||
const isAllSpaces = (text) => {
|
||||
if (typeof (text) != "string") {
|
||||
return false;
|
||||
}
|
||||
return text.trim().length === 0 || text === "<empty>";
|
||||
};
|
||||
|
||||
const normalizeData = (key, value) => {
|
||||
if (value === "<empty>") {
|
||||
value = null;
|
||||
}
|
||||
if (typeof (value) === "string") {
|
||||
value = value.trim();
|
||||
}
|
||||
if (value === "" || value === null || value === undefined) {
|
||||
value = null;
|
||||
}
|
||||
if (isAllSpaces(value)) {
|
||||
value = null;
|
||||
}
|
||||
if (["imei_number", "purchase_date"].includes(key) && typeof (value) === "string") {
|
||||
value = value.split(",")
|
||||
}
|
||||
if (typeof (value) === "object" && value?.length > 0) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
value[i] = normalizeData("text", value[i]);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export { normalizeData };
|
Loading…
Reference in New Issue
Block a user