From 1b50177681ee1a1430ff4a43ca49c71b6137d23d Mon Sep 17 00:00:00 2001 From: hamed musallam Date: Tue, 22 Oct 2024 10:54:38 +0200 Subject: [PATCH] refactor: remove sorting action of multiple spectra analysis --- src/component/reducer/Reducer.ts | 4 -- .../reducer/actions/SpectraActions.ts | 12 +++--- .../reducer/actions/SpectraAnalysisAction.ts | 39 ------------------- 3 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 src/component/reducer/actions/SpectraAnalysisAction.ts diff --git a/src/component/reducer/Reducer.ts b/src/component/reducer/Reducer.ts index 6b72a8010..74cd50c5d 100644 --- a/src/component/reducer/Reducer.ts +++ b/src/component/reducer/Reducer.ts @@ -25,7 +25,6 @@ import * as PeaksActions from './actions/PeaksActions'; import * as PreferencesActions from './actions/PreferencesActions'; import * as RangesActions from './actions/RangesActions'; import * as SpectraActions from './actions/SpectraActions'; -import * as SpectraAnalysisActions from './actions/SpectraAnalysisAction'; import * as ToolsActions from './actions/ToolsActions'; import * as ZonesActions from './actions/ZonesActions'; import { ZoomHistory } from './helper/ZoomHistoryManager'; @@ -716,9 +715,6 @@ function innerSpectrumReducer(draft: Draft, action: Action) { action, ); - case 'ORDER_MULTIPLE_SPECTRA_ANALYSIS': - return SpectraAnalysisActions.handleOrderSpectra(draft, action); - case 'RESURRECTING_SPECTRUM': return DatabaseActions.handleResurrectSpectrum(draft, action); case 'TOGGLE_SIMILARITY_TREE': diff --git a/src/component/reducer/actions/SpectraActions.ts b/src/component/reducer/actions/SpectraActions.ts index c1467ce4a..8d76789d5 100644 --- a/src/component/reducer/actions/SpectraActions.ts +++ b/src/component/reducer/actions/SpectraActions.ts @@ -75,10 +75,10 @@ type ChangeActiveSpectrumAction = ActionType< 'CHANGE_ACTIVE_SPECTRUM', { modifier?: - | 'shift[false]_ctrl[true]' - | 'shift[true]_ctrl[false]' - | 'shift[true]_ctrl[true]' - | (string & {}); + | 'shift[false]_ctrl[true]' + | 'shift[true]_ctrl[false]' + | 'shift[true]_ctrl[true]' + | (string & {}); id?: string; // spectrum id } @@ -166,7 +166,7 @@ export type SpectrumActions = | ImportSpectraMetaInfoAction | ReColorSpectraBasedOnDistinctValueAction | SimulateSpectrumAction - | UpdateSpectrumMetaAction + | UpdateSpectrumMetaAction; const { applyFilter } = FiltersManager; function checkIsVisible2D(datum: Spectrum2D): boolean { @@ -685,7 +685,6 @@ function handleRecolorSpectraBasedOnDistinctValue( } } - function handleSimulateSpectrum( draft: Draft, simulateSpectrumOptions: SimulateSpectrumAction, @@ -752,7 +751,6 @@ function handleUpdateSpectrumMeta( draft.data[activeSpectrum.index].customInfo = meta; } - export { handleChangeSpectrumVisibilityById, handleChangeSpectraVisibilityByNucleus, diff --git a/src/component/reducer/actions/SpectraAnalysisAction.ts b/src/component/reducer/actions/SpectraAnalysisAction.ts deleted file mode 100644 index d7579bb81..000000000 --- a/src/component/reducer/actions/SpectraAnalysisAction.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Draft } from 'immer'; -import { Spectrum1D } from 'nmr-load-save'; - -import { AnalysisRow } from '../../../data/data1d/multipleSpectraAnalysis'; -import { State } from '../Reducer'; -import { ActionType } from '../types/ActionType'; - -type OrderSpectraAction = ActionType< - 'ORDER_MULTIPLE_SPECTRA_ANALYSIS', - { - data: AnalysisRow[]; - } ->; - -export type SpectraAnalysisActions = OrderSpectraAction; - -function handleOrderSpectra(draft: Draft, action: OrderSpectraAction) { - const { data } = action.payload; - const spectraIndexes = {}; - let index = 0; - for (const spectrum of draft.data) { - spectraIndexes[spectrum.id] = index; - index++; - } - const sortedSpectraKey = {}; - const sortedSpectra: Spectrum1D[] = []; - - for (const record of data) { - const key = Object.keys(record)[0]; - const spectrumId = record[key].SID; - sortedSpectraKey[spectrumId] = true; - sortedSpectra.push(draft.data[spectraIndexes[spectrumId]] as Spectrum1D); - } - draft.data = draft.data - .filter((s) => !sortedSpectraKey[s.id]) - .concat(sortedSpectra); -} - -export { handleOrderSpectra };