import { Select } from '@blueprintjs/select'; import { memo, useCallback } from 'react'; import type { Control } from 'react-hook-form'; import { Button } from 'react-science/ui'; import type { ExtractFilterEntry } from '../../data/types/common/ExtractFilterEntry.js'; import { useFilterSyncOptions } from '../context/FilterSyncOptionsContext.tsx'; import ActionButtons from '../elements/ActionButtons.js'; import Label from '../elements/Label.js'; import { NumberInputField } from '../elements/NumberInputField.js'; import { useFilter } from '../hooks/useFilter.js'; import type { AirplsOptions, AlgorithmFieldProps, BaselineAlgorithmFieldsMap, BaselineAlgorithmOptions, BernsteinOptions, PolynomialOptions, WhittakerOptions, } from '../panels/filtersPanel/Filters/base/baselineCorrectionFields.ts'; import { baselineCorrectionsAlgorithms, getBaselineData, useBaselineCorrection, } from '../panels/filtersPanel/Filters/hooks/useBaselineCorrection.js'; import { headerLabelStyle } from './Header.js'; import { HeaderWrapper } from './HeaderWrapper.js'; const BaselineAlgorithmFields: Omit = { airpls: AirplsFields, polynomial: PolynomialFields, whittaker: WhittakerFields, bernstein: BernsteinFields, }; interface BaseLineCorrectionInnerPanelProps { filter: ExtractFilterEntry<'baselineCorrection'> | null; } function BaseLineCorrectionInnerPanel({ filter, }: BaseLineCorrectionInnerPanelProps) { const { form: { handleSubmit, control, reset }, onAlgorithmChange, submitHandler, handleApplyFilter, handleCancelFilter, algorithm, defaultAlgorithmSelectProps, } = useBaselineCorrection(filter); const { sharedFilterOptions } = useFilterSyncOptions(); const handleAlgorithmSelect = useCallback( (item: (typeof baselineCorrectionsAlgorithms)[number]) => { onAlgorithmChange(item); const { values } = getBaselineData(item.value, filter?.value); const { anchors = [] } = sharedFilterOptions || {}; const options = { ...values, anchors }; reset(options); setTimeout(() => handleApplyFilter(options, 'onChange'), 0); }, [ onAlgorithmChange, filter?.value, sharedFilterOptions, reset, handleApplyFilter, ], ); const handleDone = useCallback( () => handleSubmit((values) => handleApplyFilter(values))(), [handleSubmit, handleApplyFilter], ); const AlgorithmFields = algorithm?.value && algorithm.value !== 'cubic' ? BaselineAlgorithmFields[algorithm.value] : null; return ( {AlgorithmFields && ( } onValueChange={submitHandler} /> )} ); } function AirplsFields({ control, onValueChange, }: AlgorithmFieldProps) { return (
); } function PolynomialFields({ control, onValueChange, }: AlgorithmFieldProps) { return ( ); } function WhittakerFields({ control, onValueChange, }: AlgorithmFieldProps) { return ( ); } function BernsteinFields({ control, onValueChange, }: AlgorithmFieldProps) { return ( ); } const MemoizedBaseLineCorrectionPanel = memo(BaseLineCorrectionInnerPanel); export function SimpleBaseLineCorrectionOptionsPanel() { const filter = useFilter('baselineCorrection'); return ; }