@gisce/react-ooui 1.2.0-rc.4 → 1.2.0-rc.41

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 (105) hide show
  1. package/dist/actionbar/FormActionBar.d.ts.map +1 -1
  2. package/dist/actionbar/TreeActionBar.d.ts.map +1 -1
  3. package/dist/context/ActionViewContext.d.ts +5 -1
  4. package/dist/context/ActionViewContext.d.ts.map +1 -1
  5. package/dist/context/ContentRootContext.d.ts.map +1 -1
  6. package/dist/context/FormContext.d.ts +4 -1
  7. package/dist/context/FormContext.d.ts.map +1 -1
  8. package/dist/helpers/formHelper.d.ts +5 -3
  9. package/dist/helpers/formHelper.d.ts.map +1 -1
  10. package/dist/helpers/iconMapper.d.ts +5 -1
  11. package/dist/helpers/iconMapper.d.ts.map +1 -1
  12. package/dist/helpers/one2manyHelper.d.ts +2 -1
  13. package/dist/helpers/one2manyHelper.d.ts.map +1 -1
  14. package/dist/helpers/treeHelper.d.ts +1 -1
  15. package/dist/helpers/treeHelper.d.ts.map +1 -1
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/locales/ca_ES.d.ts +4 -0
  19. package/dist/locales/ca_ES.d.ts.map +1 -1
  20. package/dist/locales/en_US.d.ts +4 -0
  21. package/dist/locales/en_US.d.ts.map +1 -1
  22. package/dist/locales/es_ES.d.ts +4 -0
  23. package/dist/locales/es_ES.d.ts.map +1 -1
  24. package/dist/react-ooui.es.js +16980 -18378
  25. package/dist/react-ooui.es.js.map +1 -1
  26. package/dist/react-ooui.umd.js +78 -51
  27. package/dist/react-ooui.umd.js.map +1 -1
  28. package/dist/types/index.d.ts +1 -0
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/views/ActionView.d.ts.map +1 -1
  31. package/dist/views/RootView.d.ts.map +1 -1
  32. package/dist/views/actionViews/TreeActionView.d.ts.map +1 -1
  33. package/dist/widgets/WidgetFactory.d.ts.map +1 -1
  34. package/dist/widgets/base/Integer.d.ts.map +1 -1
  35. package/dist/widgets/base/Label.d.ts.map +1 -1
  36. package/dist/widgets/base/ReferenceTree.d.ts +8 -0
  37. package/dist/widgets/base/ReferenceTree.d.ts.map +1 -0
  38. package/dist/widgets/base/many2one/Many2one.d.ts.map +1 -1
  39. package/dist/widgets/base/many2one/Many2oneTree.d.ts +6 -0
  40. package/dist/widgets/base/many2one/Many2oneTree.d.ts.map +1 -0
  41. package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
  42. package/dist/widgets/custom/MultiCheckbox.d.ts.map +1 -1
  43. package/dist/widgets/custom/Tag.d.ts +5 -0
  44. package/dist/widgets/custom/Tag.d.ts.map +1 -0
  45. package/dist/widgets/custom/Tags.d.ts.map +1 -1
  46. package/dist/widgets/modals/ExportModal.d.ts +2 -2
  47. package/dist/widgets/modals/ExportModal.d.ts.map +1 -1
  48. package/dist/widgets/views/Dashboard/Dashboard.d.ts.map +1 -1
  49. package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
  50. package/dist/widgets/views/Form.d.ts.map +1 -1
  51. package/dist/widgets/views/SearchTree.d.ts.map +1 -1
  52. package/dist/widgets/views/Tree.d.ts +2 -0
  53. package/dist/widgets/views/Tree.d.ts.map +1 -1
  54. package/package.json +6 -5
  55. package/src/__tests__/iconMapper.test.ts +20 -5
  56. package/src/actionbar/ChangeViewButton.tsx +2 -2
  57. package/src/actionbar/FormActionBar.tsx +94 -11
  58. package/src/actionbar/TreeActionBar.tsx +86 -69
  59. package/src/context/ActionViewContext.tsx +7 -4
  60. package/src/context/ContentRootContext.tsx +15 -7
  61. package/src/context/FormContext.tsx +1 -1
  62. package/src/helpers/formHelper.ts +26 -5
  63. package/src/helpers/iconMapper.ts +134 -107
  64. package/src/helpers/one2manyHelper.ts +27 -9
  65. package/src/helpers/treeHelper.ts +17 -5
  66. package/src/index.ts +2 -0
  67. package/src/locales/ca_ES.tsx +4 -0
  68. package/src/locales/en_US.tsx +4 -0
  69. package/src/locales/es_ES.tsx +4 -0
  70. package/src/stories/Label.stories.tsx +7 -8
  71. package/src/stories/containers/Notebook.stories.tsx +27 -0
  72. package/src/stories/custom/Tag.stories.tsx +57 -0
  73. package/src/stories/mocks/models/crm_case.ts +7 -10
  74. package/src/stories/views/Tree.stories.jsx +5 -5
  75. package/src/types/index.ts +1 -0
  76. package/src/views/ActionView.tsx +15 -4
  77. package/src/views/RootView.tsx +7 -1
  78. package/src/views/actionViews/TreeActionView.tsx +10 -1
  79. package/src/widgets/WidgetFactory.tsx +3 -0
  80. package/src/widgets/base/Integer.tsx +1 -0
  81. package/src/widgets/base/Label.tsx +5 -9
  82. package/src/widgets/base/ReferenceTree.tsx +62 -0
  83. package/src/widgets/base/many2one/Many2one.tsx +8 -9
  84. package/src/widgets/base/many2one/Many2oneTree.tsx +18 -0
  85. package/src/widgets/base/one2many/One2manyInput.tsx +2 -0
  86. package/src/widgets/containers/Group.tsx +3 -3
  87. package/src/widgets/custom/ButtonGroup.tsx +1 -1
  88. package/src/widgets/custom/MultiCheckbox.tsx +1 -0
  89. package/src/widgets/custom/Tag.tsx +24 -0
  90. package/src/widgets/custom/Tags.tsx +27 -28
  91. package/src/widgets/modals/ExportModal.tsx +53 -15
  92. package/src/widgets/views/Dashboard/Dashboard.tsx +5 -1
  93. package/src/widgets/views/Dashboard/DashboardTree.tsx +1 -0
  94. package/src/widgets/views/Form.tsx +35 -24
  95. package/src/widgets/views/SearchTree.tsx +2 -0
  96. package/src/widgets/views/Tree.tsx +88 -25
  97. package/dist/helpers/icons/antd_icons.d.ts +0 -4
  98. package/dist/helpers/icons/antd_icons.d.ts.map +0 -1
  99. package/dist/helpers/icons/tabler_icons.d.ts +0 -4
  100. package/dist/helpers/icons/tabler_icons.d.ts.map +0 -1
  101. package/dist/ui/Fieldset.d.ts +0 -8
  102. package/dist/ui/Fieldset.d.ts.map +0 -1
  103. package/src/helpers/icons/antd_icons.ts +0 -1583
  104. package/src/helpers/icons/tabler_icons.ts +0 -5367
  105. package/src/ui/Fieldset.tsx +0 -31
