Skip to content

Commit 6b6a1f3

Browse files
authored
Merge pull request #182 from NFDI4Chem/custom-workspace
feat: create custom workspace for nmrXiv
2 parents ed1e8d2 + 8fa127a commit 6b6a1f3

3 files changed

Lines changed: 99 additions & 3 deletions

File tree

src/NMRiumWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default function NMRiumWrapper() {
3737
const nmriumRef = useRef<NMRiumRef>(null);
3838
const [data, setDate] = useState<NMRiumData>();
3939

40-
const { workspace, preferences, defaultEmptyMessage } = usePreferences();
40+
const { workspace, preferences, defaultEmptyMessage, customWorkspaces } =
41+
usePreferences();
4142
const dataChangeHandler = useCallback<NMRiumChangeCb>((state, source) => {
4243
events.trigger('data-change', {
4344
state,
@@ -125,6 +126,7 @@ export default function NMRiumWrapper() {
125126
onError={(error) => {
126127
events.trigger('error', error);
127128
}}
129+
customWorkspaces={customWorkspaces}
128130
/>
129131
<AboutUsModal />
130132
</RootLayout>

src/hooks/usePreferences.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { WorkspacePreferences } from 'nmr-load-save';
1+
import { CustomWorkspaces, WorkspacePreferences } from 'nmr-load-save';
22
import { NMRiumWorkspace } from 'nmrium';
33
import { useLayoutEffect, useState } from 'react';
44

5+
import { getNmrXivWorkspace } from '../workspaces/nmrxiv';
6+
57
interface Preferences {
68
preferences: WorkspacePreferences | undefined;
79
workspace: NMRiumWorkspace | undefined;
810
defaultEmptyMessage: string | undefined;
11+
customWorkspaces: CustomWorkspaces;
912
}
1013

1114
const DEFAULT_PREFERENCES = {
1215
preferences: undefined,
1316
workspace: undefined,
1417
defaultEmptyMessage: undefined,
18+
customWorkspaces: {},
1519
};
1620

1721
export function usePreferences() {
@@ -25,19 +29,46 @@ export function usePreferences() {
2529
let preferences: WorkspacePreferences | undefined;
2630
let workspace: NMRiumWorkspace | undefined;
2731
let defaultEmptyMessage: string | undefined;
32+
let hidePanelOnLoad = false;
2833

2934
if (parameters.has('workspace')) {
3035
workspace = parameters.get('workspace') as NMRiumWorkspace;
3136
}
37+
3238
if (parameters.has('preferences')) {
3339
preferences = JSON.parse(parameters.get('preferences') || '');
3440
}
3541

3642
if (parameters.has('defaultEmptyMessage')) {
3743
defaultEmptyMessage = parameters.get('defaultEmptyMessage') as string;
3844
}
39-
setConfiguration({ preferences, workspace, defaultEmptyMessage });
45+
if (parameters.has('hidePanelOnLoad')) {
46+
hidePanelOnLoad =
47+
parameters.get('hidePanelOnLoad')?.toLowerCase() === 'true';
48+
}
49+
50+
const customWorkspaces = createCustomWorkspaces({ hidePanelOnLoad });
51+
setConfiguration({
52+
preferences,
53+
workspace,
54+
defaultEmptyMessage,
55+
customWorkspaces,
56+
});
4057
}, []);
4158

4259
return configuration;
4360
}
61+
62+
interface CreateCustomWorkspacesOptions {
63+
hidePanelOnLoad?: boolean;
64+
}
65+
66+
function createCustomWorkspaces(
67+
options: CreateCustomWorkspacesOptions,
68+
): CustomWorkspaces {
69+
const { hidePanelOnLoad = false } = options;
70+
71+
return {
72+
nmrXiv: getNmrXivWorkspace(hidePanelOnLoad),
73+
};
74+
}

src/workspaces/nmrxiv.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { InnerWorkspace } from 'nmr-load-save';
2+
3+
export function getNmrXivWorkspace(hidePanelOnLoad = false): InnerWorkspace {
4+
return {
5+
version: 1,
6+
label: 'nmrXiv',
7+
general: {
8+
dimmedSpectraOpacity: 0.1,
9+
verticalSplitterPosition: '160px',
10+
verticalSplitterCloseThreshold: 600,
11+
spectraRendering: 'auto',
12+
loggingLevel: 'info',
13+
invert: false,
14+
},
15+
display: {
16+
general: {
17+
experimentalFeatures: { display: true },
18+
hidePanelOnLoad,
19+
hideHelp: true,
20+
hideLogs: true,
21+
hideMaximize: true,
22+
hideWorkspaces: true,
23+
hideGeneralSettings: true,
24+
},
25+
26+
panels: {
27+
spectraPanel: { display: true, open: true },
28+
informationPanel: { display: true, open: false },
29+
peaksPanel: { display: true, open: false },
30+
integralsPanel: { display: true, open: false },
31+
rangesPanel: { display: true, open: false },
32+
structuresPanel: { display: true, open: false },
33+
processingsPanel: { display: true, open: false },
34+
zonesPanel: { display: true, open: false },
35+
summaryPanel: { display: true, open: false },
36+
},
37+
toolBarButtons: {
38+
peakPicking: true,
39+
baselineCorrection: true,
40+
exclusionZones: true,
41+
exportAs: true,
42+
fft: true,
43+
import: true,
44+
integral: true,
45+
multipleSpectraAnalysis: true,
46+
phaseCorrection: true,
47+
rangePicking: true,
48+
realImaginary: true,
49+
slicing: true,
50+
spectraCenterAlignments: true,
51+
spectraStackAlignments: true,
52+
apodization: true,
53+
zeroFilling: true,
54+
zonePicking: true,
55+
zoomOut: true,
56+
zoom: true,
57+
autoRangeAndZonePicking: true,
58+
fftDimension1: true,
59+
fftDimension2: true,
60+
},
61+
},
62+
};
63+
}

0 commit comments

Comments
 (0)