Skip to content

Commit bf24333

Browse files
committed
chore: refactor
1 parent af33f45 commit bf24333

File tree

12 files changed

+84
-48
lines changed

12 files changed

+84
-48
lines changed

demo/diagram.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<zeebe:ioMapping>
2929
<zeebe:input source="=secret_key" target="api_key" />
3030
<zeebe:input source="=&#34;http://users.com/get&#34;" target="url" />
31+
<zeebe:input source="=false" target="publish" />
3132
<zeebe:output source="=response.body.id" target="user_id" />
3233
<zeebe:output source="=response.body.name" target="user_name" />
3334
</zeebe:ioMapping>

eslint.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ export default [
6060
return {
6161
...config,
6262
files: files.test
63-
};
63+
};
6464
}),
65+
{
66+
languageOptions: {
67+
globals: {
68+
sinon: true,
69+
}
70+
},
71+
files: files.test
72+
}
6573
];
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
1-
import React, { useMemo, useState } from 'react';
1+
import React, { useState } from 'react';
22

33
import { Button, ButtonSkeleton, Tooltip } from '@carbon/react';
44

5-
export default function RunButton({ onClick, error }) {
5+
/**
6+
* Carbon React Button wrapped in a tooltip.
7+
*
8+
* Displays a loading skeleton if `skeleton` prop is true and `onClick` returns a promise.
9+
*/
10+
export default function CustomButton({ children, onClick, kind, tooltip, skeleton }) {
611

712
const [ loading, setLoading ] = useState(false);
813

9-
const tooltipContent = useMemo(() => {
10-
if (error) {
11-
return 'Invalid JSON';
12-
}
13-
return null;
14-
}, [ error ]);
15-
1614
const handleClick = () => {
17-
if (onClick) {
18-
setLoading(true);
19-
onClick().finally(() => setLoading(false));
20-
}
15+
setLoading(true);
16+
onClick()?.finally(() => setLoading(false));
2117
};
2218

23-
if (loading) {
19+
if (loading && skeleton) {
2420
return (
2521
<ButtonSkeleton size="sm" className="cds--layout--size-sm" />
2622
);
2723
}
2824

2925
return (
3026
<Tooltip
31-
className={ `${tooltipContent ? '' : 'hide-tooltip'}` }
32-
label={ tooltipContent }
27+
className={ `${tooltip ? '' : 'hide-tooltip'}` }
28+
label={ tooltip }
3329
align="bottom"
3430
leaveDelayMs={ 100 }>
3531
<span tabIndex="0" style={ { display: 'inline-block' } }>
3632
<Button
33+
kind={ kind }
3734
onClick={ handleClick }
38-
disabled={ error }
3935
size="sm"
4036
>
41-
Run this task
37+
{ children }
4238
</Button>
4339
</span>
4440
</Tooltip>

lib/components/Input/Input.jsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { Link } from '@carbon/react';
44
import { Launch } from '@carbon/icons-react';
55

66
import InputEditor from './InputEditor';
7-
8-
import RunButton from './RunButton';
9-
10-
// import './Input.scss';
7+
import Button from '../Button/Button';
118

129
export default function Input({
1310
element,
@@ -36,10 +33,21 @@ export default function Input({
3633
</p>
3734
</div>
3835
<div className="section__header--buttons">
39-
<RunButton
40-
onClick={ () => onRunTask(input) }
41-
error={ error }
42-
/>
36+
<Button
37+
kind="ghost"
38+
onClick={ handleReset }
39+
tooltip="Reset to input mapping"
40+
>
41+
Reset
42+
</Button>
43+
<Button
44+
kind="primary"
45+
onClick={ handleRun }
46+
tooltip={ error && 'Invalid JSON' }
47+
skeleton
48+
>
49+
Run
50+
</Button>
4351
</div>
4452
</div>
4553
<div className="section__content">

lib/components/Output/Output.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ import React, { useMemo } from 'react';
22

33
import { CodeSnippet, InlineLoading } from '@carbon/react';
44

5-
// import './Output.scss';
65

7-
export default function Output({ output, loading }) {
6+
export default function Output({ output, running }) {
87

98
const value = useMemo(() => {
10-
if (output instanceof Error) {
9+
if (error) {
1110
return output.message;
1211
}
1312
return JSON.stringify(output, null, 2);
14-
}, [ output ]);
13+
}, [ output, error ]);
1514

1615
const error = useMemo(() => {
1716
return output instanceof Error;
1817
}, [ output ]);
1918

2019
const status = useMemo(() => {
21-
if (loading) {
20+
if (running) {
2221
return (
2322
<InlineLoading
2423
description="Running task..."
@@ -36,7 +35,7 @@ export default function Output({ output, loading }) {
3635
}
3736

3837
return <div>No output</div>;
39-
}, [ loading, output, error ]);
38+
}, [ running, output, error ]);
4039

4140
return (
4241
<div className="section">
@@ -53,7 +52,7 @@ export default function Output({ output, loading }) {
5352
{ status}
5453
</div>
5554
<div className="result">
56-
{value && !loading && <CodeSnippet
55+
{value && !running && <CodeSnippet
5756
className="snippet"
5857
type="multi"
5958
align="left"

lib/hooks/useSelectedElement.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { useState, useEffect } from 'react';
33
import { is } from 'bpmn-js/lib/util/ModelUtil.js';
44

55
/**
6-
* Get currently selected BPMN element.
6+
* Get currently selected BPMN element, if it is a single `bpmn:Task`.
77
*
88
* @param {Object} injector
9-
* @returns {Object|null} BPMN element or `null` if no or more than one elements are selected
9+
* @return {Object|null} Selected BPMN element or null
1010
*/
1111
export function useSelectedElement(injector) {
1212

@@ -28,7 +28,7 @@ export function useSelectedElement(injector) {
2828
return () => {
2929
eventBus.off('selection.changed', handleSelection);
3030
};
31-
}, [ injector ]);
31+
}, [ ]);
3232

3333
return selectedElement;
3434
}

lib/hooks/useVariableResolver.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ZeebeVariableResolver from '@bpmn-io/variable-resolver/lib/zeebe/Variable
77
*/
88
export function useVariableResolver(injector, element) {
99

10+
const [ variables, setVariables ] = useState();
1011
const [ fetching, setFetching ] = useState(false);
1112

1213
const variableResolver = useMemo(() => {
@@ -16,7 +17,6 @@ export function useVariableResolver(injector, element) {
1617
return resolver;
1718
}, [ injector ]);
1819

19-
const [ variables, setVariables ] = useState();
2020

2121
useEffect(() => {
2222
if (!element) {
@@ -36,10 +36,10 @@ export function useVariableResolver(injector, element) {
3636
};
3737

3838
fetchVariables();
39-
}, [ element, variableResolver ]);
39+
}, [ element ]);
4040

4141
return {
42-
variables,
43-
fetching
42+
resolvedVariables: variables,
43+
fetchingVariables: fetching
4444
};
4545
}

lib/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function TaskTesting({
2727
saveConfig
2828
}) {
2929

30-
const [ loading, setLoading ] = useState(false);
30+
const [ running, setRunning ] = useState(false);
3131

3232
const element = useSelectedElement(injector);
3333
const { variables, fetching: loadingVariables } = useVariableResolver(injector, element);
@@ -61,7 +61,7 @@ export default function TaskTesting({
6161

6262
const handleRunTask = async () => {
6363

64-
setLoading(true);
64+
setRunning(true);
6565
const camundaApi = { deploy, startInstance, getInstance };
6666

6767
try {
@@ -70,7 +70,7 @@ export default function TaskTesting({
7070
} catch (error) {
7171
setOutput(error);
7272
} finally {
73-
setLoading(false);
73+
setRunning(false);
7474
}
7575
};
7676

@@ -95,7 +95,7 @@ export default function TaskTesting({
9595
/>
9696
<Output
9797
output={ output }
98-
loading={ loading }
98+
running={ running }
9999
/>
100100
</div>
101101
);

lib/style/_editor.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,26 @@
3333
span {
3434
font-style: italic;
3535
}
36+
37+
pre {
38+
margin-top: 6px;
39+
}
40+
}
41+
42+
// JSON linter error
43+
.cm-line:has(.cm-lintPoint-error) {
44+
background-color: rgba(255, 0, 0, 0.1);
45+
46+
&::after {
47+
content: "" var(--error-message, "Error");
48+
color: #d32f2f;
49+
font-size: 12px;
50+
font-style: italic;
51+
margin-left: 8px;
52+
}
53+
}
54+
55+
.cm-lintPoint-error::after {
56+
display: none;
3657
}
3758
}

lib/style/_layout.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
.section__header--buttons {
2929
display: flex;
3030
align-items: center;
31+
gap: 3px;
3132
}
3233

3334
.section__content {

0 commit comments

Comments
 (0)