Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrich committed Mar 13, 2024
1 parent 05c69ff commit c351126
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/ui/demo/src/examples/ExcelTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function SimpleTable(p) {
aa: 42,
cc: 89
},
...map(new Array(100), () => {
...map(new Array(40), () => {
return {
a: "=sum(B:B)",
b: 12,
Expand Down
43 changes: 14 additions & 29 deletions packages/ui/src/DataTable/editCellHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _, { isString, set, toNumber } from "lodash";
import { isString, set, toNumber } from "lodash";
import { defaultValidators } from "./defaultValidators";
import { defaultFormatters } from "./defaultFormatters";
import { evaluate } from "mathjs";
Expand Down Expand Up @@ -56,9 +56,7 @@ export const editCellHelper = ({
const cellId = `${getIdOrCodeOrIndex(entity)}:${colSchema.path}`;
const oldVal = entity[path];
const { format, validate, type } = colSchema;
let errors = {
__hasErrors: false
};
let errors = {};
if (nv === undefined && colSchema.defaultValue !== undefined) {
nv = colSchema.defaultValue;
}
Expand Down Expand Up @@ -128,7 +126,10 @@ export const editCellHelper = ({
entities,
nestLevel: nestLevel + 1
});
errors = mergeErrors(errors, _errors);
errors = {
...errors,
..._errors
};
val = value?.formula ? value.value : value;
} else if (!isNaN(toNumber(val))) {
return val;
Expand Down Expand Up @@ -156,7 +157,6 @@ export const editCellHelper = ({
error: e.message
};
errors[cellId] = e.message;
errors.__hasErrors = true;
}
hasFormula = nv;
nv = nv.value;
Expand All @@ -170,9 +170,6 @@ export const editCellHelper = ({
}
if (validate && !hasErrors(errors)) {
const error = validate(nv, colSchema, entity);
if (error) {
errors.__hasErrors = true;
}
errors[cellId] = error;
}
if (!hasErrors(errors)) {
Expand All @@ -182,9 +179,6 @@ export const editCellHelper = ({
(type === undefined && defaultValidators.string);
if (validator) {
const error = validator(nv, colSchema);
if (error) {
errors.__hasErrors = true;
}
errors[cellId] = error;
}
}
Expand Down Expand Up @@ -233,15 +227,18 @@ export const editCellHelper = ({
depLevel: depLevel + 1,
nestLevel: nestLevel
});
errors = mergeErrors(errors, _errors);
errors = {
...errors,
..._errors
};
});
}
}
updateGroup[cellAlphaNum] = value?.formula ? value.value : value;
if (!hasErrors(errors)) {
errors[cellId] = undefined;
delete errors[cellId];
}
return { entity, errors, value };
return { entity, errors: errors, value };
};

function getCellAlphaNum({ entities, entity, colSchema, schema }) {
Expand All @@ -256,7 +253,7 @@ export function getCellAlphaNumHelper(colIndex, rowIndex) {
}

const hasErrors = errors => {
return errors.__hasErrors;
return !!Object.values(errors)[0];
};

export const getColLetFromIndex = index => {
Expand Down Expand Up @@ -285,6 +282,7 @@ export const replaceFormulaRanges = ({ formula, schema, entities }) => {
.toLowerCase()
.replace(/([A-Z]*[0-9]*:[A-Z]*[0-9]*)/gi, _match => {
// if (_match.includes(":")) {
// console.log(`_match:`, _match);
// }
const match = _match.toUpperCase();
const [start, end] = match.split(":");
Expand Down Expand Up @@ -324,16 +322,3 @@ export const replaceFormulaRanges = ({ formula, schema, entities }) => {
error
};
};

function mergeErrors(errors, _errors) {
let hasErrors = false;
if (_errors.__hasErrors || errors.__hasErrors) {
hasErrors = true;
}
errors = {
...errors,
..._errors,
__hasErrors: hasErrors
};
return errors;
}

0 comments on commit c351126

Please sign in to comment.