nmrium 0.58.0 → 0.59.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 (112) hide show
  1. package/lib/component/1d/integral/IntegralResizable.js +2 -2
  2. package/lib/component/1d/matrix/useMatrix.d.ts +1 -1
  3. package/lib/component/1d/multiAnalysis/AnalysisRange.js +1 -1
  4. package/lib/component/1d/ranges/Atoms.js +6 -4
  5. package/lib/component/2d/Viewer2D.js +6 -2
  6. package/lib/component/2d/zones/Zone.js +2 -2
  7. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  8. package/lib/component/context/ChartContext.js +12 -1
  9. package/lib/component/context/ShareDataContext.d.ts +1 -1
  10. package/lib/component/context/ShareDataContext.js +2 -4
  11. package/lib/component/context/ToasterContext.d.ts +1 -0
  12. package/lib/component/context/ToasterContext.js +12 -3
  13. package/lib/component/elements/ActionsButtonsPopover.js +1 -3
  14. package/lib/component/elements/Alert.d.ts +20 -0
  15. package/lib/component/elements/Alert.js +80 -0
  16. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  17. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  18. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  19. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  20. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  21. package/lib/component/elements/Select2.d.ts +12 -7
  22. package/lib/component/elements/Select2.js +5 -4
  23. package/lib/component/elements/Select2Controller.d.ts +2 -2
  24. package/lib/component/elements/Select2Controller.js +5 -5
  25. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  26. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  27. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  28. package/lib/component/elements/print/PrintContent.js +281 -0
  29. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  30. package/lib/component/elements/print/PrintProvider.js +28 -0
  31. package/lib/component/elements/print/index.d.ts +2 -0
  32. package/lib/component/elements/print/index.js +2 -0
  33. package/lib/component/header/BaseLineCorrectionPanel.js +3 -0
  34. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  35. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  36. package/lib/component/loader/DropZone.js +3 -67
  37. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  38. package/lib/component/loader/useLoadFiles.js +78 -0
  39. package/lib/component/main/InnerNMRium.d.ts +4 -3
  40. package/lib/component/main/InnerNMRium.js +4 -9
  41. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  42. package/lib/component/main/InnerNMRiumContents.js +33 -29
  43. package/lib/component/main/NMRium.d.ts +2 -5
  44. package/lib/component/main/NMRium.js +1 -1
  45. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  46. package/lib/component/main/NMRiumRefAPI.js +12 -0
  47. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  48. package/lib/component/main/NMRiumViewer.js +35 -0
  49. package/lib/component/main/index.d.ts +1 -0
  50. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  51. package/lib/component/modal/CopyClipboardModal.js +18 -32
  52. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  53. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  54. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  55. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  56. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  57. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  58. package/lib/component/modal/setting/settingsValidation.js +15 -1
  59. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  60. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  61. package/lib/component/panels/Panels.js +2 -2
  62. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  63. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -12
  64. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  65. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  66. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +6 -2
  67. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +6 -2
  68. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -0
  69. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  70. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  71. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  72. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  73. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  74. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  75. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  76. package/lib/component/reducer/IgnoreActions.js +1 -0
  77. package/lib/component/reducer/Reducer.js +2 -4
  78. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  79. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  80. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  81. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  82. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  83. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  84. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  85. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  86. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  87. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  88. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -2
  89. package/lib/component/reducer/preferences/preferencesReducer.js +4 -1
  90. package/lib/component/toolbar/ToolBar.js +33 -14
  91. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  92. package/lib/data/SpectraManager.d.ts +7 -10
  93. package/lib/data/SpectraManager.js +51 -30
  94. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  95. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  96. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  97. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  98. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  99. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -10
  100. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  101. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -10
  102. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -10
  103. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  104. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  105. package/lib/data/molecules/MoleculeManager.js +16 -38
  106. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  107. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  108. package/lib/data/utilities/removeByPaths.js +33 -0
  109. package/lib/versionInfo.js +1 -1
  110. package/package.json +34 -34
  111. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  112. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -1,4 +1,5 @@
1
- import { array, object, string, number } from 'yup';
1
+ import { EXTERNAL_API_KEYS } from 'nmr-load-save';
2
+ import { array, object, string, number, mixed } from 'yup';
2
3
  import { checkUniqueByKey } from '../../utility/checkUniqueByKey';
3
4
  const nucleiValidation = array()