@@ -73,6 +73,10 @@ function TreeActionBar(props: Props) {
73
73
  const { processAction } = contentRootContext || {};
74
74
  const [exportModalVisible, setExportModalVisible] = useState(false);
75
75
 
76
+ const hasNameSearch: boolean =
77
+ searchTreeNameSearch !== undefined &&
78
+ searchTreeNameSearch.trim().length > 0;
79
+
76
80
  function tryDelete() {
77
81
  showConfirmDialog({
78
82
  confirmMessage: t("confirmRemove"),
@@ -159,9 +163,24 @@ function TreeActionBar(props: Props) {
159
163
  }
160
164
  }}
161
165
  />
166
+ {!treeExpandable && (
167
+ <ButtonWithBadge
168
+ icon={
169
+ <FilterOutlined
170
+ style={{ color: searchVisible ? "white" : undefined }}
171
+ />
172
+ }
173
+ tooltip={t("advanced_search")}
174
+ type={searchVisible ? "primary" : "default"}
175
+ onClick={() => {
176
+ setSearchVisible?.(!searchVisible);
177
+ }}
178
+ disabled={duplicatingItem || removingItem || treeIsLoading}
179
+ badgeNumber={searchParams?.length}
180
+ />
181
+ )}
162
182
  {separator()}
163
183
  <NewButton disabled={treeIsLoading} />
164
- {separator()}
165
184
  <ActionButton
166
185
  icon={<CopyOutlined />}
167
186
  tooltip={t("duplicate")}
@@ -187,22 +206,6 @@ function TreeActionBar(props: Props) {
187
206
  {separator()}
188
207
  </>
189
208
  )}
190
- {!treeExpandable && (
191
- <ButtonWithBadge
192
- icon={
193
- <FilterOutlined
194
- style={{ color: searchVisible ? "white" : undefined }}
195
- />
196
- }
197
- tooltip={t("advanced_search")}
198
- type={searchVisible ? "primary" : "default"}
199
- onClick={() => {
200
- setSearchVisible?.(!searchVisible);
201
- }}
202
- disabled={duplicatingItem || removingItem || treeIsLoading}
203
- badgeNumber={searchParams?.length}
204
- />
205
- )}
206
209
  <ActionButton
207
210
  icon={<InfoCircleOutlined />}
208
211
  tooltip={t("showLogs")}
@@ -239,51 +242,6 @@ function TreeActionBar(props: Props) {
239
242
  </>
240
243
  )}
