@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.
@@ -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
+ };
@@ -288,6 +288,7 @@ function Form(props: FormProps, ref: any) {
288
288
  return {
289
289
  id: getCurrentId()!,
290
290
  active_id: getCurrentId()!,
291
+ active_ids: [getCurrentId()!],
291
292
  parent_id: parentId,
292
293
  ...globalValues,
293
294
  };
@@ -18,7 +18,12 @@ import {
18
18
  ActionViewContext,
19
19
  ActionViewContextType,
20
20
  } from "@/context/ActionViewContext";
21
- import { getColorMap, getTree, sortResults } from "@/helpers/treeHelper";
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(() => {