@gisce/react-ooui 2.0.0-alpha.53 → 2.0.0-alpha.55

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.
@@ -0,0 +1,276 @@
1
+ import { ReactElement, useCallback, useEffect, useMemo, useState } from "react";
2
+ import { Checkbox, Spin } from "antd";
3
+ import { parseFloatToString } from "@/helpers/timeHelper";
4
+ import { ProgressBarInput } from "../../base/ProgressBar";
5
+ import { One2manyValue } from "../../base/one2many/One2manyInput";
6
+ import { Interweave } from "interweave";
7
+ import { Many2oneTree } from "../../base/many2one/Many2oneTree";
8
+ import { ReferenceTree } from "../../base/ReferenceTree";
9
+ import dayjs from "@/helpers/dayjs";
10
+ import Avatar from "../../custom/Avatar";
11
+ import { CustomTag, TagInput } from "../../custom/Tag";
12
+ import { DatePickerConfig } from "@/common/DatePicker";
13
+ import ConnectionProvider from "@/ConnectionProvider";
14
+ import { colorFromString } from "@/helpers/formHelper";
15
+
16
+ export const BooleanComponent = ({
17
+ value,
18
+ }: {
19
+ value: boolean;
20
+ }): ReactElement => {
21
+ return useMemo(
22
+ () => (
23
+ <div
24
+ style={{
25
+ display: "flex",
26
+ justifyContent: "center",
27
+ alignContent: "center",
28
+ }}
29
+ >
30
+ <Checkbox checked={value} disabled />
31
+ </div>
32
+ ),
33
+ [value],
34
+ );
35
+ };
36
+
37
+ export const Many2OneComponent = ({ value }: { value: any }): ReactElement => {
38
+ return useMemo(() => <Many2oneTree m2oField={value} />, [value]);
39
+ };
40
+
41
+ export const TextComponent = ({ value }: { value: any }): ReactElement => {
42
+ return useMemo(
43
+ () => (
44
+ <Interweave
45
+ content={value?.toString().replace(/(?:\r\n|\r|\n)/g, "<br>")}
46
+ />
47
+ ),
48
+ [value],
49
+ );
50
+ };
51
+
52
+ export const DateComponent = ({ value }: { value: any }): ReactElement => {
53
+ return useMemo(() => {
54
+ if (!value || (value && value.length === 0)) return <></>;
55
+
56
+ const formattedValue = dayjs(
57
+ value,
58
+ DatePickerConfig.date.dateInternalFormat,
59
+ ).format(DatePickerConfig.date.dateDisplayFormat);
60
+ return <>{formattedValue}</>;
61
+ }, [value]);
62
+ };
63
+
64
+ export const DateTimeComponent = ({ value }: { value: any }): ReactElement => {
65
+ return useMemo(() => {
66
+ if (!value || (value && value.length === 0)) return <></>;
67
+ const formattedValue = dayjs(
68
+ value,
69
+ DatePickerConfig.time.dateInternalFormat,
70
+ ).format(DatePickerConfig.time.dateDisplayFormat);
71
+ return <>{formattedValue}</>;
72
+ }, [value]);
73
+ };
74
+
75
+ export const One2ManyComponent = ({
76
+ value,
77
+ }: {
78
+ value: One2manyValue;
79
+ }): ReactElement => {
80
+ return useMemo(() => {
81
+ const length = Array.isArray(value?.items) ? value?.items.length : 0;
82
+ return <>{`( ${length} )`}</>;
83
+ }, [value]);
84
+ };
85
+
86
+ export const ProgressBarComponent = ({
87
+ value,
88
+ }: {
89
+ value: any;
90
+ }): ReactElement => {
91
+ return useMemo(() => <ProgressBarInput value={value} />, [value]);
92
+ };
93
+
94
+ export const FloatTimeComponent = ({ value }: { value: any }): ReactElement => {
95
+ return useMemo(() => <>{parseFloatToString(value)}</>, [value]);
96
+ };
97
+
98
+ export const NumberComponent = ({ value }: { value: number }): ReactElement => {
99
+ return useMemo(
100
+ () => <div style={{ textAlign: "right" }}>{value}</div>,
101
+ [value],
102
+ );
103
+ };
104
+
105
+ export const ImageComponent = ({ value }: { value: string }): ReactElement => {
106
+ return useMemo(
107
+ () => (
108
+ <img
109
+ src={`data:image/*;base64,${value}`}
110
+ style={{ maxWidth: "50px", padding: "5px" }}
111
+ />
112
+ ),
113
+ [value],
114
+ );
115
+ };
116
+
117
+ export const TagComponent = ({
118
+ value,
119
+ key,
120
+ ooui,
121
+ context,
122
+ }: {
123
+ value: any;
124
+ key: string;
125
+ ooui: any;
126
+ context: any;
127
+ }): ReactElement => {
128
+ return useMemo(() => <TagInput ooui={ooui} value={value} />, [ooui, value]);
129
+ };
130
+
131
+ export const SelectionComponent = ({
132
+ value,
133
+ key,
134
+ ooui,
135
+ context,
136
+ }: {
137
+ value: any;
138
+ key: string;
139
+ ooui: any;
140
+ context: any;
141
+ }): ReactElement => {
142
+ return useMemo(() => <>{ooui.selectionValues.get(value)}</>, [ooui, value]);
143
+ };
144
+
145
+ export const ReferenceComponent = ({
146
+ value,
147
+ key,
148
+ ooui,
149
+ context,
150
+ }: {
151
+ value: any;
152
+ key: string;
153
+ ooui: any;
154
+ context: any;
155
+ }): ReactElement => {
156
+ return useMemo(
157
+ () => (
158
+ <ReferenceTree
159
+ value={value}
160
+ selectionValues={ooui.selectionValues}
161
+ context={context}
162
+ />
163
+ ),
164
+ [context, ooui.selectionValues, value],
165
+ );
166
+ };
167
+
168
+ export const AvatarComponent = ({
169
+ value,
170
+ key,
171
+ ooui,
172
+ context,
173
+ }: {
174
+ value: any;
175
+ key: string;
176
+ ooui: any;
177
+ context: any;
178
+ }): ReactElement => {
179
+ return useMemo(() => <Avatar ooui={ooui} value={value} />, [ooui, value]);
180
+ };
181
+
182
+ export const TagsComponent = ({
183
+ value,
184
+ key,
185
+ ooui,
186
+ context,
187
+ }: {
188
+ value: any;
189
+ key: string;
190
+ ooui: any;
191
+ context: any;
192
+ }): ReactElement => {
193
+ const [values, setValues] = useState<Array<{ id: number; name: string }>>([]);
194
+ const [loading, setLoading] = useState<boolean>(false);
195
+ const { relation, field } = ooui;
196
+
197
+ const loadValues = useCallback(async () => {
198
+ try {
199
+ setLoading(true);
200
+ const optionsRead = await ConnectionProvider.getHandler().search({
201
+ model: relation,
202
+ params: [["id", "in", value.items.map((v: any) => v.id)]],
203
+ fields: [field],
204
+ context,
205
+ });
206
+ setValues(
207
+ optionsRead.map((i: any) => {
208
+ const { id, name } = i;
209
+ return { id, name };
210
+ }),
211
+ );
212
+ } catch (error) {
213
+ console.error("Error loading data", error);
214
+ } finally {
215
+ setLoading(false);
216
+ }
217
+ }, [context, field, relation, value.items]);
218
+
219
+ useEffect(() => {
220
+ if (value?.items && value?.items.length > 0) {
221
+ loadValues();
222
+ }
223
+ // eslint-disable-next-line react-hooks/exhaustive-deps
224
+ }, [value?.items]);
225
+
226
+ const tags = useMemo(
227
+ () =>
228
+ values.map((entry) => {
229
+ const { id, name } = entry;
230
+ const color = colorFromString(name);
231
+ return (
232
+ <CustomTag key={`${id}`} color={color}>
233
+ {name}
234
+ </CustomTag>
235
+ );
236
+ }),
237
+ [values],
238
+ );
239
+
240
+ return useMemo(() => {
241
+ if (loading) {
242
+ return <Spin />;
243
+ }
244
+ return (
245
+ <div
246
+ style={{
247
+ maxWidth: "300px",
248
+ whiteSpace: "break-spaces",
249
+ lineHeight: "30px",
250
+ }}
251
+ >
252
+ {tags}
253
+ </div>
254
+ );
255
+ }, [tags, loading]);
256
+ };
257
+
258
+ export const COLUMN_COMPONENTS = {
259
+ boolean: BooleanComponent,
260
+ many2one: Many2OneComponent,
261
+ text: TextComponent,
262
+ one2many: One2ManyComponent,
263
+ many2many: One2ManyComponent,
264
+ progressbar: ProgressBarComponent,
265
+ float_time: FloatTimeComponent,
266
+ image: ImageComponent,
267
+ integer: NumberComponent,
268
+ float: NumberComponent,
269
+ reference: ReferenceComponent,
270
+ tag: TagComponent,
271
+ selection: SelectionComponent,
272
+ date: DateComponent,
273
+ datetime: DateTimeComponent,
274
+ avatar: AvatarComponent,
275
+ tags: TagsComponent,
276
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../../src/widgets/views/Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAUvE,OAAO,EAAE,QAAQ,EAAU,MAAM,SAAS,CAAC;AAyB3C,KAAK,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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