241
244
  {separator()}
242
- <DropdownButton
243
- icon={
244
- <Icon
245
- component={() => (
246
- <svg
247
- xmlns="http://www.w3.org/2000/svg"
248
- className="icon icon-tabler icon-tabler-database-export"
249
- width="18"
250
- height="18"
251
- viewBox="0 0 24 24"
252
- stroke-width="1.5"
253
- stroke="#2c3e50"
254
- fill="none"
255
- stroke-linecap="round"
256
- stroke-linejoin="round"
257
- >
258
- <path stroke="none" d="M0 0h24v24H0z" fill="none" />
259
- <ellipse cx="12" cy="6" rx="8" ry="3" />
260
- <path d="M4 6v6c0 1.657 3.582 3 8 3a19.84 19.84 0 0 0 3.302 -.267m4.698 -2.733v-6" />
261
- <path d="M4 12v6c0 1.599 3.335 2.905 7.538 2.995m8.462 -6.995v-2m-6 7h7m-3 -3l3 3l-3 3" />
262
- </svg>
263
- )}
264
- />
265
- }
266
- tooltip={t("export")}
267
- items={[
268
- {
269
- id: "print_screen",
270
- name: "Imprimir pantalla",
271
- },
272
- {
273
- id: "export",
274
- name: "Exportación avanzada",
275
- },
276
- ]}
277
- onItemClick={(action: any) => {
278
- if (!action) {
279
- return;
280
- }
281
-
282
- runAction(action);
283
- }}
284
- disabled={duplicatingItem || removingItem || treeIsLoading}
285
- />
286
- {separator()}
287
245
  <DropdownButton
288
246
  icon={<ThunderboltOutlined />}
289
247
  disabled={
@@ -320,23 +278,82 @@ function TreeActionBar(props: Props) {
320
278
  });
321
279
  }}
322
280
  />
281
+ {separator()}
282
+ <DropdownButton
283
+ icon={
284
+ <Icon
285
+ component={() => (
286
+ <svg
287
+ xmlns="http://www.w3.org/2000/svg"
288
+ className="icon icon-tabler icon-tabler-database-export"
289
+ width="1em"
290
+ height="1em"
291
+ viewBox="0 0 24 24"
292
+ strokeWidth="1.5"
293
+ fill="none"
294
+ stroke="currentColor"
295
+ strokeLinecap="round"
296
+ strokeLinejoin="round"
297
+ >
298
+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />
299
+ <ellipse cx="12" cy="6" rx="8" ry="3" />
300
+ <path d="M4 6v6c0 1.657 3.582 3 8 3a19.84 19.84 0 0 0 3.302 -.267m4.698 -2.733v-6" />
301
+ <path d="M4 12v6c0 1.599 3.335 2.905 7.538 2.995m8.462 -6.995v-2m-6 7h7m-3 -3l3 3l-3 3" />
302
+ </svg>
303
+ )}
304
+ />
305
+ }
306
+ tooltip={t("export")}
307
+ items={[
308
+ {
309
+ id: "print_screen",
310
+ name: t("printScreen"),
311
+ },
312
+ {
313
+ id: "export",
314
+ name: t("advancedExport"),
315
+ },
316
+ ]}
317
+ onItemClick={(itemClicked: any) => {
318
+ if (itemClicked.id === "print_screen") {
319
+ let idsToExport = selectedRowItems?.map((item) => item.id) || [];
320
+
321
+ if (idsToExport.length === 0) {
322
+ idsToExport = results?.map((item) => item.id) || [];
323
+ }
324
+
325
+ runAction({
326
+ id: -1,
327
+ model: currentModel,
328
+ report_name: "printscreen.list",
329
+ type: "ir.actions.report.xml",
330
+ datas: {
331
+ model: currentModel,
332
+ ids: idsToExport,
333
+ },
334
+ });
335
+ return;
336
+ }
337
+
338
+ setExportModalVisible(true);
339
+ }}
340
+ disabled={
341
+ duplicatingItem || removingItem || treeIsLoading || hasNameSearch
342
+ }
343
+ />
323
344
  <ExportModal
324
345
  visible={exportModalVisible}
325
346
  locale={lang}
326
347
  onClose={() => setExportModalVisible(false)}
327
348
  model={currentModel!}
328
- treeFields={searchTreeRef?.current?.getFields()}
329
349
  domain={mergeParams(
330
350
  searchTreeRef?.current?.getDomain() || [],
331
351
  searchParams || []
332
352
  )}
333
353
  limit={limit}
