@gisce/react-ooui 2.0.0-alpha.61 → 2.0.0-alpha.63

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.
Files changed (246) hide show
  1. package/dist/react-ooui.es.js +5 -2
  2. package/dist/react-ooui.es.js.map +1 -1
  3. package/dist/widgets/views/Tree/treeComponents.d.ts.map +1 -1
  4. package/package.json +6 -8
  5. package/src/ConnectionProvider.ts +0 -16
  6. package/src/__tests__/iconMapper.test.ts +0 -30
  7. package/src/__tests__/searchFilterHelper.spec.ts +0 -386
  8. package/src/actionbar/ActionButton.tsx +0 -40
  9. package/src/actionbar/AttachmentsButton.tsx +0 -132
  10. package/src/actionbar/AttachmentsButtonWrapper.tsx +0 -157
  11. package/src/actionbar/ButtonWithBadge.tsx +0 -44
  12. package/src/actionbar/ChangeViewButton.tsx +0 -137
  13. package/src/actionbar/DashboardActionBar.tsx +0 -63
  14. package/src/actionbar/DropdownButton.tsx +0 -124
  15. package/src/actionbar/FormActionBar.tsx +0 -491
  16. package/src/actionbar/GraphActionBar.tsx +0 -67
  17. package/src/actionbar/NewButton.tsx +0 -46
  18. package/src/actionbar/SearchBar.tsx +0 -73
  19. package/src/actionbar/TreeActionBar.tsx +0 -383
  20. package/src/common/ButtonWithTooltip.tsx +0 -18
  21. package/src/common/DatePicker.tsx +0 -98
  22. package/src/common/Field.tsx +0 -93
  23. package/src/common/SelectAllRecordsRow.tsx +0 -94
  24. package/src/common/TimePicker.tsx +0 -38
  25. package/src/context/ActionViewContext.tsx +0 -213
  26. package/src/context/ConfigContext.tsx +0 -28
  27. package/src/context/ContentRootContext.tsx +0 -461
  28. package/src/context/DashboardActionContext.tsx +0 -44
  29. package/src/context/FormContext.tsx +0 -79
  30. package/src/context/FormModalContext.tsx +0 -28
  31. package/src/context/LocaleContext.tsx +0 -50
  32. package/src/context/One2manyContext.tsx +0 -45
  33. package/src/context/TabManagerContext.tsx +0 -117
  34. package/src/helpers/containerHelper.ts +0 -145
  35. package/src/helpers/dayjs.ts +0 -21
  36. package/src/helpers/dynamicColumnsHelper.ts +0 -73
  37. package/src/helpers/errorHelper.ts +0 -27
  38. package/src/helpers/filesHelper.ts +0 -41
  39. package/src/helpers/formHelper.ts +0 -301
  40. package/src/helpers/iconMapper.ts +0 -164
  41. package/src/helpers/logInfoHelper.tsx +0 -30
  42. package/src/helpers/one2manyHelper.ts +0 -194
  43. package/src/helpers/searchHelper.ts +0 -196
  44. package/src/helpers/timeHelper.ts +0 -58
  45. package/src/helpers/treeHelper.tsx +0 -226
  46. package/src/helpers/viewHelper.ts +0 -23
  47. package/src/hooks/useEffectDebugger.ts +0 -43
  48. package/src/hooks/useExport.ts +0 -439
  49. package/src/hooks/useFetchViews.ts +0 -0
  50. package/src/hooks/useSearch.ts +0 -434
  51. package/src/hooks/useWindowDimensions.ts +0 -33
  52. package/src/index.ts +0 -168
  53. package/src/locales/ca_ES.tsx +0 -99
  54. package/src/locales/en_US.tsx +0 -96
  55. package/src/locales/es_ES.tsx +0 -101
  56. package/src/stories/Binary.stories.tsx +0 -23
  57. package/src/stories/Boolean.stories.tsx +0 -22
  58. package/src/stories/Button.stories.tsx +0 -130
  59. package/src/stories/Char.stories.tsx +0 -76
  60. package/src/stories/FiberGrid.stories.tsx +0 -109
  61. package/src/stories/Float.stories.tsx +0 -22
  62. package/src/stories/FloatTime.stories.tsx +0 -32
  63. package/src/stories/Image.stories.tsx +0 -25
  64. package/src/stories/Integer.stories.tsx +0 -22
  65. package/src/stories/Label.stories.tsx +0 -100
  66. package/src/stories/Many2one.stories.tsx +0 -31
  67. package/src/stories/One2many.stories.tsx +0 -288
  68. package/src/stories/ProgressBar.stories.tsx +0 -22
  69. package/src/stories/Reference.stories.tsx +0 -43
  70. package/src/stories/Selection.stories.tsx +0 -34
  71. package/src/stories/Separator.stories.tsx +0 -53
  72. package/src/stories/Text.stories.tsx +0 -35
  73. package/src/stories/Time.stories.tsx +0 -31
  74. package/src/stories/Utils.stories.tsx +0 -14
  75. package/src/stories/containers/Group.stories.tsx +0 -84
  76. package/src/stories/containers/NewLine.stories.tsx +0 -52
  77. package/src/stories/containers/Notebook.stories.tsx +0 -188
  78. package/src/stories/custom/Avatar.stories.tsx +0 -22
  79. package/src/stories/custom/ButtonGroup.stories.tsx +0 -74
  80. package/src/stories/custom/CodeEditor.stories.tsx +0 -25
  81. package/src/stories/custom/Comments.stories.tsx +0 -197
  82. package/src/stories/custom/Indicator.stories.tsx +0 -36
  83. package/src/stories/custom/Markdown.stories.tsx +0 -38
  84. package/src/stories/custom/MultiCheckbox.stories.tsx +0 -60
  85. package/src/stories/custom/Radio.stories.tsx +0 -68
  86. package/src/stories/custom/Steps.stories.tsx +0 -43
  87. package/src/stories/custom/Switch.stories.tsx +0 -23
  88. package/src/stories/custom/Tag.stories.tsx +0 -66
  89. package/src/stories/custom/Tags.stories.tsx +0 -74
  90. package/src/stories/dashboard/Dashboard.stories.tsx +0 -23
  91. package/src/stories/dashboard/DashboardGrid.stories.tsx +0 -43
  92. package/src/stories/forms/ActivacioContracteForm.stories.tsx +0 -25
  93. package/src/stories/forms/Attachment.stories.tsx +0 -24
  94. package/src/stories/forms/CUPSForm.stories.tsx +0 -25
  95. package/src/stories/forms/Company.stories.tsx +0 -25
  96. package/src/stories/forms/CrmCaseForm.stories.tsx +0 -25
  97. package/src/stories/forms/Documents.stories.tsx +0 -25
  98. package/src/stories/forms/FormWithGridFiber.stories.tsx +0 -25
  99. package/src/stories/forms/FormWithLinks.stories.tsx +0 -30
  100. package/src/stories/forms/Lead.stories.tsx +0 -25
  101. package/src/stories/forms/ModContractForm.stories.tsx +0 -26
  102. package/src/stories/forms/PartnersForm.stories.tsx +0 -25
  103. package/src/stories/forms/PolissaForm.stories.tsx +0 -25
  104. package/src/stories/forms/PreferencesForm.stories.tsx +0 -691
  105. package/src/stories/forms/Signatures.stories.tsx +0 -25
  106. package/src/stories/forms/Switching.stories.tsx +0 -25
  107. package/src/stories/graphs/GraphIndicator.stories.tsx +0 -20
  108. package/src/stories/graphs/PieGraph.stories.tsx +0 -78
  109. package/src/stories/mocks/index.ts +0 -46
  110. package/src/stories/mocks/mockProvider.ts +0 -189
  111. package/src/stories/mocks/models/activacioContracte.ts +0 -112
  112. package/src/stories/mocks/models/attachment.ts +0 -1326
  113. package/src/stories/mocks/models/butlleti.ts +0 -296
  114. package/src/stories/mocks/models/company.ts +0 -135
  115. package/src/stories/mocks/models/crm_case.ts +0 -595
  116. package/src/stories/mocks/models/cups.ts +0 -937
  117. package/src/stories/mocks/models/document.ts +0 -223
  118. package/src/stories/mocks/models/factura.ts +0 -2713
  119. package/src/stories/mocks/models/form_with_gridfiber.ts +0 -141
  120. package/src/stories/mocks/models/hist_autoconsum.ts +0 -146
  121. package/src/stories/mocks/models/lead.ts +0 -2101
  122. package/src/stories/mocks/models/modcontractual.ts +0 -952
  123. package/src/stories/mocks/models/partner.ts +0 -1340
  124. package/src/stories/mocks/models/polissa.ts +0 -3127
  125. package/src/stories/mocks/models/res_partner_category.ts +0 -15
  126. package/src/stories/mocks/models/signatura.ts +0 -558
  127. package/src/stories/mocks/models/switching.ts +0 -767
  128. package/src/stories/modals/FormModal.stories.tsx +0 -36
  129. package/src/stories/modals/SearchModal.stories.tsx +0 -37
  130. package/src/stories/trees/FacturesTree.stories.tsx +0 -16
  131. package/src/stories/ui/ActionBar.stories.tsx +0 -21
  132. package/src/stories/ui/FavouriteButton.stories.tsx +0 -16
  133. package/src/stories/ui/GoToResourceModal.stories.tsx +0 -25
  134. package/src/stories/views/ActionView.stories.tsx +0 -28
  135. package/src/stories/views/SearchTree.stories.tsx +0 -1064
  136. package/src/stories/views/Tab.stories.tsx +0 -93
  137. package/src/stories/views/TabsAndContent.stories.tsx +0 -88
  138. package/src/stories/views/Tree.stories.jsx +0 -178
  139. package/src/stories/views/searchFilter/DateRangePicker.stories.tsx +0 -22
  140. package/src/stories/views/searchFilter/DateTimeRangePicker.stories.tsx +0 -23
  141. package/src/stories/views/searchFilter/PairFields.stories.tsx +0 -23
  142. package/src/stories/views/searchFilter/SearchFilter.stories.tsx +0 -165
  143. package/src/stories/views/searchFilter/examples/PartnersSearchFilter.stories.tsx +0 -409
  144. package/src/types/index.ts +0 -392
  145. package/src/ui/ActionErrorDialog.tsx +0 -24
  146. package/src/ui/ConfirmDialog.tsx +0 -28
  147. package/src/ui/ErrorAlert.tsx +0 -37
  148. package/src/ui/FavouriteButton.tsx +0 -271
  149. package/src/ui/FormErrorsDialog.tsx +0 -17
  150. package/src/ui/GenericErrorDialog.tsx +0 -16
  151. package/src/ui/GoToResourceModal.tsx +0 -76
  152. package/src/ui/InfoDialog.tsx +0 -13
  153. package/src/ui/RefreshItemDialog.tsx +0 -29
  154. package/src/ui/RemoveItemDialog.tsx +0 -20
  155. package/src/ui/TitleHeader.tsx +0 -117
  156. package/src/ui/UnlinkItemDialog.tsx +0 -20
  157. package/src/ui/UnsavedChangesDialog.tsx +0 -29
  158. package/src/ui/WarningDialog.tsx +0 -17
  159. package/src/views/ActionView.tsx +0 -526
  160. package/src/views/CurrentTabContent.tsx +0 -21
  161. package/src/views/RootView.tsx +0 -509
  162. package/src/views/TabContent.tsx +0 -31
  163. package/src/views/TabSelector.tsx +0 -31
  164. package/src/views/Welcome.tsx +0 -18
  165. package/src/views/actionViews/DashboardActionView.tsx +0 -52
  166. package/src/views/actionViews/FormActionView.tsx +0 -70
  167. package/src/views/actionViews/GraphActionView.tsx +0 -152
  168. package/src/views/actionViews/TreeActionView.tsx +0 -87
  169. package/src/views/tabs/Tab.tsx +0 -82
  170. package/src/widgets/WidgetFactory.tsx +0 -142
  171. package/src/widgets/base/Binary.tsx +0 -145
  172. package/src/widgets/base/Boolean.tsx +0 -44
  173. package/src/widgets/base/Button.tsx +0 -77
  174. package/src/widgets/base/Char.tsx +0 -157
  175. package/src/widgets/base/Date.tsx +0 -12
  176. package/src/widgets/base/DateTime.tsx +0 -12
  177. package/src/widgets/base/Email.tsx +0 -27
  178. package/src/widgets/base/Float.tsx +0 -38
  179. package/src/widgets/base/FloatTime.tsx +0 -73
  180. package/src/widgets/base/Image.tsx +0 -120
  181. package/src/widgets/base/Integer.tsx +0 -55
  182. package/src/widgets/base/Label.tsx +0 -56
  183. package/src/widgets/base/LinkInput.tsx +0 -106
  184. package/src/widgets/base/MultiSelection.tsx +0 -90
  185. package/src/widgets/base/ProgressBar.tsx +0 -38
  186. package/src/widgets/base/Reference.tsx +0 -115
  187. package/src/widgets/base/ReferenceTree.tsx +0 -62
  188. package/src/widgets/base/Selection.tsx +0 -71
  189. package/src/widgets/base/Separator.tsx +0 -25
  190. package/src/widgets/base/Text.tsx +0 -162
  191. package/src/widgets/base/Time.tsx +0 -40
  192. package/src/widgets/base/Url.tsx +0 -26
  193. package/src/widgets/base/many2one/Many2one.tsx +0 -322
  194. package/src/widgets/base/many2one/Many2oneSuffix.tsx +0 -232
  195. package/src/widgets/base/many2one/Many2oneSuffixModal.tsx +0 -42
  196. package/src/widgets/base/many2one/Many2oneTree.tsx +0 -18
  197. package/src/widgets/base/one2many/One2many.tsx +0 -100
  198. package/src/widgets/base/one2many/One2manyInput.tsx +0 -724
  199. package/src/widgets/base/one2many/One2manyTopBar.tsx +0 -158
  200. package/src/widgets/containers/Container.tsx +0 -99
  201. package/src/widgets/containers/Group.tsx +0 -37
  202. package/src/widgets/containers/Notebook.tsx +0 -52
  203. package/src/widgets/custom/Avatar.tsx +0 -40
  204. package/src/widgets/custom/ButtonGroup.tsx +0 -169
  205. package/src/widgets/custom/CodeEditor.tsx +0 -32
  206. package/src/widgets/custom/Comments.tsx +0 -147
  207. package/src/widgets/custom/FiberGrid.tsx +0 -48
  208. package/src/widgets/custom/Indicator.tsx +0 -66
  209. package/src/widgets/custom/Markdown.tsx +0 -32
  210. package/src/widgets/custom/MultiCheckbox.tsx +0 -165
  211. package/src/widgets/custom/Radio.tsx +0 -47
  212. package/src/widgets/custom/Steps.tsx +0 -56
  213. package/src/widgets/custom/Switch.tsx +0 -26
  214. package/src/widgets/custom/Tag.tsx +0 -53
  215. package/src/widgets/custom/Tags.tsx +0 -164
  216. package/src/widgets/custom/Timeline.tsx +0 -196
  217. package/src/widgets/modals/ExportModal.tsx +0 -75
  218. package/src/widgets/modals/FormModal.tsx +0 -125
  219. package/src/widgets/modals/SearchModal.tsx +0 -130
  220. package/src/widgets/modals/TranslationModal.tsx +0 -202
  221. package/src/widgets/views/Dashboard/Dashboard.tsx +0 -381
  222. package/src/widgets/views/Dashboard/DashboardForm.tsx +0 -30
  223. package/src/widgets/views/Dashboard/DashboardTree.tsx +0 -238
  224. package/src/widgets/views/Dashboard/dashboardHelper.ts +0 -79
  225. package/src/widgets/views/DashboardGrid/DashboardGrid.tsx +0 -53
  226. package/src/widgets/views/DashboardGrid/DashboardGrid.types.ts +0 -4
  227. package/src/widgets/views/DashboardGrid/DashboardGridItem.tsx +0 -62
  228. package/src/widgets/views/DashboardGrid/DashboardGridItem.types.ts +0 -10
  229. package/src/widgets/views/DashboardGrid/index.ts +0 -4
  230. package/src/widgets/views/Form.tsx +0 -1152
  231. package/src/widgets/views/Graph/Graph.tsx +0 -145
  232. package/src/widgets/views/Graph/GraphChart.tsx +0 -113
  233. package/src/widgets/views/Graph/GraphDefaults.ts +0 -170
  234. package/src/widgets/views/Graph/GraphIndicator.tsx +0 -421
  235. package/src/widgets/views/Graph/useGraphData.tsx +0 -176
  236. package/src/widgets/views/SearchTree.tsx +0 -367
  237. package/src/widgets/views/Tree/Tree.tsx +0 -295
  238. package/src/widgets/views/Tree/index.ts +0 -1
  239. package/src/widgets/views/Tree/treeComponents.tsx +0 -276
  240. package/src/widgets/views/searchFilter/DateRangePicker.tsx +0 -16
  241. package/src/widgets/views/searchFilter/DateTimeRangePicker.tsx +0 -87
  242. package/src/widgets/views/searchFilter/PairFields.tsx +0 -56
  243. package/src/widgets/views/searchFilter/SearchBottomBar.tsx +0 -54
  244. package/src/widgets/views/searchFilter/SearchField.tsx +0 -63
  245. package/src/widgets/views/searchFilter/SearchFilter.tsx +0 -160
  246. package/src/widgets/views/searchFilter/SearchParams.tsx +0 -35