4
5
  .of(object().shape({
@@ -35,10 +36,23 @@ const spectraColorsSchemaValidation = object({
35
36
  const generalValidation = object({
36
37
  dimmedSpectraOpacity: number().min(0).max(1).required(),
37
38
  });
39
+ const externalAPIsValidation = array()
40
+ .of(object({
41
+ key: mixed()
42
+ .oneOf(EXTERNAL_API_KEYS.map(({ key }) => key))
43
+ .required(),
44
+ serverLink: string().url().required(),
45
+ APIKey: string().required(),
46
+ }))
47
+ .test('Unique', 'External API provider need te be unique', function check(apis) {
48
+ // eslint-disable-next-line no-invalid-this
49
+ return checkUniqueByKey(apis, 'key', this);
50
+ });
38
51
  export const validation = object().shape({
39
52
  nuclei: nucleiValidation,
40
53
  databases: databasesValidation,
41
54
  infoBlock: infoBlockValidation,
42
55
  general: generalValidation,
43
56
  spectraColors: spectraColorsSchemaValidation,
57
+ externalAPIs: externalAPIsValidation,
44
58
  });
@@ -7,7 +7,7 @@ import { useCallback, useMemo, useState, useRef, memo } from 'react';
7
7
  import { ImLink } from 'react-icons/im';
8
8
  import { useChartData } from '../../context/ChartContext';
9
9
  import { useDispatch } from '../../context/DispatchContext';
10
- import { useModal } from '../../elements/popup/Modal';
10
+ import { useAlert } from '../../elements/Alert';
11
11
  import { useActiveSpectrumIntegralsViewState } from '../../hooks/useActiveSpectrumIntegralsViewState';
12
12
  import useSpectrum from '../../hooks/useSpectrum';
13
13
  import ChangeSumModal from '../../modal/changeSum/ChangeSumModal';
@@ -21,7 +21,7 @@ function IntegralPanelInner({ integrals, info, activeTab, xDomain, }) {
21
21
  const [filterIsActive, setFilterIsActive] = useState(false);
22
22
  const dispatch = useDispatch();
23
23
  const { showIntegralsValues } = useActiveSpectrumIntegralsViewState();
24
- const modal = useModal();
24
+ const alert = useAlert();
25
25
  const [isFlipped, setFlipStatus] = useState(false);
26
26
  const settingRef = useRef();
27
27
  function handleShowIntegralsValues() {
@@ -34,11 +34,14 @@ function IntegralPanelInner({ integrals, info, activeTab, xDomain, }) {
34
34
  dispatch({ type: 'DELETE_INTEGRAL', payload: {} });
35
35
  }, [dispatch]);
36
36
  const handleDeleteAll = useCallback(() => {
37
- modal.showConfirmDialog({
37
+ alert.showAlert({
38
38
  message: 'All records will be deleted, Are You sure?',
39
- buttons: [{ text: 'Yes', handler: yesHandler }, { text: 'No' }],
39
+ buttons: [
40
+ { text: 'Yes', onClick: yesHandler, intent: 'danger' },
41
+ { text: 'No' },
42
+ ],
40
43
  });
41
- }, [modal, yesHandler]);
44
+ }, [alert, yesHandler]);
42
45
  const changeIntegralSumHandler = useCallback((options) => {
43
46
  dispatch({ type: 'CHANGE_INTEGRAL_SUM', payload: { options } });
44
47
  }, [dispatch]);
@@ -92,7 +92,11 @@ function InnerMatrixGenerationPanel() {
92
92
  const dispatch = useDispatch();
93
93
  const { dispatch: dispatchPreferences } = usePreferences();
94
94
  const { view: { spectra: { activeTab }, }, xDomain, originDomain, data, } = useChartData();
95
- const { getToggleVisibilityButtons } = useToggleSpectraVisibility();
95
+ const { getToggleVisibilityButtons } = useToggleSpectraVisibility({
96
+ enableHideSelected: false,
97
+ enableShowSelected: false,
98
+ enableShowSelectedOnly: false,
99
+ });
96
100
  const formRef = useRef(null);
97
101
  const nucleusMatrixOptions = usePanelPreferences('matrixGeneration', activeTab);
98
102
  const spectraPreferences = usePanelPreferences('spectra', activeTab);
@@ -58,7 +58,7 @@ const accordionItems = [
58
58
  mode: '1D',
59
59
  },
60
60
  {
61
- title: 'Ranges',
61
+ title: 'Ranges / Multiplet analysis',
62
62
  component: _jsx(RangesPanel, {}),
63
63
  hidePreferenceKey: 'rangesPanel',
64
64
  mode: '1D',
@@ -122,7 +122,7 @@ export const TOOLS_PANELS_ACCORDION = {
122
122
  null: 'Spectra',
123
123
  peakPicking: 'Peaks',
124
124
  integral: 'Integrals',
125
- rangePicking: 'Ranges',
125
+ rangePicking: 'Ranges / Multiplet analysis',
126
126
  zonePicking: 'Zones',
127
127
  multipleSpectraAnalysis: 'Multiple Spectra Analysis',
128
128
  };
@@ -10,7 +10,7 @@ import { useChartData } from '../../context/ChartContext';
10
10
  import { useDispatch } from '../../context/DispatchContext';
11
11
  import { usePreferences } from '../../context/PreferencesContext';
12
12
  import { useToaster } from '../../context/ToasterContext';
13
- import { useModal } from '../../elements/popup/Modal';
13
+ import { useAlert } from '../../elements/Alert';
14
14
  import { useActiveSpectrumPeaksViewState } from '../../hooks/useActiveSpectrumPeaksViewState';
15
15
  import useCheckExperimentalFeature from '../../hooks/useCheckExperimentalFeature';
16
16
  import { useFormatNumberByNucleus } from '../../hooks/useFormatNumberByNucleus';
@@ -26,7 +26,7 @@ function PeaksPanelInner({ peaks, info, xDomain, activeTab, peaksViewState, }) {
26
26
  const [isFlipped, setFlipStatus] = useState(false);
27
27
  const format = useFormatNumberByNucleus(info.nucleus);
28
28
  const dispatch = useDispatch();
29
- const modal = useModal();
29
+ const alert = useAlert();
30
30
  const toaster = useToaster();
31
31
  const isExperimental = useCheckExperimentalFeature();
32
32
  const settingRef = useRef();
@@ -34,11 +34,14 @@ function PeaksPanelInner({ peaks, info, xDomain, activeTab, peaksViewState, }) {
34
34
  dispatch({ type: 'DELETE_PEAK', payload: {} });
35
35
  }, [dispatch]);
36
36
  const handleDeleteAll = useCallback(() => {
37
- modal.showConfirmDialog({
37
+ alert.showAlert({
38
38
  message: 'All records will be deleted, Are You sure?',
39
- buttons: [{ text: 'Yes', handler: yesHandler }, { text: 'No' }],
39
+ buttons: [
40
+ { text: 'Yes', onClick: yesHandler, intent: 'danger' },
41
+ { text: 'No' },
42
+ ],
40
43
  });
41
- }, [modal, yesHandler]);
44
+ }, [alert, yesHandler]);
42
45
  const settingsPanelHandler = useCallback(() => {
43
46
  setFlipStatus(!isFlipped);
44
47
  }, [isFlipped]);
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { SvgNmrIntegrate, SvgNmrPeaks, SvgNmrPeaksTopLabels, } from 'cheminfo-font';
3
+ import { saveAs } from 'file-saver';
3
4
  import lodashGet from 'lodash/get';
4
- import { rangesToACS } from 'nmr-processing';
5
- import { FaFileExport, FaUnlink, FaSitemap, FaChartBar } from 'react-icons/fa';
5
+ import { rangesToACS, rangesToTSV } from 'nmr-processing';
6
+ import { useState } from 'react';
7
+ import { FaFileExport, FaUnlink, FaSitemap, FaChartBar, FaCopy, FaDownload, } from 'react-icons/fa';
6
8
  import { ImLink } from 'react-icons/im';
7
9
  import { LuSubtitles } from 'react-icons/lu';
8
10
  import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
@@ -10,6 +12,8 @@ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
10
12
  import { useAssignmentData } from '../../assignment/AssignmentsContext';
11
13
  import { useDispatch } from '../../context/DispatchContext';
12
14
  import { useToaster } from '../../context/ToasterContext';
15
+ import { useAlert } from '../../elements/Alert';
16
+ import { ToolbarPopoverItem, } from '../../elements/ToolbarPopoverItem';
13
17
  import { useModal } from '../../elements/popup/Modal';
14
18
  import { useActiveSpectrumRangesViewState } from '../../hooks/useActiveSpectrumRangesViewState';
15
19
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
@@ -17,13 +21,31 @@ import CopyClipboardModal from '../../modal/CopyClipboardModal';
17
21
  import ChangeSumModal from '../../modal/changeSum/ChangeSumModal';
18
22
  import { booleanToString } from '../../utility/booleanToString';
19
23
  import DefaultPanelHeader from '../header/DefaultPanelHeader';
24
+ const EXPORT_MENU = [
25
+ {
26
+ icon: _jsx(FaCopy, {}),
27
+ text: 'Preview publication string',
28
+ data: {
29
+ id: 'publicationString',
30
+ },
31
+ },
32
+ {
33
+ icon: _jsx(FaDownload, {}),
34
+ text: 'Export ranges as TSV',
35
+ data: {
36
+ id: 'rangesToTSV',
37
+ },
38
+ },
39
+ ];
20
40
  function RangesHeader({ ranges, info, onUnlink, onFilterActivated, onSettingClick, isFilterActive, filterCounter, activeTab, }) {
21
41
  const dispatch = useDispatch();
22
42
  const modal = useModal();
43
+ const alert = useAlert();
23
44
  const toaster = useToaster();
24
45
  const assignmentData = useAssignmentData();
25
46
  const currentSum = lodashGet(ranges, 'options.sum', null);
26
47
  const rangesPreferences = usePanelPreferences('ranges', activeTab);
48
+ const [acs, setACS] = useState();
27
49
  const { showMultiplicityTrees, showJGraph, showIntegrals, showIntegralsValues, showPeaks, displayingMode, showAssignmentsLabels, } = useActiveSpectrumRangesViewState();
28
50
  function changeRangesSumHandler(options) {
29
51
  dispatch({ type: 'CHANGE_RANGE_SUM', payload: { options } });
@@ -33,23 +55,27 @@ function RangesHeader({ ranges, info, onUnlink, onFilterActivated, onSettingClic
33
55
  onUnlink();
34
56
  }
35
57
  function handleOnRemoveAssignments() {
36
- modal.showConfirmDialog({
58
+ alert.showAlert({
37
59
  message: 'All assignments will be removed. Are you sure?',
38
- buttons: [{ text: 'Yes', handler: removeAssignments }, { text: 'No' }],
60
+ buttons: [
61
+ { text: 'Yes', onClick: removeAssignments, intent: 'danger' },
62
+ { text: 'No' },
63
+ ],
39
64
  });
40
65
  }
41
66
  function handleDeleteAll() {
42
- modal.showConfirmDialog({
67
+ alert.showAlert({
43
68
  message: 'All ranges will be deleted. Are You sure?',
44
69
  buttons: [
45
70
  {
46
71
  text: 'Yes',
47
- handler: () => {
72
+ onClick: () => {
48
73
  dispatch({
49
74
  type: 'DELETE_RANGE',
50
75
  payload: { assignmentData },
51
76
  });
52
77
  },
78
+ intent: 'danger',
53
79
  },
54
80
  { text: 'No' },
55
81
  ],
@@ -98,7 +124,7 @@ function RangesHeader({ ranges, info, onUnlink, onFilterActivated, onSettingClic
98
124
  couplingFormat: rangesPreferences.coupling.format,
99
125
  observedFrequency, //400
100
126
  });
101
- modal.show(_jsx(CopyClipboardModal, { text: result, onCopyClick: saveToClipboardHandler, onClose: () => modal.close() }), {});
127
+ setACS(result);
102
128
  }
103
129
  }
104
130
  function changeSumConstantFlagHandler() {
@@ -112,14 +138,28 @@ function RangesHeader({ ranges, info, onUnlink, onFilterActivated, onSettingClic
112
138
  function toggleDisplayingMode() {
113
139
  dispatch({ type: 'TOGGLE_RANGES_PEAKS_DISPLAYING_MODE' });
114
140
  }
141
+ function handleRangesToTSV() {
142
+ const tsv = rangesToTSV(ranges.values);
143
+ const blob = new Blob([tsv], { type: 'text/plain' });
144
+ saveAs(blob, `${info.name}.tsv`);
145
+ }
146
+ function exportHandler(data) {
147
+ switch (data?.id) {
148
+ case 'publicationString':
149
+ saveAsHTMLHandler();
150
+ break;
151
+ case 'rangesToTSV':
152
+ handleRangesToTSV();
153
+ break;
154
+ default:
155
+ break;
156
+ }
157
+ }
115
158
  const hasRanges = Array.isArray(ranges?.values) && ranges.values.length > 0;
116
159
  const total = ranges?.values?.length || 0;
117
- return (_jsxs("div", { children: [_jsx(DefaultPanelHeader, { total: total, counter: filterCounter, onDelete: handleDeleteAll, deleteToolTip: "Delete All Ranges", onFilter: onFilterActivated, filterToolTip: isFilterActive ? 'Show all ranges' : 'Hide ranges out of view', onSettingClick: onSettingClick, leftButtons: [
160
+ return (_jsxs("div", { children: [_jsx(CopyClipboardModal, { text: acs, title: "Publication string", onCopyClick: saveToClipboardHandler, onClose: () => setACS('') }), _jsx(DefaultPanelHeader, { total: total, counter: filterCounter, onDelete: handleDeleteAll, deleteToolTip: "Delete All Ranges", onFilter: onFilterActivated, filterToolTip: isFilterActive ? 'Show all ranges' : 'Hide ranges out of view', onSettingClick: onSettingClick, leftButtons: [
118
161
  {
119
- disabled: !hasRanges,
120
- icon: _jsx(FaFileExport, {}),
121
- tooltip: 'Preview publication string',
122
- onClick: saveAsHTMLHandler,
162
+ component: (_jsx(ToolbarPopoverItem, { disabled: !hasRanges, icon: _jsx(FaFileExport, {}), tooltip: "Export as", options: EXPORT_MENU, onClick: exportHandler })),
123
163
  },
124
164
  {
125
165
  component: (_jsx(ChangeSumModal, { onSave: changeRangesSumHandler, sumType: "ranges", currentSum: currentSum, sumOptions: ranges?.options })),
@@ -8,7 +8,7 @@ import { useChartData } from '../../context/ChartContext';
8
8
  import { useDispatch } from '../../context/DispatchContext';
9
9
  import { usePreferences } from '../../context/PreferencesContext';
10
10
  import { useToaster } from '../../context/ToasterContext';
11
- import { useModal } from '../../elements/popup/Modal';
11
+ import { useAlert } from '../../elements/Alert';
12
12
  import { useActiveSpectra } from '../../hooks/useActiveSpectra';
13
13
  import useSpectrum from '../../hooks/useSpectrum';
14
14
  import { useToggleSpectraVisibility } from '../../hooks/useToggleSpectraVisibility';
@@ -28,25 +28,25 @@ function getMissingProjection(spectraData, activeTab) {
28
28
  return missingNucleus;
29
29
  }
30
30
  function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTab, displayerMode, onSettingClick, }) {
31
- const modal = useModal();
31
+ const alert = useAlert();
32
32
  const toaster = useToaster();
33
33
  const dispatch = useDispatch();
34
- const { getToggleVisibilityButtons } = useToggleSpectraVisibility('selected');
35
34
  const { current: { spectraColors }, } = usePreferences();
36
35
  const handleDelete = useCallback(() => {
37
- modal.showConfirmDialog({
36
+ alert.showAlert({
38
37
  message: (_jsxs("span", { children: ["You are about to delete", _jsxs("span", { style: { color: 'black' }, children: [" ", activeSpectra?.length, " "] }), "spectra, Are you sure?"] })),
39
38
  buttons: [
40
39
  {
41
40
  text: 'Yes',
42
- handler: () => {
41
+ onClick: () => {
43
42
  dispatch({ type: 'DELETE_SPECTRA', payload: {} });
44
43
  },
44
+ intent: 'danger',
45
45
  },
46
46
  { text: 'No' },
47
47
  ],
48
48
  });
49
- }, [activeSpectra?.length, dispatch, modal]);
49
+ }, [activeSpectra?.length, alert, dispatch]);
50
50
  function addMissingProjectionHandler() {
51
51
  const missingNucleus = getMissingProjection(data, activeTab);
52
52
  if (missingNucleus.length > 0) {
@@ -79,6 +79,13 @@ function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTa
79
79
  }
80
80
  const hasActiveSpectra = activeSpectra && activeSpectra?.length > 0;
81
81
  const spectraLengthPerTab = getSpectraByNucleus(activeTab, data)?.length;
82
+ const { getToggleVisibilityButtons } = useToggleSpectraVisibility(spectraLengthPerTab < 5
83
+ ? {
84
+ enableHideSelected: false,
85
+ enableShowSelected: false,
86
+ enableShowSelectedOnly: false,
87
+ }
88
+ : {});
82
89
  let leftButtons = getToggleVisibilityButtons(!hasActiveSpectra);
83
90
  if (displayerMode === '2D' && activeSpectrum?.info.isFt) {
84
91
  leftButtons.push({
@@ -4,9 +4,11 @@ import lodashGet from 'lodash/get';
4
4
  import { useMemo, useCallback, useState } from 'react';
5
5
  import { FaCopy, FaRegTrashAlt, FaFileExport } from 'react-icons/fa';
6
6
  import { IoColorPaletteOutline } from 'react-icons/io5';
7
+ import { exportForCT } from '../../../data/SpectraManager';
7
8
  import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
8
9
  import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
9
10
  import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
11
+ import { useChartData } from '../../context/ChartContext';
10
12
  import { useDispatch } from '../../context/DispatchContext';
11
13
  import { useToaster } from '../../context/ToasterContext';
12
14
  import { ContextMenu, } from '../../elements/ContextMenuBluePrint';
@@ -46,6 +48,7 @@ var SpectraContextMenuOptionsKeys;
46
48
  SpectraContextMenuOptionsKeys["ExportAsJcamp"] = "ExportAsJcamp";
47
49
  SpectraContextMenuOptionsKeys["ExportAsText"] = "ExportAsText";
48
50
  SpectraContextMenuOptionsKeys["CopyAsText"] = "CopyAsText";
51
+ SpectraContextMenuOptionsKeys["ExportForCT"] = "ExportForCT";
49
52
  })(SpectraContextMenuOptionsKeys || (SpectraContextMenuOptionsKeys = {}));
50
53
  const Spectra2DContextMenuOptions = [
51
54
  {
@@ -59,24 +62,48 @@ const Spectra2DContextMenuOptions = [
59
62
  data: { id: SpectraContextMenuOptionsKeys.Delete },
60
63
  },
61
64
  ];
62
- const Spectra1DContextMenuOptions = [
63
- ...Spectra2DContextMenuOptions,
64
- {
65
- text: 'Export as JCAMP-DX',
66
- icon: _jsx(FaFileExport, {}),
67
- data: { id: SpectraContextMenuOptionsKeys.ExportAsJcamp },
68
- },
69
- {
70
- text: 'Export as text',
71
- icon: _jsx(FaFileExport, {}),
72
- data: { id: SpectraContextMenuOptionsKeys.ExportAsText },
73
- },
74
- {
75
- text: 'Copy as text',
76
- icon: _jsx(FaCopy, {}),
77
- data: { id: SpectraContextMenuOptionsKeys.CopyAsText },
78
- },
79
- ];
65
+ function getSpectra1DContextMenuOptions(options) {
66
+ const { molecules = [] } = options;
67
+ return [
68
+ ...Spectra2DContextMenuOptions,
69
+ {
70
+ text: 'Export as JCAMP-DX',
71
+ icon: _jsx(FaFileExport, {}),
72
+ data: { id: SpectraContextMenuOptionsKeys.ExportAsJcamp },
73
+ },
74
+ {
75
+ text: 'Export as text',
76
+ icon: _jsx(FaFileExport, {}),
77
+ data: { id: SpectraContextMenuOptionsKeys.ExportAsText },
78
+ },
79
+ {
80
+ text: 'Copy as text',
81
+ icon: _jsx(FaCopy, {}),
82
+ data: { id: SpectraContextMenuOptionsKeys.CopyAsText },
83
+ },
84
+ {
85
+ text: 'Export for CT',
86
+ icon: _jsx(FaFileExport, {}),
87
+ data: { id: SpectraContextMenuOptionsKeys.ExportForCT },
88
+ tooltip: {
89
+ content: 'A chemical structure and a processed proton spectrum are required to use CT',
90
+ },
91
+ disabled: (spectrum) => !isValidExportForCT(spectrum, molecules),
92
+ },
93
+ ];
94
+ }
95
+ function isValidExportForCT(spectrum, molecules) {
96
+ if (!isSpectrum1D(spectrum)) {
97
+ return false;
98
+ }
99
+ if (!spectrum.info.isFt) {
100
+ return false;
101
+ }
102
+ if (!(Array.isArray(molecules) && molecules.length > 0)) {
103
+ return false;
104
+ }
105
+ return true;
106
+ }
80
107
  export function SpectraTable(props) {
81
108
  const { data, activeSpectra, onChangeVisibility, onOpenSettingModal, onChangeActiveSpectrum, nucleus, } = props;
82
109
  const toaster = useToaster();
@@ -85,6 +112,7 @@ export function SpectraTable(props) {
85
112
  const activeSpectraObj = getActiveSpectraAsObject(activeSpectra);
86
113
  const [exportedSpectrum, setExportedSpectrum] = useState();
87
114
  const { rawWriteWithType, shouldFallback, cleanShouldFallback, text } = useClipboard();
115
+ const { molecules } = useChartData();
88
116
  const COLUMNS = useMemo(() => ({
89
117
  visible: {
90
118
  id: 'hide-show-spectrum',
@@ -114,7 +142,7 @@ export function SpectraTable(props) {
114
142
  },
115
143
  },
116
144
  }), [onChangeVisibility, onOpenSettingModal]);
117
- const selectContextMenuHandler = useCallback((option, spectrum) => {
145
+ const selectContextMenuHandler = useCallback(async (option, spectrum) => {
118
146
  const { id } = option;
119
147
  switch (id) {
120
148
  case SpectraContextMenuOptionsKeys.CopyToClipboard: {
@@ -152,11 +180,23 @@ export function SpectraTable(props) {
152
180
  }));
153
181
  break;
154
182
  }
183
+ case SpectraContextMenuOptionsKeys.ExportForCT: {
184
+ try {
185
+ await exportForCT({ spectrum, molecules });
186
+ }
187
+ catch (error) {
188
+ const message = error?.message;
189
+ if (message) {
190
+ toaster.show({ intent: 'danger', message });
191
+ }
192
+ }
193
+ break;
194
+ }
155
195
  default: {
156
196
  break;
157
197
  }
158
198
  }
159
- }, [dispatch, rawWriteWithType, toaster]);
199
+ }, [dispatch, molecules, rawWriteWithType, toaster]);
160
200
  function handleActiveRow(row) {
161
201
  return activeSpectraObj?.[row?.original.id] || false;
162
202
  }
@@ -219,7 +259,9 @@ export function SpectraTable(props) {
219
259
  };
220
260
  }
221
261
  const contextMenu = nucleus.split(',').length === 1
222
- ? Spectra1DContextMenuOptions
262
+ ? getSpectra1DContextMenuOptions({
263
+ molecules,
264
+ })
223
265
  : Spectra2DContextMenuOptions;
224
266
  return (_jsxs(_Fragment, { children: [_jsx(ReactTable, { rowStyle: handleRowStyle, activeRow: handleActiveRow, data: data, columns: tableColumns, onClick: (e, data) => onChangeActiveSpectrum(e, data.original), enableVirtualScroll: true, approxItemHeight: 24, contextMenu: contextMenu, onContextMenuSelect: selectContextMenuHandler, onSortEnd: handleSortEnd, style: { 'table td': { paddingTop: 0, paddingBottom: 0 } } }), exportedSpectrum && (_jsx(ExportAsJcampModal, { spectrum: exportedSpectrum, closeDialog: () => {
225
267
  setExportedSpectrum(null);
@@ -4,6 +4,7 @@ import { getCorrelationDelta, getLinkDim } from 'nmr-correlation';
4
4
  import { useCallback, useMemo, useRef } from 'react';
5
5
  import { buildID } from '../../../../data/utilities/Concatenation';
6
6
  import { findRangeOrZoneID } from '../../../../data/utilities/FindUtilities';
7
+ import { useAlert } from '../../../elements/Alert';
7
8
  import ContextMenu from '../../../elements/ContextMenu';
8
9
  import { positions, useModal } from '../../../elements/popup/Modal';
9
10
  import { useHighlight } from '../../../highlight';
@@ -13,6 +14,7 @@ import EditLinkModal from './editLink/EditLinkModal';
13
14
  function AdditionalColumnHeader({ spectraData, correlationsData, correlation, onEdit, }) {
14
15
  const contextRef = useRef();
15
16
  const modal = useModal();
17
+ const alert = useAlert();
16
18
  const highlightIDsAdditionalColumn = useMemo(() => {
17
19
  if (correlation.pseudo === true) {
18
20
  return [];
@@ -99,14 +101,15 @@ function AdditionalColumnHeader({ spectraData, correlationsData, correlation, on
99
101
  {
100
102
  label: `delete all (${correlation.label.origin})`,
101
103
  onClick: () => {
102
- modal.showConfirmDialog({
104
+ alert.showAlert({
103
105
  message: `All signals of ${correlation.label.origin} (${getCorrelationDelta(correlation).toFixed(2)}) will be deleted. Are you sure?`,
104
106
  buttons: [
105
107
  {
106
108
  text: 'Yes',
107
- handler: () => {
109
+ onClick: () => {
108
110
  onEdit([correlation], 'removeAll');
109
111
  },
112
+ intent: 'danger',
110
113
  },
111
114
  { text: 'No' },
112
115
  ],
@@ -117,6 +120,7 @@ function AdditionalColumnHeader({ spectraData, correlationsData, correlation, on
117
120
  ])
118
121
  : [];
119
122
  }, [
123
+ alert,
120
124
  correlation,
121
125
  correlationsData.values,
122
126
  highlightAdditionalColumn,
@@ -3,6 +3,7 @@ import { buildLink, getCorrelationDelta, getLabel, getLinkDim, } from 'nmr-corre
3
3
  import { useCallback, useMemo, useRef } from 'react';
4
4
  import { buildID } from '../../../../data/utilities/Concatenation';
5
5
  import { findRangeOrZoneID } from '../../../../data/utilities/FindUtilities';
6
+ import { useAlert } from '../../../elements/Alert';
6
7
  import ContextMenu from '../../../elements/ContextMenu';
7
8
  import EditableColumn from '../../../elements/EditableColumn';
8
9
  import { positions, useModal } from '../../../elements/popup/Modal';
@@ -14,6 +15,7 @@ import EditLinkModal from './editLink/EditLinkModal';
14
15
  function CorrelationTableRow({ additionalColumnData, correlations, correlation, styleRow, styleLabel, onSaveEditEquivalences, onSaveEditNumericValues, onEditCorrelationTableCellHandler, spectraData, }) {
15
16
  const contextRef = useRef();
16
17
  const modal = useModal();
18
+ const alert = useAlert();
17
19
  const highlightIDsRow = useMemo(() => {
18
20
  if (correlation.pseudo === true) {
19
21
  return [];
@@ -141,14 +143,15 @@ function CorrelationTableRow({ additionalColumnData, correlations, correlation,
141
143
  {
142
144
  label: `delete ${correlation.label.origin}`,
143
145
  onClick: () => {
144
- modal.showConfirmDialog({
146
+ alert.showAlert({
145
147
  message: `All signals of ${correlation.label.origin} (${getCorrelationDelta(correlation).toFixed(2)}) will be deleted. Are you sure?`,
146
148
  buttons: [
147
149
  {
148
150
  text: 'Yes',
149
- handler: () => {
151
+ onClick: () => {
150
152
  onEditCorrelationTableCellHandler([correlation], 'removeAll');
151
153
  },
154
+ intent: 'danger',
152
155
  },
153
156
  { text: 'No' },
154
157
  ],
@@ -164,6 +167,7 @@ function CorrelationTableRow({ additionalColumnData, correlations, correlation,
164
167
  modal,
165
168
  onEditCorrelationTableCellHandler,
166
169
  correlations,
170
+ alert,
167
171
  ]);
168
172
  const contextMenuHandler = useCallback((e) => {
169
173
  e.preventDefault();
@@ -198,6 +198,10 @@ function SummaryPanel() {
198
198
  });
199
199
  }, [dispatch]);
200
200
  const deleteCorrelationHandler = useCallback((correlation) => {
201
+ const correlationLinks = correlation?.links;
202
+ if (!(Array.isArray(correlationLinks) && correlationLinks.length > 0)) {
203
+ return;
204
+ }
201
205
  dispatch({
202
206
  type: 'DELETE_CORRELATION',
203
207
  payload: {
@@ -7,7 +7,7 @@ import { LuSubtitles } from 'react-icons/lu';
7
7
  import { useAssignmentData } from '../../assignment/AssignmentsContext';
8
8
  import { useChartData } from '../../context/ChartContext';
9
9
  import { useDispatch } from '../../context/DispatchContext';
10
- import { useModal } from '../../elements/popup/Modal';
10
+ import { useAlert } from '../../elements/Alert';
11
11
  import { useActiveSpectrumZonesViewState } from '../../hooks/useActiveSpectrumZonesViewState';
12
12
  import useSpectrum from '../../hooks/useSpectrum';
13
13
  import { booleanToString } from '../../utility/booleanToString';
@@ -20,7 +20,7 @@ function ZonesPanelInner({ zones, activeTab, xDomain, yDomain, info, showZones,
20
20
  const [filterIsActive, setFilterIsActive] = useState(false);
21
21
  const assignmentData = useAssignmentData();
22
22
  const dispatch = useDispatch();
23
- const modal = useModal();
23
+ const alert = useAlert();
24
24
  const [isFlipped, setFlipStatus] = useState(false);
25
25
  const settingRef = useRef();
26
26
  const tableData = useMemo(() => {
@@ -73,25 +73,33 @@ function ZonesPanelInner({ zones, activeTab, xDomain, yDomain, info, showZones,
73
73
  unlinkZoneHandler();
74
74
  }, [unlinkZoneHandler]);
75
75
  const handleOnRemoveAssignments = useCallback(() => {
76
- modal.showConfirmDialog({
76
+ alert.showAlert({
77
77
  message: 'All assignments will be removed. Are you sure?',
78
- buttons: [{ text: 'Yes', handler: removeAssignments }, { text: 'No' }],
78
+ buttons: [
79
+ {
80
+ text: 'Yes',
81
+ onClick: removeAssignments,
82
+ intent: 'danger',
83
+ },
84
+ { text: 'No' },
85
+ ],
79
86
  });
80
- }, [removeAssignments, modal]);
87
+ }, [removeAssignments, alert]);
81
88
  const handleDeleteAll = useCallback(() => {
82
- modal.showConfirmDialog({
89
+ alert.showAlert({
83
90
  message: 'All zones will be deleted. Are You sure?',
84
91
  buttons: [
85
92
  {
86
93
  text: 'Yes',
87
- handler: () => {
94
+ onClick: () => {
88
95
  dispatch({ type: 'DELETE_2D_ZONE', payload: { assignmentData } });
89
96
  },
97
+ intent: 'danger',
90
98
  },
91
99
  { text: 'No' },
92
100
  ],
93
101
  });
94
- }, [assignmentData, dispatch, modal]);
102
+ }, [assignmentData, dispatch, alert]);
95
103
  const settingsPanelHandler = useCallback(() => {
96
104
  setFlipStatus(!isFlipped);
97
105
  }, [isFlipped]);
@@ -177,7 +177,7 @@ function DatabasePanelInner({ nucleus, selectedTool, databases, defaultDatabase,
177
177
  }, [result.data]);
178
178
  const resurrectHandler = useCallback((rowData) => {
179
179
  const { index, baseURL, jcampURL: jcampRelativeURL } = rowData;
180
- const { ranges, solvent, names = [], id: spectrumID, } = result.data[index];
180
+ const databaseEntry = result.data[index];
181
181
  if (jcampRelativeURL) {
182
182
  const url = new URL(jcampRelativeURL, baseURL);
183
183
  setTimeout(async () => {
@@ -189,11 +189,10 @@ function DatabasePanelInner({ nucleus, selectedTool, databases, defaultDatabase,
189
189
  entries: [{ baseURL: url.origin, relativePath: url.pathname }],
190
190
  });
191
191
  const spectrum = data?.spectra?.[0] || null;
192
- if (spectrum && isSpectrum1D(spectrum) && spectrumID) {
193
- spectrum.id = spectrumID;
192
+ if (spectrum && isSpectrum1D(spectrum)) {
194
193
  dispatch({
195
- type: 'RESURRECTING_SPECTRUM_FROM_JCAMP',
196
- payload: { ranges, spectrum },
194
+ type: 'RESURRECTING_SPECTRUM',
195
+ payload: { source: 'jcamp', databaseEntry, spectrum },
197
196
  });
198
197
  }
199
198
  }
@@ -207,11 +206,11 @@ function DatabasePanelInner({ nucleus, selectedTool, databases, defaultDatabase,
207
206
  }
208
207
  else {
209
208
  dispatch({
210
- type: 'RESURRECTING_SPECTRUM_FROM_RANGES',
211
- payload: { ranges, info: { solvent, nucleus, name: names[0] } },
209
+ type: 'RESURRECTING_SPECTRUM',
210
+ payload: { source: 'rangesOrSignals', databaseEntry },
212
211
  });
213
212
  }
214
- }, [dispatch, nucleus, result.data, toaster]);
213
+ }, [dispatch, result.data, toaster]);
215
214
  const saveHandler = useCallback((row) => {
216
215
  if (row?.jcampURL) {
217
216
  setTimeout(async () => {