334
- totalRegisters={totalItems}
335
- selectedRegistersToExport={
336
- results && results.length && results.length > 0
337
- ? results.length
338
- : undefined
339
- }
354
+ totalRegisters={totalItems || 0}
355
+ selectedRegistersToExport={selectedRowItems}
356
+ visibleRegisters={results?.length || 0}
340
357
  context={parentContext}
341
358
  />
342
359
  </Space>
@@ -11,7 +11,7 @@ export type ActionViewContextType = {
11
11
  setFormIsSaving?: (value: boolean) => void;
12
12
  formHasChanges?: boolean;
13
13
  setFormHasChanges?: (value: boolean) => void;
14
- onFormSave?: () => void;
14
+ onFormSave?: () => Promise<{ succeed: boolean; id: number }>;
15
15
  formRef?: any;
16
16
  searchTreeRef?: any;
17
17
  onNewClicked: () => void;
@@ -53,6 +53,7 @@ export type ActionViewContextType = {
53
53
  setSearchValues?: (value: any) => void;
54
54
  limit?: number;
55
55
  setLimit?: (value: number) => void;
56
+ setTitle?: (value: string) => void;
56
57
  };
57
58
 
58
59
  export const ActionViewContext =
@@ -66,7 +67,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
66
67
  const {
67
68
  children,
68
69
  currentView,
69
- title,
70
+ title: titleProps,
70
71
  setCurrentView,
71
72
  availableViews,
72
73
  formRef,
@@ -106,6 +107,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
106
107
  const [limit, setLimit] = useState<number>(
107
108
  limitProps !== undefined ? limitProps : DEFAULT_SEARCH_LIMIT
108
109
  );
110
+ const [title, setTitle] = useState<string>(titleProps);
109
111
 
110
112
  useEffect(() => {
111
113
  if (results && results.length > 0 && !currentItemIndex) {
@@ -139,8 +141,8 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
139
141
  }
140
142
  }, [currentView]);
141
143
 
142
- const callOnFormSave = () => {
143
- (formRef.current as any)?.submitForm();
144
+ const callOnFormSave = async () => {
145
+ return await (formRef.current as any)?.submitForm();
144
146
  };
145
147
 
146
148
  return (
@@ -196,6 +198,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
196
198
  setSearchValues,
197
199
  limit,
198
200
  setLimit,
201
+ setTitle,
199
202
  }}
200
203
  >
201
204
  {children}
@@ -43,15 +43,20 @@ type ActionModalOpts = {
43
43
  actionData?: any;
44
44
  };
45
45
 
46
- export const ContentRootContext = React.createContext<ContentRootContextType | null>(
47
- null
48
- );
46
+ export const ContentRootContext =
47
+ React.createContext<ContentRootContextType | null>(null);
49
48
 
50
49
  type ContentRootProviderProps = {
51
50
  children: React.ReactNode;
52
51
  globalValues?: any;
53
52
  };
54
53
 
54
+ const callRefreshValues = async (fns: any[]) => {
55
+ for (let i = 0; i < fns.length; i++) {
56
+ await fns?.[i]?.();
57
+ }
58
+ };
59
+
55
60
  const ContentRootProvider = (
56
61
  props: ContentRootProviderProps,
57
62
  ref: any
@@ -64,7 +69,7 @@ const ContentRootProvider = (
64
69
  TabManagerContext
65
70
  ) as TabManagerContextType;
66
71
  const { openAction } = tabManagerContext || {};
67
- const onRefreshParentValues = useRef<any>();
72
+ const onRefreshParentValues = useRef<any>([]);
68
73
  const { t } = useContext(LocaleContext) as LocaleContextType;
69
74
 
70
75
  useImperativeHandle(ref, () => ({
@@ -167,7 +172,7 @@ const ContentRootProvider = (
167
172
  onRefreshParentValues?: any;
168
173
  }) {
169
174
  const { type } = actionData;
170
- onRefreshParentValues.current = onRefreshParentValuesFn;
175
+ onRefreshParentValues.current.push(onRefreshParentValuesFn);
171
176
 
172
177
  if (type === "ir.actions.report.xml") {
173
178
  return await generateReport({
@@ -230,6 +235,7 @@ const ContentRootProvider = (
230
235
  fields,
231
236
  values: { ...values, ...globalValues },
232
237
  }),
238
+ fields,
233
239
  context: mergedContext,
234
240
  });
235
241
  }
@@ -347,7 +353,8 @@ const ContentRootProvider = (
347
353
  }
348
354
 
349
355
  async function onFormModalSucceed() {
350
- onRefreshParentValues.current?.();
356
+ callRefreshValues(onRefreshParentValues.current);
357
+ onRefreshParentValues.current = [];
351
358
  setActionModalVisible(false);
352
359
  setActionModalOptions({
353
360
  domain: undefined,
@@ -386,7 +393,8 @@ const ContentRootProvider = (
386
393
  visible={actionModalVisible}
387
394
  onSubmitSucceed={onFormModalSucceed}
388
395
  onCancel={() => {
389
- onRefreshParentValues.current?.();
396
+ callRefreshValues(onRefreshParentValues.current);
397
+ onRefreshParentValues.current = [];
390
398
  setActionModalVisible(false);
391
399
  setActionModalOptions({
392
400
  domain: undefined,
@@ -22,7 +22,7 @@ export type FormContextType = {
22
22
  domain: any[];
23
23
  submitForm?: (options?: {
24
24
  callOnSubmitSucceed?: boolean;
25
- }) => Promise<boolean>;
25
+ }) => Promise<{ succeed: boolean; id: number }>;
26
26
  fetchValues?: () => void;
27
27
  formHasChanges?: () => boolean;
28
28
  elementHasLostFocus?: () => void;
@@ -1,4 +1,5 @@
1
1
  import { One2manyItem } from "@/widgets/base/one2many/One2manyInput";
2
+ import { Form as FormOoui } from "@gisce/ooui";
2
3
 
3
4
  const filteredValues = (values: any, fields: any) => {
4
5
  if (!fields) {
@@ -100,15 +101,16 @@ export const getTouchedValues = ({
100
101
 
101
102
  export const checkFieldsType = ({
102
103
  changedFields,
103
- fields,
104
+ formOoui,
104
105
  types,
105
106
  }: {
106
107
  changedFields: string[];
107
- fields: any;
108
+ formOoui: FormOoui;
108
109
  types: string[];
109
110
  }) => {
110
111
  const valuesChecked = changedFields.map((key) => {
111
- return types.includes(fields[key]?.type);
112
+ const fieldType = formOoui?.findById(key)?.type!;
113
+ return types.includes(fieldType);
112
114
  });
113
115
  return valuesChecked.some((i) => i === true);
114
116
  };
@@ -152,16 +154,35 @@ export const getValuesForDomain = (domain: any[]) => {
152
154
  export const getOnChangePayload = ({
153
155
  onChangeFieldActionArgs,
154
156
  values,
157
+ parentValues = {},
155
158
  }: {
156
159
  onChangeFieldActionArgs: any[];
157
160
  values: any;
161
+ parentValues?: any;
158
162
  }) => {
159
163
  const payload: any = {};
160
164
  onChangeFieldActionArgs.forEach((arg: string) => {
161
- if (values[arg]) {
165
+ const splittedArg = arg.split("");
166
+
167
+ if (arg === "True") {
168
+ payload[arg] = true;
169
+ } else if (arg === "False") {
170
+ payload[arg] = false;
171
+ } else if (values[arg]) {
162
172
  payload[arg] = values[arg];
163
- } else if (arg[0] === "'") {
173
+ } else if (
174
+ splittedArg[0] === "'" &&
175
+ splittedArg[splittedArg.length - 1] === "'" &&
176
+ splittedArg.filter((i: string) => i === "'").length === 2
177
+ ) {
164
178
  payload[arg] = arg.replace(/'/g, "");
179
+ } else if (splittedArg.includes("'")) {
180
+ // This is a string with a variable in it.
181
+ // TODO: pending implement.
182
+ payload[arg] = arg;
183
+ } else if (arg.indexOf("parent.") !== -1) {
184
+ const parentKey = arg.replace("parent.", "");
185
+ payload[arg] = parentValues[parentKey] || false;
165
186
  } else {
166
187
  payload[arg] = false;
167
188
  }
@@ -1,112 +1,120 @@
1
1
  import React from "react";
2
+ import * as AntIcons from "@ant-design/icons";
3
+ import * as TablerIcons from "@tabler/icons-react";
2
4
  import Icon from "@ant-design/icons";
3
- import { AntIcons as Icons } from "./icons/antd_icons";
4
- import { TablerIcons } from "./icons/tabler_icons";
5
5
 
6
- const iconMapping: { [key: string]: React.ElementType } = {
7
- "terp-purchase": Icons.ShoppingCartOutlined,
8
- "terp-graph": Icons.PieChartOutlined,
9
- "terp-crm": Icons.ContactsOutlined,
10
- "terp-hr": TablerIcons.IconFriends,
11
- "terp-account": TablerIcons.IconBuildingBank,
12
- "terp-project": TablerIcons.IconChecklist,
13
- "terp-administration": TablerIcons.IconAdjustments,
14
- "terp-partner": Icons.TeamOutlined,
15
- "terp-mrp": Icons.BuildOutlined,
16
- "terp-product": Icons.ShoppingOutlined,
17
- STOCK_JUSTIFY_FILL: Icons.UnorderedListOutlined,
18
- STOCK_INDENT: TablerIcons.IconIndentIncrease,
19
- STOCK_HELP: Icons.QuestionOutlined,
20
- STOCK_GO_UP: Icons.ArrowUpOutlined,
21
- STOCK_SORT_DESCENDING: Icons.SortDescendingOutlined,
22
- STOCK_ADD: Icons.PlusOutlined,
23
- STOCK_GOTO_LAST: Icons.FastForwardOutlined,
24
- STOCK_FIND: Icons.SearchOutlined,
25
- STOCK_PROPERTIES: Icons.ControlOutlined,
26
- STOCK_DIALOG_INFO: Icons.InfoOutlined,
27
- STOCK_FLOPPY: Icons.UsbOutlined,
28
- STOCK_JUSTIFY_CENTER: Icons.AlignCenterOutlined,
29
- STOCK_GO_BACK: Icons.ArrowLeftOutlined,
30
- STOCK_UNDERLINE: Icons.UnderlineOutlined,
31
- STOCK_BOLD: Icons.BoldOutlined,
32
- STOCK_APPLY: Icons.CheckOutlined,
33
- STOCK_ZOOM_OUT: Icons.ZoomOutOutlined,
34
- STOCK_STRIKETHROUGH: Icons.StrikethroughOutlined,
35
- STOCK_MEDIA_REWIND: Icons.BackwardOutlined,
36
- STOCK_PRINT: Icons.PrinterOutlined,
37
- STOCK_NO: Icons.CloseOutlined,
38
- STOCK_GOTO_FIRST: Icons.FastBackwardOutlined,
39
- STOCK_CLOSE: Icons.CloseOutlined,
40
- STOCK_REMOVE: Icons.MinusOutlined,
41
- STOCK_CUT: Icons.ScissorOutlined,
42
- STOCK_DIALOG_AUTHENTICATION: Icons.SafetyOutlined,
43
- STOCK_ZOOM_FIT: Icons.ExpandOutlined,
44
- STOCK_JUMP_TO: Icons.SelectOutlined,
45
- STOCK_HARDDISK: Icons.HddOutlined,
46
- STOCK_SAVE_AS: Icons.SaveOutlined,
47
- STOCK_UNDO: Icons.UndoOutlined,
48
- STOCK_JUSTIFY_RIGHT: Icons.AlignRightOutlined,
49
- STOCK_DIALOG_ERROR: Icons.CloseCircleOutlined,
50
- STOCK_INDEX: Icons.ProfileOutlined,
51
- STOCK_GOTO_BOTTOM: Icons.VerticalAlignBottomOutlined,
52
- STOCK_MEDIA_NEXT: Icons.StepForwardOutlined,
53
- STOCK_REDO: Icons.RedoOutlined,
54
- STOCK_COPY: Icons.CopyOutlined,
55
- STOCK_MEDIA_PAUSE: Icons.PauseOutlined,
56
- STOCK_GO_FORWARD: Icons.ArrowRightOutlined,
57
- STOCK_UNDELETE: Icons.UndoOutlined,
58
- STOCK_EXECUTE: Icons.SettingOutlined,
59
- STOCK_SAVE: Icons.SaveOutlined,
60
- STOCK_DIALOG_QUESTION: Icons.QuestionCircleOutlined,
61
- STOCK_SORT_ASCENDING: Icons.SortAscendingOutlined,
62
- STOCK_REFRESH: Icons.ReloadOutlined,
63
- STOCK_MEDIA_FORWARD: Icons.ForwardOutlined,
64
- STOCK_STOP: Icons.BorderOutlined,
65
- STOCK_PRINT_PREVIEW: Icons.PrinterOutlined,
66
- STOCK_HOME: Icons.HomeOutlined,
67
- STOCK_PASTE: Icons.CarryOutOutlined,
68
- STOCK_ZOOM_100: Icons.ZoomInOutlined,
69
- STOCK_FIND_AND_REPLACE: Icons.FileSearchOutlined,
70
- STOCK_DIALOG_WARNING: Icons.WarningOutlined,
71
- STOCK_ZOOM_IN: Icons.ZoomInOutlined,
72
- STOCK_CONVERT: Icons.ExportOutlined,
73
- STOCK_ITALIC: Icons.ItalicOutlined,
74
- STOCK_YES: Icons.CheckOutlined,
75
- STOCK_MEDIA_PLAY: Icons.PlayCircleOutlined,
76
- STOCK_MEDIA_RECORD: Icons.VideoCameraOutlined,
77
- STOCK_MEDIA_PREVIOUS: Icons.StepBackwardOutlined,
78
- STOCK_NEW: Icons.FileAddOutlined,
79
- STOCK_CANCEL: Icons.CloseOutlined,
80
- STOCK_DISCONNECT: Icons.ApiOutlined,
81
- STOCK_JUSTIFY_LEFT: Icons.AlignLeftOutlined,
82
- STOCK_FILE: Icons.FileOutlined,
83
- STOCK_QUIT: Icons.LogoutOutlined,
84
- STOCK_EDIT: Icons.EditOutlined,
85
- STOCK_CONNECT: Icons.ApiOutlined,
86
- STOCK_GO_DOWN: Icons.CaretDownOutlined,
87
- STOCK_NETWORK: Icons.ApartmentOutlined,
88
- STOCK_OK: Icons.CheckOutlined,
89
- STOCK_GOTO_TOP: Icons.VerticalAlignTopOutlined,
90
- STOCK_ABOUT: Icons.StarOutlined,
91
- STOCK_COLOR_PICKER: Icons.AimOutlined,
92
- STOCK_SELECT_FONT: Icons.FontSizeOutlined,
93
- STOCK_DELETE: Icons.DeleteOutlined,
94
- STOCK_DND: Icons.FileTextOutlined,
95
- STOCK_CLEAR: Icons.CloseSquareOutlined,
96
- STOCK_UNINDENT: Icons.AlignLeftOutlined,
97
- STOCK_PREFERENCES: Icons.SettingOutlined,
6
+ type TablerKey = keyof typeof TablerIcons;
7
+ type AntKey = keyof typeof AntIcons;
8
+
9
+ const iconMapping: { [key: string]: string } = {
10
+ "terp-purchase": "ShoppingCart",
11
+ "terp-graph": "PieChart",
12
+ "terp-crm": "Contacts",
13
+ "terp-hr": "Friends",
14
+ "terp-account": "BuildingBank",
15
+ "terp-project": "Checklist",
16
+ "terp-administration": "Adjustments",
17
+ "terp-partner": "Team",
18
+ "terp-mrp": "Build",
19
+ "terp-product": "Shopping",
20
+ STOCK_JUSTIFY_FILL: "UnorderedList",
21
+ STOCK_INDENT: "IndentIncrease",
22
+ STOCK_HELP: "Question",
23
+ STOCK_GO_UP: "ArrowUp",
24
+ STOCK_SORT_DESCENDING: "SortDescending",
25
+ STOCK_ADD: "Plus",
26
+ STOCK_GOTO_LAST: "FastForward",
27
+ STOCK_FIND: "Search",
28
+ STOCK_PROPERTIES: "Control",
29
+ STOCK_DIALOG_INFO: "Info",
30
+ STOCK_FLOPPY: "Usb",
31
+ STOCK_JUSTIFY_CENTER: "AlignCenter",
32
+ STOCK_GO_BACK: "ArrowLeft",
33
+ STOCK_UNDERLINE: "Underline",
34
+ STOCK_BOLD: "Bold",
35
+ STOCK_APPLY: "Check",
36
+ STOCK_ZOOM_OUT: "ZoomOut",
37
+ STOCK_STRIKETHROUGH: "Strikethrough",
38
+ STOCK_MEDIA_REWIND: "Backward",
39
+ STOCK_PRINT: "Printer",
40
+ STOCK_NO: "Close",
41
+ STOCK_GOTO_FIRST: "FastBackward",
42
+ STOCK_CLOSE: "Close",
43
+ STOCK_REMOVE: "Minus",
44
+ STOCK_CUT: "Scissor",
45
+ STOCK_DIALOG_AUTHENTICATION: "Safety",
46
+ STOCK_ZOOM_FIT: "Expand",
47
+ STOCK_JUMP_TO: "Select",
48
+ STOCK_HARDDISK: "Hdd",
49
+ STOCK_SAVE_AS: "Save",
50
+ STOCK_UNDO: "Undo",
51
+ STOCK_JUSTIFY_RIGHT: "AlignRight",
52
+ STOCK_DIALOG_ERROR: "CloseCircle",
53
+ STOCK_INDEX: "Profile",
54
+ STOCK_GOTO_BOTTOM: "VerticalAlignBottom",
55
+ STOCK_MEDIA_NEXT: "StepForward",
56
+ STOCK_REDO: "Redo",
57
+ STOCK_COPY: "Copy",
58
+ STOCK_MEDIA_PAUSE: "Pause",
59
+ STOCK_GO_FORWARD: "ArrowRight",
60
+ STOCK_UNDELETE: "Undo",
61
+ STOCK_EXECUTE: "Setting",
62
+ STOCK_SAVE: "Save",
63
+ STOCK_DIALOG_QUESTION: "QuestionCircle",
64
+ STOCK_SORT_ASCENDING: "SortAscending",
65
+ STOCK_REFRESH: "Reload",
66
+ STOCK_MEDIA_FORWARD: "Forward",
67
+ STOCK_STOP: "Border",
68
+ STOCK_PRINT_PREVIEW: "Printer",
69
+ STOCK_HOME: "Home",
70
+ STOCK_PASTE: "CarryOut",
71
+ STOCK_ZOOM_100: "ZoomIn",
72
+ STOCK_FIND_AND_REPLACE: "FileSearch",
73
+ STOCK_DIALOG_WARNING: "Warning",
74
+ STOCK_ZOOM_IN: "ZoomIn",
75
+ STOCK_CONVERT: "Export",
76
+ STOCK_ITALIC: "Italic",
77
+ STOCK_YES: "Check",
78
+ STOCK_MEDIA_PLAY: "PlayCircle",
79
+ STOCK_MEDIA_RECORD: "VideoCamera",
80
+ STOCK_MEDIA_PREVIOUS: "StepBackward",
81
+ STOCK_NEW: "FileAdd",
82
+ STOCK_CANCEL: "Close",
83
+ STOCK_DISCONNECT: "Api",
84
+ STOCK_JUSTIFY_LEFT: "AlignLeft",
85
+ STOCK_FILE: "File",
86
+ STOCK_QUIT: "Logout",
87
+ STOCK_EDIT: "Edit",
88
+ STOCK_CONNECT: "Api",
89
+ STOCK_GO_DOWN: "CaretDown",
90
+ STOCK_NETWORK: "Apartment",
91
+ STOCK_OK: "Check",
92
+ STOCK_GOTO_TOP: "VerticalAlignTop",
93
+ STOCK_ABOUT: "Star",
94
+ STOCK_COLOR_PICKER: "Aim",
95
+ STOCK_SELECT_FONT: "FontSize",
96
+ STOCK_DELETE: "Delete",
97
+ STOCK_DND: "FileText",
98
+ STOCK_CLEAR: "CloseSquare",
99
+ STOCK_UNINDENT: "AlignLeft",
100
+ STOCK_PREFERENCES: "Setting",
98
101
  };
99
102
 
100
- export default (key: string): React.ElementType | undefined => {
103
+ export default (key: string, className?: any) => {
101
104
  if (key.indexOf("gtk-") !== -1) {
102
- const rootIcon = key.replace("gtk-", "").replace("-", "_");
103
- const newKey = `STOCK_${rootIcon.toUpperCase()}`;
104
- return iconMapping[newKey];
105
+ const rootIcon = key.replace("gtk-", "").replace(/\-/g, "_");
106
+ key = `STOCK_${rootIcon.toUpperCase()}`;
105
107
  }
108
+
106
109
  if (iconMapping.hasOwnProperty(key)) {
107
- return iconMapping[key];
110
+ return getIconForKey(iconMapping[key], className);
108
111
  }
109
- const IconCamelCase = `${key
112
+
113
+ return getIconForKey(key, className);
114
+ };
115
+
116
+ function toCamelCase(key: string): string {
117
+ return `${key
110
118
  .split("-")
111
119
  .map((word) =>
112
120
  word.replace(
@@ -115,18 +123,37 @@ export default (key: string): React.ElementType | undefined => {
115
123
  )
116
124
  )
117
125
  .join("")}`;
126
+ }
127
+
128
+ function getIconForKey(key: string, className?: any) {
129
+ let IconCamelCase = key.charAt(0).toUpperCase() + key.slice(1); // Capitalize first letter
130
+ if (IconCamelCase.indexOf("-") !== -1) {
131
+ IconCamelCase = toCamelCase(IconCamelCase);
132
+ }
118
133
 
119
- const antKey = `${IconCamelCase}Outlined`;
120
- if (Icons.hasOwnProperty(antKey)) {
121
- return Icons[antKey];
134
+ const antKey: AntKey = `${IconCamelCase}Outlined` as any;
135
+ if (AntIcons[antKey]) {
136
+ return () =>
137
+ React.createElement(AntIcons[antKey] as any, {
138
+ className,
139
+ });
122
140
  }
123
141
 
124
- const tablerKey = `Icon${IconCamelCase}`;
125
- if (TablerIcons.hasOwnProperty(tablerKey)) {
142
+ const tablerKey: TablerKey = `Icon${IconCamelCase}` as any;
143
+ if (TablerIcons[tablerKey]) {
144
+ const TablerIcon = () =>
145
+ React.createElement(TablerIcons[tablerKey] as any, {
146
+ fill: "transparent",
147
+ height: 17,
148
+ width: 17,
149
+ });
126
150
  const CustomIcon = () =>
127
- React.createElement(Icon, { component: TablerIcons[tablerKey] });
151
+ React.createElement(Icon, {
152
+ component: TablerIcon,
153
+ className,
154
+ });
128
155
  return CustomIcon;
129
156
  }
130
157
 
131
158
  return undefined;
132
- };
159
+ }