how mock hoc whic return two props activePeriodIndex and… · The Chat Archive
Explore how mock hoc whic return two props activePeriodIndex and reateIndex Save Share Download ▾ Reporthow mock hoc whic return two props activePeriodIndex and reateIndex
Assistant2024-07-19 17:19 UTC Copy response
const mockData = {
activePeriodIndex: 1,
rateIndex: 5
};
const mockFunction = () => {
return mockData;
};
console.log(mockFunction()); // { activePeriodIndex: 1, rateIndex: 5 }
import { memo } from 'react';
import { useFormContext } from 'react-hook-form';
import { Select, useFormValueSelector } from '@sber-efsdf-ui/ufs-form-components';
import { Box, Flex, Text } from '@atomic-ui/react';
import type {
BaseIndicatorTypeLabel,
InterestRatesFormState,
TermIndexesType,
} from '$entities/rates';
import type { WithRateParametersProps } from '../../../model';
import { baseIndicatorSelector, withRateParameters } from '../../../model';
Assistant2024-07-19 17:19 UTC Copy response
To add the activePeriodIndex and props to the interface and pass them to the component, you can modify the code as follows:
Copy first prompt Copy first response
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 2 (4 messages)
Language en
Conversation date Jul 19, 2024
Added to archive Nov 16, 2026
ID 01m7h41rs961ddfkfeyxkwjacySource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 6c5065d8573a23105391884264a50b1b
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
interface BaseIndicatorParamsProps extends WithRateParametersProps {
baseIndicatorKindItems: Labeled[];
termIndexTypeItems: Labeled[];
defaultValue?: Labeled;
disabled?: boolean;
}
export const EnhancedBaseIndicatorParams = memo(
({
baseIndicatorKindItems,
termIndexTypeItems,
defaultValue,
activePeriodIndex,
rateIndex,
disabled = false,
}: BaseIndicatorParamsProps) => {
const { resetField } = useFormContext();
const { kind } = useFormValueSelector(
(formState: InterestRatesFormState) =>
baseIndicatorSelector({ formState, activePeriodIndex, rateIndex }),
[activePeriodIndex, rateIndex],
);
const handleChange = () => {
resetField(
`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`,
);
};
return (
<Flex direction="column" gap={4} w="50%">
<Text fontWeight="semibold" typography="16_24">
Базовый индикатор (БИ)
</Text>
<Box w="full">
<Select<InterestRatesFormState, Labeled<BaseIndicatorTypeLabel>>
title="Наименование индикатора"
placeholder="Наименование индикатора"
fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.kind`}
items={baseIndicatorKindItems}
labelExtractor={(item) => item.name}
onChange={handleChange}
defaultValue={defaultValue}
showClearIcon={false}
disabled={disabled}
/>
</Box>
{kind && kind?.id !== 'CBR_KEY_RATE' && (
<Box w="full">
<Select<InterestRatesFormState, Labeled<TermIndexesType>>
title="Индекс срока"
placeholder="Индекс срока"
fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`}
items={termIndexTypeItems}
labelExtractor={(item) => item.name}
showClearIcon={false}
/>
</Box>
)}
</Flex>
);
},
export const BaseIndicatorParams = withRateParameters(EnhancedBaseIndicatorParams);
rateIndex
BaseIndicatorParamsProps
EnhancedBaseIndicatorParams
interface BaseIndicatorParamsProps extends WithRateParametersProps {
baseIndicatorKindItems: Labeled<BaseIndicatorTypeLabel>[];
termIndexTypeItems: Labeled<TermIndexesType>[];
defaultValue?: Labeled<BaseIndicatorTypeLabel>;
disabled?: boolean;
activePeriodIndex: number; // Add activePeriodIndex prop
rateIndex: number; // Add rateIndex prop
}
export const EnhancedBaseIndicatorParams = memo(
({
baseIndicatorKindItems,
termIndexTypeItems,
defaultValue,
activePeriodIndex,
rateIndex,
disabled = false,
}: BaseIndicatorParamsProps) => {
const { resetField } = useFormContext<InterestRatesFormState>();
const { kind } = useFormValueSelector(
(formState: InterestRatesFormState) =>
baseIndicatorSelector({ formState, activePeriodIndex, rateIndex }),
[activePeriodIndex, rateIndex],
);
const handleChange = () => {
resetField(
`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`,
);
};
return (
<Flex direction="column" gap={4} w="50%">
<Text fontWeight="semibold" typography="16_24">
Базовый индикатор (БИ)
</Text>
<Box w="full">
<Select<InterestRatesFormState, Labeled<BaseIndicatorTypeLabel>>
title="Наименование индикатора"
placeholder="Наименование индикатора"
fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.kind`}
items={baseIndicatorKindItems}
labelExtractor={(item) => item.name}
onChange={handleChange}
defaultValue={defaultValue}
showClearIcon={false}
disabled={disabled}
/>
</Box>
{kind && kind?.id !== 'CBR_KEY_RATE' && (
<Box w="full">
<Select<InterestRatesFormState, Labeled<TermIndexesType>>
title="Индекс срока"
placeholder="Индекс срока"
fieldName={`INTEREST_RATES.${rateIndex}.periods.${activePeriodIndex}.baseIndicator.termIndex`}
items={termIndexTypeItems}
labelExtractor={(item) => item.name}
showClearIcon={false}
/>
</Box>
)}
</Flex>
);
},
);
By adding the activePeriodIndex and rateIndex props to the BaseIndicatorParamsProps interface and passing them to the EnhancedBaseIndicatorParams component, you can access these props within the component and use them as needed.
Not yet included in a published release.