nmrium 0.38.2 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
- package/lib/component/EventsTrackers/KeysListenerTracker.js +90 -67
- package/lib/component/NMRium.d.ts +1 -0
- package/lib/component/NMRium.js +4 -2
- package/lib/component/context/LoggerContext.js +5 -0
- package/lib/component/context/PreferencesContext.d.ts +4 -2
- package/lib/component/elements/formik/FormikError.d.ts +8 -0
- package/lib/component/elements/formik/FormikError.js +22 -0
- package/lib/component/hooks/useSaveSettings.js +18 -16
- package/lib/component/modal/LoadJCAMPModal.js +41 -28
- package/lib/component/modal/PredictSpectraModal.js +12 -2
- package/lib/component/modal/editRange/EditRangeModal.d.ts +7 -6
- package/lib/component/modal/editRange/EditRangeModal.js +33 -13
- package/lib/component/modal/setting/GeneralSettings.js +1 -1
- package/lib/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
- package/lib/component/panels/Panels.js +2 -2
- package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.d.ts +1 -1
- package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
- package/lib/component/panels/predictionPanel/PredictionPanel.js +3 -1
- package/lib/component/reducer/actions/DatabaseActions.js +6 -4
- package/lib/component/reducer/actions/DomainActions.js +3 -0
- package/lib/component/reducer/actions/IntegralsActions.js +3 -1
- package/lib/component/reducer/actions/SpectrumsActions.js +6 -6
- package/lib/component/reducer/actions/ToolsActions.js +3 -32
- package/lib/component/reducer/actions/ZonesActions.js +2 -4
- package/lib/component/reducer/helper/ZoomHistoryManager.d.ts +8 -0
- package/lib/component/reducer/helper/ZoomHistoryManager.js +35 -0
- package/lib/component/reducer/preferences/actions/addWorkspace.js +2 -2
- package/lib/component/reducer/preferences/preferencesReducer.d.ts +2 -2
- package/lib/data/PredictionManager.d.ts +3 -1
- package/lib/data/PredictionManager.js +27 -1
- package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.d.ts +1 -2
- package/lib/data/data1d/Spectrum1D/integrals/initiateIntegrals.d.ts +1 -1
- package/lib/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
- package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +1 -1
- package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
- package/lib/versionInfo.js +1 -1
- package/lib-cjs/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
- package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +90 -67
- package/lib-cjs/component/NMRium.js +4 -2
- package/lib-cjs/component/context/LoggerContext.js +5 -0
- package/lib-cjs/component/elements/formik/FormikError.js +27 -0
- package/lib-cjs/component/hooks/useSaveSettings.js +17 -15
- package/lib-cjs/component/modal/LoadJCAMPModal.js +41 -28
- package/lib-cjs/component/modal/PredictSpectraModal.js +12 -2
- package/lib-cjs/component/modal/editRange/EditRangeModal.js +32 -12
- package/lib-cjs/component/modal/setting/GeneralSettings.js +1 -1
- package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
- package/lib-cjs/component/panels/Panels.js +2 -2
- package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
- package/lib-cjs/component/panels/predictionPanel/PredictionPanel.js +3 -1
- package/lib-cjs/component/reducer/actions/DatabaseActions.js +6 -4
- package/lib-cjs/component/reducer/actions/DomainActions.js +3 -0
- package/lib-cjs/component/reducer/actions/IntegralsActions.js +3 -1
- package/lib-cjs/component/reducer/actions/SpectrumsActions.js +6 -6
- package/lib-cjs/component/reducer/actions/ToolsActions.js +26 -32
- package/lib-cjs/component/reducer/actions/ZonesActions.js +2 -4
- package/lib-cjs/component/reducer/helper/ZoomHistoryManager.js +37 -0
- package/lib-cjs/component/reducer/preferences/actions/addWorkspace.js +2 -2
- package/lib-cjs/data/PredictionManager.js +27 -1
- package/lib-cjs/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
- package/lib-cjs/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
- package/lib-cjs/versionInfo.js +1 -1
- package/package.json +10 -10
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AnalysisColumnsTypes } from 'nmr-load-save';
|
|
2
3
|
import { memo } from 'react';
|
|
3
4
|
import { useChartData } from '../../context/ChartContext';
|
|
4
5
|
import { usePanelPreferences } from '../../hooks/usePanelPreferences';
|
|
5
6
|
import AnalysisRange from './AnalysisRange';
|
|
6
|
-
import { AnalysisColumnsTypes } from 'nmr-load-save';
|
|
7
7
|
function MultiAnalysisRangesInner({ columns, displayerKey, activeTab, }) {
|
|
8
8
|
const ranges = Object.keys(columns).filter((key) => columns[key].type !== AnalysisColumnsTypes.FORMULA);
|
|
9
9
|
if (!ranges || ranges.length === 0) {
|
|
@@ -29,81 +29,98 @@ function KeysListenerTracker() {
|
|
|
29
29
|
return displayerMode === DISPLAYER_MODE.DM_1D && data && data.length > 0;
|
|
30
30
|
}, [data, displayerMode]);
|
|
31
31
|
const deleteHandler = useCallback(async (sourceData) => {
|
|
32
|
-
const { type, extra
|
|
32
|
+
const { type, extra } = sourceData;
|
|
33
33
|
switch (type) {
|
|
34
34
|
case HighlightEventSource.INTEGRAL: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
const { id } = extra || {};
|
|
36
|
+
if (id) {
|
|
37
|
+
dispatch({
|
|
38
|
+
type: 'DELETE_INTEGRAL',
|
|
39
|
+
payload: {
|
|
40
|
+
id,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
// remove keys from the highlighted list after delete
|
|
44
|
+
remove();
|
|
45
|
+
}
|
|
43
46
|
break;
|
|
44
47
|
}
|
|
45
48
|
case HighlightEventSource.PEAK: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const { id } = extra || {};
|
|
50
|
+
if (id) {
|
|
51
|
+
dispatch({
|
|
52
|
+
type: 'DELETE_PEAK',
|
|
53
|
+
payload: {
|
|
54
|
+
id,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
// remove keys from the highlighted list after delete
|
|
58
|
+
remove();
|
|
59
|
+
}
|
|
54
60
|
break;
|
|
55
61
|
}
|
|
56
62
|
case HighlightEventSource.RANGE: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const { id } = extra || {};
|
|
64
|
+
if (id) {
|
|
65
|
+
dispatch({
|
|
66
|
+
type: 'DELETE_RANGE',
|
|
67
|
+
payload: {
|
|
68
|
+
id,
|
|
69
|
+
assignmentData,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
// remove keys from the highlighted list after delete
|
|
73
|
+
remove();
|
|
74
|
+
}
|
|
66
75
|
break;
|
|
67
76
|
}
|
|
68
77
|
case HighlightEventSource.ZONE: {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const { id } = extra || {};
|
|
79
|
+
if (id) {
|
|
80
|
+
dispatch({
|
|
81
|
+
type: 'DELETE_2D_ZONE',
|
|
82
|
+
payload: {
|
|
83
|
+
id,
|
|
84
|
+
assignmentData,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
// remove keys from the highlighted list after delete
|
|
88
|
+
remove();
|
|
89
|
+
}
|
|
78
90
|
break;
|
|
79
91
|
}
|
|
80
92
|
case HighlightEventSource.EXCLUSION_ZONE: {
|
|
93
|
+
const { zone, spectrumID } = extra || {};
|
|
81
94
|
const buttons = [
|
|
82
95
|
{
|
|
83
96
|
text: 'Yes, for all spectra',
|
|
84
97
|
handler: async () => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
if (zone) {
|
|
99
|
+
const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
|
|
100
|
+
dispatch({
|
|
101
|
+
type: 'DELETE_EXCLUSION_ZONE',
|
|
102
|
+
payload: {
|
|
103
|
+
zone,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
hideLoading();
|
|
107
|
+
}
|
|
93
108
|
},
|
|
94
109
|
},
|
|
95
110
|
{
|
|
96
111
|
text: 'Yes',
|
|
97
112
|
handler: async () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
if (spectrumID) {
|
|
114
|
+
const hideLoading = await alert.showLoading('Delete exclusion zones in progress');
|
|
115
|
+
dispatch({
|
|
116
|
+
type: 'DELETE_EXCLUSION_ZONE',
|
|
117
|
+
payload: {
|
|
118
|
+
zone,
|
|
119
|
+
spectrumId: spectrumID,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
hideLoading();
|
|
123
|
+
}
|
|
107
124
|
},
|
|
108
125
|
},
|
|
109
126
|
{ text: 'No' },
|
|
@@ -115,19 +132,22 @@ function KeysListenerTracker() {
|
|
|
115
132
|
break;
|
|
116
133
|
}
|
|
117
134
|
case HighlightEventSource.MATRIX_GENERATION_EXCLUSION_ZONE: {
|
|
135
|
+
const { zone } = extra || {};
|
|
118
136
|
const buttons = [
|
|
119
137
|
{
|
|
120
138
|
text: 'Yes',
|
|
121
139
|
handler: async () => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
if (zone) {
|
|
141
|
+
const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
|
|
142
|
+
dispatchPreferences({
|
|
143
|
+
type: 'DELETE_MATRIX_GENERATION_EXCLUSION_ZONE',
|
|
144
|
+
payload: {
|
|
145
|
+
zone,
|
|
146
|
+
nucleus: activeTab,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
hideLoading();
|
|
150
|
+
}
|
|
131
151
|
},
|
|
132
152
|
},
|
|
133
153
|
{ text: 'No' },
|
|
@@ -139,12 +159,15 @@ function KeysListenerTracker() {
|
|
|
139
159
|
break;
|
|
140
160
|
}
|
|
141
161
|
case HighlightEventSource.MULTIPLE_ANALYSIS_ZONE: {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
162
|
+
const { colKey } = extra || {};
|
|
163
|
+
if (colKey) {
|
|
164
|
+
dispatchPreferences({
|
|
165
|
+
type: 'DELETE_ANALYSIS_COLUMN',
|
|
166
|
+
payload: { columnKey: colKey, nucleus: activeTab },
|
|
167
|
+
});
|
|
168
|
+
// remove keys from the highlighted list after delete
|
|
169
|
+
remove();
|
|
170
|
+
}
|
|
148
171
|
break;
|
|
149
172
|
}
|
|
150
173
|
default:
|
|
@@ -12,6 +12,7 @@ export type OnNMRiumChange = (state: NmriumState, source: 'data' | 'view' | 'set
|
|
|
12
12
|
export interface NMRiumProps {
|
|
13
13
|
data?: NMRiumData;
|
|
14
14
|
onChange?: OnNMRiumChange;
|
|
15
|
+
noErrorBoundary?: boolean;
|
|
15
16
|
onError?: ErrorBoundaryPropsWithComponent['onError'];
|
|
16
17
|
workspace?: NMRiumWorkspace;
|
|
17
18
|
customWorkspaces?: CustomWorkspaces;
|
package/lib/component/NMRium.js
CHANGED
|
@@ -79,8 +79,10 @@ const defaultData = {
|
|
|
79
79
|
spectra: [],
|
|
80
80
|
};
|
|
81
81
|
const NMRium = forwardRef(function NMRium(props, ref) {
|
|
82
|
-
const { onError, ...otherProps } = props;
|
|
83
|
-
|
|
82
|
+
const { noErrorBoundary = false, onError, ...otherProps } = props;
|
|
83
|
+
const innerNmrium = _jsx(InnerNMRium, { ...otherProps, innerRef: ref });
|
|
84
|
+
const children = noErrorBoundary ? (innerNmrium) : (_jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, onError: onError, children: innerNmrium }));
|
|
85
|
+
return _jsx(RootLayout, { style: { width: '100%' }, children: children });
|
|
84
86
|
});
|
|
85
87
|
function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner, onChange, emptyText, innerRef, }) {
|
|
86
88
|
const rootRef = useRef(null);
|
|
@@ -16,6 +16,11 @@ export function LoggerProvider({ children }) {
|
|
|
16
16
|
const [logsHistory, setLogsHistory] = useState([]);
|
|
17
17
|
const loggerRef = useRef(new FifoLogger({
|
|
18
18
|
onChange: (log, logs) => {
|
|
19
|
+
if (log?.error &&
|
|
20
|
+
(log?.levelLabel === 'error' || log?.levelLabel === 'fatal')) {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.error(log.error);
|
|
23
|
+
}
|
|
19
24
|
setLogsHistory(logs.slice());
|
|
20
25
|
},
|
|
21
26
|
}));
|
|
@@ -15,7 +15,7 @@ export declare function usePreferences(): {
|
|
|
15
15
|
dispatch: (action?: ({
|
|
16
16
|
type: "ADD_WORKSPACE";
|
|
17
17
|
payload: {
|
|
18
|
-
|
|
18
|
+
workspaceKey: string;
|
|
19
19
|
data?: Omit<import("nmr-load-save").Workspace, "label" | "version"> | undefined;
|
|
20
20
|
};
|
|
21
21
|
} | {
|
|
@@ -81,10 +81,12 @@ export declare function usePreferences(): {
|
|
|
81
81
|
customWorkspaces: Record<string, import("nmr-load-save").Workspace>;
|
|
82
82
|
dispatch: any;
|
|
83
83
|
};
|
|
84
|
-
} | {
|
|
84
|
+
} | ({
|
|
85
85
|
type: "SET_PREFERENCES";
|
|
86
86
|
payload: Partial<import("nmr-load-save").Workspace>;
|
|
87
87
|
} | {
|
|
88
|
+
type: "SET_PREFERENCES";
|
|
89
|
+
}) | {
|
|
88
90
|
type: "SET_PANELS_PREFERENCES";
|
|
89
91
|
payload: {
|
|
90
92
|
key: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
export interface FormikErrorProps {
|
|
3
|
+
style?: Partial<Record<'container' | 'text', CSSProperties>>;
|
|
4
|
+
name: string;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare function FormikError({ style, name, children }: FormikErrorProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default FormikError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useFormikContext } from 'formik';
|
|
3
|
+
import lodashGet from 'lodash/get';
|
|
4
|
+
const styles = {
|
|
5
|
+
container: {
|
|
6
|
+
padding: '0.4rem',
|
|
7
|
+
display: 'flex',
|
|
8
|
+
flexDirection: 'column',
|
|
9
|
+
},
|
|
10
|
+
text: {
|
|
11
|
+
color: '#fd000c',
|
|
12
|
+
margin: '0.5px',
|
|
13
|
+
fontSize: '0.9em',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
function FormikError({ style, name, children }) {
|
|
17
|
+
const { errors, isValid, dirty, touched } = useFormikContext();
|
|
18
|
+
const errorText = lodashGet(errors, name);
|
|
19
|
+
const isTouched = lodashGet(touched, name);
|
|
20
|
+
return (_jsxs("div", { style: { ...styles.container, ...style?.container }, children: [children, !isValid && dirty && isTouched && (_jsx("span", { style: { ...styles.text, ...style?.text }, children: errorText }))] }));
|
|
21
|
+
}
|
|
22
|
+
export default FormikError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Formik } from 'formik';
|
|
3
|
-
import { useRef, forwardRef
|
|
3
|
+
import { useRef, forwardRef } from 'react';
|
|
4
4
|
import { Modal, useOnOff } from 'react-science/ui';
|
|
5
5
|
import * as Yup from 'yup';
|
|
6
6
|
import { usePreferences } from '../context/PreferencesContext';
|
|
@@ -23,30 +23,32 @@ const WorkspaceAddForm = forwardRef(({ className, message, onSave }, ref) => {
|
|
|
23
23
|
export function useSaveSettings() {
|
|
24
24
|
const alert = useAlert();
|
|
25
25
|
const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
|
|
26
|
-
const
|
|
26
|
+
const settingsRef = useRef();
|
|
27
27
|
const { dispatch, current } = usePreferences();
|
|
28
28
|
const formRef = useRef(null);
|
|
29
|
-
function addNewWorkspace(workspaceName
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
function addNewWorkspace({ workspaceName }) {
|
|
30
|
+
if (settingsRef.current) {
|
|
31
|
+
dispatch({
|
|
32
|
+
type: 'ADD_WORKSPACE',
|
|
33
|
+
payload: {
|
|
34
|
+
workspaceKey: workspaceName,
|
|
35
|
+
data: settingsRef.current,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
closeDialog();
|
|
39
|
+
alert.success('Preferences saved successfully');
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
return {
|
|
41
|
-
saveSettings: (values
|
|
42
|
-
|
|
43
|
+
saveSettings: (values) => {
|
|
44
|
+
settingsRef.current = values;
|
|
43
45
|
if (current.source !== 'user') {
|
|
44
46
|
openDialog();
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
49
|
dispatch({
|
|
48
50
|
type: 'SET_PREFERENCES',
|
|
49
|
-
payload: values,
|
|
51
|
+
...(values && { payload: values }),
|
|
50
52
|
});
|
|
51
53
|
closeDialog();
|
|
52
54
|
}
|
|
@@ -54,7 +56,7 @@ export function useSaveSettings() {
|
|
|
54
56
|
SaveSettingsModal: () => {
|
|
55
57
|
const alertConfig = {
|
|
56
58
|
message: 'Please enter a new user workspace name in order to save your changes locally',
|
|
57
|
-
render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave:
|
|
59
|
+
render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: addNewWorkspace, ref: formRef })),
|
|
58
60
|
buttons: [
|
|
59
61
|
{
|
|
60
62
|
text: 'Save',
|
|
@@ -8,12 +8,27 @@ import * as Yup from 'yup';
|
|
|
8
8
|
import { useDispatch } from '../context/DispatchContext';
|
|
9
9
|
import Button from '../elements/Button';
|
|
10
10
|
import Label from '../elements/Label';
|
|
11
|
+
import FormikError from '../elements/formik/FormikError';
|
|
11
12
|
import FormikInput from '../elements/formik/FormikInput';
|
|
12
13
|
import { useAlert } from '../elements/popup/Alert/Context';
|
|
13
|
-
import { extractFileMetaFromPath } from '../utility/FileUtility';
|
|
14
14
|
const allowedExtensions = new Set(['dx', 'jdx', 'jcamp']);
|
|
15
15
|
const loadFormValidation = Yup.object({
|
|
16
|
-
url: Yup.string()
|
|
16
|
+
url: Yup.string()
|
|
17
|
+
.url()
|
|
18
|
+
.required()
|
|
19
|
+
.test('file type', 'Imported file must be one of those extensions [ .jdx, .dx, .jcamp ]', (url) => {
|
|
20
|
+
try {
|
|
21
|
+
const fileURL = new URL(url);
|
|
22
|
+
const extension = fileURL.pathname.split('.')?.[1] || '';
|
|
23
|
+
if (allowedExtensions.has(extension)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}),
|
|
17
32
|
});
|
|
18
33
|
const labelStyle = {
|
|
19
34
|
wrapper: { display: 'flex', height: '100%', flex: 1 },
|
|
@@ -25,33 +40,31 @@ export function LoadJCAMPModal({ onCloseDialog, isOpen }) {
|
|
|
25
40
|
if (!isOpen)
|
|
26
41
|
return;
|
|
27
42
|
async function loadJCAMPHandler({ url }) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
alert.error(`Failed to load ${url}`);
|
|
43
|
-
}
|
|
44
|
-
finally {
|
|
45
|
-
hidLoading();
|
|
46
|
-
onCloseDialog?.();
|
|
47
|
-
}
|
|
43
|
+
const hidLoading = await alert.showLoading('Load JCAMP from external URL in progress ...');
|
|
44
|
+
const { pathname, origin } = new URL(url);
|
|
45
|
+
try {
|
|
46
|
+
const nmriumState = await readFromWebSource({
|
|
47
|
+
entries: [{ relativePath: pathname, baseURL: origin }],
|
|
48
|
+
});
|
|
49
|
+
dispatch({
|
|
50
|
+
type: 'LOAD_DROP_FILES',
|
|
51
|
+
payload: { nmriumState, resetSourceObject: false },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
alert.error(`Failed to load ${url}`);
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
finally {
|
|
58
|
+
hidLoading();
|
|
59
|
+
onCloseDialog?.();
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
|
-
return (_jsxs(Modal, { hasCloseButton: true, isOpen: true, onRequestClose: onCloseDialog, children: [_jsx(Modal.Header, { children: "Load JCAMP Dialog" }), _jsx(Modal.Body, { children: _jsx("div", { style: { minWidth: '400px', padding: '1.5em' }, children: _jsx(Formik, { initialValues: { url: '' }, validationSchema: loadFormValidation, onSubmit: loadJCAMPHandler, innerRef: ref, children: _jsx(Label, { title: "URL", style: labelStyle, children: _jsx(FormikInput, { name: "url", type: "string", style: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
return (_jsxs(Modal, { hasCloseButton: true, isOpen: true, onRequestClose: onCloseDialog, children: [_jsx(Modal.Header, { children: "Load JCAMP Dialog" }), _jsx(Modal.Body, { children: _jsx("div", { style: { minWidth: '400px', padding: '1.5em' }, children: _jsx(Formik, { initialValues: { url: '' }, validationSchema: loadFormValidation, onSubmit: loadJCAMPHandler, innerRef: ref, children: _jsx(Label, { title: "URL", style: labelStyle, children: _jsx(FormikError, { name: "url", style: { container: { flex: 1 } }, children: _jsx(FormikInput, { name: "url", type: "string", style: {
|
|
63
|
+
input: {
|
|
64
|
+
padding: '0.8em',
|
|
65
|
+
textAlign: 'left',
|
|
66
|
+
width: '100%',
|
|
67
|
+
},
|
|
68
|
+
inputWrapper: { width: '100%' },
|
|
69
|
+
}, placeholder: "Enter URL to JCAMP-DX file" }) }) }) }) }) }), _jsx(Modal.Footer, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button.Done, { onClick: () => ref.current?.submitForm(), children: "Load" }) }) })] }));
|
|
57
70
|
}
|
|
@@ -5,6 +5,7 @@ import { useCallback, useRef, useState, useMemo } from 'react';
|
|
|
5
5
|
import { defaultPredictionOptions, predictSpectra, } from '../../data/PredictionManager';
|
|
6
6
|
import { useChartData } from '../context/ChartContext';
|
|
7
7
|
import { useDispatch } from '../context/DispatchContext';
|
|
8
|
+
import { useLogger } from '../context/LoggerContext';
|
|
8
9
|
import Button from '../elements/Button';
|
|
9
10
|
import CheckBox from '../elements/CheckBox';
|
|
10
11
|
import CloseButton from '../elements/CloseButton';
|
|
@@ -53,6 +54,7 @@ function PredictSpectraModal({ onClose = () => null, molecule, }) {
|
|
|
53
54
|
name: `Prediction ${predictionIndex + 1}`,
|
|
54
55
|
});
|
|
55
56
|
}, [predictionPreferences, predictionIndex]);
|
|
57
|
+
const { logger } = useLogger();
|
|
56
58
|
const submitHandler = useCallback((values) => {
|
|
57
59
|
void (async () => {
|
|
58
60
|
if (molecule) {
|
|
@@ -66,7 +68,7 @@ function PredictSpectraModal({ onClose = () => null, molecule, }) {
|
|
|
66
68
|
}
|
|
67
69
|
const hideLoading = await alert.showLoading(`Predict ${predictedSpectra.join(',')} in progress`);
|
|
68
70
|
try {
|
|
69
|
-
const data = await predictSpectra(molfile);
|
|
71
|
+
const data = await predictSpectra(molfile, logger);
|
|
70
72
|
dispatch({
|
|
71
73
|
type: 'PREDICT_SPECTRA',
|
|
72
74
|
payload: {
|
|
@@ -85,7 +87,15 @@ function PredictSpectraModal({ onClose = () => null, molecule, }) {
|
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
})();
|
|
88
|
-
}, [
|
|
90
|
+
}, [
|
|
91
|
+
alert,
|
|
92
|
+
dispatch,
|
|
93
|
+
isApproved,
|
|
94
|
+
molecule,
|
|
95
|
+
onClose,
|
|
96
|
+
logger,
|
|
97
|
+
setPredictionPreferences,
|
|
98
|
+
]);
|
|
89
99
|
const approveCheckHandler = useCallback((e) => {
|
|
90
100
|
setApproved(e.target.checked);
|
|
91
101
|
}, []);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Range } from 'nmr-processing';
|
|
1
2
|
interface EditRangeModalProps {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
onSave: (value: any) => Promise<void> | null | void;
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
onRest: (originalRange: Range) => void;
|
|
6
|
+
onZoom: (value: any) => void;
|
|
7
|
+
rangeId: string;
|
|
7
8
|
}
|
|
8
|
-
declare function EditRangeModal({
|
|
9
|
+
declare function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }: EditRangeModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
|
|
9
10
|
export default EditRangeModal;
|
|
@@ -4,7 +4,7 @@ import { css } from '@emotion/react';
|
|
|
4
4
|
import { v4 } from '@lukeed/uuid';
|
|
5
5
|
import { Formik } from 'formik';
|
|
6
6
|
import { splitPatterns, translateMultiplet } from 'nmr-processing';
|
|
7
|
-
import { useMemo, useCallback, useRef } from 'react';
|
|
7
|
+
import { useMemo, useCallback, useRef, useEffect } from 'react';
|
|
8
8
|
import { FaSearchPlus } from 'react-icons/fa';
|
|
9
9
|
import { useChartData } from '../../context/ChartContext';
|
|
10
10
|
import { useDispatch } from '../../context/DispatchContext';
|
|
@@ -52,18 +52,36 @@ const styles = css `
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
`;
|
|
55
|
-
function EditRangeModal({
|
|
55
|
+
function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }) {
|
|
56
56
|
const formRef = useRef(null);
|
|
57
57
|
const { view: { spectra: { activeTab }, }, } = useChartData();
|
|
58
58
|
const dispatch = useDispatch();
|
|
59
|
+
const range = useRange(rangeId);
|
|
60
|
+
const originalRangeRef = useRef(range);
|
|
59
61
|
const rangesPreferences = usePanelPreferences('ranges', activeTab);
|
|
60
|
-
const range = useRange(originRange, manualRange);
|
|
61
62
|
const handleOnZoom = useCallback(() => {
|
|
62
|
-
|
|
63
|
-
}, [
|
|
63
|
+
onZoom(range);
|
|
64
|
+
}, [onZoom, range]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
dispatch({
|
|
67
|
+
type: 'SET_SELECTED_TOOL',
|
|
68
|
+
payload: {
|
|
69
|
+
selectedTool: 'zoom',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
if (!range) {
|
|
73
|
+
onClose?.();
|
|
74
|
+
}
|
|
75
|
+
}, [activeTab, dispatch, onClose, range]);
|
|
64
76
|
const handleOnClose = useCallback(() => {
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
dispatch({
|
|
78
|
+
type: 'SET_SELECTED_TOOL',
|
|
79
|
+
payload: {
|
|
80
|
+
selectedTool: 'zoom',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
onRest(originalRangeRef.current);
|
|
84
|
+
}, [dispatch, onRest]);
|
|
67
85
|
const getCouplings = useCallback((couplings) => couplings
|
|
68
86
|
.filter((coupling) => coupling.coupling !== '')
|
|
69
87
|
.map((coupling) => {
|
|
@@ -88,9 +106,9 @@ function EditRangeModal({ onSaveEditRangeModal = () => null, onCloseEditRangeMod
|
|
|
88
106
|
void (async () => {
|
|
89
107
|
const _range = { ...range };
|
|
90
108
|
_range.signals = getSignals(formValues.signals);
|
|
91
|
-
await
|
|
109
|
+
await onSave(_range);
|
|
92
110
|
})();
|
|
93
|
-
}, [getSignals,
|
|
111
|
+
}, [getSignals, onSave, range]);
|
|
94
112
|
const data = useMemo(() => {
|
|
95
113
|
const signals = range?.signals.map((signal) => {
|
|
96
114
|
// counter within j array to access to right j values
|
|
@@ -114,7 +132,7 @@ function EditRangeModal({ onSaveEditRangeModal = () => null, onCloseEditRangeMod
|
|
|
114
132
|
return { ...signal, js: couplings };
|
|
115
133
|
});
|
|
116
134
|
return { activeTab: '0', signals };
|
|
117
|
-
}, [range?.signals, rangesPreferences
|
|
135
|
+
}, [range?.signals, rangesPreferences]);
|
|
118
136
|
const changeHandler = useCallback((values) => {
|
|
119
137
|
const signals = getSignals(values.signals);
|
|
120
138
|
if (JSON.stringify(range?.signals, (key, value) => {
|
|
@@ -131,14 +149,16 @@ function EditRangeModal({ onSaveEditRangeModal = () => null, onCloseEditRangeMod
|
|
|
131
149
|
});
|
|
132
150
|
}
|
|
133
151
|
}, [dispatch, getSignals, range]);
|
|
152
|
+
if (!rangesPreferences || !range) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
134
155
|
return (_jsxs("div", { css: styles, children: [_jsxs("div", { className: "header handle", children: [_jsx(Button.Action, { onClick: handleOnZoom, fill: "outline", style: { fontSize: '14' }, color: { base: '#5f5f5f', hover: 'white' }, children: _jsx(FaSearchPlus, { title: "Set to default view on range in spectrum" }) }), _jsx("span", { className: "title", children: ` Range and Signal edition: ${formatNumber(range?.from, rangesPreferences.from.format)} ppm to ${formatNumber(range?.to, rangesPreferences.to.format)} ppm` }), _jsx(SaveButton, { onClick: () => formRef.current.submitForm(), popupTitle: "Save and Exit" }), _jsx(CloseButton, { onClick: handleOnClose })] }), _jsx(Formik, { innerRef: formRef, initialValues: data, validationSchema: editRangeFormValidation, onSubmit: handleOnSave, children: _jsxs(_Fragment, { children: [_jsx(SignalsForm, { range: range, preferences: rangesPreferences }), _jsx(FormikOnChange, { onChange: changeHandler })] }) })] }));
|
|
135
156
|
}
|
|
136
|
-
function useRange(
|
|
157
|
+
function useRange(rangeId) {
|
|
137
158
|
const { ranges } = useSpectrum({
|
|
138
159
|
ranges: { values: [] },
|
|
139
160
|
});
|
|
140
|
-
const
|
|
141
|
-
const index = ranges.values.findIndex((rangeRecord) => rangeRecord.id === id);
|
|
161
|
+
const index = ranges.values.findIndex((rangeRecord) => rangeRecord.id === rangeId);
|
|
142
162
|
return ranges.values[index];
|
|
143
163
|
}
|
|
144
164
|
export default EditRangeModal;
|
package/lib/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useFormikContext } from 'formik';
|
|
3
|
+
import { AnalysisColumnsTypes } from 'nmr-load-save';
|
|
3
4
|
import { useMemo, useCallback } from 'react';
|
|
4
5
|
import { FaPlus, FaTimes } from 'react-icons/fa';
|
|
5
6
|
import Button from '../../../elements/Button';
|
|
6
7
|
import ReactTable from '../../../elements/ReactTable/ReactTable';
|
|
7
8
|
import FormikInput from '../../../elements/formik/FormikInput';
|
|
8
|
-
import { AnalysisColumnsTypes } from 'nmr-load-save';
|
|
9
9
|
const inputStyle = { input: { width: '100%', fontSize: '1.15em' } };
|
|
10
10
|
export function AnalysisTablePreferences() {
|
|
11
11
|
const { values: { analysisOptions: { columns }, }, setFieldValue, } = useFormikContext();
|