Skip to content

Commit 2b3e3e6

Browse files
authored
feat(processings): tools integrate operation generation (#4325)
1 parent 36a4d74 commit 2b3e3e6

7 files changed

Lines changed: 103 additions & 76 deletions

File tree

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
"@hookform/resolvers": "^5.9.1",
6666
"@tanstack/react-form": "^1.33.5",
6767
"@tanstack/react-store": "^0.11.1",
68-
"@zakodium/nmr-types": "^0.5.25",
69-
"@zakodium/nmrium-core": "^0.7.62",
70-
"@zakodium/nmrium-core-plugins": "^0.7.83",
68+
"@zakodium/nmr-types": "^0.5.26",
69+
"@zakodium/nmrium-core": "^0.7.64",
70+
"@zakodium/nmrium-core-plugins": "^0.7.86",
7171
"@zakodium/pdnd-esm": "^1.1.1",
7272
"@zakodium/utils": "^0.5.1",
7373
"@zip.js/zip.js": "^2.8.53",

src/component/panels/filtersPanel/processings_sections_panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function ProcessingsSectionsPanel() {
103103
{operatorsUI.map((operatorUI) => (
104104
<CoreOperatorPanelTool
105105
key={operatorUI.id}
106-
operator={operatorUI}
106+
operatorUI={operatorUI}
107107
activeOperatorId={selected}
108108
spectrum={spectrum}
109109
onTriggerOperation={(operation) =>

src/component/toolbar/nmr_toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export default function NMRToolbar() {
536536
pluginTools.map((operatorUI) => (
537537
<CoreOperatorTool
538538
key={operatorUI.id}
539-
operator={operatorUI}
539+
operatorUI={operatorUI}
540540
spectrum={stableSpectrum}
541541
activeOperatorId={activeOperatorId}
542542
onTriggerOperation={(operation) => {
Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,23 @@
1-
import type { ProcessingOperatorId } from '@zakodium/nmr-types';
2-
import type {
3-
ProcessingOperatorUI,
4-
ProcessingOperatorUIToolProps,
5-
} from '@zakodium/nmrium-core';
6-
import type { PartialPick } from '@zakodium/utils';
71
import { ErrorBoundary } from 'react-error-boundary';
82

9-
import { useCore } from '../../context/CoreContext.tsx';
103
import { ToolbarItemError } from '../toolbar_item_error.tsx';
114

12-
interface CoreOperatorPanelToolProps {
13-
operator: ProcessingOperatorUI<ProcessingOperatorId>;
14-
}
5+
import type { CoreOperatorToolProps } from './core_operator_tool.commons.ts';
6+
import { useToolProps } from './core_operator_tool.commons.ts';
157

16-
export function CoreOperatorPanelTool(
17-
props: PartialPick<
18-
Omit<ProcessingOperatorUIToolProps<ProcessingOperatorId>, 'core'>,
19-
'spectrum'
20-
> &
21-
CoreOperatorPanelToolProps,
22-
) {
23-
const { spectrum, activeOperatorId, onTriggerOperation, operator } = props;
24-
const core = useCore();
8+
export function CoreOperatorPanelTool(props: CoreOperatorToolProps) {
9+
const { spectrum, operatorUI } = props;
10+
const toolProps = useToolProps(props);
2511

2612
if (!spectrum) return null;
27-
if (!operator.PanelTool) return null;
13+
if (!toolProps) return null;
14+
if (!operatorUI.PanelTool) return null;
2815

29-
const { PanelTool } = operator;
16+
const { PanelTool } = operatorUI;
3017

3118
return (
3219
<ErrorBoundary FallbackComponent={ToolbarItemError}>
33-
<PanelTool
34-
core={core}
35-
spectrum={spectrum}
36-
activeOperatorId={activeOperatorId}
37-
onTriggerOperation={onTriggerOperation}
38-
/>
20+
<PanelTool {...toolProps} />
3921
</ErrorBoundary>
4022
);
4123
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type {
2+
ProcessingOperatorId,
3+
SpectrumProcessingOperation,
4+
} from '@zakodium/nmr-types';
5+
import type {
6+
ProcessingOperatorUI,
7+
ProcessingOperatorUIToolProps,
8+
} from '@zakodium/nmrium-core';
9+
import { generateID } from '@zakodium/nmrium-core';
10+
import type { PartialPick } from '@zakodium/utils';
11+
import { assertDefined, assertNotNullish } from '@zakodium/utils';
12+
import { useEventCallback } from 'usehooks-ts';
13+
14+
import { useCore } from '../../context/CoreContext.tsx';
15+
16+
interface CoreOperatorToolExtraProps {
17+
operatorUI: ProcessingOperatorUI<ProcessingOperatorId>;
18+
onTriggerOperation: (
19+
operation: SpectrumProcessingOperation<any, any>,
20+
) => void;
21+
}
22+
23+
export type CoreOperatorToolProps = PartialPick<
24+
Omit<ProcessingOperatorUIToolProps, 'core' | 'onTriggerOperation'>,
25+
'spectrum'
26+
> &
27+
CoreOperatorToolExtraProps;
28+
29+
export function useToolProps(
30+
props: CoreOperatorToolProps,
31+
): ProcessingOperatorUIToolProps | null {
32+
const {
33+
spectrum,
34+
activeOperatorId,
35+
onTriggerOperation: onTriggerOperationProp,
36+
operatorUI,
37+
} = props;
38+
const core = useCore();
39+
40+
const onTriggerOperation = useEventCallback(() => {
41+
const operator = core.getOperator(operatorUI.id);
42+
assertNotNullish(operator);
43+
assertDefined(spectrum);
44+
45+
onTriggerOperationProp({
46+
operatorId: operatorUI.id,
47+
uid: generateID(),
48+
settings: operator.getDefaultSettings(spectrum),
49+
options: undefined,
50+
enabled: true,
51+
error: undefined,
52+
});
53+
});
54+
55+
if (!spectrum) return null;
56+
57+
return {
58+
core,
59+
spectrum,
60+
activeOperatorId,
61+
onTriggerOperation,
62+
};
63+
}
Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,23 @@
1-
import type { ProcessingOperatorId } from '@zakodium/nmr-types';
2-
import type {
3-
ProcessingOperatorUI,
4-
ProcessingOperatorUIToolProps,
5-
} from '@zakodium/nmrium-core';
6-
import type { PartialPick } from '@zakodium/utils';
71
import { ErrorBoundary } from 'react-error-boundary';
82

9-
import { useCore } from '../../context/CoreContext.tsx';
103
import { ToolbarItemError } from '../toolbar_item_error.tsx';
114

12-
interface CoreOperatorToolProps {
13-
operator: ProcessingOperatorUI<ProcessingOperatorId>;
14-
}
5+
import type { CoreOperatorToolProps } from './core_operator_tool.commons.ts';
6+
import { useToolProps } from './core_operator_tool.commons.ts';
157

16-
export function CoreOperatorTool(
17-
props: PartialPick<
18-
Omit<ProcessingOperatorUIToolProps<ProcessingOperatorId>, 'core'>,
19-
'spectrum'
20-
> &
21-
CoreOperatorToolProps,
22-
) {
23-
const { spectrum, activeOperatorId, onTriggerOperation, operator } = props;
24-
const core = useCore();
8+
export function CoreOperatorTool(props: CoreOperatorToolProps) {
9+
const { spectrum, operatorUI } = props;
10+
const toolProps = useToolProps(props);
2511

2612
if (!spectrum) return null;
27-
if (!operator.Tool) return null;
13+
if (!toolProps) return null;
14+
if (!operatorUI.Tool) return null;
2815

29-
const { Tool } = operator;
16+
const { Tool } = operatorUI;
3017

3118
return (
3219
<ErrorBoundary FallbackComponent={ToolbarItemError}>
33-
<Tool
34-
core={core}
35-
spectrum={spectrum}
36-
activeOperatorId={activeOperatorId}
37-
onTriggerOperation={onTriggerOperation}
38-
/>
20+
<Tool {...toolProps} />
3921
</ErrorBoundary>
4022
);
4123
}

0 commit comments

Comments
 (0)