diff --git a/src/component/1d/ExclusionZoneAnnotation.tsx b/src/component/1d/ExclusionZoneAnnotation.tsx index fccbb1f33..5cc41a234 100644 --- a/src/component/1d/ExclusionZoneAnnotation.tsx +++ b/src/component/1d/ExclusionZoneAnnotation.tsx @@ -1,6 +1,6 @@ /** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; -import { Filters } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { memo } from 'react'; import type { ExclusionZone } from '../../data/types/data1d/ExclusionZone.js'; @@ -31,7 +31,7 @@ function ExclusionZoneAnnotation({ }: ExclusionZoneProps) { const { scaleX, scaleY } = useScaleChecked(); const type = - filterId === Filters.signalProcessing.id + filterId === Filters1D.signalProcessing.id ? HighlightEventSource.MATRIX_GENERATION_EXCLUSION_ZONE : HighlightEventSource.EXCLUSION_ZONE; const highlight = useHighlight([], { @@ -50,7 +50,7 @@ function ExclusionZoneAnnotation({ width={`${scaleX()(zone.from) - scaleX()(zone.to)}`} height="10px" style={{ - fill: filterId === Filters.signalProcessing.id ? 'gray' : color, + fill: filterId === Filters1D.signalProcessing.id ? 'gray' : color, opacity, }} {...highlight.onHover} diff --git a/src/component/1d/ExclusionZonesAnnotations.tsx b/src/component/1d/ExclusionZonesAnnotations.tsx index 43e0ae445..50c7e58c2 100644 --- a/src/component/1d/ExclusionZonesAnnotations.tsx +++ b/src/component/1d/ExclusionZonesAnnotations.tsx @@ -1,5 +1,5 @@ import type { Spectrum1D } from 'nmr-load-save'; -import { Filters } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { memo } from 'react'; import type { ExclusionZone } from '../../data/types/data1d/ExclusionZone.js'; @@ -76,11 +76,11 @@ function getExclusionZones( ): Array<{ id: string; zones: ExclusionZone[] }> { const zones: Array<{ id: string; zones: ExclusionZone[] }> = []; for (const filter of data.filters) { - if (filter.name === Filters.exclusionZones.id && filter.flag) { - zones.push({ id: Filters.exclusionZones.id, zones: filter.value }); - } else if (filter.name === Filters.signalProcessing.id && filter.flag) { + if (filter.name === Filters1D.exclusionZones.id && filter.flag) { + zones.push({ id: Filters1D.exclusionZones.id, zones: filter.value }); + } else if (filter.name === Filters1D.signalProcessing.id && filter.flag) { zones.push({ - id: Filters.signalProcessing.id, + id: Filters1D.signalProcessing.id, zones: filter.value.exclusionsZones, }); } diff --git a/src/component/1d/matrix/useMatrix.ts b/src/component/1d/matrix/useMatrix.ts index a6e5bb6cf..be8ab826b 100644 --- a/src/component/1d/matrix/useMatrix.ts +++ b/src/component/1d/matrix/useMatrix.ts @@ -1,13 +1,13 @@ import type { NumberArray } from 'cheminfo-types'; import type { Spectrum } from 'nmr-load-save'; -import { Filters } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { useMemo } from 'react'; import { isSpectrum1D } from '../../../data/data1d/Spectrum1D/index.js'; import { useChartData } from '../../context/ChartContext.js'; import useSpectraByActiveNucleus from '../../hooks/useSpectraPerNucleus.js'; -const { signalProcessing } = Filters; +const { signalProcessing } = Filters1D; /** * This method will slice the array from the fromIndex to the toIndex and add the first and last element of the original array diff --git a/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx b/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx index c4cfb9435..32c85dba0 100644 --- a/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx +++ b/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx @@ -1,5 +1,5 @@ import type { Spectrum1D, Spectrum2D } from 'nmr-load-save'; -import { Filters } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import type { ReactNode } from 'react'; import { getSlice } from '../../../../data/data2d/Spectrum2D/index.js'; @@ -143,7 +143,7 @@ function InnerSpectrumPhaseTrace(props: InnerSpectrumPhaseTraceProps) { info: { isComplex: true, isFid: false }, }; - Filters.phaseCorrection.apply(spectrum as unknown as Spectrum1D, { + Filters1D.phaseCorrection.apply(spectrum as unknown as Spectrum1D, { ph0, ph1, }); diff --git a/src/component/header/SimpleApodizationOptionsPanel.tsx b/src/component/header/SimpleApodizationOptionsPanel.tsx index 7bad6b4ab..4391cf501 100644 --- a/src/component/header/SimpleApodizationOptionsPanel.tsx +++ b/src/component/header/SimpleApodizationOptionsPanel.tsx @@ -1,5 +1,5 @@ import { Checkbox } from '@blueprintjs/core'; -import { Filter1D, Filters1D } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { memo } from 'react'; import ActionButtons from '../elements/ActionButtons.js'; @@ -11,6 +11,7 @@ import { useSharedApodization } from '../panels/filtersPanel/Filters/hooks/useSh import { headerLabelStyle } from './Header.js'; import { HeaderWrapper } from './HeaderWrapper.js'; +import type { Filter1D } from 'nmr-processing'; interface ApodizationOptionsInnerPanelProps { filter: Extract | null; } @@ -69,14 +70,9 @@ function ApodizationOptionsInnerPanel( const MemoizedApodizationPanel = memo(ApodizationOptionsInnerPanel); export function SimpleApodizationOptionsPanel() { - const filter = useFilter(Filters1D.apodization.id); - if (isApodizationFilter(filter)) { - return ; - } -} - -function isApodizationFilter( - filter: Filter1D | null, -): filter is Extract { - return filter?.name === 'apodization'; + const filter = useFilter(Filters1D.apodization.id) as Extract< + Filter1D, + { name: 'apodization' } + >; + return ; } diff --git a/src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx b/src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx index 4c322a455..8ef05dd3c 100644 --- a/src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx +++ b/src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx @@ -1,6 +1,6 @@ import { Checkbox } from '@blueprintjs/core'; import { Select } from '@blueprintjs/select'; -import { Filter1D, Filters1D } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { memo } from 'react'; import { Button } from 'react-science/ui'; @@ -17,6 +17,8 @@ import { import { headerLabelStyle } from './Header.js'; import { HeaderWrapper } from './HeaderWrapper.js'; +import type { Filter1D } from 'nmr-processing'; + interface BaseLineCorrectionInnerPanelProps { filter: Extract; } @@ -137,15 +139,10 @@ function BaseLineCorrectionInnerPanel( const MemoizedBaseLineCorrectionPanel = memo(BaseLineCorrectionInnerPanel); export function SimpleBaseLineCorrectionOptionsPanel() { - const filter = useFilter(Filters1D.baselineCorrection.id); - - if (isBaselineCorrectionFilter(filter)) { - return ; - } -} + const filter = useFilter(Filters1D.baselineCorrection.id) as Extract< + Filter1D, + { name: 'baselineCorrection' } + >; -function isBaselineCorrectionFilter( - filter: Filter1D | null, -): filter is Extract { - return filter?.name === 'baselineCorrection'; + return ; } diff --git a/src/component/header/SimplePhaseCorrectionOptionsPanel.tsx b/src/component/header/SimplePhaseCorrectionOptionsPanel.tsx index c1619b4db..ef656a4d1 100644 --- a/src/component/header/SimplePhaseCorrectionOptionsPanel.tsx +++ b/src/component/header/SimplePhaseCorrectionOptionsPanel.tsx @@ -1,5 +1,5 @@ import { Select } from '@blueprintjs/select'; -import { Filters } from 'nmr-processing'; +import { Filters1D } from 'nmr-processing'; import { Button } from 'react-science/ui'; import ActionButtons from '../elements/ActionButtons.js'; @@ -14,7 +14,7 @@ import { import { HeaderWrapper } from './HeaderWrapper.js'; export function SimplePhaseCorrectionOptionsPanel() { - const filter = useFilter(Filters.phaseCorrection.id); + const filter = useFilter(Filters1D.phaseCorrection.id); const { handleApplyFilter, diff --git a/src/component/header/SimplePhaseCorrectionTwoDimensionsPanel.tsx b/src/component/header/SimplePhaseCorrectionTwoDimensionsPanel.tsx index 5463c6dde..2f72af314 100644 --- a/src/component/header/SimplePhaseCorrectionTwoDimensionsPanel.tsx +++ b/src/component/header/SimplePhaseCorrectionTwoDimensionsPanel.tsx @@ -1,6 +1,6 @@ /** @jsxImportSource @emotion/react */ import { Select } from '@blueprintjs/select'; -import { Filters } from 'nmr-processing'; +import { Filters2D } from 'nmr-processing'; import { FaRulerHorizontal, FaRulerVertical } from 'react-icons/fa'; import { MdLooksTwo } from 'react-icons/md'; import { Button, Toolbar } from 'react-science/ui'; @@ -19,7 +19,7 @@ import { headerLabelStyle } from './Header.js'; import { HeaderWrapper } from './HeaderWrapper.js'; export function SimplePhaseCorrectionTwoDimensionsPanel() { - const filter = useFilter(Filters.phaseCorrectionTwoDimensions.id); + const filter = useFilter(Filters2D.phaseCorrectionTwoDimensions.id); const { ph0Ref, ph1Ref, diff --git a/src/component/hooks/useFilter.ts b/src/component/hooks/useFilter.ts index ee74d1be4..d5d075c37 100644 --- a/src/component/hooks/useFilter.ts +++ b/src/component/hooks/useFilter.ts @@ -1,13 +1,13 @@ -import { Spectrum1D } from 'nmr-load-save'; -import { Filter1D } from 'nmr-processing'; +import type { Spectrum1D, Spectrum2D } from 'nmr-load-save'; +import type { Filter1D, Filter2D } from 'nmr-processing'; import { useMemo } from 'react'; import useSpectrum from './useSpectrum.js'; const emptyData = { filters: {} }; -export function useFilter(filterID: string): Filter1D | null { - const { filters } = useSpectrum(emptyData) as Spectrum1D; +export function useFilter(filterID: Filter1D['name'] | Filter2D['name']) { + const { filters } = useSpectrum(emptyData) as Spectrum1D | Spectrum2D; return useMemo( () => filters.find((filter) => filter.name === filterID) || null, diff --git a/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx b/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx index 8c394b5f4..2fbe4a799 100644 --- a/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx +++ b/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx @@ -1,7 +1,12 @@ import { Switch } from '@blueprintjs/core'; import styled from '@emotion/styled'; import { v4 } from '@lukeed/uuid'; -import { Filter1D, Filter2D } from 'nmr-processing'; +import { + Filters1D, + Filters2D, + type Filter1D, + type Filter2D, +} from 'nmr-processing'; import { memo, useEffect, useRef, useState } from 'react'; import { FaRegEyeSlash, FaRegTrashAlt } from 'react-icons/fa'; import { ObjectInspector } from 'react-inspector'; @@ -23,11 +28,12 @@ const IconButton = styled(Button)` font-size: 16px; `; -type FiltersProps = Filter1D & - Filter2D & { - error?: any; - }; +type FiltersProps = Filter1D | Filter2D; +const Filters = { + ...Filters1D, + ...Filters2D, +}; interface FilterElementsProps { filter: Filter1D | Filter2D; spectraCounter: number; @@ -212,7 +218,7 @@ function FiltersInner(props: FiltersInnerProps) { id: v4(), name, label, - value: null, + value: {}, isDeleteAllow: true, }); } else { diff --git a/src/component/panels/filtersPanel/Filters/hooks/useBaselineCorrection.tsx b/src/component/panels/filtersPanel/Filters/hooks/useBaselineCorrection.tsx index 7e279f195..feb4622de 100644 --- a/src/component/panels/filtersPanel/Filters/hooks/useBaselineCorrection.tsx +++ b/src/component/panels/filtersPanel/Filters/hooks/useBaselineCorrection.tsx @@ -1,5 +1,5 @@ import { yupResolver } from '@hookform/resolvers/yup'; -import { BaselineCorrectionOptions, Filter1D } from 'nmr-processing'; +import type { BaselineCorrectionOptions, Filter1D } from 'nmr-processing'; import { useCallback, useEffect, useRef } from 'react'; import { useForm } from 'react-hook-form'; import { useSelect } from 'react-science/ui'; diff --git a/src/component/panels/filtersPanel/Filters/index.tsx b/src/component/panels/filtersPanel/Filters/index.tsx index 447f3491e..365da7f3a 100644 --- a/src/component/panels/filtersPanel/Filters/index.tsx +++ b/src/component/panels/filtersPanel/Filters/index.tsx @@ -1,5 +1,7 @@ import { ButtonProps } from '@blueprintjs/core'; -import { Filter1D, Filters1D, Filters2D } from 'nmr-processing'; + +import type { Filter1D } from 'nmr-processing'; +import { Filters1D, Filters2D } from 'nmr-processing'; import type { LabelStyle } from '../../../elements/Label.js';