@gisce/react-ooui 0.10.3 → 0.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"Tags.d.ts","sourceRoot":"","sources":["../../../src/widgets/custom/Tags.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAgB,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAQ7E,aAAK,SAAS,GAAG;IACf,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,aAAK,cAAc,GAAG,SAAS,GAAG;IAChC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,SAAS,gBAQpC,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,cAAc,gBAqG9C,CAAC"}
1
+ {"version":3,"file":"Tags.d.ts","sourceRoot":"","sources":["../../../src/widgets/custom/Tags.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAgB,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAO7E,aAAK,SAAS,GAAG;IACf,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,aAAK,cAAc,GAAG,SAAS,GAAG;IAChC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,SAAS,gBAQpC,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,cAAc,gBAsH9C,CAAC"}
@@ -75,7 +75,6 @@ var Field_1 = __importDefault(require("@/common/Field"));
75
75
  var use_deep_compare_effect_1 = __importDefault(require("use-deep-compare-effect"));
76
76
  var FormContext_1 = require("@/context/FormContext");
77
77
  var antd_1 = require("antd");
78
- var one2manyHelper_1 = require("@/helpers/one2manyHelper");
79
78
  var formHelper_1 = require("@/helpers/formHelper");
80
79
  var ConnectionProvider_1 = __importDefault(require("@/ConnectionProvider"));
81
80
  var Tags = function (props) {
@@ -87,99 +86,101 @@ exports.Tags = Tags;
87
86
  var TagsInput = function (props) {
88
87
  var value = props.value, ooui = props.ooui, onChange = props.onChange;
89
88
  var _a = (value || {}).items, items = _a === void 0 ? [] : _a;
90
- var _b = react_1.useState(false), isLoading = _b[0], setIsLoading = _b[1];
89
+ var itemsToShow = items.filter(function (item) { return item.operation !== "pendingRemove"; }).map(function (item) { return item.id; });
90
+ var _b = react_1.useState([]), options = _b[0], setOptions = _b[1];
91
91
  var _c = react_1.useState(), error = _c[0], setError = _c[1];
92
+ var _d = react_1.useState(false), isLoadingOptions = _d[0], setIsLoadingOptions = _d[1];
92
93
  var relation = ooui.relation, context = ooui.context, readOnly = ooui.readOnly, field = ooui.field;
93
- var itemsToShow = items.filter(function (item) { return item.values && item.operation !== "pendingRemove"; });
94
94
  var formContext = react_1.useContext(FormContext_1.FormContext);
95
95
  var getContext = (formContext || {}).getContext;
96
96
  use_deep_compare_effect_1.default(function () {
97
- if (items.some(function (item) { return !item.values; })) {
98
- fetchData();
99
- }
97
+ fetchOptions();
100
98
  }, [items]);
101
99
  var triggerChange = function (changedValue) {
102
100
  onChange === null || onChange === void 0 ? void 0 : onChange({
103
101
  items: changedValue,
104
102
  });
105
103
  };
106
- function fetchData() {
104
+ function fetchOptions() {
107
105
  return __awaiter(this, void 0, void 0, function () {
108
- var fieldsDef, itemsWithValues, err_1;
106
+ var params, optionsRead, options_1, err_1;
109
107
  return __generator(this, function (_a) {
110
108
  switch (_a.label) {
111
109
  case 0:
112
- setIsLoading(true);
113
- setError(undefined);
114
- return [4 /*yield*/, ConnectionProvider_1.default.getHandler().getFields({
115
- model: relation,
116
- fields: [field],
117
- context: getContext(),
118
- })];
110
+ setIsLoadingOptions(true);
111
+ params = (formContext === null || formContext === void 0 ? void 0 : formContext.domain) || [];
112
+ if (readOnly) {
113
+ params = [['id', 'in', itemsToShow]];
114
+ }
115
+ _a.label = 1;
119
116
  case 1:
120
- fieldsDef = _a.sent();
121
- _a.label = 2;
122
- case 2:
123
- _a.trys.push([2, 4, 5, 6]);
124
- return [4 /*yield*/, one2manyHelper_1.readObjectValues({
125
- treeFields: {},
126
- formFields: fieldsDef,
117
+ _a.trys.push([1, 3, 4, 5]);
118
+ return [4 /*yield*/, ConnectionProvider_1.default.getHandler().search({
127
119
  model: relation,
128
- items: items,
120
+ params: params,
121
+ fields: [field],
129
122
  context: __assign(__assign({}, getContext === null || getContext === void 0 ? void 0 : getContext()), context),
130
123
  })];
124
+ case 2:
125
+ optionsRead = _a.sent();
126
+ options_1 = optionsRead.map(function (item) {
127
+ var value = item[field];
128
+ var formattedValue = value;
129
+ if (Array.isArray(value)) {
130
+ formattedValue = value[1];
131
+ }
132
+ return { label: formattedValue, value: item.id };
133
+ });
134
+ setOptions(options_1);
135
+ return [3 /*break*/, 5];
131
136
  case 3:
132
- itemsWithValues = _a.sent();
133
- triggerChange(itemsWithValues);
134
- return [3 /*break*/, 6];
135
- case 4:
136
137
  err_1 = _a.sent();
137
138
  setError(err_1);
138
- return [3 /*break*/, 6];
139
- case 5:
140
- setIsLoading(false);
139
+ return [3 /*break*/, 5];
140
+ case 4:
141
+ setIsLoadingOptions(false);
141
142
  return [7 /*endfinally*/];
142
- case 6: return [2 /*return*/];
143
+ case 5:
144
+ if (error) {
145
+ return [2 /*return*/, react_1.default.createElement(antd_1.Alert, { className: "mt-10", message: error, type: "error", banner: true })];
146
+ }
147
+ return [2 /*return*/];
143
148
  }
144
149
  });
145
150
  });
146
151
  }
147
- if (error) {
148
- return react_1.default.createElement(antd_1.Alert, { className: "mt-10", message: error, type: "error", banner: true });
149
- }
150
- if (isLoading) {
151
- return react_1.default.createElement(antd_1.Spin, null);
152
- }
153
- var removeItem = function (item) {
154
- var newItems = items.map(function (i) {
155
- if (i.id === item.id) {
156
- return __assign(__assign({}, item), { operation: "pendingRemove" });
152
+ ;
153
+ var onChangeSelected = function (ids) {
154
+ var newItems = items.map(function (item) {
155
+ if (ids.includes(item.id)) {
156
+ if (item.operation == "pendingRemove") {
157
+ return __assign(__assign({}, item), { operation: "pendingLink" });
158
+ }
159
+ else {
160
+ return item;
161
+ }
157
162
  }
158
163
  else {
159
- return i;
164
+ return { id: item.id, operation: 'pendingRemove' };
160
165
  }
161
166
  });
167
+ var currentIds = newItems.map(function (item) { return item.id; });
168
+ ids.filter(function (id) { return !currentIds.includes(id); }).map(function (id) {
169
+ newItems.push({ id: id, operation: 'pendingLink' });
170
+ });
162
171
  triggerChange(newItems);
163
172
  };
173
+ var tagRender = function (props) {
174
+ var label = props.label, closable = props.closable, onClose = props.onClose;
175
+ var onPreventMouseDown = function (event) {
176
+ event.preventDefault();
177
+ event.stopPropagation();
178
+ };
179
+ return (react_1.default.createElement(antd_1.Tag, { color: formHelper_1.colorFromString(label), onMouseDown: onPreventMouseDown, style: { margin: '5px' }, closable: closable, onClose: onClose }, label));
180
+ };
164
181
  return (react_1.default.createElement(react_1.default.Fragment, null,
165
- react_1.default.createElement("div", { style: { padding: "1rem" } }, itemsToShow.map(function (item, index) {
166
- var _a;
167
- var value = (_a = item.values) === null || _a === void 0 ? void 0 : _a[field];
168
- var formattedValue = value;
169
- if (ooui.selectionValues.size) {
170
- formattedValue = ooui.selectionValues.get(value);
171
- }
172
- else if (Array.isArray(value)) {
173
- formattedValue = value[1];
174
- }
175
- if (!value) {
176
- return null;
177
- }
178
- return (react_1.default.createElement(antd_1.Tag, { key: index, color: formHelper_1.colorFromString(formattedValue), closable: !readOnly, style: { margin: '5px' }, onClose: function (e) {
179
- e.preventDefault();
180
- removeItem(item);
181
- } }, formattedValue));
182
- }))));
182
+ react_1.default.createElement("div", { style: { padding: "1rem" } },
183
+ react_1.default.createElement(antd_1.Select, { mode: "multiple", value: options.length ? itemsToShow : [], tagRender: tagRender, bordered: !readOnly, disabled: readOnly, options: options, onChange: onChangeSelected, loading: isLoadingOptions }))));
183
184
  };
184
185
  exports.TagsInput = TagsInput;
185
186
  //# sourceMappingURL=Tags.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tags.js","sourceRoot":"","sources":["../../../src/widgets/custom/Tags.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAoD;AAEpD,yDAAmC;AAEnC,oFAA2D;AAC3D,qDAAqE;AACrE,6BAA2E;AAC3E,2DAA4D;AAC5D,mDAAuD;AACvD,4EAAsD;AAW/C,IAAM,IAAI,GAAG,UAAC,KAAgB;IAC3B,IAAA,IAAI,GAAK,KAAK,KAAV,CAAW;IAEvB,OAAO,CACL,8BAAC,eAAK,aAAC,IAAI,EAAE,OAAO,IAAM,KAAK;QAC7B,8BAAC,iBAAS,IAAC,IAAI,EAAE,IAAI,GAAK,CACpB,CACT,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,IAAI,QAQf;AAEK,IAAM,SAAS,GAAG,UAAC,KAAqB;IACrC,IAAA,KAAK,GAAqB,KAAK,MAA1B,EAAE,IAAI,GAAe,KAAK,KAApB,EAAE,QAAQ,GAAK,KAAK,SAAV,CAAW;IAChC,IAAA,KAAe,CAAA,KAAK,IAAI,EAAE,CAAA,MAAhB,EAAV,KAAK,mBAAG,EAAE,KAAA,CAAiB;IAE7B,IAAA,KAA4B,gBAAQ,CAAU,KAAK,CAAC,EAAnD,SAAS,QAAA,EAAE,YAAY,QAA4B,CAAC;IACrD,IAAA,KAAoB,gBAAQ,EAAU,EAArC,KAAK,QAAA,EAAE,QAAQ,QAAsB,CAAC;IACrC,IAAA,QAAQ,GAA+B,IAAI,SAAnC,EAAE,OAAO,GAAsB,IAAI,QAA1B,EA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AAC,CAAC,CAAC,EAAE,EACxC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,CAAC,QAAQ,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,gBAAgB,GAElB,CACL,CACL,CACJ,CAAC;AAEJ,CAAC,CAAC;AAtHW,QAAA,SAAS,aAsHpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "0.10.3",
3
+ "version": "0.11.0",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -4,7 +4,6 @@ import { TagsInput } from "../../widgets/custom/Tags";
4
4
  import { Tags as TagsOoui } from "@gisce/ooui";
5
5
  import "antd/dist/antd.css";
6
6
  import LocaleProvider from "../../context/LocaleContext";
7
- import { One2manyInput } from "../../widgets/base/one2many/One2manyInput";
8
7
 
9
8
  export default {
10
9
  title: "Components/Widgets/Custom/Tags",
@@ -14,15 +13,16 @@ export const Default = (): React.ReactElement => {
14
13
  const ooui = new TagsOoui({
15
14
  name: "button_field",
16
15
  string: "Lorem ipsum",
17
- field: "name"
16
+ field: "name",
17
+ relation: "res.partner.category"
18
18
  });
19
19
 
20
20
  return (
21
21
  <LocaleProvider lang="en_US">
22
22
  <TagsInput ooui={ooui} value={{items: [
23
- {id: 1, operation: "original", values: {name: "test"}},
24
- {id: 2, operation: "original", values: {name: "foo"}},
25
- {id: 3, operation: "pendingRemove", values: {name: "remove"}}
23
+ {id: 1, operation: "original"},
24
+ {id: 2, operation: "original"},
25
+ {id: 3, operation: "pendingRemove"}
26
26
  ]}}
27
27
  />
28
28
  </LocaleProvider>
@@ -34,15 +34,16 @@ export const Readonly = (): React.ReactElement => {
34
34
  name: "button_field",
35
35
  string: "Lorem ipsum",
36
36
  field: "name",
37
- readonly: true
37
+ readonly: true,
38
+ relation: "res.partner.category",
38
39
  });
39
40
 
40
41
  return (
41
42
  <LocaleProvider lang="en_US">
42
43
  <TagsInput ooui={ooui} value={{items: [
43
- {id: 1, operation: "original", values: {name: "test"}},
44
- {id: 2, operation: "original", values: {name: "foo"}},
45
- {id: 3, operation: "pendingRemove", values: {name: "remove"}}
44
+ {id: 1, operation: "original"},
45
+ {id: 2, operation: "original"},
46
+ {id: 3, operation: "pendingRemove"}
46
47
  ]}}
47
48
  />
48
49
  </LocaleProvider>
@@ -13,6 +13,7 @@ import switching from "./models/switching";
13
13
  import attachment from "./models/attachment";
14
14
  import crm_case from "./models/crm_case";
15
15
  import form_with_gridfiber from "./models/form_with_gridfiber";
16
+ import partner_category from "./models/res_partner_category";
16
17
 
17
18
  const allModels = [
18
19
  cups,
@@ -30,6 +31,7 @@ const allModels = [
30
31
  attachment,
31
32
  crm_case,
32
33
  form_with_gridfiber,
34
+ partner_category,
33
35
  ];
34
36
 
35
37
  const getMock = (model: string) => {
@@ -19,6 +19,7 @@ import {
19
19
  SearchAllIdsRequest,
20
20
  NameSearchRequest,
21
21
  SearchCountRequest,
22
+ GetFieldsRequest,
22
23
  } from "../../types/index";
23
24
 
24
25
  const init = () => {
@@ -50,6 +51,14 @@ const init = () => {
50
51
  const data = getMock(model);
51
52
  return data[type];
52
53
  },
54
+ getFields: async (options: GetFieldsRequest) => {
55
+ const { model, fields } = options;
56
+ await new Promise((resolve) => setTimeout(resolve, timeout));
57
+ const data = getMock(model);
58
+ const fieldsDef = Object.fromEntries(Object.entries(data.form.fields).filter(([key]) => fields.includes(key)));
59
+ return fieldsDef;
60
+
61
+ },
53
62
  searchAllIds: async (options: SearchCountRequest) => {
54
63
  await new Promise((resolve) => setTimeout(resolve, timeout));
55
64
  return [6];
@@ -57,10 +66,7 @@ const init = () => {
57
66
  search: async (options: SearchRequest) => {
58
67
  await new Promise((resolve) => setTimeout(resolve, timeout));
59
68
  const data = getMock(options.model);
60
- return {
61
- totalItems: 1,
62
- results: [data.exampleValues],
63
- };
69
+ return [data.exampleValues];
64
70
  },
65
71
  searchForTree: async (options: SearchRequest) => {
66
72
  await new Promise((resolve) => setTimeout(resolve, timeout));
@@ -0,0 +1,15 @@
1
+ export default {
2
+ model: "res.partner.category",
3
+ exampleValues: {
4
+ id: 1,
5
+ name: "foo",
6
+ },
7
+ form: {
8
+ fields: {
9
+ name: {
10
+ string: "Name",
11
+ type: "char",
12
+ },
13
+ }
14
+ }
15
+ }
@@ -4,8 +4,7 @@ import Field from "@/common/Field";
4
4
  import { One2manyItem, One2manyValue } from "../base/one2many/One2manyInput";
5
5
  import useDeepCompareEffect from "use-deep-compare-effect";
6
6
  import { FormContext, FormContextType } from "@/context/FormContext";
7
- import { Spin, Alert, Timeline as AntTimeline, Tag as AntTag } from "antd";
8
- import { readObjectValues } from "@/helpers/one2manyHelper";
7
+ import { Alert, Tag as AntTag, Select } from "antd";
9
8
  import { colorFromString } from "@/helpers/formHelper";
10
9
  import ConnectionProvider from "@/ConnectionProvider";
11
10
 
@@ -31,21 +30,21 @@ export const Tags = (props: TagsProps) => {
31
30
  export const TagsInput = (props: TagsInputProps) => {
32
31
  const { value, ooui, onChange } = props;
33
32
  const { items = [] } = value || {};
33
+ const itemsToShow = items.filter(
34
+ (item) => item.operation !== "pendingRemove"
35
+ ).map((item) => item.id) as number[];
34
36
 
35
- const [isLoading, setIsLoading] = useState<boolean>(false);
37
+ const [options, setOptions] = useState<any[]>([]);
36
38
  const [error, setError] = useState<string>();
39
+ const [isLoadingOptions, setIsLoadingOptions] = useState<boolean>(false);
37
40
  const { relation, context, readOnly, field } = ooui;
38
- const itemsToShow = items.filter(
39
- (item) => item.values && item.operation !== "pendingRemove"
40
- );
41
+
41
42
 
42
43
  const formContext = useContext(FormContext) as FormContextType;
43
44
  const { getContext } = formContext || {};
44
45
 
45
46
  useDeepCompareEffect(() => {
46
- if (items.some((item) => !item.values)) {
47
- fetchData();
48
- }
47
+ fetchOptions();
49
48
  }, [items]);
50
49
 
51
50
  const triggerChange = (changedValue: Array<One2manyItem>) => {
@@ -54,79 +53,96 @@ export const TagsInput = (props: TagsInputProps) => {
54
53
  });
55
54
  };
56
55
 
57
- async function fetchData() {
58
- setIsLoading(true);
59
- setError(undefined);
60
-
61
- const fieldsDef = await ConnectionProvider.getHandler().getFields({
62
- model: relation,
63
- fields: [field],
64
- context: getContext(),
65
- });
66
-
56
+ async function fetchOptions() {
57
+ setIsLoadingOptions(true);
58
+ let params = formContext?.domain || [];
59
+ if (readOnly) {
60
+ params = [['id', 'in', itemsToShow]]
61
+ }
67
62
  try {
68
- const itemsWithValues = await readObjectValues({
69
- treeFields: {},
70
- formFields: fieldsDef,
63
+ const optionsRead = await ConnectionProvider.getHandler().search({
71
64
  model: relation,
72
- items,
65
+ params: params,
66
+ fields: [field],
73
67
  context: { ...getContext?.(), ...context },
74
68
  });
75
- triggerChange(itemsWithValues);
69
+ const options = optionsRead.map((item:any) => {
70
+ const value = item[field];
71
+ let formattedValue = value;
72
+ if (Array.isArray(value)) {
73
+ formattedValue = value[1];
74
+ }
75
+ return {label: formattedValue, value: item.id}
76
+ });
77
+ setOptions(options);
78
+
76
79
  } catch (err) {
77
- setError(err as any);
80
+ setError(err as any)
78
81
  } finally {
79
- setIsLoading(false);
82
+ setIsLoadingOptions(false);
83
+ }
84
+ if (error) {
85
+ return <Alert className="mt-10" message={error} type="error" banner />;
80
86
  }
81
- }
82
-
83
- if (error) {
84
- return <Alert className="mt-10" message={error} type="error" banner />;
85
- }
86
87
 
87
- if (isLoading) {
88
- return <Spin />;
89
- }
88
+ };
90
89
 
91
- const removeItem = (item: One2manyItem) => {
92
- const newItems: One2manyItem[] = items.map(i => {
93
- if (i.id === item.id) {
94
- return {
95
- ...item,
96
- operation: "pendingRemove",
90
+ const onChangeSelected = (ids: number[]) => {
91
+ const newItems: One2manyItem[] = items.map((item) => {
92
+ if (ids.includes(item.id as number)) {
93
+ if (item.operation == "pendingRemove") {
94
+ return {
95
+ ...item,
96
+ operation: "pendingLink"
97
+ }
98
+ } else {
99
+ return item
97
100
  }
98
101
  } else {
99
- return i
102
+ return {id: item.id, operation: 'pendingRemove'}
100
103
  }
104
+ })
105
+ const currentIds = newItems.map(item => item.id)
106
+ ids.filter(id => !currentIds.includes(id)).map((id) => {
107
+ newItems.push({id, operation: 'pendingLink'});
101
108
  });
102
109
  triggerChange(newItems);
103
110
  };
104
111
 
112
+ const tagRender = (props: any) => {
113
+ const { label, closable, onClose } = props;
114
+ const onPreventMouseDown = (event: React.MouseEvent<HTMLSpanElement>) => {
115
+ event.preventDefault();
116
+ event.stopPropagation();
117
+ };
118
+ return (
119
+ <AntTag
120
+ color={colorFromString(label)}
121
+ onMouseDown={onPreventMouseDown}
122
+ style={{margin: '5px'}}
123
+ closable={closable}
124
+ onClose={onClose}>
125
+ {label}
126
+ </AntTag>
127
+ );
128
+ };
129
+
105
130
  return (
106
131
  <>
107
132
  <div style={{ padding: "1rem" }}>
108
-
109
- {itemsToShow.map((item, index) => {
110
- const value = item.values?.[field];
111
- let formattedValue = value;
112
- if (ooui.selectionValues.size) {
113
- formattedValue = ooui.selectionValues.get(value);
114
- } else if (Array.isArray(value)) {
115
- formattedValue = value[1];
116
- }
117
- if (!value) {
118
- return null;
119
- }
120
- return (
121
- <AntTag key={index} color={colorFromString(formattedValue)} closable={!readOnly} style={{margin: '5px'}} onClose={e => {
122
- e.preventDefault();
123
- removeItem(item);
124
-
125
- }}>{formattedValue}</AntTag>
126
- );
127
- })}
133
+ <Select
134
+ mode="multiple"
135
+ value={options.length ? itemsToShow : []}
136
+ tagRender={tagRender}
137
+ bordered={!readOnly}
138
+ disabled={readOnly}
139
+ options={options}
140
+ onChange={onChangeSelected}
141
+ loading={isLoadingOptions}
142
+ >
143
+ </Select>
128
144
  </div>
129
-
130
145
  </>
131
146
  );
147
+
132
148
  };