в поле Тип дегрессии/сезонности selectSeasonType должны отображаться только те значения,

* которых нет в массиве поля "Недопустимые Типы дегрессий/сезонности" evo_seasons_type_exception
   * (добавить в текущую фильтрацию поля)
This commit is contained in:
vchikalkin 2023-01-30 11:37:40 +03:00
parent bdc360fec0
commit ff465ae65e
3 changed files with 49 additions and 1 deletions

View File

@ -127,7 +127,7 @@ export type GetTarif_ProcessConfiguratorQueryVariables = Exact<{
}>;
export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array<number> | null } | null };
export type GetTarif_ProcessConfiguratorQuery = { __typename?: 'Query', evo_tarif: { __typename?: 'evo_tarif', evo_irr: number | null, evo_graphtype_exception: Array<number> | null, evo_seasons_type_exception: Array<number> | null } | null };
export type GetLeaseObjectTypes_ProcessConfiguratorQueryVariables = Exact<{ [key: string]: never; }>;

View File

@ -6,6 +6,7 @@ export const QUERY_GET_TARIF = gql`
evo_tarif(evo_tarifid: $tarifId) {
evo_irr
evo_graphtype_exception
evo_seasons_type_exception
}
}
`;

View File

@ -2,7 +2,9 @@
import { gql } from '@apollo/client';
import type * as CRMTypes from 'graphql/crm.types';
import { reaction } from 'mobx';
import { SEASON_TYPES } from 'process/payments/lib/seasons-constants';
import type { ReactionsContext } from 'process/types';
import { diff } from 'radash';
import { normalizeOptions } from 'tools';
import { QUERY_GET_TARIF } from '../lib/query';
@ -302,4 +304,49 @@ export default function commonReactions({ store, apolloClient }: ReactionsContex
$calculation.element('radioGraphType').setOptions(filteredGraphTypes);
}
);
/**
* в поле Тип дегрессии/сезонности selectSeasonType должны отображаться только те значения,
* которых нет в массиве поля "Недопустимые Типы дегрессий/сезонности" evo_seasons_type_exception
* (добавить в текущую фильтрацию поля)
*/
reaction(
() => ({
tarif: $calculation.element('selectTarif').getValue(),
graphType: $calculation.element('radioGraphType').getValue(),
}),
async ({ tarif, graphType }) => {
let evo_tarif: CRMTypes.GetTarif_ProcessConfiguratorQuery['evo_tarif'] = null;
if (tarif) {
const { data } = await apolloClient.query<
CRMTypes.GetTarif_ProcessConfiguratorQuery,
CRMTypes.GetTarif_ProcessConfiguratorQueryVariables
>({
query: QUERY_GET_TARIF,
variables: {
tarifId: tarif,
},
});
({ evo_tarif } = data);
}
const seasonTypesExeption = evo_tarif?.evo_seasons_type_exception || [];
let seasonTypes: Array<number> = [];
if (graphType === 100_000_001 || graphType === 100_000_003) {
seasonTypes = SEASON_TYPES[graphType];
}
const allowedSeasonTypes = diff(seasonTypes, seasonTypesExeption);
const filteredSeasonTypesOptions = $calculation
.element('selectSeasonType')
.getOptions()
.filter((seasonTypeOption) => allowedSeasonTypes.includes(seasonTypeOption.value));
$calculation.element('selectSeasonType').setOptions(filteredSeasonTypesOptions);
}
);
}