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: rename relative column header in ranges #3376

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
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
84 changes: 46 additions & 38 deletions src/component/1d/FloatingRanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { usePanelPreferences } from '../hooks/usePanelPreferences.js';
import { useSVGUnitConverter } from '../hooks/useSVGUnitConverter.js';
import useSpectraByActiveNucleus from '../hooks/useSpectraPerNucleus.js';
import { useCheckExportStatus } from '../hooks/useViewportSize.js';
import { extractChemicalElement } from '../utility/extractChemicalElement.js';
import { formatNumber } from '../utility/formatNumber.js';

const ReactRnd = styled(Rnd)`
Expand Down Expand Up @@ -47,44 +48,6 @@ interface RangeItem {
coupling: string;
}

const columns: Array<SVGTableColumn<RangeItem>> = [
{
accessorKey: 'delta',
header: 'δ (ppm)',
width: 100,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'integration',
header: 'Rel. H',
width: 60,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'multiplicity',
header: 'Mult.',
width: 60,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'coupling',
header: 'J (Hz)',
width: 120,
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
];

function useMapRanges(ranges: Ranges['values']) {
const output: RangeItem[] = [];
const {
Expand Down Expand Up @@ -143,10 +106,55 @@ function useMapRanges(ranges: Ranges['values']) {
}
function InnerSVGRangesTable(props: RangesTableProps) {
const { ranges } = props;
const {
view: {
spectra: { activeTab },
},
} = useChartData();
const data = useMapRanges(ranges);

if (!data) return null;

const element = extractChemicalElement(activeTab);

const columns: Array<SVGTableColumn<RangeItem>> = [
{
accessorKey: 'delta',
header: 'δ (ppm)',
width: 100,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'integration',
header: `Rel. ${element}`,
width: 60,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'multiplicity',
header: 'Mult.',
width: 60,
rowSpanGroupKey: 'id',
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
{
accessorKey: 'coupling',
header: 'J (Hz)',
width: 120,
headerTextProps: { fontWeight: 'bold' },
cellBoxProps: { stroke: '#dedede', fill: 'white', fillOpacity: 0.8 },
headerBoxProps: { stroke: '#dedede', fill: '#E5E8EB' },
},
];

return <SVGTable<RangeItem> data={data} columns={columns} />;
}

Expand Down
3 changes: 2 additions & 1 deletion src/component/panels/RangesPanel/RangesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EmptyText } from '../../elements/EmptyText.js';
import type { TableContextMenuProps } from '../../elements/ReactTable/ReactTable.js';
import useTableSortBy from '../../hooks/useTableSortBy.js';
import { EditRangeModal } from '../../modal/editRange/EditRangeModal.js';
import { extractChemicalElement } from '../../utility/extractChemicalElement.js';
import { NoDataForFid } from '../extra/placeholder/NoDataForFid.js';

import RangesTableRow from './RangesTableRow.js';
Expand Down Expand Up @@ -76,7 +77,7 @@ function RangesTable({
preferences,
info,
}: RangesTableProps) {
const element = activeTab?.replace(/\d/g, '');
const element = extractChemicalElement(activeTab);
const { items: sortedData, isSortedDesc, onSort } = useTableSortBy(tableData);
const data = useMapRanges(sortedData);

Expand Down
3 changes: 3 additions & 0 deletions src/component/utility/extractChemicalElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function extractChemicalElement(isotope: string) {
return isotope?.replace(/\d/g, '');
}
Loading