Skip to content

Commit

Permalink
refactor: move axis preferences to general settings
Browse files Browse the repository at this point in the history
chore: update to nmr-load-save version 0.31.0
refactor: 'Formatting' tab preferences and rename it to 'Nuclei'
refactor:  formatting object in the workspace and the predefined workspaces
  • Loading branch information
hamed-musallam committed May 16, 2024
1 parent d0bab9b commit 33a46fa
Show file tree
Hide file tree
Showing 25 changed files with 970 additions and 1,024 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions src/component/EventsTrackers/KeysListenerTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useModal } from '../elements/popup/Modal';
import { HighlightEventSource, useHighlightData } from '../highlight/index';
import { useCheckToolsVisibility } from '../hooks/useCheckToolsVisibility';
import useExport from '../hooks/useExport';
import { usePanelPreferences } from '../hooks/usePanelPreferences';
import useToolsFunctions from '../hooks/useToolsFunctions';
import SaveAsModal from '../modal/SaveAsModal';
import { options } from '../toolbar/ToolTypes';
Expand All @@ -33,7 +32,10 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
},
} = useChartData();
const dispatch = useDispatch();
const { dispatch: dispatchPreferences } = usePreferences();
const {
dispatch: dispatchPreferences,
current: { nuclei },
} = usePreferences();
const toaster = useToaster();
const modal = useModal();
const openLoader = useLoader();
Expand All @@ -51,7 +53,6 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
const isToolVisible = useCheckToolsVisibility();

const { highlight, remove } = useHighlightData();
const { axisDomain } = usePanelPreferences('spectra', activeTab);

const mouseIsOverDisplayer = useRef(false);
useEffect(() => {
Expand Down Expand Up @@ -445,7 +446,10 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
if (e.shiftKey) {
switch (e.key) {
case 'F': {
dispatch({ type: 'SET_AXIS_DOMAIN', payload: { axisDomain } });
dispatch({
type: 'SET_AXIS_DOMAIN',
payload: { nucleiPreferences: nuclei },
});
break;
}
default:
Expand All @@ -470,12 +474,12 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
[
alignSpectraVerticallyHandler,
allow1DTool,
axisDomain,
changeDisplayViewModeHandler,
dispatch,
handleChangeOption,
handleFullZoomOut,
isToolVisible,
nuclei,
openLoader,
openSaveAsDialog,
saveAsJSONHandler,
Expand Down
35 changes: 20 additions & 15 deletions src/component/hooks/useFormatNumberByNucleus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { formatNumber } from '../utility/formatNumber';

export type ReturnFunction = (
value?: number | string,
formatKey?: string,
// eslint-disable-next-line @typescript-eslint/ban-types
formatKey?: 'ppmFormat' | 'hzFormat' | (string & {}),
prefix?: string,
suffix?: string,
) => string;
Expand All @@ -15,22 +16,26 @@ export function useFormatNumberByNucleus(nucleus?: string[]): ReturnFunction[];
export function useFormatNumberByNucleus(nucleus?: string): ReturnFunction;
export function useFormatNumberByNucleus(nucleus?: string | string[]) {
const preferences = usePreferences();
const nucleusByKey = lodashGet(preferences.current, `formatting.nuclei`, {
ppm: '0.0',
hz: '0.0',
});
const nucleiPreferences = lodashGet(preferences.current, `nuclei`, []);

return useMemo(() => {
function formatFun(n: string) {
return (value: any, formatKey = 'ppm', prefix = '', suffix = '') => {
return formatNumber(
value,
nucleusByKey?.[n.toLowerCase()]?.[formatKey],
{
prefix,
suffix,
},
);
const preferences = nucleiPreferences?.find(
({ nucleus }) => nucleus.toLowerCase() === n.toLowerCase(),
) || {
ppmFormat: '0.0',
hzFormat: '0.0',
};
return (
value: any,
formatKey = 'ppmFormat',
prefix = '',
suffix = '',
) => {
return formatNumber(value, preferences[formatKey], {
prefix,
suffix,
});
};
}

Expand All @@ -45,5 +50,5 @@ export function useFormatNumberByNucleus(nucleus?: string | string[]) {
} else {
throw new Error('nuclus must be string or array of string');
}
}, [nucleus, nucleusByKey]);
}, [nucleiPreferences, nucleus]);
}
4 changes: 1 addition & 3 deletions src/component/hooks/usePanelPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
} from '../reducer/preferences/panelsPreferencesDefaultValues';
import { getValue } from '../utility/LocalStorage';

const basePath = 'formatting.panels';

type Panel =
| 'spectra'
| 'peaks'
Expand Down Expand Up @@ -82,7 +80,7 @@ function getPanelPreferences(
nucleus?: string,
returnOnlyNucleusPreferences = false,
) {
const panelPath = `${basePath}.${panelKey}`;
const panelPath = `panels.${panelKey}`;
let path = panelPath;

if (nucleus) {
Expand Down
8 changes: 2 additions & 6 deletions src/component/modal/setting/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import PredefinedWorkspaces from '../../workspaces';
import WorkspaceItem from './WorkspaceItem';
import DatabasesTabContent from './settings-tabs/DatabasesTabContent';
import DisplayTabContent from './settings-tabs/DisplayTabContent';
import FormattingTabContent from './settings-tabs/FormattingTabContent';
import GeneralTabContent from './settings-tabs/GeneralTabContent';
import ImportationFiltersTabContent from './settings-tabs/ImportationFiltersTabContent';
import InfoBlockTabContent from './settings-tabs/InfoBlockTabContent';
import NucleiTabContent from './settings-tabs/NucleiTabContent';
import OnLoadProcessingTabContent from './settings-tabs/OnLoadProcessingTabContent';
import SpectraColorsTabContent from './settings-tabs/SpectraColorsTabContent';
import ToolsTabContent from './settings-tabs/ToolsTabContent';
Expand Down Expand Up @@ -361,11 +361,7 @@ function GeneralSettingsModal({ height }: GeneralSettingsModalProps) {
panel={<GeneralTabContent />}
/>

<Tab
title="Formatting"
id="formatting"
panel={<FormattingTabContent />}
/>
<Tab title="Nuclei" id="nuclei" panel={<NucleiTabContent />} />

<Tab
title="Panels"
Expand Down
150 changes: 0 additions & 150 deletions src/component/modal/setting/settings-tabs/FormattingTabContent.tsx

This file was deleted.

Loading

0 comments on commit 33a46fa

Please sign in to comment.