nmrium 0.57.1 → 0.58.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.
Files changed (34) hide show
  1. package/lib/component/1d-2d/components/SpectrumInfoBlock.d.ts +1 -1
  2. package/lib/component/1d-2d/components/SpectrumInfoBlock.js +114 -7
  3. package/lib/component/elements/ActionsButtonsPopover.d.ts +7 -1
  4. package/lib/component/elements/ActionsButtonsPopover.js +9 -6
  5. package/lib/component/elements/Input2.js +2 -2
  6. package/lib/component/elements/Input2Controller.d.ts +4 -2
  7. package/lib/component/elements/Input2Controller.js +22 -6
  8. package/lib/component/elements/MoleculeSelection.js +2 -2
  9. package/lib/component/elements/NextPrev.d.ts +4 -5
  10. package/lib/component/elements/NextPrev.js +76 -79
  11. package/lib/component/header/ApodizationOptionsPanel.js +14 -7
  12. package/lib/component/header/BaseLineCorrectionPanel.js +17 -10
  13. package/lib/component/header/ZeroFillingOptionsPanel.js +17 -10
  14. package/lib/component/hooks/useSaveSettings.js +43 -26
  15. package/lib/component/hooks/useWorkspaceAction.js +12 -14
  16. package/lib/component/modal/LoadJCAMPModal.d.ts +3 -1
  17. package/lib/component/modal/LoadJCAMPModal.js +17 -18
  18. package/lib/component/modal/SaveAsModal.d.ts +3 -1
  19. package/lib/component/modal/SaveAsModal.js +20 -30
  20. package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
  21. package/lib/component/modal/changeSum/ChangeSumModalContents.js +35 -47
  22. package/lib/component/modal/changeSum/SelectMolecule.d.ts +2 -5
  23. package/lib/component/modal/changeSum/SelectMolecule.js +9 -8
  24. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +5 -3
  25. package/lib/component/panels/Panels.js +13 -13
  26. package/lib/component/panels/predictionPanel/PredictionPanel.js +2 -2
  27. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.d.ts +3 -0
  28. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.js +5 -0
  29. package/lib/component/reducer/preferences/actions/toggleInformationBlock.d.ts +3 -0
  30. package/lib/component/reducer/preferences/actions/toggleInformationBlock.js +7 -0
  31. package/lib/component/reducer/preferences/preferencesReducer.d.ts +10 -1
  32. package/lib/component/reducer/preferences/preferencesReducer.js +6 -0
  33. package/lib/versionInfo.js +1 -1
  34. package/package.json +16 -16
@@ -1,33 +1,46 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Dialog } from '@blueprintjs/core';
3
- import { Formik } from 'formik';
4
- import { useRef, forwardRef } from 'react';
3
+ import { yupResolver } from '@hookform/resolvers/yup';
4
+ import { useRef } from 'react';
5
+ import { useForm } from 'react-hook-form';
5
6
  import { useOnOff } from 'react-science/ui';
6
7
  import * as Yup from 'yup';
7
8
  import { usePreferences } from '../context/PreferencesContext';
8
9
  import { useToaster } from '../context/ToasterContext';
9
- import FormikInput from '../elements/formik/FormikInput';
10
+ import { Input2Controller } from '../elements/Input2Controller';
10
11
  import ConfirmationDialog from '../elements/popup/Modal/ConfirmDialog';
11
12
  import { useWorkspaceAction } from './useWorkspaceAction';
12
13
  const schema = Yup.object().shape({
13
14
  workspaceName: Yup.string().required(),
14
15
  });
15
- const WorkspaceAddForm = forwardRef(({ className, message, onSave }, ref) => {
16
- return (_jsxs("div", { className: className, children: [_jsx("p", { style: { paddingBottom: '10px' }, children: message }), _jsx(Formik, { initialValues: { workspaceName: '' }, validationSchema: schema, onSubmit: onSave, innerRef: ref, children: _jsx(FormikInput, { name: "workspaceName", placeholder: "Enter workspace Name", style: {
17
- input: {
18
- padding: '0.5em',
19
- width: '90%',
20
- fontWeight: 'normal',
21
- color: 'black',
22
- },
23
- }, autoFocus: true }) })] }));
24
- });
16
+ function keyDownCheck(event) {
17
+ if (event.key === 'Enter') {
18
+ return true;
19
+ }
20
+ else if (event.key === 'Escape') {
21
+ return false;
22
+ }
23
+ }
24
+ function WorkspaceAddForm(props) {
25
+ const { className, message, control, onEnter } = props;
26
+ return (_jsxs("div", { className: className, children: [_jsx("p", { style: { paddingBottom: '10px' }, children: message }), _jsx(Input2Controller, { control: control, name: "workspaceName", placeholder: "Enter workspace Name", style: {
27
+ width: '90%',
28
+ borderRadius: '5px',
29
+ }, autoFocus: true, large: true, onKeyDown: (event) => {
30
+ if (keyDownCheck(event)) {
31
+ onEnter();
32
+ }
33
+ } })] }));
34
+ }
25
35
  export function useSaveSettings() {
26
36
  const toaster = useToaster();
27
37
  const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
28
38
  const settingsRef = useRef();
29
39
  const { current } = usePreferences();
30
- const formRef = useRef(null);
40
+ const { handleSubmit, control, reset } = useForm({
41
+ defaultValues: { workspaceName: '' },
42
+ resolver: yupResolver(schema),
43
+ });
31
44
  const { saveWorkspace, addNewWorkspace } = useWorkspaceAction();
32
45
  function handleAddNewWorkspace({ workspaceName }) {
33
46
  addNewWorkspace(workspaceName, settingsRef.current);
@@ -37,26 +50,30 @@ export function useSaveSettings() {
37
50
  intent: 'success',
38
51
  });
39
52
  }
