Skip to content

Commit

Permalink
fix: set the first FT spectrum for 2d projection if none selected
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Nov 28, 2023
1 parent 1995e6d commit cc0ac08
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/component/hooks/useActiveSpectrumIntegralsViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export function useActiveSpectrumIntegralsViewState() {
view: { integrals },
} = useChartData();

if (activeSpectrum?.id && integrals[activeSpectrum?.id]) {
if (
activeSpectrum?.id &&
activeSpectrum?.selected &&

Check failure on line 19 in src/component/hooks/useActiveSpectrumIntegralsViewState.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
integrals[activeSpectrum?.id]
) {
return integrals[activeSpectrum?.id];
} else {
return defaultIntegralsViewState;
Expand Down
6 changes: 5 additions & 1 deletion src/component/hooks/useActiveSpectrumPeaksViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export function useActiveSpectrumPeaksViewState() {
view: { peaks },
} = useChartData();

if (activeSpectrum?.id && peaks[activeSpectrum?.id]) {
if (
activeSpectrum?.id &&
activeSpectrum?.selected &&

Check failure on line 22 in src/component/hooks/useActiveSpectrumPeaksViewState.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
peaks[activeSpectrum?.id]
) {
return peaks[activeSpectrum?.id];
} else {
return defaultPeaksViewState;
Expand Down
6 changes: 5 additions & 1 deletion src/component/hooks/useActiveSpectrumRangesViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export function useActiveSpectrumRangesViewState() {
view: { ranges },
} = useChartData();

if (activeSpectrum?.id && ranges[activeSpectrum?.id]) {
if (
activeSpectrum?.id &&
activeSpectrum?.selected &&

Check failure on line 24 in src/component/hooks/useActiveSpectrumRangesViewState.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
ranges[activeSpectrum?.id]
) {
return ranges[activeSpectrum?.id];
} else {
return defaultRangesViewState;
Expand Down
10 changes: 8 additions & 2 deletions src/component/hooks/useActiveSpectrumStyleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ export default function useActiveSpectrumStyleOptions(

return useMemo(() => {
const index = activeSpectra?.findIndex(
(activeSpectrum) => activeSpectrum.id === id,
(activeSpectrum) => activeSpectrum?.selected && activeSpectrum.id === id,

Check failure on line 21 in src/component/hooks/useActiveSpectrumStyleOptions.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
);
const isActive = !!(activeSpectra?.length === 0 || index !== -1);
let isNoneSelected = false;
isNoneSelected =
activeSpectra?.every((activeSpectrum) => !activeSpectrum?.selected) ||

Check failure on line 25 in src/component/hooks/useActiveSpectrumStyleOptions.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
false;

const isActive =
!!(activeSpectra?.length === 0 || index !== -1) || isNoneSelected;
const opacity = isActive
? 1
: get(preferences.current, 'general.dimmedSpectraOpacity', 0.1);
Expand Down
6 changes: 5 additions & 1 deletion src/component/hooks/useActiveSpectrumZonesViewState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export function useActiveSpectrumZonesViewState() {
view: { zones },
} = useChartData();

if (activeSpectrum?.id && zones[activeSpectrum?.id]) {
if (
activeSpectrum?.id &&
activeSpectrum?.selected &&

Check failure on line 21 in src/component/hooks/useActiveSpectrumZonesViewState.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
zones[activeSpectrum?.id]
) {
return zones[activeSpectrum?.id];
} else {
return defaultZonesViewState;
Expand Down
2 changes: 1 addition & 1 deletion src/component/hooks/useSpectrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function useSpectrum(defaultValue: any = null) {
const activeSpectrum = useActiveSpectrum();

return useMemo<Spectrum>(() => {
if (data && activeSpectrum?.id) {
if (data && activeSpectrum?.id && activeSpectrum?.selected) {

Check failure on line 13 in src/component/hooks/useSpectrum.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-check-types

Property 'selected' does not exist on type 'ActiveSpectrum'.
const datum =
data.find((datum) => datum.id === activeSpectrum.id) || defaultValue;
return datum;
Expand Down
4 changes: 3 additions & 1 deletion src/component/panels/SpectrumsPanel/SpectraTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function getActiveSpectraAsObject(activeSpectra: ActiveSpectrum[] | null) {
const result = {};
if (activeSpectra) {
for (const activeSpectrum of activeSpectra) {
result[activeSpectrum.id] = true;
if (activeSpectrum?.selected) {
result[activeSpectrum.id] = true;
}
}
}
return result;
Expand Down
1 change: 1 addition & 0 deletions src/component/reducer/Reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ZoomHistory } from './helper/ZoomHistoryManager';
export interface ActiveSpectrum {
id: string;
index: number;
selected: boolean;
}

export type DisplayerMode = '1D' | '2D';
Expand Down
1 change: 1 addition & 0 deletions src/component/reducer/actions/SpectrumsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ function handleChangeActiveSpectrum(
newActiveSpectra.push({
id: spectrumId,
index: spectraObj[spectrumId].index,
selected: true,
});
}

Expand Down
17 changes: 9 additions & 8 deletions src/component/reducer/actions/ToolsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,25 +505,26 @@ function setTabActiveSpectrum(draft: Draft<State>, dataGroupByTab) {

if (data.length === 1) {
const index = draft.data.findIndex((datum) => datum.id === data[0].id);
tabActiveSpectrum[tabKey] = [{ id: data[0].id, index }];
tabActiveSpectrum[tabKey] = [{ id: data[0].id, index, selected: true }];
} else {
const tabSpectra = dataGroupByTab[tabKey];
const tabSpectraLength = tabSpectra.length;
if (tabSpectraLength >= 2) {
const FTSpectrums = tabSpectra.filter((d) => !d.info.isFid);
if (
FTSpectrums.length > 0 &&
(nucleusLength === 2 ||
(nucleusLength === 1 && tabSpectraLength !== FTSpectrums.length))
) {
if (FTSpectrums.length > 0) {
const selected =
nucleusLength === 2 ||
(nucleusLength === 1 && tabSpectraLength !== FTSpectrums.length);
const index = draft.data.findIndex(
(datum) => datum.id === FTSpectrums[0].id,
);
tabActiveSpectrum[tabKey] = [{ id: FTSpectrums[0].id, index }];
tabActiveSpectrum[tabKey] = [
{ id: FTSpectrums[0].id, index, selected },
];
} else if (tabSpectraLength - FTSpectrums > 0) {
const id = tabSpectra[0].id;
const index = draft.data.findIndex((datum) => datum.id === id);
tabActiveSpectrum[tabKey] = [{ id, index }];
tabActiveSpectrum[tabKey] = [{ id, index, selected: true }];
} else {
tabActiveSpectrum[tabKey] = null;
}
Expand Down
5 changes: 4 additions & 1 deletion src/component/reducer/helper/getActiveSpectra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { State } from '../Reducer';

export function getActiveSpectra(state: Draft<State> | State) {
const { activeSpectra, activeTab } = state.view.spectra;
const spectra = activeSpectra?.[activeTab]?.filter(
(spectrum) => spectrum?.selected,
);

return activeSpectra?.[activeTab] || null;
return Array.isArray(spectra) && spectra.length > 0 ? spectra : null;
}
2 changes: 1 addition & 1 deletion src/component/reducer/helper/getActiveSpectrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getActiveSpectrum(state: Draft<State> | State) {
const { activeSpectra, activeTab } = state.view.spectra;

const spectra = activeSpectra[activeTab];
if (spectra?.length === 1) {
if (spectra?.length === 1 && spectra[0]?.selected) {
return spectra[0];
}

Expand Down

0 comments on commit cc0ac08

Please sign in to comment.