Skip to content

Commit 3499ea3

Browse files
fix: rollback to full processed spectrum when cancelling filter edit
close #3654
1 parent 4808d0d commit 3499ea3

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

src/component/reducer/actions/FiltersActions.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,13 @@ function rollbackSpectrumByFilter(
446446
const filterIndex = spectrum.filters.findIndex((f) => f[searchBy] === key);
447447
if (filterIndex === -1 || reset) {
448448
if (draft.tempData) {
449-
const activeFilterIndex = toolData.activeFilterID
450-
? spectrum.filters.findIndex((f) => f.id === toolData.activeFilterID)
451-
: spectrum.filters.length - 1;
449+
const activeFilterIndex =
450+
!reset && toolData.activeFilterID
451+
? spectrum.filters.findIndex(
452+
(f) => f.id === toolData.activeFilterID,
453+
)
454+
: spectrum.filters.length;
455+
452456
const filters = spectrum.filters.slice(0, activeFilterIndex);
453457
reapplyFilters(spectrum, filters);
454458
}
@@ -793,6 +797,8 @@ function handleShiftSpectrumAlongXAxis(
793797
return;
794798
}
795799

800+
const activeFilterIndex = getActiveFilterIndex(draft);
801+
796802
//apply filter into the spectrum
797803
const options = action.payload;
798804

@@ -808,9 +814,14 @@ function handleShiftSpectrumAlongXAxis(
808814
applyFilter: false,
809815
});
810816

811-
Filters1DManager.applyFilters(draft.data[index] as Spectrum1D, [
812-
{ name: 'shiftX', value: { shift } },
813-
]);
817+
Filters1DManager.applyFilters(
818+
draft.data[index] as Spectrum1D,
819+
[{ name: 'shiftX', value: { shift } }],
820+
{
821+
filterIndex: activeFilterIndex,
822+
forceReapply: activeFilterIndex !== -1,
823+
},
824+
);
814825

815826
updateView(draft, shiftX.domainUpdateRules);
816827
}
@@ -824,9 +835,14 @@ function handleShiftSpectrumAlongXAxis(
824835
searchBy: 'name',
825836
applyFilter: false,
826837
});
827-
Filters2DManager.applyFilters(draft.data[index] as Spectrum2D, [
828-
{ name: 'shift2DX', value: { shift: shiftX } },
829-
]);
838+
Filters2DManager.applyFilters(
839+
draft.data[index] as Spectrum2D,
840+
[{ name: 'shift2DX', value: { shift: shiftX } }],
841+
{
842+
filterIndex: activeFilterIndex,
843+
forceReapply: activeFilterIndex !== -1,
844+
},
845+
);
830846
updateView(draft, shift2DX.domainUpdateRules);
831847
}
832848

@@ -836,9 +852,14 @@ function handleShiftSpectrumAlongXAxis(
836852
searchBy: 'name',
837853
applyFilter: false,
838854
});
839-
Filters2DManager.applyFilters(draft.data[index] as Spectrum2D, [
840-
{ name: 'shift2DY', value: { shift: shiftY } },
841-
]);
855+
Filters2DManager.applyFilters(
856+
draft.data[index] as Spectrum2D,
857+
[{ name: 'shift2DY', value: { shift: shiftY } }],
858+
{
859+
filterIndex: activeFilterIndex,
860+
forceReapply: activeFilterIndex !== -1,
861+
},
862+
);
842863

843864
updateView(draft, shift2DY.domainUpdateRules);
844865
}

src/component/reducer/actions/ToolsActions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ function handleResetSelectedTool(draft: Draft<State>) {
148148
resetSelectedTool(draft);
149149
}
150150
function resetSelectedTool(draft: Draft<State>) {
151-
if (
152-
draft.toolOptions.selectedTool &&
153-
Tools[draft.toolOptions.selectedTool].isFilter
154-
) {
151+
const {
152+
selectedTool,
153+
data: { activeFilterID },
154+
} = draft.toolOptions;
155+
if ((selectedTool && Tools[selectedTool].isFilter) || activeFilterID) {
155156
resetTool(draft, { reset: true, toolId: draft.toolOptions.selectedTool });
156157
}
157158
}

0 commit comments

Comments
 (0)