53
+ function saveSettings(values) {
54
+ settingsRef.current = values;
55
+ if (current.source !== 'user') {
56
+ reset({ workspaceName: '' });
57
+ openDialog();
58
+ }
59
+ else {
60
+ saveWorkspace(values);
61
+ closeDialog();
62
+ }
63
+ }
40
64
  return {
41
- saveSettings: (values) => {
42
- settingsRef.current = values;
43
- if (current.source !== 'user') {
44
- openDialog();
45
- }
46
- else {
47
- saveWorkspace(values);
48
- closeDialog();
49
- }
50
- },
65
+ saveSettings,
51
66
  SaveSettingsModal: () => {
52
67
  const alertConfig = {
53
68
  message: 'Please enter a new user workspace name in order to save your changes locally',
54
- render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: handleAddNewWorkspace, ref: formRef })),
69
+ render: (props) => (_jsx(WorkspaceAddForm, { ...props, onEnter: () => {
70
+ void handleSubmit(handleAddNewWorkspace)();
71
+ }, control: control })),
55
72
  buttons: [
56
73
  {
57
74
  text: 'Save',
58
75
  handler: () => {
59
- void formRef.current?.submitForm();
76
+ void handleSubmit(handleAddNewWorkspace)();
60
77
  },
61
78
  preventClose: true,
62
79
  },
@@ -61,20 +61,18 @@ export function useWorkspaceAction() {
61
61
  });
62
62
  }
