@gisce/react-ooui 1.1.2-rc.2 → 1.1.2-rc.4

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 (33) hide show
  1. package/dist/context/ContentRootContext.d.ts.map +1 -1
  2. package/dist/hooks/useSearch.d.ts +5 -2
  3. package/dist/hooks/useSearch.d.ts.map +1 -1
  4. package/dist/react-ooui.es.js +3962 -3946
  5. package/dist/react-ooui.es.js.map +1 -1
  6. package/dist/react-ooui.umd.js +15 -15
  7. package/dist/react-ooui.umd.js.map +1 -1
  8. package/dist/views/RootView.d.ts.map +1 -1
  9. package/dist/views/actionViews/GraphActionView.d.ts.map +1 -1
  10. package/dist/views/actionViews/TreeActionView.d.ts.map +1 -1
  11. package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
  12. package/dist/widgets/custom/MultiCheckbox.d.ts.map +1 -1
  13. package/dist/widgets/custom/Tags.d.ts.map +1 -1
  14. package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
  15. package/dist/widgets/views/Graph/GraphChart.d.ts.map +1 -1
  16. package/dist/widgets/views/Graph/useGraphData.d.ts +1 -0
  17. package/dist/widgets/views/Graph/useGraphData.d.ts.map +1 -1
  18. package/dist/widgets/views/searchFilter/SearchFilter.d.ts +1 -0
  19. package/dist/widgets/views/searchFilter/SearchFilter.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/src/context/ContentRootContext.tsx +5 -1
  22. package/src/helpers/searchHelper.ts +1 -1
  23. package/src/hooks/useSearch.ts +107 -106
  24. package/src/views/RootView.tsx +5 -1
  25. package/src/views/actionViews/GraphActionView.tsx +60 -50
  26. package/src/views/actionViews/TreeActionView.tsx +0 -1
  27. package/src/widgets/base/one2many/One2manyInput.tsx +7 -2
  28. package/src/widgets/custom/MultiCheckbox.tsx +54 -43
  29. package/src/widgets/custom/Tags.tsx +8 -5
  30. package/src/widgets/views/Dashboard/DashboardTree.tsx +1 -27
  31. package/src/widgets/views/Graph/GraphChart.tsx +4 -1
  32. package/src/widgets/views/Graph/useGraphData.tsx +9 -1
  33. package/src/widgets/views/searchFilter/SearchFilter.tsx +5 -1
@@ -4,8 +4,9 @@ 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 { Alert, Checkbox, Spin, Col, Row, Button, Space } from "antd";
7
+ import { Alert, Checkbox, Spin, Col, Row, Button, Space } from "antd";
8
8
  import ConnectionProvider from "@/ConnectionProvider";
9
+ import { transformPlainMany2Ones } from "@/helpers/formHelper";
9
10
 
