Skip to content

Commit 1e504e5

Browse files
Merge pull request #190 from NFDI4Chem/development
Development
2 parents e5aaa0d + 656058b commit 1e504e5

File tree

11 files changed

+196
-18
lines changed

11 files changed

+196
-18
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@blueprintjs/core": "^5.7.2",
1616
"@blueprintjs/icons": "^5.5.0",
1717
"@emotion/react": "^11.11.1",
18+
"fifo-logger": "^0.6.1",
1819
"filelist-utils": "^1.10.2",
1920
"nmr-load-save": "^0.23.11",
2021
"nmr-processing": "^11.7.0",
@@ -62,4 +63,4 @@
6263
"typescript": "^5.3.3",
6364
"vite": "^5.0.10"
6465
}
65-
}
66+
}

public/data/sample-with-error.zip

12.8 MB
Binary file not shown.

src/NMRiumWrapper.tsx

Lines changed: 11 additions & 6 deletions
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,
@@ -84,13 +85,16 @@ export default function NMRiumWrapper() {
8485
case 'nmrium':
8586
setDate(loadData.data);
8687
break;
87-
case 'file':
88-
loadSpectra({ files: loadData.data });
88+
case 'file': {
89+
const { data: files, activeTab } = loadData;
90+
loadSpectra({ files, activeTab });
8991
break;
90-
case 'url':
91-
loadSpectra({ urls: loadData.data });
92+
}
93+
case 'url': {
94+
const { data: urls, activeTab } = loadData;
95+
loadSpectra({ urls, activeTab });
9296
break;
93-
97+
}
9498
default: {
9599
throw new Error(
96100
`ERROR! Property 'type' accept only nmrium, url or file.`,
@@ -125,6 +129,7 @@ export default function NMRiumWrapper() {
125129
onError={(error) => {
126130
events.trigger('error', error);
127131
}}
132+
customWorkspaces={customWorkspaces}
128133
/>
129134
<AboutUsModal />
130135
</RootLayout>

src/allowed-origins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"https://pregl.ac.rwth-aachen.de",
2626
"https://schindler-ag.rwth-aachen.de",
2727
"10.195.9.248",
28-
"https://dev1.zit.ph.tum.de"
28+
"https://dev1.zit.ph.tum.de",
29+
"org2619.chemie.uni-leipzig.de"
2930
]

src/demo/NMRiumWrapperDemo.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function NMRiumWrapperDemo() {
7272
Test Load URL without extension
7373
</Button.Done>
7474
<Button.Done
75+
style={{ marginRight: '10px' }}
7576
onClick={() => {
7677
void loadFilesFromURLs([
7778
'../data/COSY-12.zip',
@@ -81,12 +82,29 @@ export default function NMRiumWrapperDemo() {
8182
events.trigger('load', {
8283
data: files,
8384
type: 'file',
85+
activeTab: '13C',
8486
});
8587
});
8688
}}
8789
>
8890
Test Load Files
8991
</Button.Done>
92+
<Button.Done
93+
className="logger-btn"
94+
onClick={() => {
95+
void loadFilesFromURLs(['../data/sample-with-error.zip']).then(
96+
(files) => {
97+
events.trigger('load', {
98+
data: files,
99+
type: 'file',
100+
activeTab: '13C',
101+
});
102+
},
103+
);
104+
}}
105+
>
106+
Test Logger
107+
</Button.Done>
90108
</div>
91109

92110
<NMRiumWrapper />

src/events/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ type EventType =
1111
type LoadData =
1212
| {
1313
data: string[];
14+
activeTab?: string;
1415
type: 'url';
1516
}
1617
| {
1718
data: File[];
19+
activeTab?: string;
1820
type: 'file';
1921
}
2022
| {

src/hooks/useLoadSpectra.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1+
import { FifoLogger } from 'fifo-logger';
12
import { fileCollectionFromFiles } from 'filelist-utils';
23
import {
34
read,
45
readFromWebSource,
56
NmriumState,
67
CURRENT_EXPORT_VERSION,
78
ParsingOptions,
9+
ViewState,
810
} from 'nmr-load-save';
911
import { useCallback, useMemo, useState } from 'react';
1012

1113
import events from '../events';
1214
import { getFileNameFromURL } from '../utilities/getFileNameFromURL';
1315
import { isArrayOfString } from '../utilities/isArrayOfString';
1416

17+
type DeepPartial<T> = {
18+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
19+
};
20+
21+
const logger = new FifoLogger({
22+
onChange: (log) => {
23+
if (log && ['error', 'fatal'].includes(log.levelLabel) && log?.error) {
24+
events.trigger('error', log.error);
25+
// eslint-disable-next-line no-console
26+
console.log(log.error);
27+
}
28+
},
29+
});
30+
1531
const PARSING_OPTIONS: Partial<ParsingOptions> = {
1632
onLoadProcessing: { autoProcessing: true },
1733
sourceSelector: { general: { dataSelection: 'preferFT' } },
34+
logger,
1835
};
1936

2037
async function loadSpectraFromFiles(files: File[]) {
@@ -44,7 +61,9 @@ async function loadSpectraFromURLs(urls: string[]) {
4461

4562
type NMRiumData = NmriumState['data'];
4663

47-
type LoadOptions = { urls: string[] } | { files: File[] };
64+
type LoadOptions =
65+
| { urls: string[]; activeTab?: string }
66+
| { files: File[]; activeTab?: string };
4867

4968
interface UseLoadSpectraResult {
5069
data: { version: number; data: NMRiumData };
@@ -54,6 +73,7 @@ interface UseLoadSpectraResult {
5473

5574
export function useLoadSpectra(): UseLoadSpectraResult {
5675
const [data, setData] = useState<NMRiumData>({ spectra: [], molecules: [] });
76+
const [activeTab, setActiveTab] = useState<string>();
5777
const [isLoading, setLoading] = useState<boolean>(false);
5878

5979
const load = useCallback(async (options: LoadOptions) => {
@@ -63,12 +83,14 @@ export function useLoadSpectra(): UseLoadSpectraResult {
6383
if (isArrayOfString(options.urls)) {
6484
const result = await loadSpectraFromURLs(options.urls);
6585
setData(result as NMRiumData);
86+
setActiveTab(options?.activeTab);
6687
} else {
6788
throw new Error('The input must be a valid urls array of string[]');
6889
}
6990
} else if ('files' in options) {
7091
const result = await loadSpectraFromFiles(options.files);
7192
setData(result as NMRiumData);
93+
setActiveTab(options?.activeTab);
7294
}
7395
} catch (error: unknown) {
7496
const loadError = error as Error;
@@ -80,12 +102,16 @@ export function useLoadSpectra(): UseLoadSpectraResult {
80102
}
81103
}, []);
82104

83-
return useMemo(
84-
() => ({
85-
data: { version: CURRENT_EXPORT_VERSION, data },
105+
return useMemo(() => {
106+
let view: DeepPartial<ViewState> = {};
107+
if (activeTab) {
108+
view = { spectra: { activeTab } };
109+
}
110+
111+
return {
112+
data: { version: CURRENT_EXPORT_VERSION, data, view },
86113
load,
87114
isLoading,
88-
}),
89-
[data, isLoading, load],
90-
);
115+
};
116+
}, [activeTab, data, isLoading, load]);
91117
}

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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
hideWorkspaces: true,
22+
hideGeneralSettings: true,
23+
},
24+
25+
panels: {
26+
spectraPanel: { display: true, open: true },
27+
informationPanel: { display: true, open: false },
28+
rangesPanel: { display: true, open: false },
29+
structuresPanel: { display: true, open: false },
30+
processingsPanel: { display: true, open: false },
31+
zonesPanel: { display: true, open: false },
32+
summaryPanel: { display: true, open: false },
33+
},
34+
toolBarButtons: {
35+
baselineCorrection: true,
36+
exclusionZones: true,
37+
exportAs: true,
38+
fft: true,
39+
import: true,
40+
multipleSpectraAnalysis: true,
41+
phaseCorrection: true,
42+
rangePicking: true,
43+
realImaginary: true,
44+
slicing: true,
45+
spectraCenterAlignments: true,
46+
spectraStackAlignments: true,
47+
apodization: true,
48+
zeroFilling: true,
49+
zonePicking: true,
50+
zoomOut: true,
51+
zoom: true,
52+
autoRangeAndZonePicking: true,
53+
fftDimension1: true,
54+
fftDimension2: true,
55+
},
56+
},
57+
};
58+
}

0 commit comments

Comments
 (0)