@@ -1,157 +0,0 @@
1
- import React, { useContext, useState } from "react";
2
- import {
3
- DownOutlined,
4
- FormOutlined,
5
- DownloadOutlined,
6
- LinkOutlined,
7
- FileAddOutlined,
8
- TableOutlined,
9
- } from "@ant-design/icons";
10
- import { Popover, Button, Row, Col, Tooltip, Spin } from "antd";
11
- import {
12
- LocaleContext,
13
- LocaleContextType,
14
- tForLang,
15
- } from "@/context/LocaleContext";
16
-
17
- export type Attachment = {
18
- id: number;
19
- name: string;
20
- datas: string;
21
- link: string;
22
- };
23
-
24
- export type AttachmentsButtonWrapperProps = {
25
- attachments: Attachment[] | undefined;
26
- numberOfAttachments: number;
27
- disabled: boolean;
28
- loading: boolean;
29
- onAddNewAttachment: () => void;
30
- onListAllAttachments: () => void;
31
- onopenAttachmentLink: (attachment: Attachment) => void;
32
- onOpenAttachmentDetail: (attachment: Attachment) => void;
33
- };
34
-
35
- export const AttachmentsButtonWrapper = (
36
- props: AttachmentsButtonWrapperProps,
37
- ) => {
38
- const { numberOfAttachments, disabled } = props;
39
- const { t, lang } = useContext(LocaleContext) as LocaleContextType;
40
- const [popoverVisible, setPopoverVisible] = useState<boolean>(false);
41
-
42
- const button = (
43
- <Button disabled={disabled}>
44
- <LinkOutlined />
45
- {`(${numberOfAttachments})`}
46
- <DownOutlined style={{ fontSize: 12 }} />
47
- </Button>
48
- );
49
-
50
- if (disabled) {
51
- return button;
52
- }
53
-
54
- return (
55
- <Popover
56
- onVisibleChange={(visible: boolean) => setPopoverVisible(visible)}
57
- visible={popoverVisible}
58
- placement="bottom"
59
- content={Content(props, setPopoverVisible, lang)}
60
- title={t("attachments")}
61
- arrowContent={null}
62
- >
63
- {button}
64
- </Popover>
65
- );
66
- };
67
-
68
- const Content = (
69
- props: AttachmentsButtonWrapperProps,
70
- setPopoverVisible: (visible: boolean) => void,
71
- locale: string,
72
- ) => {
73
- const {
74
- attachments = [],
75
- loading,
76
- onAddNewAttachment,
77
- onopenAttachmentLink,
78
- onOpenAttachmentDetail,
79
- onListAllAttachments,
80
- } = props;
81
- if (loading) {
82
- return <Spin style={{ padding: 20 }} />;
83
- }
84
-
85
- return (
86
- <>
87
- <a
88
- style={{ display: "block", paddingBottom: 5 }}
89
- href="#"
90
- onClick={() => {
91
- setPopoverVisible(false);
92
- onListAllAttachments();
93
- }}
94
- >
95
- <TableOutlined /> {tForLang("listAllAttachments", locale)}
96
- </a>
97
- <a
98
- style={{ display: "block" }}
99
- href="#"
100
- onClick={() => {
101
- setPopoverVisible(false);
102
- onAddNewAttachment();
103
- }}
104
- >
105
- <FileAddOutlined /> {tForLang("addNewAttachment", locale)}
106
- </a>
107
- {attachments.length > 0 && (
108
- <>
109
- <li className="ant-dropdown-menu-item-divider"></li>
110
- {attachments.map((attachment: any) => {
111
- const Icon = attachment.link ? LinkOutlined : DownloadOutlined;
112
- return (
113
- <Row
114
- style={{ paddingTop: 4, paddingBottom: 4 }}
115
- wrap={false}
116
- align="middle"
117
- key={attachment.id}
118
- >
119
- <Col flex="auto">{attachment.name}</Col>
120
- <Col flex="25px" style={{ textAlign: "center" }}>
121
- {(attachment.datas_fname || attachment.link) && (
122
- <Tooltip
123
- title={
124
- attachment.link
125
- ? tForLang("openAttachmentLink", locale)
126
- : tForLang("download", locale)
127
- }
128
- >
129
- <Icon
130
- style={{ cursor: "pointer" }}
131
- onClick={() => {
132
- setPopoverVisible(false);
133
- onopenAttachmentLink(attachment);
134
- }}
135
- />
136
- </Tooltip>
137
- )}
138
- </Col>
139
- <Col flex="25px" style={{ textAlign: "center" }}>
140
- <Tooltip title={tForLang("openAttachment", locale)}>
141
- <FormOutlined
142
- style={{ cursor: "pointer" }}
143
- onClick={() => {
144
- setPopoverVisible(false);
145
- onOpenAttachmentDetail(attachment);
146
- }}
147
- />
148
- </Tooltip>
149
- </Col>
150
- </Row>
151
- );
152
- })}
153
- </>
154
- )}
155
- </>
156
- );
157
- };
@@ -1,44 +0,0 @@
1
- import React from "react";
2
- import ButtonWithTooltip, {
3
- Props as ButtonWithTooltipProps,
4
- } from "@/common/ButtonWithTooltip";
5
- import { theme } from "antd";
6
- const { useToken } = theme;
7
-
8
- type Props = ButtonWithTooltipProps & {
9
- badgeNumber?: number;
10
- };
11
-
12
- function ButtonWithBadge(props: Props) {
13
- const { badgeNumber = 0, ...restProps } = props;
14
- const { token } = useToken();
15
-
16
- return (
17
- <div style={{ position: "relative" }}>
18
- {badgeNumber > 0 && (
19
- <div style={{ position: "absolute", left: -10, top: -10, zIndex: 2 }}>
20
- <span
21
- style={{
22
- display: "inline-block",
23
- minWidth: "22px",
24
- padding: "2px",
25
- borderRadius: "50%",
26
- fontSize: "12px",
27
- textAlign: "center",
28
- background: token.colorPrimaryHover,
29
- color: token.colorPrimaryBg,
30
- }}
31
- >
32
- {badgeNumber}
33
- </span>
34
- </div>
35
- )}
36
- <ButtonWithTooltip
37
- {...restProps}
38
- style={{ width: 46, zIndex: 0 }}
39
- ></ButtonWithTooltip>
40
- </div>
41
- );
42
- }
43
-
44
- export default ButtonWithBadge;
@@ -1,137 +0,0 @@
1
- import React, { useContext } from "react";
2
- import { Menu, Dropdown, Row, Col, Button } from "antd";
3
- import {
4
- DownOutlined,
5
- TableOutlined,
6
- FormOutlined,
7
- CheckOutlined,
8
- AreaChartOutlined,
9
- CalendarOutlined,
10
- } from "@ant-design/icons";
11
- import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
12
- import showUnsavedChangesDialog from "@/ui/UnsavedChangesDialog";
13
- import ButtonWithTooltip from "@/common/ButtonWithTooltip";
14
- import { GraphView, View } from "@/types";
15
-
16
- type Props = {
17
- onChangeView: (view: View) => void;
18
- currentView: View;
19
- availableViews: View[];
20
- disabled?: boolean;
21
- formHasChanges?: boolean;
22
- previousView?: View;
23
- };
24
-
25
- const iconsForViewTypes = {
26
- tree: <TableOutlined />,
27
- form: <FormOutlined />,
28
- graph: <AreaChartOutlined />,
29
- calendar: <CalendarOutlined />,
30
- };
31
-
32
- function getIconForView(view?: View) {
33
- if (!view) {
34
- return <FormOutlined />;
35
- }
36
-
37
- return (iconsForViewTypes as any)?.[view.type] || <FormOutlined />;
38
- }
39
-
40
- function ChangeViewButton(props: Props) {
41
- const {
42
- currentView,
43
- availableViews,
44
- onChangeView,
45
- disabled = false,
46
- formHasChanges = false,
47
- previousView,
48
- } = props;
49
- const { t, lang } = useContext(LocaleContext) as LocaleContextType;
50
-
51
- function getMenu() {
52
- const menuItems = availableViews.map((view, idx) => {
53
- return (
54
- <Menu.Item key={view.view_id || idx}>
55
- <Row wrap={false}>
56
- <Col flex="none" style={{ paddingRight: 20 }}>
57
- {getIconForView(view)}
58
- </Col>
59
- <Col flex="auto" style={{ paddingRight: 20 }}>
60
- {view.type.charAt(0).toUpperCase() + view.type.slice(1)}
61
- </Col>
62
- <Col flex="none">
63
- <CheckOutlined
64
- style={{
65
- opacity: currentView.view_id === view.view_id ? 1 : 0,
66
- }}
67
- />
68
- </Col>
69
- </Row>
70
- </Menu.Item>
71
- );
72
- });
73
-
74
- return (
75
- <Menu onClick={handleMenuClick}>
76
- <Menu.ItemGroup title={t("viewAs")}>{menuItems}</Menu.ItemGroup>
77
- </Menu>
78
- );
79
- }
80
-
81
- function tryNavigate(callback: any) {
82
- if (formHasChanges) {
83
- showUnsavedChangesDialog({
84
- lang,
85
- onOk: () => {
86
- callback();
87
- },
88
- });
89
- return;
90
- }
91
-
92
- callback();
93
- }
94
-
95
- function handleMenuClick(event: any) {
96
- tryNavigate(() => {
97
- const selectedView = availableViews.find(
98
- (view) => view.view_id === parseInt(event.key),
99
- );
100
- onChangeView(selectedView!);
101
- });
102
- }
103
-
104
- return (
105
- <div style={{ display: "flex" }}>
106
- <ButtonWithTooltip
107
- tooltip={previousView ? t("viewAs") + " " + t(previousView.type) : ""}
108
- icon={getIconForView(previousView)}
109
- style={{
110
- width: 50,
111
- borderTopRightRadius: 0,
112
- borderBottomRightRadius: 0,
113
- }}
114
- onClick={() => {
115
- handleMenuClick({ key: previousView?.view_id });
116
- }}
117
- disabled={disabled || availableViews.length === 1}
118
- />
119
- <Dropdown
120
- overlay={getMenu()}
121
- disabled={disabled || availableViews.length === 1}
122
- >
123
- <Button
124
- style={{
125
- width: 25,
126
- borderTopLeftRadius: 0,
127
- borderBottomLeftRadius: 0,
128
- }}
129
- icon={<DownOutlined style={{ fontSize: "0.5em" }} />}
130
- onClick={(e) => e.preventDefault()}
131
- ></Button>
132
- </Dropdown>
133
- </div>
134
- );
135
- }
136
-
137
- export default ChangeViewButton;
@@ -1,63 +0,0 @@
1
- import React, { useContext } from "react";
2
- import {
3
- DashboardActionContext,
4
- DashboardActionContextType,
5
- } from "@/context/DashboardActionContext";
6
- import { Space } from "antd";
7
- import ActionButton from "./ActionButton";
8
- import {
9
- ReloadOutlined,
10
- SettingOutlined,
11
- BorderOuterOutlined,
12
- } from "@ant-design/icons";
13
- import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
14
-
15
- function DashboardActionBar() {
16
- const { isLoading, dashboardRef, moveItemsEnabled, setMoveItemsEnabled } =
17
- useContext(DashboardActionContext) as DashboardActionContextType;
18
- const { t } = useContext(LocaleContext) as LocaleContextType;
19
-
20
- return (
21
- <Space wrap={true}>
22
- <ActionButton
23
- icon={
24
- <BorderOuterOutlined
25
- style={{ color: moveItemsEnabled ? "white" : undefined }}
26
- />
27
- }
28
- type={moveItemsEnabled ? "primary" : "default"}
29
- tooltip={t("moveDashboard")}
30
- disabled={isLoading}
31
- loading={false}
32
- onClick={() => {
33
- setMoveItemsEnabled(!moveItemsEnabled);
34
- }}
35
- />
36
- {separator()}
37
- <ActionButton
38
- icon={<SettingOutlined />}
39
- tooltip={t("configDashboard")}
40
- disabled={isLoading}
41
- loading={false}
42
- onClick={() => {
43
- dashboardRef?.current.configDashboard();
44
- }}
45
- />
46
- <ActionButton
47
- icon={<ReloadOutlined />}
48
- tooltip={t("refresh")}
49
- disabled={isLoading}
50
- loading={false}
51
- onClick={() => {
52
- dashboardRef?.current.refresh();
53
- }}
54
- />
55
- </Space>
56
- );
57
- }
58
-
59
- function separator() {
60
- return <div className="inline-block w-2" />;
61
- }
62
-
63
- export default DashboardActionBar;
@@ -1,124 +0,0 @@
1
- import { memo, useState, useMemo, useCallback } from "react";
2
- import { Menu, Dropdown, Button, Input } from "antd";
3
- import { DownOutlined } from "@ant-design/icons";
4
-
5
- const { Search } = Input;
6
-
7
- type Props = {
8
- onItemClick: (event: any) => void;
9
- items: any[];
10
- tooltip: string;
11
- icon: any;
12
- label?: string;
13
- disabled?: boolean;
14
- searchable?: true | false | "auto";
15
- };
16
-
17
- const DropdownButton: React.FC<Props> = memo(
18
- ({
19
- icon,
20
- tooltip,
21
- items = [],
22
- onItemClick,
23
- label,
24
- disabled = false,
25
- searchable = "auto",
26
- }: Props) => {
27
- const [searchValue, setSearchValue] = useState<string>();
28
-
29
- const mustShowSearch =
30
- searchable === true || (searchable === "auto" && items.length > 3);
31
-
32
- const onSearch = useCallback((value?: string) => {
33
- const sanitizedValue = value?.trim();
34
- if (sanitizedValue && sanitizedValue.length > 0) {
35
- setSearchValue(sanitizedValue);
36
- return;
37
- }
38
- setSearchValue(undefined);
39
- }, []);
40
-
41
- const filteredItems = useMemo(() => {
42
- if (searchValue) {
43
- return items
44
- .map((item) => {
45
- if (item.name.toLowerCase().includes(searchValue.toLowerCase())) {
46
- return { ...item };
47
- }
48
- return { ...item, name: "no_match" };
49
- })
50
- .sort((a, b) => {
51
- // all the items with name "no_match" have to be in the end of the array
52
- if (a.name === "no_match") return 1;
53
- if (b.name === "no_match") return -1;
54
- return 0;
55
- });
56
- }
57
- return items;
58
- }, [items, searchValue]);
59
-
60
- const handleMenuClick = useCallback(
61
- (event: any) => {
62
- const itemClicked = filteredItems.find(
63
- (item: any) => item.id.toString() === event.key,
64
- );
65
- if (itemClicked && itemClicked.name !== "no_match")
66
- onItemClick(itemClicked);
67
- },
68
- [onItemClick, filteredItems],
69
- );
70
-
71
- const getMenu = useMemo(() => {
72
- const menuItems = filteredItems.map((item, idx) => {
73
- if (item.name === "divider")
74
- return <Menu.Divider key={"divider" + idx} />;
75
- if (item.name === "no_match")
76
- return (
77
- <Menu.Item
78
- key={"no_match" + idx}
79
- style={{ cursor: "auto", pointerEvents: "none", opacity: 0 }}
80
- >
81
- {item.name}
82
- </Menu.Item>
83
- );
84
- return <Menu.Item key={item.id}>{item.name}</Menu.Item>;
85
- });
86
-
87
- return (
88
- <Menu onClick={handleMenuClick}>
89
- {mustShowSearch && (
90
- <div style={{ padding: 5 }}>
91
- <Search
92
- onChange={(e) => onSearch(e.target.value)}
93
- onSearch={onSearch}
94
- allowClear
95
- />
96
- </div>
97
- )}
98
- <div
99
- style={{
100
- width: 300,
101
- maxHeight: 300,
102
- overflowY: "auto",
103
- }}
104
- >
105
- <Menu.ItemGroup title={tooltip}>{menuItems}</Menu.ItemGroup>
106
- </div>
107
- </Menu>
108
- );
109
- }, [filteredItems, handleMenuClick, mustShowSearch, onSearch, tooltip]);
110
-
111
- return (
112
- <>
113
- <Dropdown overlay={getMenu} disabled={disabled || items.length === 0}>
114
- <Button>
115
- {icon} {label} <DownOutlined />
116
- </Button>
117
- </Dropdown>
118
- </>
119
- );
120
- },
121
- );
122
- DropdownButton.displayName = "DropdownButton";
123
-
124
- export default DropdownButton;