Skip to content

Commit fb978cd

Browse files
authored
feat: adapt to flat nmrium archive structure (#3811)
1 parent d161f03 commit fb978cd

14 files changed

Lines changed: 109 additions & 109 deletions

File tree

‎package-lock.json‎

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

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
"@emotion/styled": "^11.14.1",
7070
"@hookform/resolvers": "^5.2.2",
7171
"@zakodium/nmr-types": "^0.4.1",
72-
"@zakodium/nmrium-core": "^0.4.7",
73-
"@zakodium/nmrium-core-plugins": "^0.6.6",
72+
"@zakodium/nmrium-core": "^0.4.8",
73+
"@zakodium/nmrium-core-plugins": "^0.6.8",
7474
"@zakodium/pdnd-esm": "^1.0.2",
7575
"@zip.js/zip.js": "^2.8.10",
7676
"cheminfo-font": "^1.13.1",
@@ -82,7 +82,7 @@
8282
"dlv": "^1.1.3",
8383
"eventemitter3": "^5.0.1",
8484
"fifo-logger": "^2.0.1",
85-
"file-collection": "^6.2.0",
85+
"file-collection": "^6.2.1",
8686
"file-saver": "^2.0.5",
8787
"immer": "^10.2.0",
8888
"lodash": "^4.17.21",

‎src/component/hooks/useExport.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function useExport() {
9494
const archive = await core.serializeNmriumArchive({
9595
molecules: state.molecules,
9696
spectra: state.data,
97-
fileCollections: state.fileCollections,
97+
aggregator: state.aggregator,
9898
includeData: options.include.dataType === 'SELF_CONTAINED',
9999
serializedState: blob,
100100
});

‎src/component/loader/useLoadFiles.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,28 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
4242
let parseMetaFileResult: ParseResult<any> | null = null;
4343
const { onLoadProcessing, spectraColors, defaultMoleculeSettings } =
4444
workspacePreferences;
45-
const { nmrLoaders: sourceSelector } = preferences.current;
45+
const { nmrLoaders: selector } = preferences.current;
4646

4747
const parsingOptions: Partial<ParsingOptions> = {
48-
sourceSelector,
48+
selector,
4949
logger: logger.child({ context: 'nmr-processing' }),
5050
onLoadProcessing,
5151
experimentalFeatures,
5252
};
5353

54+
let aggregator: FileCollection | undefined;
5455
let fileCollection: FileCollection | undefined;
55-
let fileCollections: Map<string, FileCollection> | undefined;
56+
let selectorRoot: string | undefined;
57+
let resetSourceObject = false;
58+
5659
if (files.length === 1 && files[0].name.endsWith('.nmrium.zip')) {
57-
[nmriumState, fileCollections] = await core.readNMRiumArchive(
60+
const [state, ium] = await core.readNMRiumArchive(
5861
files[0].stream(),
5962
parsingOptions,
6063
);
64+
nmriumState = state;
6165
containsNmrium = true;
66+
aggregator = ium;
6267
} else {
6368
for (const file of files) {
6469
if (file.name.endsWith('.nmrium.zip')) {
@@ -85,10 +90,13 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
8590
if (metaFile) {
8691
parseMetaFileResult = await parseMetaFile(metaFile);
8792
}
88-
({ nmriumState, containsNmrium } = await core.read(
93+
({ nmriumState, containsNmrium, selectorRoot } = await core.read(
8994
fileCollection,
9095
parsingOptions,
9196
));
97+
if (containsNmrium) {
98+
resetSourceObject = true;
99+
}
92100
}
93101

94102
if (nmriumState.settings) {
@@ -107,8 +115,10 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
107115
containsNmrium,
108116
parseMetaFileResult,
109117
spectraColors,
118+
aggregator,
110119
fileCollection,
111-
fileCollections,
120+
selectorRoot,
121+
resetSourceObject,
112122
defaultMoleculeSettings,
113123
},
114124
});

‎src/component/main/NMRiumStateProvider.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export default function NMRiumStateProvider(props: NMRiumStateProviderProps) {
7878
sources,
7979
view,
8080
actionType,
81-
fileCollections: {},
8281
},
8382
{ current: workspaces[workspace.current] },
8483
{ serialize: false, exportTarget: 'onChange' },
@@ -120,7 +119,7 @@ export default function NMRiumStateProvider(props: NMRiumStateProviderProps) {
120119
void core
121120
.readNMRiumObject(nmriumData)
122121
.then((result) => {
123-
const [nmriumState, fileCollections] = result;
122+
const [nmriumState, aggregator] = result;
124123
if (nmriumState?.settings) {
125124
dispatchPreferences({
126125
type: 'SET_WORKSPACE',
@@ -132,7 +131,7 @@ export default function NMRiumStateProvider(props: NMRiumStateProviderProps) {
132131
}
133132
dispatch({
134133
type: 'INITIATE',
135-
payload: { nmriumState, fileCollections },
134+
payload: { nmriumState, aggregator },
136135
});
137136
})
138137
.catch((error: unknown) => {

‎src/component/modal/LoadJCAMPModal.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,19 @@ function InnerLoadJCAMPModal({ onCloseDialog }: InnerLoadJCAMPModalProps) {
6666
});
6767
const { pathname, origin } = new URL(url);
6868
try {
69-
const [nmriumState, fileCollection] = await core.readFromWebSource({
70-
entries: [{ relativePath: pathname, baseURL: origin }],
71-
});
69+
const [nmriumState, fileCollection, selectorRoot] =
70+
await core.readFromWebSource({
71+
entries: [{ relativePath: pathname, baseURL: origin }],
72+
});
7273

7374
dispatch({
7475
type: 'LOAD_DROP_FILES',
75-
payload: { nmriumState, resetSourceObject: false, fileCollection },
76+
payload: {
77+
nmriumState,
78+
resetSourceObject: false,
79+
fileCollection,
80+
selectorRoot,
81+
},
7682
});
7783
} catch {
7884
toaster.show({ message: `Failed to load ${url}`, intent: 'danger' });

‎src/component/modal/SaveAsModal.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Radio,
66
RadioGroup,
77
} from '@blueprintjs/core';
8+
import { useMemo } from 'react';
89
import { Controller, useForm } from 'react-hook-form';
910

1011
import type { ExportOptions } from '../../data/SpectraManager.js';
@@ -58,7 +59,7 @@ function SaveAsModal(props: SaveAsModalProps) {
5859
}
5960
function InnerSaveAsModal(props: InnerSaveAsModalProps) {
6061
const { onCloseDialog } = props;
61-
const { sources, data } = useChartData();
62+
const { sources, data, aggregator } = useChartData();
6263
const { saveHandler } = useExport();
6364
const experimentalFlagEnabled = useCheckExperimentalFeature();
6465

@@ -72,6 +73,11 @@ function InnerSaveAsModal(props: InnerSaveAsModalProps) {
7273
const { handleSubmit, control, register } = useForm({
7374
defaultValues: { ...INITIAL_VALUE, name: fileName },
7475
});
76+
77+
const containsLinkedFiles = useMemo(() => {
78+
return aggregator.sources.some((s) => !s.baseURL?.startsWith('ium:'));
79+
}, [aggregator]);
80+
7581
return (
7682
<Dialog
7783
isOpen
@@ -129,7 +135,7 @@ function InnerSaveAsModal(props: InnerSaveAsModalProps) {
129135
{experimentalFlagEnabled && (
130136
<Radio
131137
label="Full data (external data linked, experimental)"
132-
disabled={Object.keys(sources).length === 0}
138+
disabled={!containsLinkedFiles}
133139
value={
134140
DataExportOptions.SELF_CONTAINED_EXTERNAL_DATASOURCE
135141
}

‎src/component/reducer/Reducer.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BaselineCorrectionZone } from '@zakodium/nmr-types';
22
import type { Spectrum, ViewState } from '@zakodium/nmrium-core';
3-
import type { FileCollection, Source } from 'file-collection';
3+
import type { Source } from 'file-collection';
4+
import { FileCollection } from 'file-collection';
45
import type { Draft } from 'immer';
56
import { original, produce } from 'immer';
67
import type { CorrelationData } from 'nmr-correlation';
@@ -114,7 +115,7 @@ export function getDefaultViewState(): ViewState {
114115
export const getInitialState = (): State => ({
115116
actionType: 'INITIALIZE_NMRIUM',
116117
sources: {},
117-
fileCollections: {},
118+
aggregator: new FileCollection(),
118119
data: [],
119120
tempData: null,
120121
xDomain: [],
@@ -192,15 +193,20 @@ export interface State {
192193

193194
/**
194195
* web source of data
195-
* Record key is identifier of the source (stored in spectra)
196+
* Record key is an identifier of the source (stored in spectra)
197+
*
198+
* Is needed until we remove the support of the old nmrium format
196199
*/
197200
sources: Record<string, Source>;
198201

199202
/**
200-
* File collections of the loaded files
201-
* Record key is identifier of the fileCollection (stored in spectra)
203+
* Aggregation of file collections used to load the data
204+
* - external data sources (web-source, import jdx from url, ...)
205+
* - multiples files open / drag and drop
206+
*
207+
* Each of them is separated in an uuid folder
202208
*/
203-
fileCollections: Record<string, FileCollection>;
209+
aggregator: FileCollection;
204210

205211
/**
206212
* spectra list (1d and 2d)

0 commit comments

Comments
 (0)