@gisce/react-ooui 1.3.0 → 1.4.0-rc.1

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":"SearchTree.d.ts","sourceRoot":"","sources":["SearchTree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBnD,aAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,aAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,uBAAuB,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,KAAK,IAAI,CAAC;CAC1D,CAAC;;AA+SF,wBAAsC"}
1
+ {"version":3,"file":"SearchTree.d.ts","sourceRoot":"","sources":["SearchTree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgBnD,aAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,aAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,uBAAuB,CAAC,EAAE,CAAC,eAAe,EAAE,GAAG,KAAK,IAAI,CAAC;CAC1D,CAAC;;AAiTF,wBAAsC"}
@@ -15,6 +15,9 @@ declare type Props = {
15
15
  colorsForResults?: {
16
16
  [key: number]: string;
17
17
  };
18
+ statusForResults?: {
19
+ [key: number]: string;
20
+ };
18
21
  onChangeSort?: (results: any) => void;
19
22
  sorter?: any;
20
23
  onFetchChildrenForRecord?: (item: any) => Promise<any[]>;
@@ -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;AAwB3C,aAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC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,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,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;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA+GF,iBAAS,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,YAAY,CAoN9C;AAED,eAAe,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.3.0",
3
+ "version": "1.4.0-rc.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -33,9 +33,9 @@
33
33
  "dependencies": {
34
34
  "@ant-design/plots": "^1.0.9",
35
35
  "@gisce/fiber-diagram": "^1.1.0-rc.3",
36
- "@gisce/ooui": "^0.21.0",
36
+ "@gisce/ooui": "^0.22.0",
37
37
  "@gisce/react-formiga-components": "^1.0.9-rc.21",
38
- "@gisce/react-formiga-table": "^0.7.0",
38
+ "@gisce/react-formiga-table": "^0.8.0",
39
39
  "@monaco-editor/react": "^4.4.5",
40
40
  "@tabler/icons-react": "^2.11.0",
41
41
  "antd": "^5.5.2",
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useState } from "react";
2
- import { Space } from "antd";
2
+ import { Space, Spin } from "antd";
3
3
  import ChangeViewButton from "./ChangeViewButton";
4
4
  import {
5
5
  ActionViewContext,
@@ -151,6 +151,13 @@ function TreeActionBar(props: Props) {
151
151
 
152
152
  return (
153
153
  <Space wrap={true}>
154
+ {treeIsLoading && (
155
+ <>
156
+ <Spin />
157
+ {separator()}
158
+ {separator()}
159
+ </>
160
+ )}
154
161
  {treeExpandable ? null : (
155
162
  <>
156
163
  <SearchBar
@@ -6,6 +6,7 @@ import {
6
6
  Reference,
7
7
  } from "@gisce/ooui";
8
8
  import { TreeView, Column } from "@/types";
9
+ import {object} from "@storybook/addon-knobs";
9
10
 
10
11
  const getTree = (treeView: TreeView): TreeOoui => {
11
12
  const xml = treeView.arch;
@@ -121,12 +122,20 @@ function convertBooleansToNumeric({
121
122
  }
122
123
 
123
124
  function getColorMap(colorsValue: any) {
124
- if (!colorsValue) {
125
- return undefined;
125
+ return getItemsAttributes(colorsValue, "colors");
126
+ }
127
+
128
+ function getStatusMap(values: any){
129
+ return getItemsAttributes(values, "status");
130
+ }
131
+
132
+ function getItemsAttributes(attributes: object[], attribute: string) {
133
+ if (!attributes) {
134
+ return undefined
126
135
  }
127
136
  const map: any = {};
128
- colorsValue.forEach((colorEntry: any) => {
129
- map[colorEntry.id] = colorEntry.colors;
137
+ attributes.forEach((entry: any) => {
138
+ map[entry.id] = entry[attribute];
130
139
  });
131
140
  return map;
132
141
  }
@@ -179,5 +188,6 @@ export {
179
188
  convertBooleansToNumeric,
180
189
  itemHasBooleans,
181
190
  getColorMap,
191
+ getStatusMap,
182
192
  sortResults,
183
193
  };
@@ -1,6 +1,6 @@
1
1
  import { mergeParams } from "@/helpers/searchHelper";
2
2
  import {
3
- getColorMap,
3
+ getColorMap, getStatusMap,
4
4
  getTableItems,
5
5
  getTree,
6
6
  sortResults,
@@ -72,6 +72,7 @@ export const useSearch = (opts: UseSearchOpts) => {
72
72
  const [totalItems, setTotalItems] = useState<number>();
73
73
  const [resultsInternal, setResultsInternal] = useState<any>([]);
74
74
  const [colorsForResults, setColorsForResults] = useState<any>(undefined);
75
+ const [statusForResults, setStatusForResults] = useState<any>(undefined);
75
76
  const internalLimit = useRef(limit || DEFAULT_SEARCH_LIMIT);
76
77
 
77
78
  const originalResults = useRef<any[]>([]);
@@ -105,7 +106,14 @@ export const useSearch = (opts: UseSearchOpts) => {
105
106
  return item?.[0];
106
107
  });
107
108
 
108
- const { colors } = getTree(treeView!);
109
+ const { colors, status } = getTree(treeView!);
110
+ const attrs: any = {};
111
+ if (colors) {
112
+ attrs.colors = colors;
113
+ }
114
+ if (status) {
115
+ attrs.status = status;
116
+ }
109
117
 
110
118
  const resultsWithData =
111
119
  await ConnectionProvider.getHandler().readEvalUiObjects({
@@ -116,15 +124,14 @@ export const useSearch = (opts: UseSearchOpts) => {
116
124
  ? { ...treeView!.fields, [treeView!.field_parent]: {} }
117
125
  : treeView!.fields,
118
126
  context,
119
- attrs: colors && {
120
- colors,
121
- },
127
+ attrs,
122
128
  });
123
129
  const resultsData = resultsWithData[0];
124
130
 
125
131
  originalResults.current = [...resultsData];
126
132
 
127
133
  setColorsForResults(getColorMap(resultsWithData[1]));
134
+ setStatusForResults(getStatusMap(resultsWithData[1]));
128
135
 
129
136
  const newResultIds = resultsData.map((item: any) => item.id);
130
137
 
@@ -169,7 +176,14 @@ export const useSearch = (opts: UseSearchOpts) => {
169
176
  const { params, newOffset } = opts || {};
170
177
 
171
178
  const mergedParams = mergeParams(params || searchParams, domain);
172
- const { colors } = getTree(treeView!);
179
+ const { colors, status } = getTree(treeView!); const attrs: any = {};
180
+ if (colors) {
181
+ attrs.colors = colors;
182
+ }
183
+ if (status) {
184
+ attrs.status = status;
185
+ }
186
+
173
187
 
174
188
  const { totalItems, results, attrsEvaluated } =
175
189
  await ConnectionProvider.getHandler().searchForTree({
@@ -181,9 +195,10 @@ export const useSearch = (opts: UseSearchOpts) => {
181
195
  ? { ...treeView!.fields, [treeView!.field_parent]: {} }
182
196
  : treeView!.fields,
183
197
  context,
184
- attrs: colors && { colors },
198
+ attrs,
185
199
  });
186
200
  setColorsForResults(getColorMap(attrsEvaluated));
201
+ setStatusForResults(getStatusMap(attrsEvaluated));
187
202
 
188
203
  originalResults.current = [...results];
189
204
 
@@ -278,6 +293,7 @@ export const useSearch = (opts: UseSearchOpts) => {
278
293
 
279
294
  const changeSort = useCallback(
280
295
  (newSorter: any) => {
296
+ if (JSON.stringify(newSorter) === JSON.stringify(sorter)) return;
281
297
  setSorter?.(newSorter);
282
298
  const sortedResults =
283
299
  newSorter !== undefined
@@ -400,6 +416,7 @@ export const useSearch = (opts: UseSearchOpts) => {
400
416
  changeSort,
401
417
  fetchChildrenForRecord,
402
418
  colorsForResults,
419
+ statusForResults,
403
420
  totalItems,
404
421
  };
405
422
  };
@@ -99,6 +99,10 @@ Default.args = {
99
99
  progressbar: 20.01,
100
100
  },
101
101
  ],
102
+ colorsForResults: {
103
+ 32: "red",
104
+ 33: "red"
105
+ },
102
106
  treeView: {
103
107
  arch:
104
108
  `<tree string="Partners">\n<field name="numeric" sum="Numeric"/><field name="user_id" widget="avatar"/><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>`,
@@ -123,6 +123,7 @@ function SearchTree(props: Props, ref: any) {
123
123
  changeSort,
124
124
  fetchChildrenForRecord,
125
125
  colorsForResults,
126
+ statusForResults,
126
127
  totalItems,
127
128
  } = useSearch({
128
129
  model: currentModel!,
@@ -181,9 +182,9 @@ function SearchTree(props: Props, ref: any) {
181
182
  setInitialFetchDone(true);
182
183
  } catch (error) {
183
184
  setInitialError(error);
185
+ setTreeIsLoading?.(false);
184
186
  } finally {
185
187
  setIsLoading(false);
186
- setTreeIsLoading?.(false);
187
188
  }
188
189
  };
189
190
 
@@ -319,6 +320,7 @@ function SearchTree(props: Props, ref: any) {
319
320
  onRowClicked={onRowClickedHandler}
320
321
  scrollY={treeScrollY || calculateTableHeight()}
321
322
  colorsForResults={colorsForResults}
323
+ statusForResults={statusForResults}
322
324
  rowSelection={{
323
325
  selectedRowKeys: selectedRowItems?.map((item) => item.id),
324
326
  onChange: changeSelectedRowKeys,
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useEffect, useRef, useState } from "react";
2
- import { Pagination, Checkbox, Space, Row, Col, Spin, Tag } from "antd";
2
+ import { Pagination, Checkbox, Space, Row, Col, Spin, Tag, Badge } from "antd";
3
3
  import { getTree, getTableColumns, getTableItems } from "@/helpers/treeHelper";
4
4
  import { Tree as TreeOoui } from "@gisce/ooui";
5
5
 
@@ -40,6 +40,7 @@ type Props = {
40
40
  rowSelection?: any;
41
41
  scrollY?: number;
42
42
  colorsForResults?: { [key: number]: string };
43
+ statusForResults?: { [key: number]: string };
43
44
  onChangeSort?: (results: any) => void;
44
45
  sorter?: any;
45
46
  onFetchChildrenForRecord?: (item: any) => Promise<any[]>;
@@ -117,7 +118,7 @@ const imageComponent = (value: string): React.ReactElement => {
117
118
  };
118
119
 
119
120
  const TagComponent = (
120
- value: any,
121
+ value: any,
121
122
  key: string,
122
123
  ooui: any,
123
124
  context: any
@@ -126,14 +127,12 @@ value: any,
126
127
  };
127
128
 
128
129
  const SelectionComponent = (
129
- value: any,
130
+ value: any,
130
131
  key: string,
131
132
  ooui: any,
132
133
  context: any
133
134
  ): React.ReactElement => {
134
- return (
135
- <>{ooui.selectionValues.get(value)}</>
136
- );
135
+ return <>{ooui.selectionValues.get(value)}</>;
137
136
  };
138
137
 
139
138
  const referenceComponent = (
@@ -153,9 +152,12 @@ const referenceComponent = (
153
152
  );
154
153
  };
155
154
 
156
- const AvatarFn = (value: any, key:string, ooui: any, context: any): React.ReactElement => (
157
- <Avatar ooui={ooui} value={value} />
158
- )
155
+ const AvatarFn = (
156
+ value: any,
157
+ key: string,
158
+ ooui: any,
159
+ context: any
160
+ ): React.ReactElement => <Avatar ooui={ooui} value={value} />;
159
161
 
160
162
  function Tree(props: Props): React.ReactElement {
161
163
  const {
@@ -171,6 +173,7 @@ function Tree(props: Props): React.ReactElement {
171
173
  rowSelection,
172
174
  scrollY,
173
175
  colorsForResults = {},
176
+ statusForResults = {},
174
177
  onChangeSort,
175
178
  sorter,
176
179
  onFetchChildrenForRecord,
@@ -306,9 +309,7 @@ function Tree(props: Props): React.ReactElement {
306
309
  summary.push(`${sumField.label}: ${Math.round(total * 100) / 100}`);
307
310
  });
308
311
 
309
- return (
310
- <div className="p-1 pb-0 pl-2 mt-2 ">{summary.join(", ")}</div>
311
- );
312
+ return <div className="p-1 pb-0 pl-2 mt-2 ">{summary.join(", ")}</div>;
312
313
  }
313
314
 
314
315
  let dataTable;
@@ -331,11 +332,12 @@ function Tree(props: Props): React.ReactElement {
331
332
  ) : (
332
333
  <div>
333
334
  {pagination()}
335
+ {loading && <Spin className="pb-4" />}
334
336
  <GisceTable
335
337
  height={adjustedHeight!}
336
338
  columns={dataTable.columns}
337
339
  dataSource={items}
338
- loading={loading}
340
+ loading={false}
339
341
  loadingComponent={<Spin />}
340
342
  onRowStyle={(record: any) => {
341
343
  if (colorsForResults![record.id]) {
@@ -343,6 +345,12 @@ function Tree(props: Props): React.ReactElement {
343
345
  }
344
346
  return undefined;
345
347
  }}
348
+ onRowStatus={(record: any) => {
349
+ if (statusForResults![record.id]) {
350
+ return <Badge color={statusForResults[record.id]}/>
351
+ }
352
+ return undefined
353
+ }}
346
354
  onRowDoubleClick={onRowClicked}
347
355
  onRowSelectionChange={rowSelection?.onChange}
348
356
  onChangeSort={onChangeSort}