@gisce/react-ooui 1.2.0-rc.37 → 1.2.0-rc.39

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.
@@ -1 +1 @@
1
- {"version":3,"file":"WidgetFactory.d.ts","sourceRoot":"","sources":["WidgetFactory.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAoH1B,QAAA,MAAM,iBAAiB,UAAW,GAAG,+DAWpC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"WidgetFactory.d.ts","sourceRoot":"","sources":["WidgetFactory.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAuH1B,QAAA,MAAM,iBAAiB,UAAW,GAAG,+DAWpC,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { WidgetProps } from '../../types';
3
+ export declare const Tag: (props: WidgetProps) => JSX.Element;
4
+ export declare const TagInput: (props: any) => JSX.Element | null;
5
+ //# sourceMappingURL=Tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tag.d.ts","sourceRoot":"","sources":["Tag.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,eAAO,MAAM,GAAG,UAAW,WAAW,gBAMrC,CAAC;AAEF,eAAO,MAAM,QAAQ,oCASpB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAKvE,OAAO,EAAE,QAAQ,EAAU,MAAM,SAAS,CAAC;AAoB3C,aAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM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AAC;IACnB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACtC,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC;AA2FF,iBAAS,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,YAAY,CAyM9C;AAED,eAAe,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.2.0-rc.37",
3
+ "version": "1.2.0-rc.39",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ant-design/plots": "^1.0.9",
39
- "@gisce/ooui": "^0.17.13-rc.0",
39
+ "@gisce/ooui": "^0.17.14-rc.0",
40
40
  "@gisce/react-formiga-components": "^1.0.9-rc.14",
41
41
  "@gisce/react-formiga-table": "^0.5.0",
42
42
  "@monaco-editor/react": "^4.4.5",
@@ -339,10 +339,15 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
339
339
  disabled={mustDisableButtons}
340
340
  tooltip={t("actions")}
341
341
  items={toolbar?.action}
342
- onItemClick={(action: any) => {
342
+ onItemClick={async (action: any) => {
343
343
  if (!action) {
344
344
  return;
345
345
  }
346
+ const savedSucceed = await onFormSave?.();
347
+
348
+ if (!savedSucceed) {
349
+ return;
350
+ }
346
351
 
347
352
  runAction(action);
348
353
  }}
@@ -352,10 +357,15 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
352
357
  disabled={mustDisableButtons}
353
358
  tooltip={t("reports")}
354
359
  items={toolbar?.print}
355
- onItemClick={(report: any) => {
360
+ onItemClick={async (report: any) => {
356
361
  if (!report) {
357
362
  return;
358
363
  }
364
+ const savedSucceed = await onFormSave?.();
365
+
366
+ if (!savedSucceed) {
367
+ return;
368
+ }
359
369
 
360
370
  runAction({
361
371
  ...report,
@@ -373,6 +383,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
373
383
  return;
374
384
  }
375
385
 
386
+ const savedSucceed = await onFormSave?.();
387
+
388
+ if (!savedSucceed) {
389
+ return;
390
+ }
391
+
376
392
  openRelate({
377
393
  relateData: relate,
378
394
  values: (formRef.current as any).getValues(),
@@ -385,7 +401,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
385
401
  <AttachmentsButton
386
402
  disabled={mustDisableButtons}
387
403
  attachments={attachments}
388
- onAddNewAttachment={() => {
404
+ onAddNewAttachment={async () => {
405
+ const savedSucceed = await onFormSave?.();
406
+
407
+ if (!savedSucceed) {
408
+ return;
409
+ }
410
+
389
411
  const res_id = currentId as number;
390
412
  const res_model = currentModel as string;
391
413
  openDefaultActionForModel({
@@ -400,7 +422,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
400
422
  initialViewType: "form",
401
423
  });
402
424
  }}
403
- onListAllAttachments={() => {
425
+ onListAllAttachments={async () => {
426
+ const savedSucceed = await onFormSave?.();
427
+
428
+ if (!savedSucceed) {
429
+ return;
430
+ }
431
+
404
432
  const res_id = currentId as number;
405
433
  const res_model = currentModel as string;
406
434
  openDefaultActionForModel({
@@ -412,7 +440,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
412
440
  initialViewType: "tree",
413
441
  });
414
442
  }}
415
- onViewAttachmentDetails={(attachment: Attachment) => {
443
+ onViewAttachmentDetails={async (attachment: Attachment) => {
444
+ const savedSucceed = await onFormSave?.();
445
+
446
+ if (!savedSucceed) {
447
+ return;
448
+ }
449
+
416
450
  openDefaultActionForModel({
417
451
  model: "ir.attachment",
418
452
  res_id: attachment.id,
@@ -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<void>;
15
15
  formRef?: any;
16
16
  searchTreeRef?: any;
17
17
  onNewClicked: () => void;
@@ -141,8 +141,8 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
141
141
  }
142
142
  }, [currentView]);
143
143
 
144
- const callOnFormSave = () => {
145
- (formRef.current as any)?.submitForm();
144
+ const callOnFormSave = async () => {
145
+ await (formRef.current as any)?.submitForm();
146
146
  };
147
147
 
148
148
  return (
@@ -28,7 +28,7 @@ const getTableColumns = (
28
28
 
29
29
  if (component) {
30
30
  render = (item: any) => {
31
- return component(item, key, tree.fields[key], context);
31
+ return component(item, key, column, context);
32
32
  };
33
33
  }
34
34
 
@@ -68,7 +68,7 @@ const getTableItems = (treeOoui: TreeOoui, results: Array<any>): Array<any> => {
68
68
  parsedItem[key] = item[key];
69
69
  } else if (widget instanceof Selection) {
70
70
  const selection = widget;
71
- parsedItem[key] = selection.selectionValues.get(item[key]);
71
+ parsedItem[key] = item[key];
72
72
  } else if (widget instanceof Many2one) {
73
73
  parsedItem[key] = item[key] &&
74
74
  Array.isArray(item[key]) &&
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ import { Image } from "@/widgets/base/Image";
37
37
  import showConfirmDialog from "@/ui/ConfirmDialog";
38
38
  import Dashboard from "@/widgets/views/Dashboard/Dashboard";
39
39
  import { Tags } from "@/widgets/custom/Tags";
40
+ import { Tag } from "@/widgets/custom/Tag";
40
41
  import { MultiCheckbox } from "./widgets/custom/MultiCheckbox";
41
42
  import { Radio } from "@/widgets/custom/Radio";
42
43
  import { Switch } from "@/widgets/custom/Switch";
@@ -145,6 +146,7 @@ export {
145
146
  DashboardGridItem,
146
147
  DashboardGrid,
147
148
  Tags,
149
+ Tag,
148
150
  MultiCheckbox,
149
151
  Radio,
150
152
  Switch,
@@ -0,0 +1,57 @@
1
+ import React from "react";
2
+
3
+ import { Tag as TagOoui } from "@gisce/ooui";
4
+ import "antd/dist/antd.css";
5
+ import LocaleProvider from "../../context/LocaleContext";
6
+ import { TagInput } from "../../widgets/custom/Tag";
7
+
8
+ export default {
9
+ title: "Components/Widgets/Custom/Tag",
10
+ };
11
+
12
+ export const Default = (): React.ReactElement => {
13
+ const ooui = new TagOoui({
14
+ name: "status",
15
+ string: "Status",
16
+ field: "status",
17
+ selection: [['draft', 'Draft'], ['open', 'Open']],
18
+ widget_props: '{"colors": {"draft": "blue", "open": "green"}}'
19
+ });
20
+
21
+ return (
22
+ <LocaleProvider lang="en_US">
23
+ <TagInput value="draft" ooui={ooui}/>
24
+ </LocaleProvider>
25
+ );
26
+ };
27
+
28
+ export const WithoutColor = (): React.ReactElement => {
29
+ const ooui = new TagOoui({
30
+ name: "status",
31
+ string: "Status",
32
+ field: "status",
33
+ selection: [['draft', 'Draft'], ['open', 'Open']],
34
+ });
35
+
36
+ return (
37
+ <LocaleProvider lang="en_US">
38
+ <TagInput value="draft" ooui={ooui}/>
39
+ </LocaleProvider>
40
+ );
41
+ };
42
+
43
+ export const WithColorAuto = (): React.ReactElement => {
44
+ const ooui = new TagOoui({
45
+ name: "status",
46
+ string: "Status",
47
+ field: "status",
48
+ selection: [['draft', 'Draft'], ['open', 'Open']],
49
+ widget_props: '{"colors": "auto"}'
50
+ });
51
+
52
+ return (
53
+ <LocaleProvider lang="en_US">
54
+ <TagInput value="draft" ooui={ooui}/>
55
+ </LocaleProvider>
56
+ );
57
+ };
@@ -30,7 +30,7 @@ Default.args = {
30
30
  lang: false,
31
31
  name: "AGRI ENERGIA ELECTRICA, S.A.",
32
32
  ref: "0112",
33
- title: false,
33
+ title: "corp",
34
34
  numeric: 30.1,
35
35
  progressbar: 100,
36
36
  },
@@ -41,7 +41,7 @@ Default.args = {
41
41
  lang: false,
42
42
  name: "Agrolait",
43
43
  ref: false,
44
- title: false,
44
+ title: "ltd",
45
45
  numeric: 30.1,
46
46
  progressbar: 70.434331,
47
47
  },
@@ -85,14 +85,14 @@ Default.args = {
85
85
  lang: false,
86
86
  name: "Aragón",
87
87
  ref: "02",
88
- title: false,
88
+ title: "corp",
89
89
  numeric: 30.1,
90
90
  progressbar: 20.01,
91
91
  },
92
92
  ],
93
93
  treeView: {
94
94
  arch:
95
- '<tree string="Partners">\n<field name="numeric" sum="Numeric"/><field name="name"/>\n <field name="title"/>\n <field name="ref"/>\n <field name="city" select="2"/>\n <field name="country" select="2"/>\n <field name="lang"/>\n <field name="progressbar" string="Progress" /> </tree>',
95
+ `<tree string="Partners">\n<field name="numeric" sum="Numeric"/><field name="name"/>\n <field name="title" widget="tag" widget_props="{'colors': {'corp': 'red', 'ltd': 'green'}}"/>\n <field name="ref"/>\n <field name="city" select="2"/>\n <field name="country" select="2"/>\n <field name="lang"/>\n <field name="progressbar" string="Progress" /> </tree>`,
96
96
  fields: {
97
97
  progressbar: {
98
98
  string: "Progress bar",
@@ -149,7 +149,7 @@ Default.args = {
149
149
  },
150
150
  title: {
151
151
  selection: [
152
- ["Corp.", "Corp."],
152
+ ["corp", "Corp."],
153
153
  ["ltd", "Ltd"],
154
154
  ["", ""],
155
155
  ],
@@ -29,6 +29,7 @@ import {
29
29
  Radio,
30
30
  Switch,
31
31
  Steps,
32
+ Tag,
32
33
  CodeEditor,
33
34
  } from "@/index";
34
35
  import { Image } from "./base/Image";
@@ -99,6 +100,8 @@ const getWidgetType = (type: string) => {
99
100
  return Indicator;
100
101
  case "tags":
101
102
  return Tags;
103
+ case "tag":
104
+ return Tag;
102
105
  case "multicheckbox":
103
106
  return MultiCheckbox;
104
107
  case "radio":
@@ -0,0 +1,24 @@
1
+ import Field from "@/common/Field";
2
+ import { WidgetProps } from "@/types";
3
+ import { Tag as AntdTag } from 'antd';
4
+ import { colorFromString } from "@/helpers/formHelper";
5
+
6
+
7
+ export const Tag = (props: WidgetProps) => {
8
+ return (
9
+ <Field {...props}>
10
+ <TagInput {...props}/>
11
+ </Field>
12
+ );
13
+ };
14
+
15
+ export const TagInput = (props) => {
16
+ const {ooui, value} = props;
17
+ if (!value) {
18
+ return null
19
+ }
20
+ const color = ooui.colors === "auto" ? colorFromString(value) : ooui.colors[value]
21
+ return (
22
+ <AntdTag color={color}>{ooui.selectionValues.get(value)}</AntdTag>
23
+ );
24
+ }
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useEffect, useRef, useState } from "react";
2
- import { Pagination, Checkbox, Space, Row, Col, Spin } from "antd";
2
+ import { Pagination, Checkbox, Space, Row, Col, Spin, Tag } from "antd";
3
3
  import { getTree, getTableColumns, getTableItems } from "@/helpers/treeHelper";
4
4
  import { Tree as TreeOoui } from "@gisce/ooui";
5
5
 
@@ -92,17 +92,41 @@ const imageComponent = (value: string): React.ReactElement => {
92
92
  );
93
93
  };
94
94
 
95
+ const TagComponent = (
96
+ value: any,
97
+ key: string,
98
+ ooui: any,
99
+ context: any
100
+ ): React.ReactElement => {
101
+ return (
102
+ <>
103
+ {value ? <Tag color={ooui.colors[value]}>{ooui.selectionValues.get(value)}</Tag> : null}
104
+ </>
105
+ );
106
+ };
107
+
108
+ const SelectionComponent = (
109
+ value: any,
110
+ key: string,
111
+ ooui: any,
112
+ context: any
113
+ ): React.ReactElement => {
114
+ return (
115
+ <>{ooui.selectionValues.get(value)}</>
116
+ );
117
+ };
118
+
95
119
  const referenceComponent = (
96
120
  value: any,
97
121
  key: string,
98
- fieldDefinitions: any,
122
+ ooui: any,
99
123
  context: any
100
124
  ): React.ReactElement => {
101
125
  return (
102
126
  <>
103
127
  <ReferenceTree
104
128
  value={value}
105
- selectionValues={new Map(fieldDefinitions?.selection)}
129
+ selectionValues={ooui.selectionValues}
106
130
  context={context}
107
131
  />
108
132
  </>
@@ -164,6 +188,8 @@ function Tree(props: Props): React.ReactElement {
164
188
  integer: numberComponent,
165
189
  float: numberComponent,
166
190
  reference: referenceComponent,
191
+ tag: TagComponent,
192
+ selection: SelectionComponent,
167
193
  },
168
194
  context
169
195
  );