rename validations vars

This commit is contained in:
Chika 2020-11-26 17:23:00 +03:00
parent caabb6a459
commit a1a8b070f4
2 changed files with 18 additions and 18 deletions

View File

@ -269,20 +269,22 @@ const actions: TAction = {
calculate: async () => {
validate();
const { elements, tables } = checkValidation();
if (elements.length > 0 || tables.length > 0) {
if (elements.length > 0)
const { invalidElements, invalidTables } = checkValidation();
if (invalidElements.length > 0 || invalidTables.length > 0) {
if (invalidElements.length > 0)
openNotification({
type: 'error',
title: 'Ошибка во время расчета графика',
description: 'Некорректно заполнены поля: ' + elements.join(', '),
description:
'Некорректно заполнены поля: ' + invalidElements.join(', '),
})();
if (tables.length > 0)
if (invalidTables.length > 0)
openNotification({
type: 'error',
title: 'Ошибка во время расчета графика',
description: 'Некорректно заполнены таблицы: ' + tables.join(', '),
description:
'Некорректно заполнены таблицы: ' + invalidTables.join(', '),
})();
return;
}

View File

@ -4,29 +4,27 @@ import tablesTitles from 'client/constants/Calculation/tablesTitles';
import CalculationStore from 'client/stores/CalculationStore';
export default () => {
let elements: string[] = [];
const { validations } = CalculationStore;
let invalidElements: string[] = [];
const { validations: storeValidations } = CalculationStore;
const validations = toJS(storeValidations);
Object.keys(validations).forEach(elementName => {
if (validations[elementName] === false) {
elements.push(elementsTitles[elementName]);
invalidElements.push(elementsTitles[elementName]);
}
});
let tables: string[] = [];
let invalidTables: string[] = [];
const { tables: storeTables } = CalculationStore;
const jsTables = toJS(storeTables);
Object.keys(jsTables).forEach(tableName => {
const tables = toJS(storeTables);
Object.keys(tables).forEach(tableName => {
if (
jsTables[tableName].rows.some(row =>
tables[tableName].rows.some(row =>
Object.keys(row).some(propName => row[propName].validation === false),
)
) {
tables.push(tablesTitles[tableName]);
invalidTables.push(tablesTitles[tableName]);
}
});
return { elements, tables };
return { invalidElements, invalidTables };
};