@deviceinsight/ng-ui-scale-lib 9.14.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.
@@ -0,0 +1,370 @@
1
+ import { at as e, cz as E, aK as V, dl as F, dd as L, dk as B, ag as d, ah as G, bc as U, bf as D, bi as h, b4 as w, dm as R, di as P, dn as k, aq as M, dp as H, dq as X, bN as _, aU as z, dr as Y } from "./ContextBarContext-f745a63a.js";
2
+ import { useState as T, useEffect as $ } from "react";
3
+ import { useLocation as J, useHistory as Q, useParams as W } from "react-router-dom";
4
+ import { getPropertyById as Z, updateProperty as ee, createProperty as re } from "@deviceinsight/ng-ui-api-client";
5
+ import { Button as v, Checkbox as A, Icon as K, ButtonRow as te, Spinner as se } from "@deviceinsight/ng-ui-basic-components";
6
+ import { messageBoxError as O, ContentHeader as ae } from "@deviceinsight/ng-ui-components";
7
+ import { P as ne } from "./react-router-f15627c1.js";
8
+ import "react-dom";
9
+ import "./extends-0a3e0827.js";
10
+ function le(r) {
11
+ const { options: s, children: x, onChange: c, values: i, ...t } = r;
12
+ function a(u) {
13
+ i.includes(u.value) ? c(i.filter((f) => f !== u.value)) : c([...i, u.value]);
14
+ }
15
+ return /* @__PURE__ */ e.jsx(E, { ...t, children: /* @__PURE__ */ e.jsx("div", { className: "buttonpicker", children: s.map((u) => /* @__PURE__ */ e.jsx(
16
+ v,
17
+ {
18
+ onClick: () => a(u),
19
+ className: V({
20
+ active: i.includes(u.value)
21
+ }),
22
+ disabled: r.disabled,
23
+ children: /* @__PURE__ */ e.jsx(F, { translationDescriptor: u.label })
24
+ },
25
+ String(u.value)
26
+ )) }) });
27
+ }
28
+ function ie() {
29
+ const {
30
+ getValues: r,
31
+ formState: { errors: s },
32
+ trigger: x
33
+ } = L(), [c, i] = T(!!r("allowedValues")), {
34
+ field: { value: t, onChange: a },
35
+ fieldState: { invalid: u }
36
+ } = B({
37
+ name: "allowedValues",
38
+ rules: {
39
+ validate: (n) => n == null || n != null && n.some((p) => p !== "") ? void 0 : "Required"
40
+ }
41
+ });
42
+ function f(n) {
43
+ a(t == null ? void 0 : t.filter((p, m) => m !== n));
44
+ }
45
+ function b(n) {
46
+ a(t ? [...t, n] : [n]);
47
+ }
48
+ function g(n, p) {
49
+ a(t == null ? void 0 : t.map((m, j) => p === j ? n : m));
50
+ }
51
+ async function y(n) {
52
+ a(n ? [] : null), i(n), !n && u && await x();
53
+ }
54
+ return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
55
+ /* @__PURE__ */ e.jsxs(
56
+ E,
57
+ {
58
+ label: /* @__PURE__ */ e.jsxs("div", { className: "di allowed-values-header", children: [
59
+ /* @__PURE__ */ e.jsx(A, { type: "toggle", value: c, toggleSmall: !0, onChange: y }),
60
+ " ",
61
+ /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.allowedValues", children: "Allowed Values" })
62
+ ] }),
63
+ error: s.allowedValues ? "Required" : void 0,
64
+ className: "di allowed-values-container",
65
+ children: [
66
+ /* @__PURE__ */ e.jsx(A, { value: c, onChange: y }),
67
+ (t == null ? void 0 : t.length) === 0 ? /* @__PURE__ */ e.jsx("div", { className: "empty-placeholder", children: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.allowedValuesEmptyPlaceholder", children: "No values" }) }) : /* @__PURE__ */ e.jsx("ul", { children: t == null ? void 0 : t.map((n, p) => /* @__PURE__ */ e.jsxs("li", { className: "item", children: [
68
+ /* @__PURE__ */ e.jsx(E, { className: "value-container", children: /* @__PURE__ */ e.jsx(
69
+ "input",
70
+ {
71
+ type: "text",
72
+ value: n,
73
+ onChange: (m) => g(m.target.value, p)
74
+ }
75
+ ) }),
76
+ /* @__PURE__ */ e.jsx(v, { onClick: () => f(p), children: /* @__PURE__ */ e.jsx(K, { del: !0 }) })
77
+ ] }, p)) })
78
+ ]
79
+ }
80
+ ),
81
+ c && /* @__PURE__ */ e.jsxs(v, { onClick: () => b(""), children: [
82
+ /* @__PURE__ */ e.jsx(K, { add: !0 }),
83
+ /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.allowedValuesAdd", children: "Add" })
84
+ ] })
85
+ ] });
86
+ }
87
+ const oe = ["STRING", "TEXT", "DATE", "LONG", "DOUBLE", "BOOLEAN", "IP", "GEO"].map((r) => ({
88
+ value: r,
89
+ name: r
90
+ })), de = ["ASSET", "ASSET_GROUP", "ACCOUNT", "ACCOUNT_GROUP", "DATAPOINT"].map(
91
+ (r) => ({
92
+ value: r,
93
+ label: r
94
+ })
95
+ );
96
+ function ce() {
97
+ return {
98
+ key: "",
99
+ type: "STRING",
100
+ entityTargets: [],
101
+ addToAll: !1,
102
+ deletable: !0
103
+ };
104
+ }
105
+ function ue({ editedProperty: r, isReadonly: s, onSubmit: x, onCancel: c }) {
106
+ const { t: i } = G(), t = U({
107
+ defaultValues: r || ce()
108
+ }), {
109
+ control: a,
110
+ handleSubmit: u,
111
+ watch: f,
112
+ setError: b,
113
+ formState: { isSubmitting: g, isDirty: y }
114
+ } = t;
115
+ function n() {
116
+ async function l(o) {
117
+ try {
118
+ await x(o);
119
+ } catch (S) {
120
+ if (M.isAxiosError(S)) {
121
+ const { fieldName: N, message: C } = H(S, i);
122
+ N ? b(N, { message: C }) : O(C);
123
+ } else
124
+ O(X(i));
125
+ }
126
+ }
127
+ return u(l, (o) => {
128
+ console.warn("Validation error", o);
129
+ })();
130
+ }
131
+ const p = f("type"), m = !!r, j = p === "STRING" || p === "TEXT", I = !!f("allowedValues");
132
+ return /* @__PURE__ */ e.jsx(D, { ...t, children: /* @__PURE__ */ e.jsxs("div", { className: "property-form", children: [
133
+ /* @__PURE__ */ e.jsx(
134
+ h,
135
+ {
136
+ name: "key",
137
+ control: a,
138
+ rules: {
139
+ required: i("properties.form.validation.key.required", {
140
+ defaultValue: "Please enter a property key"
141
+ })
142
+ },
143
+ render: ({ field: l, fieldState: { error: o } }) => /* @__PURE__ */ e.jsx(
144
+ w,
145
+ {
146
+ ...l,
147
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.key", children: "Key" }),
148
+ error: o == null ? void 0 : o.message,
149
+ required: !0,
150
+ disabled: s || m
151
+ }
152
+ )
153
+ }
154
+ ),
155
+ /* @__PURE__ */ e.jsx(
156
+ h,
157
+ {
158
+ name: "type",
159
+ control: a,
160
+ render: ({ field: l }) => /* @__PURE__ */ e.jsx(
161
+ R,
162
+ {
163
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.type", children: "Type" }),
164
+ ...l,
165
+ options: oe,
166
+ required: !0,
167
+ disabled: s || m
168
+ }
169
+ )
170
+ }
171
+ ),
172
+ /* @__PURE__ */ e.jsx(
173
+ h,
174
+ {
175
+ name: "entityTargets",
176
+ control: a,
177
+ rules: { validate: (l) => l.length === 0 ? "Required" : void 0 },
178
+ render: ({ field: { value: l, onChange: o }, fieldState: { error: S } }) => /* @__PURE__ */ e.jsx(
179
+ le,
180
+ {
181
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.entityTargets", children: "Entity targets" }),
182
+ values: l,
183
+ onChange: o,
184
+ options: de,
185
+ error: S ? i("properties.form.validation.entityTargets.required", {
186
+ defaultValue: "Please select a at least one entity target"
187
+ }) : void 0,
188
+ required: !0,
189
+ disabled: s
190
+ }
191
+ )
192
+ }
193
+ ),
194
+ /* @__PURE__ */ e.jsx(
195
+ h,
196
+ {
197
+ name: "addToAll",
198
+ control: a,
199
+ render: ({ field: l }) => /* @__PURE__ */ e.jsx(
200
+ P,
201
+ {
202
+ ...l,
203
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.addToSearch", children: "Add to Search" }),
204
+ disabled: s || m
205
+ }
206
+ )
207
+ }
208
+ ),
209
+ /* @__PURE__ */ e.jsx(
210
+ h,
211
+ {
212
+ name: "unique",
213
+ control: a,
214
+ render: ({ field: { value: l, onChange: o } }) => /* @__PURE__ */ e.jsx(
215
+ P,
216
+ {
217
+ value: !!l,
218
+ onChange: o,
219
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.unique", children: "Unique" }),
220
+ disabled: s
221
+ }
222
+ )
223
+ }
224
+ ),
225
+ /* @__PURE__ */ e.jsx(
226
+ h,
227
+ {
228
+ name: "final",
229
+ control: a,
230
+ render: ({ field: { value: l, onChange: o } }) => /* @__PURE__ */ e.jsx(
231
+ P,
232
+ {
233
+ value: !!l,
234
+ onChange: o,
235
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.final", children: "Final" }),
236
+ disabled: s
237
+ }
238
+ )
239
+ }
240
+ ),
241
+ j && !I && /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
242
+ /* @__PURE__ */ e.jsx(
243
+ h,
244
+ {
245
+ name: "minLength",
246
+ control: a,
247
+ render: ({ field: { value: l, ...o } }) => /* @__PURE__ */ e.jsx(
248
+ k,
249
+ {
250
+ ...o,
251
+ value: l ?? void 0,
252
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.label.minLength", children: "Minimum length" }),
253
+ placeholder: s ? i("properties.placeholder.notSet", { defaultValue: "Not set" }) : "0",
254
+ readOnly: s
255
+ }
256
+ )
257
+ }
258
+ ),
259
+ /* @__PURE__ */ e.jsx(
260
+ h,
261
+ {
262
+ name: "maxLength",
263
+ control: a,
264
+ render: ({ field: { value: l, ...o } }) => /* @__PURE__ */ e.jsx(
265
+ k,
266
+ {
267
+ ...o,
268
+ value: l ?? void 0,
269
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.label.maxLength", children: "Maximum length" }),
270
+ placeholder: s ? i("properties.placeholder.notSet", { defaultValue: "Not set" }) : "0",
271
+ readOnly: s
272
+ }
273
+ )
274
+ }
275
+ ),
276
+ /* @__PURE__ */ e.jsx(
277
+ h,
278
+ {
279
+ name: "regularExpression",
280
+ control: a,
281
+ render: ({ field: { value: l, ...o } }) => /* @__PURE__ */ e.jsx(
282
+ w,
283
+ {
284
+ ...o,
285
+ value: l ?? void 0,
286
+ label: /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.labels.regularExpression", children: "Regular expression" }),
287
+ readOnly: s,
288
+ placeholder: s ? i("properties.placeholder.notSet", { defaultValue: "Not set" }) : ""
289
+ }
290
+ )
291
+ }
292
+ )
293
+ ] }),
294
+ p === "STRING" && /* @__PURE__ */ e.jsx(ie, {}),
295
+ /* @__PURE__ */ e.jsxs("div", { className: "formRequired", children: [
296
+ "* ",
297
+ /* @__PURE__ */ e.jsx(d, { i18nKey: "form.field.required", children: "required" })
298
+ ] }),
299
+ /* @__PURE__ */ e.jsxs(te, { dividing: !0, children: [
300
+ /* @__PURE__ */ e.jsx(v, { className: "with-spinner", primary: !0, onClick: n, disabled: g, children: /* @__PURE__ */ e.jsx(d, { i18nKey: "general.actions.save", children: "Save" }) }),
301
+ /* @__PURE__ */ e.jsx(v, { disabled: g, onClick: c, children: /* @__PURE__ */ e.jsx(d, { i18nKey: "general.actions.cancel", children: "Cancel" }) })
302
+ ] }),
303
+ /* @__PURE__ */ e.jsx(ne, { message: "", when: y && !g })
304
+ ] }) });
305
+ }
306
+ const pe = (r) => r ? {
307
+ id: "properties.create.title",
308
+ defaultValue: "Create Property"
309
+ } : {
310
+ id: "properties.edit.title",
311
+ defaultValue: "Edit Property"
312
+ }, me = /* @__PURE__ */ e.jsx(d, { i18nKey: "properties.saveSuccessMessage", children: "Property has been saved successfully." });
313
+ function q(r) {
314
+ if (r.type === "STRING" && r.allowedValues && r.allowedValues.length > 0) {
315
+ const { regularExpression: s, maxLength: x, minLength: c, allowedValues: i, ...t } = r;
316
+ return { ...t, allowedValues: [...new Set(i.filter((a) => a !== ""))] };
317
+ }
318
+ if (r.allowedValues && r.allowedValues.length === 0) {
319
+ const { allowedValues: s, ...x } = r;
320
+ return x;
321
+ }
322
+ if (r.type !== "STRING" && r.type !== "TEXT") {
323
+ const { regularExpression: s, maxLength: x, minLength: c, ...i } = r;
324
+ return i;
325
+ }
326
+ return r;
327
+ }
328
+ function Te() {
329
+ const { pathname: r } = J(), s = Q(), { propertyKey: x } = W(), [c, i] = T(void 0), [t, a] = T(!0), [u, f] = T(!1);
330
+ async function b(m) {
331
+ try {
332
+ const j = await Z(m);
333
+ i(j);
334
+ } catch (j) {
335
+ console.error(j), f(!0);
336
+ } finally {
337
+ a(!1);
338
+ }
339
+ }
340
+ $(() => {
341
+ x && x !== "create" ? b(x) : a(!1);
342
+ }, [x]);
343
+ function g() {
344
+ s.push(r.substring(0, r.lastIndexOf("/")));
345
+ }
346
+ async function y(m) {
347
+ c ? await ee(q(m)) : await re(q(m)), Y(me), g();
348
+ }
349
+ function n() {
350
+ g();
351
+ }
352
+ if (u)
353
+ return /* @__PURE__ */ e.jsx(_, {});
354
+ const p = pe(!c);
355
+ return t ? /* @__PURE__ */ e.jsx(se, { center: !0 }) : /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
356
+ /* @__PURE__ */ e.jsx(ae, { title: p, parentPageLink: !0 }),
357
+ /* @__PURE__ */ e.jsx(
358
+ ue,
359
+ {
360
+ editedProperty: c,
361
+ isReadonly: !!c && !z(["UPDATE_PROPERTY"]),
362
+ onSubmit: y,
363
+ onCancel: n
364
+ }
365
+ )
366
+ ] });
367
+ }
368
+ export {
369
+ Te as default
370
+ };
@@ -0,0 +1,265 @@
1
+ import { aU as c, at as t, ag as a, b9 as f, ah as y, d8 as b, dc as T } from "./ContextBarContext-f745a63a.js";
2
+ import { useContext as m, useState as h, useEffect as P } from "react";
3
+ import { deleteProperty as A } from "@deviceinsight/ng-ui-api-client";
4
+ import { Bubble as g, Button as x, Icon as I, withConfirm as O } from "@deviceinsight/ng-ui-basic-components";
5
+ import { ContentHeader as E } from "@deviceinsight/ng-ui-components";
6
+ import { Link as v } from "react-router-dom";
7
+ import "react-dom";
8
+ const D = [
9
+ "name",
10
+ "urn",
11
+ "parentId",
12
+ "createdAt",
13
+ "assetGroupId",
14
+ "accountNumber",
15
+ "username",
16
+ "emailAddress",
17
+ "accountGroupId",
18
+ "assetGroupDefinitionId",
19
+ "description",
20
+ "locale",
21
+ "timezone",
22
+ "state",
23
+ "transitiveAssetGroupId",
24
+ "transitiveAssetGroupDefinitionId",
25
+ "isGateway",
26
+ "gatewayId",
27
+ "roleId",
28
+ "displayName",
29
+ "definitionId"
30
+ ];
31
+ function G(n, l) {
32
+ const o = c(["DELETE_PROPERTY"]);
33
+ return [
34
+ {
35
+ name: "propertyKey",
36
+ label: /* @__PURE__ */ t.jsx(a, { i18nKey: "properties.tableHeaders.key", children: "Property" }),
37
+ sortable: !0,
38
+ filterable: {
39
+ filterType: "text",
40
+ filterFn: (e, r) => e.key.toLowerCase().indexOf(r.toLowerCase()) >= 0
41
+ },
42
+ render: (e) => /* @__PURE__ */ t.jsx(
43
+ v,
44
+ {
45
+ to: `properties/${e.key}`,
46
+ state: e,
47
+ children: e.key
48
+ }
49
+ )
50
+ },
51
+ {
52
+ name: "propertyType",
53
+ label: /* @__PURE__ */ t.jsx(a, { i18nKey: "properties.tableHeaders.type", children: "Type" }),
54
+ width: "10%",
55
+ filterable: {
56
+ filterType: "options",
57
+ filterOptions: [
58
+ {
59
+ value: "STRING",
60
+ label: {
61
+ id: "string",
62
+ defaultValue: "String"
63
+ }
64
+ },
65
+ {
66
+ value: "TEXT",
67
+ label: {
68
+ id: "text",
69
+ defaultValue: "Text"
70
+ }
71
+ },
72
+ {
73
+ value: "DATE",
74
+ label: {
75
+ id: "date",
76
+ defaultValue: "Date"
77
+ }
78
+ },
79
+ {
80
+ value: "LONG",
81
+ label: {
82
+ id: "long",
83
+ defaultValue: "Long"
84
+ }
85
+ },
86
+ {
87
+ value: "DOUBLE",
88
+ label: {
89
+ id: "double",
90
+ defaultValue: "Double"
91
+ }
92
+ },
93
+ {
94
+ value: "BOOLEAN",
95
+ label: {
96
+ id: "boolean",
97
+ defaultValue: "Boolean"
98
+ }
99
+ },
100
+ {
101
+ value: "IP",
102
+ label: {
103
+ id: "ip",
104
+ defaultValue: "Ip"
105
+ }
106
+ },
107
+ {
108
+ value: "GEO",
109
+ label: {
110
+ id: "geo",
111
+ defaultValue: "Geo"
112
+ }
113
+ }
114
+ ],
115
+ filterFn: (e, r) => e.type === r
116
+ },
117
+ render: (e) => e.type
118
+ },
119
+ {
120
+ name: "propertyEntityTargets",
121
+ label: /* @__PURE__ */ t.jsx(a, { i18nKey: "properties.tableHeaders.entityTargets", children: "Scope" }),
122
+ width: "30%",
123
+ filterable: {
124
+ filterType: "options",
125
+ filterOptions: [
126
+ {
127
+ value: "DATAPOINT",
128
+ label: {
129
+ id: "properties.filterOptions.datapoint",
130
+ defaultValue: "Datapoint"
131
+ }
132
+ },
133
+ {
134
+ value: "ASSET",
135
+ label: {
136
+ id: "properties.filterOptions.asset",
137
+ defaultValue: "Asset"
138
+ }
139
+ },
140
+ {
141
+ value: "ASSET_GROUP",
142
+ label: {
143
+ id: "properties.filterOptions.assetGroup",
144
+ defaultValue: "Asset Group"
145
+ }
146
+ },
147
+ {
148
+ value: "ACCOUNT",
149
+ label: {
150
+ id: "properties.filterOptions.account",
151
+ defaultValue: "Account"
152
+ }
153
+ },
154
+ {
155
+ value: "ACCOUNT_GROUP",
156
+ label: {
157
+ id: "properties.filterOptions.accountGroup",
158
+ defaultValue: "Account Group"
159
+ }
160
+ }
161
+ ],
162
+ filterFn: (e, r) => e.entityTargets.includes(r)
163
+ },
164
+ render: (e) => [...e.entityTargets].sort().join(", ")
165
+ },
166
+ {
167
+ name: "actions",
168
+ label: "",
169
+ width: "10%",
170
+ align: "right",
171
+ render: (e) => {
172
+ const r = D.includes(e.key);
173
+ if (o) {
174
+ const i = /* @__PURE__ */ t.jsx(
175
+ x,
176
+ {
177
+ naked: !0,
178
+ title: {
179
+ id: "properties.tableHeaders.deleteProperty",
180
+ defaultValue: "Delete this Property"
181
+ },
182
+ onClick: () => l(e),
183
+ disabled: r,
184
+ children: /* @__PURE__ */ t.jsx(I, { del: !0 })
185
+ }
186
+ );
187
+ return r ? /* @__PURE__ */ t.jsx(
188
+ g,
189
+ {
190
+ content: /* @__PURE__ */ t.jsx(a, { i18nKey: "properties.tableHeaders.reserved", children: "This property is reserved and can't be deleted" }),
191
+ children: i
192
+ }
193
+ ) : i;
194
+ } else
195
+ return null;
196
+ }
197
+ }
198
+ ];
199
+ }
200
+ const C = {
201
+ page: 0,
202
+ size: 15,
203
+ sort: {
204
+ property: "key",
205
+ direction: "ASC"
206
+ }
207
+ }, V = ({ confirm: n }) => {
208
+ const { properties: l, reloadProperties: o } = m(f), [e, r] = h(!1), { t: i } = y(), d = /* @__PURE__ */ t.jsx(a, { i18nKey: "portalAdmin.sidebarElements.properties.create", children: "Create new property" });
209
+ async function p() {
210
+ try {
211
+ r(!0), await o();
212
+ } finally {
213
+ r(!1);
214
+ }
215
+ }
216
+ P(() => {
217
+ p();
218
+ }, []);
219
+ async function u(s) {
220
+ await n(
221
+ {
222
+ id: "properties.confirmDeletePropertyTitle",
223
+ defaultValue: "Delete Property"
224
+ },
225
+ {
226
+ id: "properties.confirmDeletePropertyMessage",
227
+ defaultValue: "Do you really want to delete this Property?"
228
+ }
229
+ ), r(!0), await A(s), await p();
230
+ }
231
+ return /* @__PURE__ */ t.jsxs("div", { "data-testid": "properties-list", children: [
232
+ /* @__PURE__ */ t.jsx(
233
+ E,
234
+ {
235
+ title: {
236
+ id: "route.label.properties.name",
237
+ defaultValue: "Properties"
238
+ }
239
+ }
240
+ ),
241
+ /* @__PURE__ */ t.jsx(
242
+ b,
243
+ {
244
+ tooltip: d,
245
+ authorities: "CREATE_PROPERTY",
246
+ path: "properties/create",
247
+ dataTestId: "create-property-button"
248
+ }
249
+ ),
250
+ /* @__PURE__ */ t.jsx(
251
+ T,
252
+ {
253
+ columnDefs: G(i, u),
254
+ items: l,
255
+ isLoading: e,
256
+ uniqueItemKey: (s) => s.key,
257
+ paginationSettings: C,
258
+ "data-testid": "properties-table"
259
+ }
260
+ )
261
+ ] });
262
+ }, K = O(V);
263
+ export {
264
+ K as default
265
+ };