From 16e0016b6b61d46fb8edc77afba8950d89f87570 Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 27 Jan 2021 15:08:46 +0300 Subject: [PATCH] bypass get param value --- src/client/hooks/Calculation/useStatus.js | 10 ++- .../stores/CalculationStore/Data/tables.js | 11 ++- .../stores/CalculationStore/Data/values.js | 6 ++ .../reactions/recalcWoRevisionReactions.ts | 82 ++++++++++++++----- src/client/stores/CalculationStore/index.ts | 28 ++++++- src/core/types/Calculation/Store/index.ts | 4 +- src/core/types/Calculation/Store/process.ts | 1 + 7 files changed, 116 insertions(+), 26 deletions(-) diff --git a/src/client/hooks/Calculation/useStatus.js b/src/client/hooks/Calculation/useStatus.js index 7e590b4..b9ee1b4 100644 --- a/src/client/hooks/Calculation/useStatus.js +++ b/src/client/hooks/Calculation/useStatus.js @@ -2,14 +2,16 @@ import { useStores } from '../useStores'; export const useStatus = elementName => { const { calculationStore } = useStores(); - const status = calculationStore.statuses[elementName]; - + const status = calculationStore.getStatus(elementName); return { status }; }; export const useTableStatus = ({ tableName, rowIndex, propName }) => { const { calculationStore } = useStores(); - const status = - calculationStore.tables[tableName].rows[rowIndex][propName].status; + const status = calculationStore.getTableRowValues( + tableName, + rowIndex, + 'status', + )[propName]; return { status }; }; diff --git a/src/client/stores/CalculationStore/Data/tables.js b/src/client/stores/CalculationStore/Data/tables.js index fd53d61..d1e8e8e 100644 --- a/src/client/stores/CalculationStore/Data/tables.js +++ b/src/client/stores/CalculationStore/Data/tables.js @@ -14,8 +14,17 @@ const tablesActions = { let values = {}; const row = this.tables[tableName].rows[rowIndex]; const keys = Object.keys(row); + + let overridedValue; + if (this.stores.calculationProcess.bypass[paramName]) { + const { target, value } = this.stores.calculationProcess.bypass.status; + if (target.indexOf(tableName) > -1) { + overridedValue = value; + } + } + for (let key of keys) { - values[key] = row[key][paramName || 'value']; + values[key] = overridedValue || row[key][paramName]; } return values; }, diff --git a/src/client/stores/CalculationStore/Data/values.js b/src/client/stores/CalculationStore/Data/values.js index df3a27d..8baf005 100644 --- a/src/client/stores/CalculationStore/Data/values.js +++ b/src/client/stores/CalculationStore/Data/values.js @@ -24,6 +24,12 @@ const valuesActions = { }, getStatus(elementName) { + if (this.stores.calculationProcess.bypass.status) { + const { target, value } = this.stores.calculationProcess.bypass.status; + if (target.indexOf(elementName) > -1) { + return value || undefined; + } + } return this.statuses[elementName]; }, setStatus(elementName, status) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index 5e496c1..eb9b3b7 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -1,6 +1,8 @@ import { openNotification } from 'client/Elements/Notification'; import valuesConstants from 'core/constants/values'; import { IReactionEffect } from 'core/types/Calculation/Store/effect'; +import { ElementsNames } from 'core/types/Calculation/Store/elements'; +import { TableNames } from 'core/types/Calculation/Store/tables'; import { ElementStatus } from 'core/types/statuses'; import { convertPrice } from '../lib/tools'; @@ -58,25 +60,6 @@ const reactionEffects: IReactionEffect[] = [ }, }), - calculationStore => ({ - expression: () => { - const { recalcWithRevision } = calculationStore.values; - return recalcWithRevision; - }, - effect: recalcWithRevision => { - if (recalcWithRevision === true) { - calculationStore.setStatus('selectLead', ElementStatus.Disabled); - calculationStore.setStatus('selectOpportunity', ElementStatus.Disabled); - } else { - calculationStore.setStatus('selectLead', ElementStatus.Default); - calculationStore.setStatus('selectOpportunity', ElementStatus.Default); - } - }, - options: { - fireImmediately: true, - }, - }), - calculationStore => ({ expression: () => { const { recalcWithRevision } = calculationStore.values; @@ -366,6 +349,67 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + (calculationStore, calculationProcess) => ({ + expression: () => { + const { recalcWithRevision } = calculationStore.values; + return recalcWithRevision; + }, + effect: recalcWithRevision => { + if (recalcWithRevision) { + calculationProcess.setBypass({ + param: 'status', + target: elementsToDisable, + value: ElementStatus.Disabled, + }); + } else { + calculationProcess.clearBypass('status'); + } + }, + }), +]; + +const elementsToDisable: (ElementsNames | TableNames)[] = [ + 'tablePayments', + 'selectLead', + 'selectOpportunity', + 'selectProduct', + 'selectClientRisk', + 'selectClientType', + 'tbxLeasingPeriod', + 'tbxLastPaymentPerc', + 'tbxLastPaymentRub', + 'radioLastPaymentRule', + 'radioGraphType', + 'tbxParmentsDecreasePercent', + 'radioSeasonType', + 'selectHighSeasonStart', + 'selectLeaseObjectType', + 'radioDeliveryTime', + 'cbxLeaseObjectUsed', + 'selectBrand', + 'selectModel', + 'selectConfiguration', + 'selectLeaseObjectCategory', + 'selectDealer', + 'selectDealerPerson', + 'selectIndAgent', + 'selectCalcBroker', + 'selectCalcFinDepartment', + 'selectRegionRegistration', + 'selectTownRegistration', + 'tbxInsKaskoPriceLeasePeriod', + 'selectTarif', + 'tbxCreditRate', + 'selectRate', + 'tbxMaxPriceChange', + 'tbxImporterRewardPerc', + 'tbxImporterRewardRub', + 'selectRegistration', + 'radioRequirementTelematic', + 'selectTelematic', + 'selectTracker', + 'tbxMileage', ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/index.ts b/src/client/stores/CalculationStore/index.ts index 6ac1c4d..5a5a8c5 100644 --- a/src/client/stores/CalculationStore/index.ts +++ b/src/client/stores/CalculationStore/index.ts @@ -1,5 +1,8 @@ +import { TableNames } from 'core/types/Calculation/Store/tables'; +import { ElementStatus } from 'core/types/statuses'; +import { ElementsNames } from 'core/types/Calculation/Store/elements'; import { LinksNames } from 'core/types/Calculation/Store/links'; -import { ICalculationStore } from 'core/types/Calculation/Store'; +import { ICalculationStore, ElementParam } from 'core/types/Calculation/Store'; import { Process } from 'core/types/Calculation/Store/process'; import { isEqual } from 'lodash'; import { autorun, makeAutoObservable, reaction } from 'mobx'; @@ -19,6 +22,24 @@ export const calculationProcess = makeAutoObservable({ setProcess(process) { this.process = process; }, + + bypass: { + status: undefined, + }, + setBypass({ + param, + target, + value, + }: { + param: ElementParam; + target: (ElementsNames | TableNames)[]; + value?: ElementStatus; + }) { + this.bypass[param] = { target, value }; + }, + clearBypass(prop) { + this.bypass[prop] = undefined; + }, }); export const calculationUrls = makeAutoObservable({ @@ -37,6 +58,11 @@ const CalculationStore: ICalculationStore = makeAutoObservable( computedEffects, actionsEffects, modal, + { + stores: { + calculationProcess, + }, + }, ), ); diff --git a/src/core/types/Calculation/Store/index.ts b/src/core/types/Calculation/Store/index.ts index 18ed682..9830d7b 100644 --- a/src/core/types/Calculation/Store/index.ts +++ b/src/core/types/Calculation/Store/index.ts @@ -15,6 +15,8 @@ import { } from './tables'; import { TValue, TValues, ValuesNames, ResultValuesNames } from './values'; +export type ElementParam = 'value' | 'status' | 'options' | 'filter' | 'validation'; + interface ICalculationValues { staticData: TStaticData; getStaticData: (dataName: CRMEntityNames) => TCRMEntity[]; @@ -67,7 +69,7 @@ interface ICalculationTables { getTableRowValues: ( tableName: TableNames, rowIndex: number, - paramName: string, + paramName: ElementParam, ) => { values: TableProps }; setTableRows: ( diff --git a/src/core/types/Calculation/Store/process.ts b/src/core/types/Calculation/Store/process.ts index 04b4559..022bca1 100644 --- a/src/core/types/Calculation/Store/process.ts +++ b/src/core/types/Calculation/Store/process.ts @@ -1,4 +1,5 @@ export enum Process { Default, LoadKp, + RecalcWithoutRevision, }