Skip to content

Commit

Permalink
chore: work in progress refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jobo322 committed Nov 1, 2024
1 parent 25636bf commit cb2736e
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/component/1d/ExclusionZoneAnnotation.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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([], {
Expand All @@ -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}
Expand Down
10 changes: 5 additions & 5 deletions src/component/1d/ExclusionZonesAnnotations.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/component/1d/matrix/useMatrix.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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, {

Check failure on line 146 in src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Argument of type 'Spectrum1D' is not assignable to parameter of type 'Entry1D'.
ph0,
ph1,
});
Expand Down
18 changes: 7 additions & 11 deletions src/component/header/SimpleApodizationOptionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Check failure on line 14 in src/component/header/SimpleApodizationOptionsPanel.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Expected 1 empty line after import statement not followed by another import

Check warning on line 14 in src/component/header/SimpleApodizationOptionsPanel.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

`nmr-processing` type import should occur before import of `react`
interface ApodizationOptionsInnerPanelProps {
filter: Extract<Filter1D, { name: 'apodization' }> | null;
}
Expand Down Expand Up @@ -69,14 +70,9 @@ function ApodizationOptionsInnerPanel(
const MemoizedApodizationPanel = memo(ApodizationOptionsInnerPanel);

export function SimpleApodizationOptionsPanel() {
const filter = useFilter(Filters1D.apodization.id);
if (isApodizationFilter(filter)) {
return <MemoizedApodizationPanel filter={filter} />;
}
}

function isApodizationFilter(
filter: Filter1D | null,
): filter is Extract<Filter1D, { name: 'apodization' }> {
return filter?.name === 'apodization';
const filter = useFilter(Filters1D.apodization.id) as Extract<
Filter1D,
{ name: 'apodization' }
>;
return <MemoizedApodizationPanel filter={filter} />;
}
19 changes: 8 additions & 11 deletions src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -17,6 +17,8 @@ import {
import { headerLabelStyle } from './Header.js';
import { HeaderWrapper } from './HeaderWrapper.js';

import type { Filter1D } from 'nmr-processing';

Check warning on line 20 in src/component/header/SimpleBaseLineCorrectionOptionsPanel.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

`nmr-processing` type import should occur before import of `react`

interface BaseLineCorrectionInnerPanelProps {
filter: Extract<Filter1D, { name: 'baselineCorrection' }>;
}
Expand Down Expand Up @@ -137,15 +139,10 @@ function BaseLineCorrectionInnerPanel(
const MemoizedBaseLineCorrectionPanel = memo(BaseLineCorrectionInnerPanel);

export function SimpleBaseLineCorrectionOptionsPanel() {
const filter = useFilter(Filters1D.baselineCorrection.id);

if (isBaselineCorrectionFilter(filter)) {
return <MemoizedBaseLineCorrectionPanel filter={filter} />;
}
}
const filter = useFilter(Filters1D.baselineCorrection.id) as Extract<
Filter1D,
{ name: 'baselineCorrection' }
>;

function isBaselineCorrectionFilter(
filter: Filter1D | null,
): filter is Extract<Filter1D, { name: 'baselineCorrection' }> {
return filter?.name === 'baselineCorrection';
return <MemoizedBaseLineCorrectionPanel filter={filter} />;
}
4 changes: 2 additions & 2 deletions src/component/header/SimplePhaseCorrectionOptionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/component/hooks/useFilter.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
18 changes: 12 additions & 6 deletions src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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,

Check failure on line 7 in src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Prefer using a top-level type-only import instead of inline type specifiers
type Filter2D,

Check failure on line 8 in src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Prefer using a top-level type-only import instead of inline type specifiers
} from 'nmr-processing';
import { memo, useEffect, useRef, useState } from 'react';
import { FaRegEyeSlash, FaRegTrashAlt } from 'react-icons/fa';
import { ObjectInspector } from 'react-inspector';
Expand All @@ -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;
Expand Down Expand Up @@ -212,7 +218,7 @@ function FiltersInner(props: FiltersInnerProps) {
id: v4(),
name,
label,
value: null,
value: {},
isDeleteAllow: true,
});
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 3 additions & 1 deletion src/component/panels/filtersPanel/Filters/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ButtonProps } from '@blueprintjs/core';

Check failure on line 1 in src/component/panels/filtersPanel/Filters/index.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

All imports in the declaration are only used as types. Use `import type`
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';

Expand Down

0 comments on commit cb2736e

Please sign in to comment.