Skip to content

Commit

Permalink
feat: create custom workspace for nmrXiv
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Jan 4, 2024
1 parent ed1e8d2 commit 8fa127a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/NMRiumWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default function NMRiumWrapper() {
const nmriumRef = useRef<NMRiumRef>(null);
const [data, setDate] = useState<NMRiumData>();

const { workspace, preferences, defaultEmptyMessage } = usePreferences();
const { workspace, preferences, defaultEmptyMessage, customWorkspaces } =
usePreferences();
const dataChangeHandler = useCallback<NMRiumChangeCb>((state, source) => {
events.trigger('data-change', {
state,
Expand Down Expand Up @@ -125,6 +126,7 @@ export default function NMRiumWrapper() {
onError={(error) => {
events.trigger('error', error);
}}
customWorkspaces={customWorkspaces}
/>
<AboutUsModal />
</RootLayout>
Expand Down
35 changes: 33 additions & 2 deletions src/hooks/usePreferences.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { WorkspacePreferences } from 'nmr-load-save';
import { CustomWorkspaces, WorkspacePreferences } from 'nmr-load-save';
import { NMRiumWorkspace } from 'nmrium';
import { useLayoutEffect, useState } from 'react';

import { getNmrXivWorkspace } from '../workspaces/nmrxiv';

interface Preferences {
preferences: WorkspacePreferences | undefined;
workspace: NMRiumWorkspace | undefined;
defaultEmptyMessage: string | undefined;
customWorkspaces: CustomWorkspaces;
}

const DEFAULT_PREFERENCES = {
preferences: undefined,
workspace: undefined,
defaultEmptyMessage: undefined,
customWorkspaces: {},
};

export function usePreferences() {
Expand All @@ -25,19 +29,46 @@ export function usePreferences() {
let preferences: WorkspacePreferences | undefined;
let workspace: NMRiumWorkspace | undefined;
let defaultEmptyMessage: string | undefined;
let hidePanelOnLoad = false;

if (parameters.has('workspace')) {
workspace = parameters.get('workspace') as NMRiumWorkspace;
}

if (parameters.has('preferences')) {
preferences = JSON.parse(parameters.get('preferences') || '');
}

if (parameters.has('defaultEmptyMessage')) {
defaultEmptyMessage = parameters.get('defaultEmptyMessage') as string;
}
setConfiguration({ preferences, workspace, defaultEmptyMessage });
if (parameters.has('hidePanelOnLoad')) {
hidePanelOnLoad =
parameters.get('hidePanelOnLoad')?.toLowerCase() === 'true';
}

const customWorkspaces = createCustomWorkspaces({ hidePanelOnLoad });
setConfiguration({
preferences,
workspace,
defaultEmptyMessage,
customWorkspaces,
});
}, []);

return configuration;
}

interface CreateCustomWorkspacesOptions {
hidePanelOnLoad?: boolean;
}

function createCustomWorkspaces(
options: CreateCustomWorkspacesOptions,
): CustomWorkspaces {
const { hidePanelOnLoad = false } = options;

return {
nmrXiv: getNmrXivWorkspace(hidePanelOnLoad),
};
}
63 changes: 63 additions & 0 deletions src/workspaces/nmrxiv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { InnerWorkspace } from 'nmr-load-save';

export function getNmrXivWorkspace(hidePanelOnLoad = false): InnerWorkspace {
return {
version: 1,
label: 'nmrXiv',
general: {
dimmedSpectraOpacity: 0.1,
verticalSplitterPosition: '160px',
verticalSplitterCloseThreshold: 600,
spectraRendering: 'auto',
loggingLevel: 'info',
invert: false,
},
display: {
general: {
experimentalFeatures: { display: true },
hidePanelOnLoad,
hideHelp: true,
hideLogs: true,
hideMaximize: true,
hideWorkspaces: true,
hideGeneralSettings: true,
},

panels: {
spectraPanel: { display: true, open: true },
informationPanel: { display: true, open: false },
peaksPanel: { display: true, open: false },
integralsPanel: { display: true, open: false },
rangesPanel: { display: true, open: false },
structuresPanel: { display: true, open: false },
processingsPanel: { display: true, open: false },
zonesPanel: { display: true, open: false },
summaryPanel: { display: true, open: false },
},
toolBarButtons: {
peakPicking: true,
baselineCorrection: true,
exclusionZones: true,
exportAs: true,
fft: true,
import: true,
integral: true,
multipleSpectraAnalysis: true,
phaseCorrection: true,
rangePicking: true,
realImaginary: true,
slicing: true,
spectraCenterAlignments: true,
spectraStackAlignments: true,
apodization: true,
zeroFilling: true,
zonePicking: true,
zoomOut: true,
zoom: true,
autoRangeAndZonePicking: true,
fftDimension1: true,
fftDimension2: true,
},
},
};
}

0 comments on commit 8fa127a

Please sign in to comment.