check validation of tables
This commit is contained in:
parent
a41dd51590
commit
caabb6a459
10
src/client/constants/Calculation/tablesTitles.ts
Normal file
10
src/client/constants/Calculation/tablesTitles.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { TableNames } from 'core/types/Calculation/Store/tables';
|
||||
|
||||
const tablesTitles: {
|
||||
[table in TableNames]?: string;
|
||||
} = {
|
||||
tableInsurance: 'Таблица страхования',
|
||||
tablePayments: 'Таблица платежей',
|
||||
};
|
||||
|
||||
export default tablesTitles;
|
||||
@ -14,7 +14,7 @@ import checkValidation from './lib/checkValidation';
|
||||
import customValues from './lib/customValues';
|
||||
import prepareCalculationData from './lib/prepareData';
|
||||
import results from './lib/results';
|
||||
import validateElements from './lib/validateElements';
|
||||
import validate from './lib/validate';
|
||||
|
||||
const cleanResults = () => {
|
||||
for (let resultValue of resultsValues) {
|
||||
@ -268,14 +268,22 @@ const actions: TAction = {
|
||||
},
|
||||
|
||||
calculate: async () => {
|
||||
validateElements();
|
||||
const { elements } = checkValidation();
|
||||
if (elements.length > 0) {
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка во время расчета графика',
|
||||
description: 'Некорректно заполнены поля: ' + elements.join(', '),
|
||||
})();
|
||||
validate();
|
||||
const { elements, tables } = checkValidation();
|
||||
if (elements.length > 0 || tables.length > 0) {
|
||||
if (elements.length > 0)
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка во время расчета графика',
|
||||
description: 'Некорректно заполнены поля: ' + elements.join(', '),
|
||||
})();
|
||||
|
||||
if (tables.length > 0)
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка во время расчета графика',
|
||||
description: 'Некорректно заполнены таблицы: ' + tables.join(', '),
|
||||
})();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { toJS } from 'mobx';
|
||||
import elementsTitles from 'client/constants/Calculation/elementsTitles';
|
||||
import tablesTitles from 'client/constants/Calculation/tablesTitles';
|
||||
import CalculationStore from 'client/stores/CalculationStore';
|
||||
|
||||
export default () => {
|
||||
@ -11,5 +13,20 @@ export default () => {
|
||||
}
|
||||
});
|
||||
|
||||
return { elements };
|
||||
let tables: string[] = [];
|
||||
const { tables: storeTables } = CalculationStore;
|
||||
|
||||
const jsTables = toJS(storeTables);
|
||||
|
||||
Object.keys(jsTables).forEach(tableName => {
|
||||
if (
|
||||
jsTables[tableName].rows.some(row =>
|
||||
Object.keys(row).some(propName => row[propName].validation === false),
|
||||
)
|
||||
) {
|
||||
tables.push(tablesTitles[tableName]);
|
||||
}
|
||||
});
|
||||
|
||||
return { elements, tables };
|
||||
};
|
||||
|
||||
@ -35,12 +35,12 @@ const validateElement = (elementName, condition) => {
|
||||
if (condition) {
|
||||
CalculationStore.setValidation(elementName, false);
|
||||
} else {
|
||||
//TODO: antidote in reactions
|
||||
//TODO: antidote in reactions
|
||||
CalculationStore.setValidation(elementName, true);
|
||||
}
|
||||
};
|
||||
|
||||
export default () => {
|
||||
const validateElements = () => {
|
||||
Object.keys(elementsValidations).forEach(elementName => {
|
||||
validateElement(
|
||||
elementName,
|
||||
@ -48,3 +48,7 @@ export default () => {
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export default () => {
|
||||
validateElements();
|
||||
};
|
||||
Reference in New Issue
Block a user