@camunda/ccma-saas-frontend 0.17.4 → 0.17.6
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.
|
@@ -54,5 +54,5 @@ export function C4ActionableNotification(props) {
|
|
|
54
54
|
}, children: _jsxs(C3ResponsiveStack, { alignItems: 'center', justifyContent: 'space-between', children: [_jsxs(C3ResponsiveStack, { orientation: props?.orientation ?? 'horizontal', gap: 1, children: [_jsx("span", { className: 'cds--actionable-notification__title', children: props.title }), _jsx("p", { children: props.subtitle })] }), buttonSlot] }) })] }));
|
|
55
55
|
}
|
|
56
56
|
const { kind, title, subtitle, actionButtonLabel, onActionButtonClick, hideCloseButton, onCloseButtonClick, secondaryActionButtonLabel, onSecondaryActionButtonClick, } = props;
|
|
57
|
-
return (
|
|
57
|
+
return (_jsx(Alert, { variant: kindToAlertVariant(kind), title: typeof title === 'string' ? title : undefined, description: subtitle, dismissible: !hideCloseButton, onDismiss: onCloseButtonClick, children: _jsxs("div", { className: 'flex flex-wrap gap-4', children: [actionButtonLabel ? (_jsx(Button, { variant: 'link', className: 'h-auto p-0', onClick: onActionButtonClick, children: actionButtonLabel })) : undefined, secondaryActionButtonLabel && onSecondaryActionButtonClick ? (_jsx(Button, { variant: 'link', className: 'h-auto p-0', onClick: onSecondaryActionButtonClick, children: secondaryActionButtonLabel })) : undefined] }) }));
|
|
58
58
|
}
|
|
@@ -5,13 +5,27 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
* You may not use this file except in compliance with the commercial license.
|
|
6
6
|
*/
|
|
7
7
|
import { InlineLoading, ProgressIndicator, ProgressStep } from '@carbon/react';
|
|
8
|
-
import { useState } from 'react';
|
|
8
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
9
9
|
import { Button, ComposedModal, ModalBody, ModalFooter, ModalHeader, Stack, } from '../../ui/index.js';
|
|
10
10
|
import { C4InlineNotification } from '../c4-inline-notification/c4-inline-notification.js';
|
|
11
11
|
export const C4MultiStepModal = ({ title, subtitle, steps, isOpen, onClose, preventCloseOnClickOutside, }) => {
|
|
12
12
|
const [step, setStep] = useState(0);
|
|
13
13
|
const [error, setError] = useState('');
|
|
14
14
|
const [asyncWork, setAsyncWork] = useState(false);
|
|
15
|
+
// Counts the opens and closes. An action that settles after the count moved
|
|
16
|
+
// belongs to an old session, so it must not touch the state of the new one.
|
|
17
|
+
const session = useRef(0);
|
|
18
|
+
// A host keeps this component mounted while the modal is closed. Without
|
|
19
|
+
// the reset, the next open starts on the step where the last run ended. A
|
|
20
|
+
// layout effect resets before the first paint, so the old step never shows.
|
|
21
|
+
useLayoutEffect(() => {
|
|
22
|
+
session.current += 1;
|
|
23
|
+
if (isOpen) {
|
|
24
|
+
setStep(0);
|
|
25
|
+
setError('');
|
|
26
|
+
setAsyncWork(false);
|
|
27
|
+
}
|
|
28
|
+
}, [isOpen]);
|
|
15
29
|
const currentStep = steps[step];
|
|
16
30
|
const { primary, secondary } = currentStep.actions;
|
|
17
31
|
const component = (_jsxs(ComposedModal, { open: isOpen, onClose: onClose, preventCloseOnClickOutside: preventCloseOnClickOutside ?? false, children: [_jsx(ModalHeader, { title: title, label: subtitle }), _jsx(ModalBody, { children: _jsxs(Stack, { gap: 8, children: [_jsx(ProgressIndicator, { currentIndex: step, spaceEqually: true, children: steps.map((step, index) => (_jsx(ProgressStep, { label: step.title, secondaryLabel: step.subtitle }, index))) }), currentStep.content, error.length > 0 && (_jsx(C4InlineNotification, { kind: 'error', title: 'Error', subtitle: error }))] }) }), _jsxs(ModalFooter, { children: [_jsx(Button, { kind: secondary.kind, disabled: asyncWork || secondary.disabled, onClick: () => {
|
|
@@ -29,8 +43,12 @@ export const C4MultiStepModal = ({ title, subtitle, steps, isOpen, onClose, prev
|
|
|
29
43
|
if (primary.isAsync) {
|
|
30
44
|
setAsyncWork(true);
|
|
31
45
|
}
|
|
46
|
+
const startedIn = session.current;
|
|
32
47
|
try {
|
|
33
48
|
await primary.onClick(step);
|
|
49
|
+
if (startedIn !== session.current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
34
52
|
if (primary.isAsync) {
|
|
35
53
|
setAsyncWork(false);
|
|
36
54
|
}
|
|
@@ -39,6 +57,9 @@ export const C4MultiStepModal = ({ title, subtitle, steps, isOpen, onClose, prev
|
|
|
39
57
|
}
|
|
40
58
|
}
|
|
41
59
|
catch (error) {
|
|
60
|
+
if (startedIn !== session.current) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
42
63
|
// Enable the buttons again, so the user can fix the input and retry.
|
|
43
64
|
if (primary.isAsync) {
|
|
44
65
|
setAsyncWork(false);
|