10
11
  type MultiCheckboxProps = {
11
12
  ooui: MultiCheckboxOoui;
@@ -21,7 +22,7 @@ export const MultiCheckbox = (props: MultiCheckboxProps) => {
21
22
 
22
23
  return (
23
24
  <Field type={"array"} {...props}>
24
- <MultiCheckboxInput ooui={ooui} />
25
+ <MultiCheckboxInput ooui={ooui} />
25
26
  </Field>
26
27
  );
27
28
  };
@@ -29,16 +30,15 @@ export const MultiCheckbox = (props: MultiCheckboxProps) => {
29
30
  export const MultiCheckboxInput = (props: MultiCheckboxInputProps) => {
30
31
  const { value, ooui, onChange } = props;
31
32
  const { items = [] } = value || {};
32
- const itemsToShow = items.filter(
33
- (item) => item.operation !== "pendingRemove"
34
- ).map((item) => item.id) as number[];
33
+ const itemsToShow = items
34
+ .filter((item) => item.operation !== "pendingRemove")
35
+ .map((item) => item.id) as number[];
35
36
 
36
37
  const [options, setOptions] = useState<any[]>([]);
37
38
  const [error, setError] = useState<string>();
38
39
  const [isLoadingOptions, setIsLoadingOptions] = useState<boolean>(false);
39
40
  const { relation, context, readOnly, field, columns } = ooui;
40
41
 
41
-
42
42
  const formContext = useContext(FormContext) as FormContextType;
43
43
  const { getContext } = formContext || {};
44
44
 
@@ -56,13 +56,14 @@ export const MultiCheckboxInput = (props: MultiCheckboxInputProps) => {
56
56
  setIsLoadingOptions(true);
57
57
  let params: any = [];
58
58
  if (ooui.domain) {
59
- const evaluatedDomain = await ConnectionProvider.getHandler().evalDomain(
60
- {
61
- domain: ooui.domain,
59
+ const evaluatedDomain = await ConnectionProvider.getHandler().evalDomain({
60
+ domain: ooui.domain,
61
+ values: transformPlainMany2Ones({
62
+ fields: formContext?.getFields(),
62
63
  values: formContext.getPlainValues(),
63
- context: formContext.getContext(),
64
- }
65
- );
64
+ }),
65
+ context: formContext.getContext(),
66
+ });
66
67
  params = [...params, ...evaluatedDomain];
67
68
  }
68
69
  try {
@@ -72,35 +73,32 @@ export const MultiCheckboxInput = (props: MultiCheckboxInputProps) => {
72
73
  fields: [field],
73
74
  context: { ...getContext?.(), ...context },
74
75
  });
75
- const options = optionsRead.map((item:any) => {
76
+ const options = optionsRead.map((item: any) => {
76
77
  const value = item[field];
77
78
  let formattedValue = value;
78
79
  if (Array.isArray(value)) {
79
80
  formattedValue = value[1];
80
81
  }
81
- return {label: formattedValue, value: item.id}
82
+ return { label: formattedValue, value: item.id };
82
83
  });
83
84
  setOptions(options);
84
-
85
85
  } catch (err) {
86
- setError(err as any)
86
+ setError(err as any);
87
87
  } finally {
88
88
  setIsLoadingOptions(false);
89
89
  }
90
90
  if (error) {
91
91
  return <Alert className="mt-10" message={error} type="error" banner />;
92
92
  }
93
-
94
-
95
- };
93
+ }
96
94
 
97
95
  const checkAll = () => {
98
- onChangeSelected(options.map(option => option.value));
99
- }
96
+ onChangeSelected(options.map((option) => option.value));
97
+ };
100
98
 
101
99
  const uncheckAll = () => {
102
100
  onChangeSelected([]);
103
- }
101
+ };
104
102
 
105
103
  const onChangeSelected = (ids: any[]) => {
106
104
  const newItems: One2manyItem[] = items.map((item) => {
@@ -108,46 +106,59 @@ export const MultiCheckboxInput = (props: MultiCheckboxInputProps) => {
108
106
  if (item.operation == "pendingRemove") {
109
107
  return {
110
108
  ...item,
111
- operation: "original"
112
- }
109
+ operation: "original",
110
+ };
113
111
  } else {
114
- return item
112
+ return item;
115
113
  }
116
114
  } else {
117
- return {id: item.id, operation: 'pendingRemove'}
115
+ return { id: item.id, operation: "pendingRemove" };
118
116
  }
119
- })
120
- const currentIds = newItems.map(item => item.id)
121
- ids.filter(id => !currentIds.includes(id)).map((id) => {
122
- newItems.push({id, operation: 'pendingLink'});
123
117
  });
118
+ const currentIds = newItems.map((item) => item.id);
119
+ ids
120
+ .filter((id) => !currentIds.includes(id))
121
+ .map((id) => {
122
+ newItems.push({ id, operation: "pendingLink" });
123
+ });
124
124
  triggerChange(newItems);
125
125
  };
126
126
 
127
127
  if (isLoadingOptions && options.length === 0) {
128
- return <Spin />
128
+ return <Spin />;
129
129
  }
