@gisce/react-ooui 0.17.0 → 0.18.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.
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/widgets/WidgetFactory.d.ts.map +1 -1
- package/dist/widgets/WidgetFactory.js +2 -0
- package/dist/widgets/WidgetFactory.js.map +1 -1
- package/dist/widgets/custom/ButtonGroup.d.ts +8 -0
- package/dist/widgets/custom/ButtonGroup.d.ts.map +1 -0
- package/dist/widgets/custom/ButtonGroup.js +188 -0
- package/dist/widgets/custom/ButtonGroup.js.map +1 -0
- package/dist/widgets/views/Form.d.ts.map +1 -1
- package/dist/widgets/views/Form.js +1 -1
- package/dist/widgets/views/Form.js.map +1 -1
- package/dist/widgets/views/SearchTree.d.ts.map +1 -1
- package/dist/widgets/views/SearchTree.js +1 -1
- package/dist/widgets/views/SearchTree.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/stories/custom/ButtonGroup.stories.tsx +58 -0
- package/src/widgets/WidgetFactory.tsx +3 -0
- package/src/widgets/custom/ButtonGroup.tsx +155 -0
- package/src/widgets/views/Form.tsx +1 -0
- package/src/widgets/views/SearchTree.tsx +7 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import React, { useContext, useState } from "react";
|
|
2
|
+
import Field from "@/common/Field";
|
|
3
|
+
import { DownOutlined } from '@ant-design/icons';
|
|
4
|
+
import { Dropdown, Menu } from "antd";
|
|
5
|
+
import { ButtonGroup as ButtonGroupOoui, Button as ButtonOoui, Field as FieldOoui } from "@gisce/ooui";
|
|
6
|
+
import showConfirmDialog from "@/ui/ConfirmDialog";
|
|
7
|
+
import { FormContext, FormContextType } from "@/context/FormContext";
|
|
8
|
+
import { LoadingOutlined } from "@ant-design/icons";
|
|
9
|
+
import iconMapper from "@/helpers/iconMapper";
|
|
10
|
+
import { WidgetProps } from "@/types";
|
|
11
|
+
import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
|
|
12
|
+
|
|
13
|
+
type ButtonGroupProps = {
|
|
14
|
+
ooui: ButtonGroupOoui;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type ItemsProps = {
|
|
18
|
+
ooui: ButtonOoui[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const ButtonGroup = (props: ButtonGroupProps) => {
|
|
22
|
+
const { ooui } = props;
|
|
23
|
+
const { defaultButton, secondaryButtons } = ooui;
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
caption,
|
|
27
|
+
activated,
|
|
28
|
+
buttonType,
|
|
29
|
+
confirmMessage,
|
|
30
|
+
icon,
|
|
31
|
+
primary,
|
|
32
|
+
danger,
|
|
33
|
+
context,
|
|
34
|
+
readOnly,
|
|
35
|
+
} = defaultButton || {};
|
|
36
|
+
const formContext = useContext(FormContext) as FormContextType;
|
|
37
|
+
const { executeButtonAction } = formContext || {};
|
|
38
|
+
const [isRunning, setIsRunning] = useState<boolean>(false);
|
|
39
|
+
const { lang } = useContext(LocaleContext) as LocaleContextType;
|
|
40
|
+
|
|
41
|
+
function getButtonIcon() {
|
|
42
|
+
if (isRunning) return <LoadingOutlined />;
|
|
43
|
+
if (icon) {
|
|
44
|
+
const Icon: React.ElementType = iconMapper(icon);
|
|
45
|
+
return Icon && <Icon />;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function onClick_confirm() {
|
|
51
|
+
if (buttonType && id) {
|
|
52
|
+
setIsRunning(true);
|
|
53
|
+
await executeButtonAction({ type: buttonType, action: id, context });
|
|
54
|
+
setIsRunning(false);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function onClick() {
|
|
59
|
+
if (confirmMessage) {
|
|
60
|
+
showConfirmDialog({
|
|
61
|
+
confirmMessage,
|
|
62
|
+
lang,
|
|
63
|
+
onOk: () => {
|
|
64
|
+
onClick_confirm();
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
onClick_confirm();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Field ooui={new FieldOoui({...{ooui}})}>
|
|
75
|
+
<Dropdown.Button
|
|
76
|
+
disabled={!activated || readOnly}
|
|
77
|
+
onClick={onClick}
|
|
78
|
+
icon={<DownOutlined/>}
|
|
79
|
+
type={primary ? "primary" : undefined}
|
|
80
|
+
//danger={danger ? true : undefined} This works but typescript
|
|
81
|
+
// doesn't accept
|
|
82
|
+
overlay={<Items ooui={secondaryButtons} />}
|
|
83
|
+
>
|
|
84
|
+
{getButtonIcon()}{caption}
|
|
85
|
+
</Dropdown.Button>
|
|
86
|
+
</Field>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const Items = (props: ItemsProps) => {
|
|
91
|
+
const { ooui } = props;
|
|
92
|
+
const items = ooui.map((button) => {
|
|
93
|
+
const {
|
|
94
|
+
id,
|
|
95
|
+
caption,
|
|
96
|
+
activated,
|
|
97
|
+
buttonType,
|
|
98
|
+
confirmMessage,
|
|
99
|
+
icon,
|
|
100
|
+
context,
|
|
101
|
+
readOnly,
|
|
102
|
+
danger,
|
|
103
|
+
} = button;
|
|
104
|
+
const formContext = useContext(FormContext) as FormContextType;
|
|
105
|
+
const { executeButtonAction } = formContext || {};
|
|
106
|
+
const [isRunning, setIsRunning] = useState<boolean>(false);
|
|
107
|
+
const { lang } = useContext(LocaleContext) as LocaleContextType;
|
|
108
|
+
|
|
109
|
+
async function onClick_confirm() {
|
|
110
|
+
setIsRunning(true);
|
|
111
|
+
await executeButtonAction({ type: buttonType, action: id, context });
|
|
112
|
+
setIsRunning(false);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function onClick() {
|
|
116
|
+
if (confirmMessage) {
|
|
117
|
+
showConfirmDialog({
|
|
118
|
+
confirmMessage,
|
|
119
|
+
lang,
|
|
120
|
+
onOk: () => {
|
|
121
|
+
onClick_confirm();
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
onClick_confirm();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getButtonIcon() {
|
|
131
|
+
if (isRunning) return <LoadingOutlined />;
|
|
132
|
+
if (icon) {
|
|
133
|
+
const Icon: React.ElementType = iconMapper(icon);
|
|
134
|
+
return Icon && <Icon />;
|
|
135
|
+
}
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<Menu.Item
|
|
141
|
+
disabled={!activated || readOnly}
|
|
142
|
+
onClick={onClick}
|
|
143
|
+
icon={getButtonIcon()}
|
|
144
|
+
danger={danger}
|
|
145
|
+
>
|
|
146
|
+
{caption}
|
|
147
|
+
</Menu.Item>
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
return (
|
|
151
|
+
<Menu>
|
|
152
|
+
{items}
|
|
153
|
+
</Menu>
|
|
154
|
+
)
|
|
155
|
+
};
|
|
@@ -18,7 +18,12 @@ import {
|
|
|
18
18
|
ActionViewContext,
|
|
19
19
|
ActionViewContextType,
|
|
20
20
|
} from "@/context/ActionViewContext";
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
getColorMap,
|
|
23
|
+
getTableItems,
|
|
24
|
+
getTree,
|
|
25
|
+
sortResults,
|
|
26
|
+
} from "@/helpers/treeHelper";
|
|
22
27
|
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
|
23
28
|
import Measure from "react-measure";
|
|
24
29
|
import { mergeSearchFields } from "@/helpers/formHelper";
|
|
@@ -337,7 +342,7 @@ function SearchTree(props: Props, ref: any) {
|
|
|
337
342
|
|
|
338
343
|
setResults([...getResults(), ...children]);
|
|
339
344
|
|
|
340
|
-
return children;
|
|
345
|
+
return getTableItems(getTree(treeView!), children);
|
|
341
346
|
}
|
|
342
347
|
|
|
343
348
|
useEffect(() => {
|