orc-shared 5.7.0-dev.8 → 5.7.0-dev.9
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.
|
@@ -51,11 +51,13 @@ var ActionModal = function ActionModal(_ref) {
|
|
|
51
51
|
var actionPanel = /*#__PURE__*/_react.default.createElement("div", {
|
|
52
52
|
className: classes.actionPanel
|
|
53
53
|
}, actions.map(function (action) {
|
|
54
|
+
var _action$disabled;
|
|
54
55
|
return /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
55
56
|
key: action.label.id,
|
|
56
57
|
variant: action.isPrimary ? "contained" : "outlined",
|
|
57
58
|
color: action.isPrimary ? "primary" : "default",
|
|
58
59
|
disableElevation: action.isPrimary,
|
|
60
|
+
disabled: (_action$disabled = action.disabled) != null ? _action$disabled : false,
|
|
59
61
|
onClick: function onClick(e) {
|
|
60
62
|
return action.handler(e);
|
|
61
63
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ const ActionModal = ({
|
|
|
20
20
|
message,
|
|
21
21
|
open,
|
|
22
22
|
type,
|
|
23
|
-
actions, // Array of objects containing
|
|
23
|
+
actions, // Array of objects containing four properties: label, handler, isPrimary & disabled
|
|
24
24
|
backdropClickCallback,
|
|
25
25
|
}) => {
|
|
26
26
|
const classes = useStyles();
|
|
@@ -42,6 +42,7 @@ const ActionModal = ({
|
|
|
42
42
|
variant={action.isPrimary ? "contained" : "outlined"}
|
|
43
43
|
color={action.isPrimary ? "primary" : "default"}
|
|
44
44
|
disableElevation={action.isPrimary}
|
|
45
|
+
disabled={action.disabled ?? false}
|
|
45
46
|
onClick={e => action.handler(e)}
|
|
46
47
|
>
|
|
47
48
|
<FormattedMessage {...action.label} />
|
|
@@ -17,8 +17,8 @@ describe("ActionModal", () => {
|
|
|
17
17
|
const open = true;
|
|
18
18
|
const message = "message";
|
|
19
19
|
|
|
20
|
-
const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true };
|
|
21
|
-
const actionTwo = { label: sharedMessages.no, handler: jest.fn() };
|
|
20
|
+
const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true, disabled: false };
|
|
21
|
+
const actionTwo = { label: sharedMessages.no, handler: jest.fn(), disabled: false };
|
|
22
22
|
const actionThree = { label: sharedMessages.cancel, handler: jest.fn() };
|
|
23
23
|
|
|
24
24
|
const backdropClickCallback = jest.fn();
|
|
@@ -32,13 +32,81 @@ describe("ActionModal", () => {
|
|
|
32
32
|
|
|
33
33
|
const actionPanel = (
|
|
34
34
|
<div>
|
|
35
|
-
<Button
|
|
35
|
+
<Button
|
|
36
|
+
key="1"
|
|
37
|
+
variant="contained"
|
|
38
|
+
color="primary"
|
|
39
|
+
disabled={false}
|
|
40
|
+
onClick={() => actionOne.handler()}
|
|
41
|
+
disableElevation
|
|
42
|
+
>
|
|
36
43
|
{stringifyWithoutQuotes(messages["orc-shared.yes"])}
|
|
37
44
|
</Button>
|
|
38
|
-
<Button key="2" variant="outlined" onClick={() => actionTwo.handler()}>
|
|
45
|
+
<Button key="2" variant="outlined" disabled={false} onClick={() => actionTwo.handler()}>
|
|
39
46
|
{stringifyWithoutQuotes(messages["orc-shared.no"])}
|
|
40
47
|
</Button>
|
|
41
|
-
<Button key="3" variant="outlined" onClick={() => actionThree.handler()}>
|
|
48
|
+
<Button key="3" variant="outlined" disabled={false} onClick={() => actionThree.handler()}>
|
|
49
|
+
{stringifyWithoutQuotes(messages["orc-shared.cancel"])}
|
|
50
|
+
</Button>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
modalProps.set(ModalProps.propNames.actionPanel, actionPanel);
|
|
55
|
+
|
|
56
|
+
const component = (
|
|
57
|
+
<IntlProvider locale="en-US" messages={messages}>
|
|
58
|
+
<ActionModal
|
|
59
|
+
message={message}
|
|
60
|
+
open={open}
|
|
61
|
+
actions={[actionOne, actionTwo, actionThree]}
|
|
62
|
+
backdropClickCallback={backdropClickCallback}
|
|
63
|
+
/>
|
|
64
|
+
</IntlProvider>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const expected = (
|
|
68
|
+
<IntlProvider locale="en-US" messages={messages}>
|
|
69
|
+
<Modal message={message} modalProps={modalProps} />
|
|
70
|
+
</IntlProvider>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(component, "when mounted", "to satisfy", expected);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("Renders ActionModal correctly with disabled actions", () => {
|
|
77
|
+
const open = true;
|
|
78
|
+
const message = "message";
|
|
79
|
+
|
|
80
|
+
const actionOne = { label: sharedMessages.yes, handler: jest.fn(), isPrimary: true, disabled: true };
|
|
81
|
+
const actionTwo = { label: sharedMessages.no, handler: jest.fn(), disabled: false };
|
|
82
|
+
const actionThree = { label: sharedMessages.cancel, handler: jest.fn() };
|
|
83
|
+
|
|
84
|
+
const backdropClickCallback = jest.fn();
|
|
85
|
+
const modalProps = new ModalProps();
|
|
86
|
+
|
|
87
|
+
const titleComponent = stringifyWithoutQuotes(messages["orc-shared.confirmation"]);
|
|
88
|
+
|
|
89
|
+
modalProps.set(ModalProps.propNames.title, titleComponent);
|
|
90
|
+
modalProps.set(ModalProps.propNames.open, open);
|
|
91
|
+
modalProps.set(ModalProps.propNames.backdropClickCallback, backdropClickCallback);
|
|
92
|
+
modalProps.set(ModalProps.propNames.type, "fullwidth");
|
|
93
|
+
|
|
94
|
+
const actionPanel = (
|
|
95
|
+
<div>
|
|
96
|
+
<Button
|
|
97
|
+
key="1"
|
|
98
|
+
variant="contained"
|
|
99
|
+
color="primary"
|
|
100
|
+
disabled={true}
|
|
101
|
+
onClick={() => actionOne.handler()}
|
|
102
|
+
disableElevation
|
|
103
|
+
>
|
|
104
|
+
{stringifyWithoutQuotes(messages["orc-shared.yes"])}
|
|
105
|
+
</Button>
|
|
106
|
+
<Button key="2" variant="outlined" disabled={false} onClick={() => actionTwo.handler()}>
|
|
107
|
+
{stringifyWithoutQuotes(messages["orc-shared.no"])}
|
|
108
|
+
</Button>
|
|
109
|
+
<Button key="3" variant="outlined" disabled={false} onClick={() => actionThree.handler()}>
|
|
42
110
|
{stringifyWithoutQuotes(messages["orc-shared.cancel"])}
|
|
43
111
|
</Button>
|
|
44
112
|
</div>
|
|
@@ -51,6 +119,7 @@ describe("ActionModal", () => {
|
|
|
51
119
|
<ActionModal
|
|
52
120
|
message={message}
|
|
53
121
|
open={open}
|
|
122
|
+
type={"fullwidth"}
|
|
54
123
|
actions={[actionOne, actionTwo, actionThree]}
|
|
55
124
|
backdropClickCallback={backdropClickCallback}
|
|
56
125
|
/>
|