diff --git a/src/data/data1d/Spectrum1D/initiateDatum1D.ts b/src/data/data1d/Spectrum1D/initiateDatum1D.ts index 60b24f5f90..136a41654a 100644 --- a/src/data/data1d/Spectrum1D/initiateDatum1D.ts +++ b/src/data/data1d/Spectrum1D/initiateDatum1D.ts @@ -11,6 +11,7 @@ import { initiatePeaks } from './peaks/initiatePeaks'; import { initiateRanges } from './ranges/initiateRanges'; import { initSumOptions } from './SumManager'; import { StateMoleculeExtended } from '../../molecules/Molecule'; +import { initiateFilters } from '../../initiateFilters'; export interface InitiateDatum1DOptions { usedColors?: UsedColors; @@ -53,7 +54,7 @@ export function initiateDatum1D( spectrumObj.originalData = spectrumObj.data; - spectrumObj.filters = Object.assign([], spectrum.filters); //array of object {name: "FilterName", options: FilterOptions = {value | object} } + spectrumObj.filters = initiateFilters(spectrum.filters); //array of object {name: "FilterName", options: FilterOptions = {value | object} } const { nucleus } = spectrumObj.info; diff --git a/src/data/data2d/Spectrum2D/initiateDatum2D.ts b/src/data/data2d/Spectrum2D/initiateDatum2D.ts index 2385f27a8a..9441205a99 100644 --- a/src/data/data2d/Spectrum2D/initiateDatum2D.ts +++ b/src/data/data2d/Spectrum2D/initiateDatum2D.ts @@ -5,6 +5,7 @@ import { FiltersManager } from 'nmr-processing'; import { DEFAULT_CONTOURS_OPTIONS } from './contours'; import { get2DColor } from './get2DColor'; import { initiateZones } from './zones/initiateZones'; +import { initiateFilters } from '../../initiateFilters'; const defaultMinMax = { z: [], minX: 0, minY: 0, maxX: 0, maxY: 0 }; @@ -40,7 +41,7 @@ export function initiateDatum2D(spectrum: any, usedColors = {}): Spectrum2D { datum.data = getData(datum, spectrum); datum.originalData = datum.data; - datum.filters = Object.assign([], spectrum.filters); + datum.filters = initiateFilters(spectrum.filters); datum.zones = initiateZones(spectrum, datum as Spectrum2D); diff --git a/src/data/initiateFilters.ts b/src/data/initiateFilters.ts new file mode 100644 index 0000000000..fcd6a6dc5b --- /dev/null +++ b/src/data/initiateFilters.ts @@ -0,0 +1,8 @@ +import { v4 } from '@lukeed/uuid'; +import { Filter } from 'nmr-processing'; + +export function initiateFilters(inputFilters: Filter[] | undefined) { + if (!inputFilters || !Array.isArray(inputFilters)) return []; + + return inputFilters.map((filter) => ({ ...filter, id: filter?.id || v4() })); +}