63
63
  function saveWorkspace(data) {
64
- if (data) {
65
- const settings = readSettings() || {
66
- version: 0,
67
- currentWorkspace: null,
68
- workspaces: {},
69
- };
70
- updateSettings({
71
- ...settings,
72
- workspaces: {
73
- ...settings.workspaces,
74
- [workspace.current]: data,
75
- },
76
- });
77
- }
64
+ const settings = readSettings() || {
65
+ version: 0,
66
+ currentWorkspace: null,
67
+ workspaces: {},
68
+ };
69
+ updateSettings({
70
+ ...settings,
71
+ workspaces: {
72
+ ...settings.workspaces,
73
+ [workspace.current]: data ?? current,
74
+ },
75
+ });
78
76
  dispatch({
79
77
  type: 'SET_PREFERENCES',
80
78
  ...(data && { payload: data }),
@@ -1,5 +1,7 @@
1
- interface LoadJCAMPModalProps {
1
+ interface InnerLoadJCAMPModalProps {
2
2
  onCloseDialog: () => void;
3
+ }
4
+ interface LoadJCAMPModalProps extends InnerLoadJCAMPModalProps {
3
5
  isOpen: boolean;
4
6
  }
5
7
  export declare function LoadJCAMPModal({ onCloseDialog, isOpen }: LoadJCAMPModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
@@ -1,17 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
3
+ import { Button, Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
4
4
  import { css } from '@emotion/react';
5
- import { Formik } from 'formik';
5
+ import { yupResolver } from '@hookform/resolvers/yup';
6
6
  import { readFromWebSource } from 'nmr-load-save';
7
- import { useRef } from 'react';
7
+ import { useForm } from 'react-hook-form';
8
8
  import * as Yup from 'yup';
9
9
  import { useDispatch } from '../context/DispatchContext';
10
10
  import { useToaster } from '../context/ToasterContext';
11
- import Button from '../elements/Button';
11
+ import { Input2Controller } from '../elements/Input2Controller';
12
12
  import Label from '../elements/Label';
13
- import FormikError from '../elements/formik/FormikError';
14
- import FormikInput from '../elements/formik/FormikInput';
15
13
  const allowedExtensions = new Set(['dx', 'jdx', 'jcamp']);
16
14
  const loadFormValidation = Yup.object({
17
15
  url: Yup.string()
@@ -33,13 +31,21 @@ const loadFormValidation = Yup.object({
33
31
  });
34
32
  const labelStyle = {
35
33
  wrapper: { display: 'flex', height: '100%', flex: 1 },
34
+ container: { alignItems: 'flex-start' },
35
+ label: { paddingTop: '5px' },
36
36
  };
37
37
  export function LoadJCAMPModal({ onCloseDialog, isOpen }) {
38
- const dispatch = useDispatch();
39
- const toaster = useToaster();
40
- const ref = useRef(null);
41
38
  if (!isOpen)
42
39
  return;
40
+ return _jsx(InnerLoadJCAMPModal, { onCloseDialog: onCloseDialog });
41
+ }
42
+ function InnerLoadJCAMPModal({ onCloseDialog }) {
43
+ const dispatch = useDispatch();
44
+ const toaster = useToaster();
45
+ const { handleSubmit, control } = useForm({
46
+ defaultValues: { url: '' },
47
+ resolver: yupResolver(loadFormValidation),
48
+ });
43
49
  async function loadJCAMPHandler({ url }) {
44
50
  const hidLoading = toaster.showLoading({
45
51
  message: 'Load JCAMP from external URL in progress ...',
@@ -62,14 +68,7 @@ export function LoadJCAMPModal({ onCloseDialog, isOpen }) {
62
68
  onCloseDialog?.();
63
69
  }
64
70
  }
65
- return (_jsxs(Dialog, { isOpen: true, onClose: onCloseDialog, title: "Load JCAMP", style: { minWidth: '400px' }, children: [_jsx(DialogBody, { css: css `
71
+ return (_jsxs(Dialog, { isOpen: true, onClose: onCloseDialog, title: "Load JCAMP", style: { minWidth: 400 }, children: [_jsx(DialogBody, { css: css `
66
72
  background-color: white;
67
- `, 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: {
68
- input: {
69
- padding: '0.8em',
70
- textAlign: 'left',
71
- width: '100%',
72
- },
73
- inputWrapper: { width: '100%' },
74
- }, placeholder: "Enter URL to JCAMP-DX file" }) }) }) }) }), _jsx(DialogFooter, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button.Done, { onClick: () => ref.current?.submitForm(), children: "Load" }) }) })] }));
73
+ `, children: _jsx(Label, { title: "URL", style: labelStyle, children: _jsx(Input2Controller, { name: "url", control: control, fill: true, placeholder: "Enter URL to JCAMP-DX file", enableErrorMessage: true }) }) }), _jsx(DialogFooter, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button, { intent: "success", onClick: () => void handleSubmit(loadJCAMPHandler)(), children: "Load" }) }) })] }));
75
74
  }
@@ -1,7 +1,9 @@
1
1
  import { LabelStyle } from '../elements/Label';
2
2
  export declare const labelStyle: LabelStyle;
3
- interface SaveAsModalProps {
3
+ interface InnerSaveAsModalProps {
4
4
  onCloseDialog: () => void;
5
+ }
6
+ interface SaveAsModalProps extends InnerSaveAsModalProps {
5
7
  isOpen: boolean;
6
8
  }
7
9
  declare function SaveAsModal(props: SaveAsModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
@@ -1,29 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
3
+ import { Checkbox, Dialog, DialogBody, DialogFooter, Radio, RadioGroup, } from '@blueprintjs/core';
4
4
  import { css } from '@emotion/react';
5
- import { Field, Formik } from 'formik';
6
- import { useRef } from 'react';
5
+ import { Controller, useForm } from 'react-hook-form';
7
6
  import { DataExportOptions } from '../../data/SpectraManager';
8
7
  import { useChartData } from '../context/ChartContext';
9
8
  import ActionButtons from '../elements/ActionButtons';
9
+ import { Input2Controller } from '../elements/Input2Controller';
10
10
  import Label from '../elements/Label';
11
- import FormikCheckBox from '../elements/formik/FormikCheckBox';
12
- import FormikInput from '../elements/formik/FormikInput';
13
11
  import useExport from '../hooks/useExport';
14
- const styles = css `
15
- display: flex;
16
- flex-direction: column;
17
-
18
- label {
19
- margin-right: 20px;
20
- display: inline-block;
21
- }
22
-
23
- input[type='radio'] {
24
- margin-right: 5px;
25
- }
26
- `;
27
12
  const INITIAL_VALUE = {
28
13
  name: '',
29
14
  compressed: false,
@@ -37,7 +22,6 @@ const INITIAL_VALUE = {
37
22
  export const labelStyle = {
38
23
  label: {
39
24
  flex: 4,
40
- fontSize: '12px',
41
25
  color: '#232323',
42
26
  },
43
27
  wrapper: {
@@ -49,7 +33,12 @@ export const labelStyle = {
49
33
  };
50
34
  function SaveAsModal(props) {
51
35
  const { onCloseDialog, isOpen } = props;
52
- const refForm = useRef();
36
+ if (!isOpen)
37
+ return;
38
+ return _jsx(InnerSaveAsModal, { onCloseDialog: onCloseDialog });
39
+ }
40
+ function InnerSaveAsModal(props) {
41
+ const { onCloseDialog } = props;
53
42
  const { source, data } = useChartData();
54
43
  const { saveHandler } = useExport();
55
44
  const fileName = data[0]?.info?.name;
@@ -57,15 +46,16 @@ function SaveAsModal(props) {
57
46
  saveHandler(values);
58
47
  onCloseDialog?.();
59
48
  }
60
- if (!isOpen)
61
- return;
62
- return (_jsxs(Dialog, { isOpen: true, title: "Save as ... ", onClose: onCloseDialog, style: { width: 500 }, children: [_jsx(DialogBody, { css: css `
49
+ const { handleSubmit, control, register } = useForm({
50
+ defaultValues: { ...INITIAL_VALUE, name: fileName },
51
+ });
52
+ return (_jsxs(Dialog, { isOpen: true, title: "Save as ... ", onClose: onCloseDialog, style: { width: 600 }, children: [_jsxs(DialogBody, { css: css `
63
53
  background-color: white;
64
- `, children: _jsx(Formik, { innerRef: refForm, initialValues: { ...INITIAL_VALUE, name: fileName }, onSubmit: submitHandler, children: _jsxs(_Fragment, { children: [_jsx(Label, { style: labelStyle, title: "Name", children: _jsx(FormikInput, { name: "name", className: "name", style: {
65
- inputWrapper: { width: '100%' },
66
- input: { padding: '5px', textAlign: 'left' },
67
- } }) }), _jsx(Label, { style: labelStyle, title: "Compressed", children: _jsx(FormikCheckBox, { name: "compressed" }) }), _jsx(Label, { style: labelStyle, title: "Pretty format", children: _jsx(FormikCheckBox, { name: "pretty" }) }), _jsx(Label, { style: labelStyle, title: "Include view", children: _jsx(FormikCheckBox, { name: "include.view" }) }), _jsx(Label, { style: labelStyle, title: "Include settings", children: _jsx(FormikCheckBox, { name: "include.settings" }) }), _jsx(Label, { style: labelStyle, title: "Include data", children: _jsx("div", { css: styles, children: _jsxs("div", { children: [_jsxs("label", { children: [_jsx(Field, { type: "radio", name: "include.dataType", value: DataExportOptions.ROW_DATA }), "Raw data"] }), _jsxs("label", { style: {
68
- color: source ? 'black' : 'lightgray',
69
- }, children: [_jsx(Field, { type: "radio", name: "include.dataType", value: DataExportOptions.DATA_SOURCE, disabled: !source }), "Data source"] }), _jsxs("label", { children: [_jsx(Field, { type: "radio", name: "include.dataType", value: DataExportOptions.NO_DATA }), "No data"] })] }) }) })] }) }) }), _jsx(DialogFooter, { children: _jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => refForm.current.submitForm(), doneLabel: "Save", onCancel: () => onCloseDialog?.() }) })] }));
54
+ `, children: [_jsx(Label, { style: labelStyle, title: "Name", children: _jsx(Input2Controller, { name: "name", control: control, fill: true, controllerProps: { rules: { required: true } } }) }), _jsx(Label, { style: labelStyle, title: "Compressed", children: _jsx(Checkbox, { style: { margin: 0 }, ...register(`compressed`) }) }), _jsx(Label, { style: labelStyle, title: "Pretty format", children: _jsx(Checkbox, { style: { margin: 0 }, ...register(`pretty`) }) }), _jsx(Label, { style: labelStyle, title: "Include view", children: _jsx(Checkbox, { style: { margin: 0 }, ...register(`include.view`) }) }), _jsx(Label, { style: labelStyle, title: "Include settings", children: _jsx(Checkbox, { style: { margin: 0 }, ...register(`include.settings`) }) }), _jsx(Label, { style: labelStyle, title: "Include data", children: _jsx(Controller, { name: "include.dataType", control: control, render: ({ field }) => {
55
+ const { value, onChange, ...otherFieldProps } = field;
56
+ return (_jsxs(RadioGroup, { inline: true, onChange: onChange, selectedValue: value, ...otherFieldProps, children: [_jsx(Radio, { label: "Raw data", value: DataExportOptions.ROW_DATA }), _jsx(Radio, { label: "Data source", value: DataExportOptions.DATA_SOURCE, disabled: !source }), _jsx(Radio, { label: "No data", value: DataExportOptions.NO_DATA })] }));
57
+ } }) })] }), _jsx(DialogFooter, { children: _jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => {
58
+ void handleSubmit(submitHandler)();
59
+ }, doneLabel: "Save", onCancel: () => onCloseDialog?.() }) })] }));
70
60
  }
71
61
  export default SaveAsModal;
@@ -8,7 +8,7 @@ export default function ChangeSumModal(props) {
8
8
  const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
9
9
  return (_jsxs(_Fragment, { children: [_jsx(Toolbar.Item, { disabled: disabled, icon: _jsx(SvgNmrSum, {}), tooltip: currentSum
10
10
  ? `Change ${sumType} sum (${currentSum.toFixed(2)})`
11
- : `Change ${sumType} sum`, onClick: openDialog }), isOpenDialog && (_jsx(Dialog, { isOpen: true, onClose: closeDialog, style: { width: 500, height: 400 }, title: currentSum
11
+ : `Change ${sumType} sum`, onClick: openDialog }), isOpenDialog && (_jsx(Dialog, { isOpen: true, onClose: closeDialog, style: { width: 500 }, title: currentSum
12
12
  ? `Set new ${sumType} sum (Current: ${currentSum.toFixed(2)})`
13
13
  : `Set new ${sumType} Sum`, children: _jsx(ChangeSumModalContents, { ...otherProps, onClose: closeDialog }) }))] }));
14
14
  }
@@ -1,76 +1,54 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { DialogBody, DialogFooter } from '@blueprintjs/core';
3
+ import { Button, DialogBody, DialogFooter, Tab, Tabs } from '@blueprintjs/core';
4
4
  import { css } from '@emotion/react';
5
5
  import styled from '@emotion/styled';
6
- import { Formik } from 'formik';
7
- import { useEffect, useRef, useState } from 'react';
6
+ import { yupResolver } from '@hookform/resolvers/yup';
7
+ import { useEffect, useState } from 'react';
8
+ import { useForm } from 'react-hook-form';
8
9
  import * as Yup from 'yup';
9
10
  import { usePreferences } from '../../context/PreferencesContext';
10
- import Button from '../../elements/Button';
11
- import Tab from '../../elements/Tab/Tab';
12
- import Tabs from '../../elements/Tab/Tabs';
13
- import FormikInput from '../../elements/formik/FormikInput';
11
+ import { NumberInput2Controller } from '../../elements/NumberInput2Controller';
14
12
  import SelectMolecule from './SelectMolecule';
15
13
  function getValidationSchema(option) {
16
- switch (option) {
17
- case 'auto': {
18
- return Yup.object({
19
- molecule: Yup.object().required(),
20
- });
21
- }
22
- case 'manual': {
23
- return Yup.object({
24
- sum: Yup.number().required(),
25
- });
26
- }
27
- default:
28
- return null;
14
+ if (option === 'auto') {
15
+ return Yup.object({
16
+ molecule: Yup.object().required(),
17
+ });
29
18
  }
19
+ return Yup.object({
20
+ sum: Yup.number().min(0).required(),
21
+ });
30
22
  }
31
23
  const ManualContainer = styled.div `
32
24
  padding: 30px 5px;
33
-
34
- .input {
35
- width: 80% !important;
36
- height: 36px;
37
- margin: 0 auto;
38
- }
39
-
40
- .input input {
41
- padding: 5px;
42
- text-align: center;
43
- }
25
+ display: flex;
26
+ justify-content: center;
44
27
  `;
45
28
  export function ChangeSumModalContents(props) {
46
29
  const { sumOptions, onSave, onClose } = props;
47
30
  const { current: { display: { panels }, }, } = usePreferences();
48
31
  const [setOption, setActiveOption] = useState('auto');
49
- const formRef = useRef(null);
32
+ const { control, handleSubmit, reset } = useForm({
33
+ resolver: yupResolver(getValidationSchema(setOption)),
34
+ });
50
35
  useEffect(() => {
51
36
  if (sumOptions?.sumAuto && panels?.structuresPanel?.display) {
52
37
  setActiveOption('auto');
53
38
  const { mf, moleculeId: id } = sumOptions;
54
- formRef.current.setValues({
55
- sum: null,
39
+ reset({
56
40
  molecule: id && mf ? { mf, id } : null,
57
41
  });
58
42
  }
59
43
  else {
60
44
  setActiveOption('manual');
61
- formRef.current.setValues({
62
- sum: sumOptions?.sum ?? '',
63
- molecule: null,
45
+ reset({
46
+ sum: sumOptions?.sum,
64
47
  });
65
48
  }
66
- }, [panels?.structuresPanel, sumOptions]);
67
- function handleKeyDown(event) {
68
- if (event.key === 'Enter') {
69
- formRef.current.submitForm();
70
- }
71
- }
72
- function onTabChangeHandler(tab) {
73
- setActiveOption(tab.tabid);
49
+ }, [panels?.structuresPanel, reset, sumOptions]);
50
+ function onTabChangeHandler(tabKey) {
51
+ setActiveOption(tabKey);
74
52
  }
75
53
  function saveHandler(values) {
76
54
  switch (setOption) {
@@ -91,7 +69,17 @@ export function ChangeSumModalContents(props) {
91
69
  }
92
70
  const isStructurePanelVisible = panels?.structuresPanel?.display || false;
93
71
  return (_jsxs(_Fragment, { children: [_jsx(DialogBody, { css: css `
94
- padding: 0;
72
+ padding: 5px;
95
73
  background-color: white;
96
- `, children: _jsx(Formik, { innerRef: formRef, onSubmit: saveHandler, initialValues: { sum: '', molecule: null }, validationSchema: getValidationSchema(setOption), children: _jsxs(Tabs, { activeTab: setOption, onClick: onTabChangeHandler, children: [isStructurePanelVisible && (_jsx(Tab, { title: "Auto", tabid: "auto", children: _jsx(SelectMolecule, { name: "molecule" }) })), _jsx(Tab, { title: "Manual", tabid: "manual", children: _jsx(ManualContainer, { children: _jsx(FormikInput, { name: "sum", type: "number", placeholder: "Enter the new value", onKeyDown: handleKeyDown }) }) })] }) }) }), _jsx(DialogFooter, { children: _jsx(Button.Done, { onClick: () => formRef.current.submitForm(), style: { width: 80 }, children: "Set" }) })] }));
74
+
75
+ [role='tablist'] {
76
+ border-bottom: 1px solid #f0f0f0;
77
+ }
78
+ `, children: _jsxs(Tabs, { selectedTabId: setOption, onChange: onTabChangeHandler, renderActiveTabPanelOnly: true, children: [isStructurePanelVisible && (_jsx(Tab, { title: "Auto", id: "auto", panel: _jsx(SelectMolecule, { control: control, name: "molecule" }) })), _jsx(Tab, { title: "Manual", id: "manual", panel: _jsx(ManualContainer, { children: _jsx(NumberInput2Controller, { name: "sum", control: control, placeholder: "Enter the new value", onKeyDown: (event) => {
79
+ if (event.key !== 'Enter')
80
+ return;
81
+ void handleSubmit(saveHandler)();
82
+ }, style: { width: '250px' }, autoFocus: true, min: 0 }) }) })] }) }), _jsx(DialogFooter, { children: _jsx(Button, { intent: "success", onClick: () => {
83
+ void handleSubmit(saveHandler)();
84
+ }, style: { width: 80 }, children: "Set" }) })] }));
97
85
  }
@@ -1,5 +1,2 @@
1
- interface SelectMoleculeProps {
2
- name: string;
3
- }
4
- export default function SelectMolecule(props: SelectMoleculeProps): import("@emotion/react/jsx-runtime").JSX.Element;
5
- export {};
1
+ import { ControllerProps, FieldValues } from 'react-hook-form';
2
+ export default function SelectMolecule<FieldType extends FieldValues = FieldValues>(props: Pick<ControllerProps<FieldType>, 'control' | 'name'>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { css } from '@emotion/react';
4
- import { useFormikContext } from 'formik';
5
4
  import { useCallback, useState, useEffect, useMemo } from 'react';
5
+ import { useController } from 'react-hook-form';
6
6
  import getAtom from '../../../data/utilities/getAtom';
7
7
  import { useChartData } from '../../context/ChartContext';
8
8
  import MoleculeSelection from '../../elements/MoleculeSelection';
@@ -39,8 +39,9 @@ const styles = css `
39
39
  }
40
40
  `;
41
41
  export default function SelectMolecule(props) {
42
+ const { name, control } = props;
42
43
  const [currentIndex, setCurrentIndex] = useState();
43
- const { setFieldValue, errors, values } = useFormikContext();
44
+ const { field: { onChange, value }, fieldState: { invalid }, } = useController({ name, control });
44
45
  const { molecules, view: { spectra: { activeTab }, }, } = useChartData();
45
46
  const element = getAtom(activeTab);
46
47
  const newSum = useMemo(() => {
@@ -54,18 +55,18 @@ export default function SelectMolecule(props) {
54
55
  }, [currentIndex, element, molecules]);
55
56
  const setValue = useCallback((index) => {
56
57
  setCurrentIndex(index);
57
- void setFieldValue(props.name, molecules[index]);
58
- }, [molecules, props.name, setFieldValue]);
58
+ onChange(molecules[index]);
59
+ }, [molecules, onChange]);
59
60
  useEffect(() => {
60
61
  if (molecules && molecules.length > 0) {
61
- const index = values[props.name]
62
- ? molecules.findIndex((molecule) => molecule.id === values[props.name].id)
62
+ const index = value
63
+ ? molecules.findIndex((molecule) => molecule.id === value.id)
63
64
  : -1;
64
65
  setValue(index !== -1 ? index : 0);
65
66
  }
66
- }, [molecules, props.name, setValue, values]);
67
+ }, [molecules, setValue, value]);
67
68
  const onChangeMoleculeSelectionHandler = useCallback((index) => {
68
69
  setValue(index);
69
70
  }, [setValue]);
70
- return (_jsx("div", { css: styles, children: element && molecules && molecules.length > 0 ? (_jsxs("div", { className: "molecule-container", children: [_jsx("p", { className: "title", children: "Select a molecule as reference!" }), _jsxs("div", { className: "molecule-selection-container", children: [_jsx(MoleculeSelection, { index: currentIndex, molecules: molecules, onChange: onChangeMoleculeSelectionHandler }), _jsxs("p", { className: "new-sum-text", children: ["New sum for ", element, " will be ", newSum, "!"] })] })] })) : (_jsx("p", { className: "empty", style: { color: errors[props.name] ? 'red' : 'black' }, children: "You have to Select a spectrum and Add a molecule from the Structure panel to select as a reference!" })) }));
71
+ return (_jsx("div", { css: styles, children: element && molecules && molecules.length > 0 ? (_jsxs("div", { className: "molecule-container", children: [_jsx("p", { className: "title", children: "Select a molecule as reference!" }), _jsxs("div", { className: "molecule-selection-container", children: [_jsx(MoleculeSelection, { index: currentIndex, molecules: molecules, onChange: onChangeMoleculeSelectionHandler }), _jsxs("p", { className: "new-sum-text", children: ["New sum for ", element, " will be ", newSum, "!"] })] })] })) : (_jsx("p", { className: "empty", style: { color: invalid ? 'red' : 'black' }, children: "You have to Select a spectrum and Add a molecule from the Structure panel to select as a reference!" })) }));
71
72
  }
@@ -7,7 +7,7 @@ import { ResponsiveChart } from 'react-d3-utils';
7
7
  import OCLnmr from 'react-ocl-nmr';
8
8
  import { useChartData } from '../../context/ChartContext';
9
9
  import { useDispatch } from '../../context/DispatchContext';
10
- import NextPrev from '../../elements/NextPrev';
10
+ import { NextPrev } from '../../elements/NextPrev';
11
11
  import useSpectrum from '../../hooks/useSpectrum';
12
12
  import { useMoleculeEditor } from '../../modal/MoleculeStructureEditorModal';
13
13
  import MoleculeHeader from './MoleculeHeader';
@@ -69,8 +69,10 @@ function MoleculePanelInner(props) {
69
69
  function moleculeIndexHandler(index) {
70
70
  setCurrentIndex(index);
71
71
  }
72
- return (_jsxs("div", { css: styles.panel, children: [_jsx(MoleculePanelHeader, { currentIndex: currentIndex, moleculesView: moleculesView, molecules: molecules, onOpenMoleculeEditor: () => openMoleculeEditor(), onMoleculeIndexChange: moleculeIndexHandler }), _jsx("div", { css: styles.innerPanel, children: _jsx("div", { css: styles.molecule, children: _jsx(ResponsiveChart, { children: ({ height, width }) => {
73
- return (_jsx(NextPrev, { onChange: (slideIndex) => setCurrentIndex(slideIndex), defaultIndex: currentIndex, children: molecules && molecules.length > 0 ? (molecules.map((mol, index) => (_jsxs("div", { css: styles.items, children: [_jsx(MoleculeHeader, { currentMolecule: mol, molecules: molecules }), _jsx("div", { css: styles.slider, className: "mol-svg-container", onDoubleClick: () => openMoleculeEditor(mol), style: {
72
+ const lastIndex = molecules?.length > 0 ? molecules.length - 1 : 0;
73
+ const activeIndex = currentIndex > lastIndex ? lastIndex : currentIndex;
74
+ return (_jsxs("div", { css: styles.panel, children: [_jsx(MoleculePanelHeader, { currentIndex: activeIndex, moleculesView: moleculesView, molecules: molecules, onOpenMoleculeEditor: () => openMoleculeEditor(), onMoleculeIndexChange: moleculeIndexHandler }), _jsx("div", { css: styles.innerPanel, children: _jsx("div", { css: styles.molecule, children: _jsx(ResponsiveChart, { children: ({ height, width }) => {
75
+ return (_jsx(NextPrev, { onChange: (slideIndex) => setCurrentIndex(slideIndex), index: currentIndex, children: molecules && molecules.length > 0 ? (molecules.map((mol, index) => (_jsxs("div", { css: styles.items, children: [_jsx(MoleculeHeader, { currentMolecule: mol, molecules: molecules }), _jsx("div", { css: styles.slider, className: "mol-svg-container", onDoubleClick: () => openMoleculeEditor(mol), style: {
74
76
  backgroundColor: (index + 1) % 2 !== 0 ? '#fafafa' : 'white',
75
77
  }, children: _jsx(OCLnmr, { OCL: OCL, id: `molSVG${index}`, width: width, height: height - 60, molfile: mol.molfile || '', setMolfile: (molfile) => handleReplaceMolecule(mol, molfile), setSelectedAtom: handleOnClickAtom, atomHighlightColor: currentDiaIDsToHighlight &&
76
78
  currentDiaIDsToHighlight.length > 0
@@ -5,6 +5,7 @@ import { FaRegEdit } from 'react-icons/fa';
5
5
  import { Accordion, Toolbar, } from 'react-science/ui';
6
6
  import { useChartData } from '../context/ChartContext';
7
7
  import { usePreferences } from '../context/PreferencesContext';
8
+ import { useActiveSpectrum } from '../hooks/useActiveSpectrum';
8
9
  import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature';
9
10
  import { useDialogToggle } from '../hooks/useDialogToggle';
10
11
  import AutomaticAssignment from './AutomaticAssignment/AutomaticAssignment';
@@ -158,26 +159,25 @@ function PanelsInner({ displayerMode: displayedMode }) {
158
159
  const panelOptions = getPanelPreferences(item);
159
160
  return panelOptions?.display && panelOptions?.open;
160
161
  }
161
- const toolbars = {
162
- informationPanel: [
163
- {
164
- icon: _jsx(FaRegEdit, {}),
165
- onClick: ({ event }) => {
166
- event.stopPropagation();
167
- openDialog('informationModal');
168
- },
169
- },
170
- ],
171
- };
172
162
  return (_jsxs("div", { style: { width: '100%', height: '100%', flex: '1 1 0%' }, children: [_jsx(InformationEditionModal, { isOpen: dialog.informationModal, onCloseDialog: closeDialog }), _jsx(Accordion, { children: accordionItems.map((item) => {
173
163
  const { title, component, id } = item;
174
164
  let toolbar;
175
- if (id && toolbars[id]) {
176
- toolbar = (_jsx(Toolbar, { children: toolbars[id]?.map((options, index) => (_jsx(Toolbar.Item, { ...options }, index))) }));
165
+ if (id === 'informationPanel') {
166
+ toolbar = (_jsx(InformationPanelToolBar, { onEdit: ({ event }) => {
167
+ event.stopPropagation();
168
+ openDialog('informationModal');
169
+ } }));
177
170
  }
178
171
  return (check(item) && (_jsx(Accordion.Item, { title: title, defaultOpened: isOpened(item), toolbar: toolbar, children: component }, title)));
179
172
  }) })] }));
180
173
  }
174
+ function InformationPanelToolBar(props) {
175
+ const { onEdit } = props;
176
+ const activeSpectrum = useActiveSpectrum();
177
+ return (_jsx(Toolbar, { children: _jsx(Toolbar.Item, { disabled: !activeSpectrum, tooltipProps: { intent: !activeSpectrum ? 'danger' : 'none' }, icon: _jsx(FaRegEdit, {}), onClick: onEdit, tooltip: !activeSpectrum
178
+ ? 'Select a spectrum to edit its meta information'
179
+ : 'Edit spectrum meta information' }) }));
180
+ }
181
181
  const MemoizedPanels = memo(PanelsInner);
182
182
  export default function Panels() {
183
183
  const { displayerMode, toolOptions: { selectedTool }, } = useChartData();
@@ -9,7 +9,7 @@ import { useDispatch } from '../../context/DispatchContext';
9
9
  import { useLogger } from '../../context/LoggerContext';
10
10
  import { useToaster } from '../../context/ToasterContext';
11
11
  import Button from '../../elements/Button';
12
- import NextPrev from '../../elements/NextPrev';
12
+ import { NextPrev } from '../../elements/NextPrev';
13
13
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
14
14
  import { useMoleculeEditor } from '../../modal/MoleculeStructureEditorModal';
15
15
  import MoleculeHeader from '../MoleculesPanel/MoleculeHeader';
@@ -115,7 +115,7 @@ export default function PredictionPanel() {
115
115
  return (_jsx(NextPrev, { onChange: (slideIndex) => {
116
116
  setCurrentIndex(slideIndex);
117
117
  setMolfile(molecules[slideIndex].molfile);
118
- }, defaultIndex: currentIndex, style: {
118
+ }, index: currentIndex, style: {
119
119
  arrowContainer: {
120
120
  top: '40px',
121
121
  padding: '0 10px 0 55px',
@@ -0,0 +1,3 @@
1
+ import { Draft } from 'immer';
2
+ import { ChangeInformationBlockPosition, PreferencesState } from '../preferencesReducer';
3
+ export declare function changeInformationBlockPosition(draft: Draft<PreferencesState>, action: ChangeInformationBlockPosition): void;
@@ -0,0 +1,5 @@
1
+ import { getActiveWorkspace } from '../utilities/getActiveWorkspace';
2
+ export function changeInformationBlockPosition(draft, action) {
3
+ const currentWorkspacePreferences = getActiveWorkspace(draft);
4
+ currentWorkspacePreferences.infoBlock.position = action.payload.coordination;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { Draft } from 'immer';
2
+ import { ToggleInformationBlock, PreferencesState } from '../preferencesReducer';
3
+ export declare function toggleInformationBlock(draft: Draft<PreferencesState>, action: ToggleInformationBlock): void;
@@ -0,0 +1,7 @@
1
+ import { getActiveWorkspace } from '../utilities/getActiveWorkspace';
2
+ export function toggleInformationBlock(draft, action) {
3
+ const currentWorkspacePreferences = getActiveWorkspace(draft);
4
+ const { visible } = action.payload || {};
5
+ currentWorkspacePreferences.infoBlock.visible =
6
+ visible ?? !currentWorkspacePreferences.infoBlock.visible;
7
+ }