130
-
130
+
131
131
  return (
132
132
  <>
133
133
  <div className="flex flex-row">
134
- <Checkbox.Group value={options.length ? itemsToShow : []} disabled={readOnly} onChange={onChangeSelected} style={{width: '100%'}}>
134
+ <Checkbox.Group
135
+ value={options.length ? itemsToShow : []}
136
+ disabled={readOnly}
137
+ onChange={onChangeSelected}
138
+ style={{ width: "100%" }}
139
+ >
135
140
  <Row>
136
- {options.map((option) => (
137
- <Col span={Math.floor(24 / columns)}>
138
- <Checkbox value={option.value}>{option.label}</Checkbox>
139
- </Col>
140
- ))}
141
+ {options.map((option) => (
142
+ <Col span={Math.floor(24 / columns)}>
143
+ <Checkbox value={option.value}>{option.label}</Checkbox>
144
+ </Col>
145
+ ))}
141
146
  </Row>
142
147
  </Checkbox.Group>
143
- {!readOnly &&
148
+ {!readOnly && (
144
149
  <Space>
145
- <Button onClick={checkAll} disabled={itemsToShow.length == options.length}>Check all</Button>
146
- <Button onClick={uncheckAll} disabled={itemsToShow.length === 0}>Uncheck all</Button>
150
+ <Button
151
+ onClick={checkAll}
152
+ disabled={itemsToShow.length == options.length}
153
+ >
154
+ Check all
155
+ </Button>
156
+ <Button onClick={uncheckAll} disabled={itemsToShow.length === 0}>
157
+ Uncheck all
158
+ </Button>
147
159
  </Space>
148
- }
160
+ )}
149
161
  </div>
150
162
  </>
151
163
  );
152
-
153
164
  };
@@ -6,7 +6,7 @@ import { One2manyItem, One2manyValue } from "../base/one2many/One2manyInput";
6
6
  import useDeepCompareEffect from "use-deep-compare-effect";
7
7
  import { FormContext, FormContextType } from "@/context/FormContext";
8
8
  import { Alert, Tag as AntTag, Select } from "antd";
9
- import { colorFromString } from "@/helpers/formHelper";
9
+ import { colorFromString, transformPlainMany2Ones } from "@/helpers/formHelper";
10
10
  import ConnectionProvider from "@/ConnectionProvider";
11
11
 
12
12
  type TagsProps = WidgetProps & {
@@ -65,8 +65,11 @@ export const TagsInput = (props: TagsInputProps) => {
65
65
  const evaluatedDomain = await ConnectionProvider.getHandler().evalDomain(
66
66
  {
67
67
  domain: ooui.domain,
68
- values: formContext.getPlainValues(),
69
- context: formContext.getContext(),
68
+ values: transformPlainMany2Ones({
69
+ fields: formContext?.getFields(),
70
+ values: formContext.getPlainValues(),
71
+ }),
72
+ context: formContext.getContext(),
70
73
  }
71
74
  );
72
75
  params = [...params, ...evaluatedDomain];
@@ -87,7 +90,7 @@ export const TagsInput = (props: TagsInputProps) => {
87
90
  return {label: formattedValue, value: item.id}
88
91
  });
89
92
  setOptions(options);
90
-
93
+
91
94
  } catch (err) {
92
95
  setError(err as any)
93
96
  } finally {
@@ -156,5 +159,5 @@ export const TagsInput = (props: TagsInputProps) => {
156
159
  </div>
157
160
  </>
158
161
  );
159
-
162
+
160
163
  };
@@ -6,6 +6,7 @@ import { FormView, TreeView } from "@/types/index";
6
6
  import ConnectionProvider from "@/ConnectionProvider";
7
7
 
8
8
  import { getColorMap, getTree, sortResults } from "@/helpers/treeHelper";
9
+ import { mergeParams } from "@/helpers/searchHelper";
9
10
 
10
11
  const DEFAULT_SEARCH_LIMIT = 80;
11
12
 
@@ -67,33 +68,6 @@ function DashboardTree(props: Props) {
67
68
  setOffset((page - 1) * limitRef.current!);
68
69
  };
69
70
 
