Skip to content

Commit b1407f4

Browse files
Merge pull request #176 from NFDI4Chem/development
Development
2 parents 34b6505 + 2e609df commit b1407f4

File tree

11 files changed

+2219
-1871
lines changed

11 files changed

+2219
-1871
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build
55
src/*.json
66
vite.config.*
77
lib
8+
coverage

package-lock.json

Lines changed: 1269 additions & 894 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
"version": "1.0.0",
44
"private": false,
55
"license": "MIT",
6-
"main": "lib-cjs/NMRiumWrapper.js",
6+
"main": "lib/NMRiumWrapper.js",
77
"module": "lib/NMRiumWrapper.js",
88
"files": [
9-
"lib",
10-
"lib-cjs"
9+
"lib"
1110
],
1211
"volta": {
1312
"node": "20.2.0"
1413
},
1514
"dependencies": {
15+
"@blueprintjs/core": "^5.7.2",
16+
"@blueprintjs/icons": "^5.5.0",
1617
"@emotion/react": "^11.11.1",
1718
"filelist-utils": "^1.10.2",
18-
"nmr-load-save": "^0.21.0",
19-
"nmr-processing": "^11.2.0",
20-
"nmrium": "0.44.1-pre.1696502379",
21-
"react-science": "^0.27.0",
22-
"vite-plugin-pwa": "^0.16.5"
19+
"nmr-load-save": "^0.23.11",
20+
"nmr-processing": "^11.7.0",
21+
"nmrium": "^0.46.1",
22+
"react-science": "^0.32.2",
23+
"vite-plugin-pwa": "^0.17.4"
2324
},
2425
"scripts": {
2526
"start": "vite --host localhost --port 3000 --open",
@@ -29,36 +30,36 @@
2930
"test": "jest --coverage",
3031
"eslint": "eslint . --cache",
3132
"eslint-fix": "npm run eslint -- --fix",
32-
"compile": "tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
33+
"compile": "tsc --project tsconfig.esm.json",
3334
"check-types": "tsc --project tsconfig.esm.json",
3435
"prettier": "prettier --check src",
3536
"prettier-write": "prettier --write src",
3637
"test-e2e": "playwright test --project chromium",
3738
"test-e2e-server": "serve -l tcp://localhost:3000 build"
3839
},
3940
"devDependencies": {
40-
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
41-
"@babel/preset-react": "^7.22.15",
42-
"@babel/preset-typescript": "^7.23.0",
43-
"@playwright/test": "^1.38.1",
41+
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
42+
"@babel/preset-react": "^7.23.3",
43+
"@babel/preset-typescript": "^7.23.3",
44+
"@playwright/test": "^1.40.1",
4445
"@simbathesailor/use-what-changed": "^2.0.0",
45-
"@types/jest": "^29.5.5",
46-
"@types/node": "^20.8.2",
47-
"@types/react": "^18.2.25",
48-
"@types/react-dom": "^18.2.10",
46+
"@types/jest": "^29.5.11",
47+
"@types/node": "^20.10.5",
48+
"@types/react": "^18.2.45",
49+
"@types/react-dom": "^18.2.18",
4950
"@types/react-router-dom": "^5.3.3",
50-
"@vitejs/plugin-react-swc": "^3.4.0",
51+
"@vitejs/plugin-react-swc": "^3.5.0",
5152
"cross-env": "^7.0.3",
52-
"eslint": "^8.50.0",
53-
"eslint-config-cheminfo-react": "^10.0.0",
54-
"eslint-config-cheminfo-typescript": "^12.0.4",
53+
"eslint": "^8.56.0",
54+
"eslint-config-cheminfo-react": "^10.1.0",
55+
"eslint-config-cheminfo-typescript": "^12.1.0",
5556
"jest": "^29.7.0",
56-
"prettier": "3.0.3",
57+
"prettier": "3.1.1",
5758
"react": "^18.2.0",
5859
"react-dom": "^18.2.0",
59-
"react-router-dom": "^6.16.0",
60+
"react-router-dom": "^6.21.0",
6061
"serve": "^14.2.1",
61-
"typescript": "^5.2.2",
62-
"vite": "^4.4.11"
62+
"typescript": "^5.3.3",
63+
"vite": "^5.0.10"
6364
}
64-
}
65+
}

src/NMRiumWrapper.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export default function NMRiumWrapper() {
3939

4040
const { workspace, preferences, defaultEmptyMessage } = usePreferences();
4141
const dataChangeHandler = useCallback<NMRiumChangeCb>((state, source) => {
42-
events.trigger('data-change', { state, source });
42+
events.trigger('data-change', {
43+
state,
44+
source,
45+
});
4346
}, []);
4447

4548
const { load: loadSpectra, isLoading, data: loadedData } = useLoadSpectra();
@@ -82,10 +85,10 @@ export default function NMRiumWrapper() {
8285
setDate(loadData.data);
8386
break;
8487
case 'file':
85-
void loadSpectra({ files: loadData.data });
88+
loadSpectra({ files: loadData.data });
8689
break;
8790
case 'url':
88-
void loadSpectra({ urls: loadData.data });
91+
loadSpectra({ urls: loadData.data });
8992
break;
9093

9194
default: {
@@ -119,6 +122,9 @@ export default function NMRiumWrapper() {
119122
preferences={preferences}
120123
workspace={workspace}
121124
emptyText={defaultEmptyMessage}
125+
onError={(error) => {
126+
events.trigger('error', error);
127+
}}
122128
/>
123129
<AboutUsModal />
124130
</RootLayout>

src/events/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ interface DataChange {
4040
type EventData<T extends EventType> = T extends 'data-change'
4141
? DataChange
4242
: T extends 'load'
43-
? LoadData
44-
: T extends 'action-request'
45-
? ActionRequest
46-
: T extends 'action-response'
47-
? ActionResponse
48-
: T extends 'error'
49-
? Error
50-
: never;
43+
? LoadData
44+
: T extends 'action-request'
45+
? ActionRequest
46+
: T extends 'action-response'
47+
? ActionResponse
48+
: T extends 'error'
49+
? Error
50+
: never;
5151
export type { EventType, EventData };

src/hooks/useLoadSpectra.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@ import {
44
readFromWebSource,
55
NmriumState,
66
CURRENT_EXPORT_VERSION,
7+
ParsingOptions,
78
} from 'nmr-load-save';
89
import { useCallback, useMemo, useState } from 'react';
910

1011
import events from '../events';
11-
import { appendFilters } from '../utilities/appendFilters';
1212
import { getFileNameFromURL } from '../utilities/getFileNameFromURL';
1313
import { isArrayOfString } from '../utilities/isArrayOfString';
1414

15+
const PARSING_OPTIONS: Partial<ParsingOptions> = {
16+
onLoadProcessing: { autoProcessing: true },
17+
sourceSelector: { general: { dataSelection: 'preferFT' } },
18+
};
19+
1520
async function loadSpectraFromFiles(files: File[]) {
1621
const fileCollection = await fileCollectionFromFiles(files);
1722

1823
const {
1924
nmriumState: { data },
20-
} = await read(fileCollection);
25+
} = await read(fileCollection, PARSING_OPTIONS);
2126
return data;
2227
}
2328

@@ -33,48 +38,47 @@ async function loadSpectraFromURLs(urls: string[]) {
3338
return { relativePath: path, baseURL: refURL.origin };
3439
}, []);
3540

36-
const { data } = await readFromWebSource({ entries });
41+
const { data } = await readFromWebSource({ entries }, PARSING_OPTIONS);
3742
return data;
3843
}
3944

4045
type NMRiumData = NmriumState['data'];
4146

42-
export function useLoadSpectra() {
47+
type LoadOptions = { urls: string[] } | { files: File[] };
48+
49+
interface UseLoadSpectraResult {
50+
data: { version: number; data: NMRiumData };
51+
load: (options: LoadOptions) => void;
52+
isLoading: boolean;
53+
}
54+
55+
export function useLoadSpectra(): UseLoadSpectraResult {
4356
const [data, setData] = useState<NMRiumData>({ spectra: [], molecules: [] });
4457
const [isLoading, setLoading] = useState<boolean>(false);
4558

46-
const load = useCallback(
47-
async (options: { urls: string[] } | { files: File[] }) => {
48-
setLoading(true);
49-
try {
50-
if ('urls' in options) {
51-
if (isArrayOfString(options.urls)) {
52-
const result = await loadSpectraFromURLs(options.urls);
53-
if (result?.spectra) {
54-
appendFilters(result?.spectra);
55-
}
56-
setData(result as NMRiumData);
57-
} else {
58-
throw new Error('The input must be a valid urls array of string[]');
59-
}
60-
} else if ('files' in options) {
61-
const result = await loadSpectraFromFiles(options.files);
62-
if (result?.spectra) {
63-
appendFilters(result?.spectra);
64-
}
59+
const load = useCallback(async (options: LoadOptions) => {
60+
setLoading(true);
61+
try {
62+
if ('urls' in options) {
63+
if (isArrayOfString(options.urls)) {
64+
const result = await loadSpectraFromURLs(options.urls);
6565
setData(result as NMRiumData);
66+
} else {
67+
throw new Error('The input must be a valid urls array of string[]');
6668
}
67-
} catch (error: unknown) {
68-
const loadError = error as Error;
69-
events.trigger('error', loadError);
70-
// eslint-disable-next-line no-console
71-
console.log(error);
72-
} finally {
73-
setLoading(false);
69+
} else if ('files' in options) {
70+
const result = await loadSpectraFromFiles(options.files);
71+
setData(result as NMRiumData);
7472
}
75-
},
76-
[],
77-
);
73+
} catch (error: unknown) {
74+
const loadError = error as Error;
75+
events.trigger('error', loadError);
76+
// eslint-disable-next-line no-console
77+
console.log(error);
78+
} finally {
79+
setLoading(false);
80+
}
81+
}, []);
7882

7983
return useMemo(
8084
() => ({

src/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'react-science/styles/preflight.css';
2+
import '@blueprintjs/core/lib/css/blueprint.css';
3+
import '@blueprintjs/icons/lib/css/blueprint-icons.css';
24

35
import { createRoot } from 'react-dom/client';
46
import { HashRouter as Router, Route, Routes } from 'react-router-dom';
@@ -21,10 +23,6 @@ const updateSW = registerSW({
2123
void updateSW(true);
2224
}
2325
},
24-
onOfflineReady() {
25-
// eslint-disable-next-line no-alert
26-
window.alert('NMRium wrapper is ready to run in offline mode');
27-
},
2826
});
2927

3028
const root = createRoot(rootContainer);

src/utilities/appendFilters.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)