Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: display the number of spectra in the corresponding panel #2776

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/component/panels/SpectrumsPanel/SpectraPanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { useActiveSpectra } from '../../hooks/useActiveSpectra';
import useSpectrum from '../../hooks/useSpectrum';
import { DisplayerMode } from '../../reducer/Reducer';
import { getSpectraByNucleus } from '../../utility/getSpectraByNucleus';
import DefaultPanelHeader from '../header/DefaultPanelHeader';
import DefaultPanelHeader, {
createFilterLabel,
} from '../header/DefaultPanelHeader';
import { SpectraAutomaticPickingButton } from '../header/SpectraAutomaticPickingButton';

function getMissingProjection(SpectrumsData, activeTab) {
Expand Down Expand Up @@ -56,8 +58,6 @@ function SpectraPanelHeaderInner({
const alert = useAlert();
const dispatch = useDispatch();

const spectra = getSpectraByNucleus(activeTab, data);

const handleDelete = useCallback(() => {
modal.showConfirmDialog({
message: (
Expand Down Expand Up @@ -119,13 +119,14 @@ function SpectraPanelHeaderInner({
payload: {},
});
}

const hasActiveSpectra = activeSpectra && activeSpectra?.length > 0;
const spectraLengthPerTab = getSpectraByNucleus(activeTab, data)?.length;

return (
<DefaultPanelHeader
onDelete={handleDelete}
counter={spectra?.length}
counter={data?.length}
counterLabel={createFilterLabel(data?.length, spectraLengthPerTab)}
deleteToolTip="Delete selected spectra"
disableDelete={!hasActiveSpectra}
showSettingButton
Expand Down Expand Up @@ -156,7 +157,7 @@ function SpectraPanelHeaderInner({
<FaCreativeCommonsSamplingPlus />
</Button.BarButton>
)}
{displayerMode === '1D' && spectra.length > 1 && (
{displayerMode === '1D' && spectraLengthPerTab > 1 && (
<>
<Button.BarButton
tooltipOrientation="horizontal"
Expand Down Expand Up @@ -200,6 +201,7 @@ export default function SpectrumsTabs({
} = useChartData();
const spectrum = useSpectrum() as Spectrum2D;
const activeSpectra = useActiveSpectra();

return (
<MemoizedSpectraPanelHeader
{...{
Expand Down
Loading