70
- const getUniqueFieldsForParams = (params: any[]) => {
71
- const uniqueFields: any = {};
72
-
73
- params.forEach((param) => {
74
- if (Array.isArray(param) && param[0]) {
75
- uniqueFields[param[0]] = true;
76
- }
77
- });
78
-
79
- return Object.keys(uniqueFields);
80
- };
81
-
82
- const mergeParams = (searchParams: any[], domainParams: any[]) => {
83
- const finalParams = searchParams;
84
- const uniqueParams = getUniqueFieldsForParams(searchParams);
85
-
86
- domainParams.forEach((element) => {
87
- if (Array.isArray(element) && element[0]) {
88
- if (!uniqueParams.includes(element[0])) {
89
- finalParams.push(element);
90
- }
91
- }
92
- });
93
-
94
- return finalParams;
95
- };
96
-
97
71
  const searchResults = async () => {
98
72
  const domainParams =
99
73
  actionDomain.current.length > 0 ? actionDomain.current : domain;
@@ -23,7 +23,7 @@ export const GraphChart = (props: GraphChartProps) => {
23
23
  const { model, domain, context, xml, limit } = props;
24
24
  const { t } = useContext(LocaleContext) as LocaleContextType;
25
25
 
26
- const { error, loading, values, type } = useGraphData({
26
+ const { error, loading, values, type, evaluatedEntries } = useGraphData({
27
27
  model,
28
28
  xml,
29
29
  limit,
@@ -54,6 +54,9 @@ export const GraphChart = (props: GraphChartProps) => {
54
54
 
55
55
  return (
56
56
  <div style={{ padding: "1rem" }}>
57
+ <p style={{ textAlign: "right" }}>
58
+ {`${t("totalRegisters")} ${evaluatedEntries?.length}`}
59
+ </p>
57
60
  <Chart
58
61
  {...getGraphProps({
59
62
  type,
@@ -36,6 +36,7 @@ export const useGraphData = (opts: GraphDataOpts) => {
36
36
  const [loading, setLoading] = useState(false);
37
37
  const [error, setError] = useState<any>();
38
38
  const [processedValues, setProcessedValues] = useState<any>();
39
+ const [evaluatedEntries, setEvaluatedEntries] = useState<any[]>();
39
40
  const [type, setType] = useState<GraphType>("line");
40
41
 
41
42
  useDeepCompareEffect(() => {
@@ -74,6 +75,7 @@ export const useGraphData = (opts: GraphDataOpts) => {
74
75
  return;
75
76
  }
76
77
 
78
+ setEvaluatedEntries(values);
77
79
  const _processedValues = processGraphData({
78
80
  ooui,
79
81
  values,
@@ -93,7 +95,13 @@ export const useGraphData = (opts: GraphDataOpts) => {
93
95
  })();
94
96
  }, [xml, model, limit, context, domain]);
95
97
 
96
- return { loading, error, type, values: processedValues };
98
+ return {
99
+ loading,
100
+ error,
101
+ type,
102
+ values: processedValues,
103
+ evaluatedEntries,
104
+ };
97
105
  };
98
106
 
99
107
  async function getFieldsForModel({
@@ -29,6 +29,7 @@ type Props = {
29
29
  setSearchFilterHeight?: (height: number) => void;
30
30
  searchError?: string;
31
31
  searchValues?: any;
32
+ showLimitOptions?: boolean;
32
33
  };
33
34
 
34
35
  function SearchFilter(props: Props) {
@@ -45,6 +46,7 @@ function SearchFilter(props: Props) {
45
46
  setSearchFilterHeight,
46
47
  searchError,
47
48
  searchValues,
49
+ showLimitOptions = true,
48
50
  } = props;
49
51
 
50
52
  const [simpleSearchFields, setSimpleSearchFields] = useState<Container>();
@@ -116,7 +118,9 @@ function SearchFilter(props: Props) {
116
118
  initialValues={{ offset, limit }}
117
119
  >
118
120
  {rows}
119
- {advancedFilter && <SearchParams onLimitChange={onLimitChange} />}
121
+ {advancedFilter && showLimitOptions && (
122
+ <SearchParams onLimitChange={onLimitChange} />
123
+ )}
120
124
  <SearchBottomBar
121
125
  advancedFilter={advancedFilter}
122
126
  onAdvancedFilterToggle={() => {