@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,54 @@
1
+ import { dd as S, dk as j, at as t, cz as C, ag as g } from "./ContextBarContext-f745a63a.js";
2
+ import { useState as u, useEffect as v, useCallback as y } from "react";
3
+ import { C as V, j as b } from "./index-4f55daa8.js";
4
+ import "react-router-dom";
5
+ import "@deviceinsight/ng-ui-basic-components";
6
+ import "@deviceinsight/ng-ui-components";
7
+ import "@deviceinsight/ng-ui-api-client";
8
+ import "react-dom";
9
+ import "./extends-0a3e0827.js";
10
+ function w({ setting: e, ...c }) {
11
+ const { setValue: n, setError: o, clearErrors: i, control: p } = S(), {
12
+ field: r,
13
+ fieldState: { error: s }
14
+ } = j({ name: e.name, control: p }), [f, l] = u(""), [d, h] = u(!1);
15
+ v(() => {
16
+ if (!d && r.value) {
17
+ const a = JSON.stringify(r.value, null, 2);
18
+ l(a), h(!0);
19
+ }
20
+ }, [r.value, d]);
21
+ const x = y(
22
+ (a) => {
23
+ try {
24
+ l(a);
25
+ const m = a === "" ? void 0 : JSON.parse(a);
26
+ n(e.name, m, { shouldValidate: !0, shouldDirty: !0 }), i(e.name);
27
+ } catch {
28
+ o(e.name, { message: "Invalid JSON syntax" });
29
+ }
30
+ },
31
+ [i, o, n, e.name]
32
+ );
33
+ return /* @__PURE__ */ t.jsx(t.Fragment, { children: /* @__PURE__ */ t.jsx(
34
+ C,
35
+ {
36
+ label: /* @__PURE__ */ t.jsx(g, { i18nKey: `appSettings.property.${e.name}`, children: e.name }),
37
+ error: (s == null ? void 0 : s.message) ?? "",
38
+ size: "full-width",
39
+ children: /* @__PURE__ */ t.jsx(
40
+ V,
41
+ {
42
+ "data-testid": c["data-testid"],
43
+ onChange: x,
44
+ value: f,
45
+ basicSetup: { lineNumbers: !0 },
46
+ extensions: [b()]
47
+ }
48
+ )
49
+ }
50
+ ) });
51
+ }
52
+ export {
53
+ w as default
54
+ };
@@ -0,0 +1,143 @@
1
+ import { ah as w, bc as C, at as e, ag as n, bi as y, b4 as b, bN as V } from "./ContextBarContext-f745a63a.js";
2
+ import { useState as d, useEffect as v } from "react";
3
+ import { Prompt as q, useHistory as B, useLocation as H, useParams as T } from "react-router-dom";
4
+ import { fetchLicenses as D, fetchLicenseByName as I, updateLicense as R, createLicense as k } from "@deviceinsight/ng-ui-api-client";
5
+ import { SpinnerContainer as U, ButtonRow as A, Button as S, Spinner as O } from "@deviceinsight/ng-ui-basic-components";
6
+ import { messageBoxError as P, ContentHeader as z, messageBoxSuccess as F } from "@deviceinsight/ng-ui-components";
7
+ import "react-dom";
8
+ function G({ editedLicense: c, onSubmit: u, onCancel: r }) {
9
+ const { t } = w(), {
10
+ handleSubmit: p,
11
+ control: l,
12
+ formState: { isSubmitting: a, isDirty: x },
13
+ setError: g
14
+ } = C({
15
+ defaultValues: c ?? { name: "", displayName: "", description: "" }
16
+ }), [j, m] = d([]), [f, L] = d(!1);
17
+ v(() => {
18
+ L(!0), D().then(m).catch(() => {
19
+ P(/* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.form.fetchingError", children: "Fetching licenses failed" }));
20
+ }).finally(() => L(!1));
21
+ }, []);
22
+ function E(i) {
23
+ return c ? void 0 : j.some((h) => h.name === i) ? t("licenses.form.validation.nameInUse", {
24
+ defaultValue: "A license with the same technical name already exists"
25
+ }) : void 0;
26
+ }
27
+ function K() {
28
+ return p(async (s) => {
29
+ var h, N;
30
+ try {
31
+ await u(s);
32
+ } catch (o) {
33
+ o && o.response && o.response.status === 409 && ((h = o.response.data) != null && h.message) && g("name", {
34
+ message: t("licenses.form.validation.nameInUse", {
35
+ defaultValue: (N = o.response.data) == null ? void 0 : N.message
36
+ })
37
+ });
38
+ }
39
+ }, (s) => {
40
+ console.warn("Validation error", s);
41
+ })();
42
+ }
43
+ return /* @__PURE__ */ e.jsxs(U, { show: a || f, className: "di license-form", children: [
44
+ /* @__PURE__ */ e.jsx(
45
+ y,
46
+ {
47
+ control: l,
48
+ name: "name",
49
+ rules: {
50
+ required: t("licenses.form.validation.nameRequired", {
51
+ defaultValue: "Please enter the technical name"
52
+ }),
53
+ validate: E
54
+ },
55
+ render: ({ field: i, fieldState: { error: s } }) => /* @__PURE__ */ e.jsx(
56
+ b,
57
+ {
58
+ ...i,
59
+ disabled: !!c,
60
+ label: /* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.tableHeaders.name", children: "Technical Name" }),
61
+ required: !0,
62
+ error: s == null ? void 0 : s.message
63
+ }
64
+ )
65
+ }
66
+ ),
67
+ /* @__PURE__ */ e.jsx(
68
+ y,
69
+ {
70
+ control: l,
71
+ name: "displayName",
72
+ rules: {
73
+ required: t("licenses.form.validation.displayNameRequired", {
74
+ defaultValue: "Please enter the display name"
75
+ })
76
+ },
77
+ render: ({ field: i, fieldState: { error: s } }) => /* @__PURE__ */ e.jsx(
78
+ b,
79
+ {
80
+ ...i,
81
+ label: /* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.tableHeaders.displayName", children: "Name" }),
82
+ required: !0,
83
+ error: s == null ? void 0 : s.message
84
+ }
85
+ )
86
+ }
87
+ ),
88
+ /* @__PURE__ */ e.jsx(
89
+ y,
90
+ {
91
+ control: l,
92
+ name: "description",
93
+ render: ({ field: i }) => /* @__PURE__ */ e.jsx(
94
+ b,
95
+ {
96
+ ...i,
97
+ label: /* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.tableHeaders.description", children: "Description" })
98
+ }
99
+ )
100
+ }
101
+ ),
102
+ /* @__PURE__ */ e.jsxs(A, { dividing: !0, children: [
103
+ /* @__PURE__ */ e.jsx(S, { primary: !0, onClick: K, disabled: a, children: /* @__PURE__ */ e.jsx(n, { i18nKey: "general.actions.save", children: "Save" }) }),
104
+ /* @__PURE__ */ e.jsx(S, { disabled: a, onClick: r, children: /* @__PURE__ */ e.jsx(n, { i18nKey: "general.actions.cancel", children: "Cancel" }) })
105
+ ] }),
106
+ /* @__PURE__ */ e.jsx(q, { message: "", when: x && !a })
107
+ ] });
108
+ }
109
+ function _() {
110
+ const c = B(), { pathname: u } = H(), { licenseName: r } = T(), [t, p] = d(), [l, a] = d(!1), [x, g] = d(!1);
111
+ if (v(() => {
112
+ r && (a(!0), I(r).then(p).catch(() => {
113
+ P(/* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.editPage.fetchingError", children: "Fetching license failed" })), g(!0);
114
+ }).finally(() => a(!1)));
115
+ }, [r]), x)
116
+ return /* @__PURE__ */ e.jsx(V, {});
117
+ if (l)
118
+ return /* @__PURE__ */ e.jsx(O, { center: !0 });
119
+ const j = async (f) => {
120
+ r ? (await R(f), F(/* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.updateSuccess", children: "License updated" }))) : (await k(f), F(/* @__PURE__ */ e.jsx(n, { i18nKey: "licenses.createSuccess", children: "License created" }))), m();
121
+ }, m = () => {
122
+ c.push(u.substring(0, u.lastIndexOf("/")));
123
+ };
124
+ return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
125
+ /* @__PURE__ */ e.jsx(
126
+ z,
127
+ {
128
+ title: t ? {
129
+ id: "licenses.edit.title",
130
+ defaultValue: "Edit License"
131
+ } : {
132
+ id: "licenses.create.title",
133
+ defaultValue: "Create License"
134
+ },
135
+ parentPageLink: !0
136
+ }
137
+ ),
138
+ /* @__PURE__ */ e.jsx(G, { editedLicense: t, onSubmit: j, onCancel: m })
139
+ ] });
140
+ }
141
+ export {
142
+ _ as default
143
+ };
@@ -0,0 +1,146 @@
1
+ import { at as s, ag as a, ah as y, d8 as b, dc as g, aN as j } from "./ContextBarContext-f745a63a.js";
2
+ import { useState as c, useEffect as f } from "react";
3
+ import { Link as u } from "react-router-dom";
4
+ import { fetchRolesForLicense as N, fetchLicenses as C, deleteLicense as E } from "@deviceinsight/ng-ui-api-client";
5
+ import { messageBoxError as h, ContentHeader as S } from "@deviceinsight/ng-ui-components";
6
+ import { useConfirm as w, Button as D, Icon as I } from "@deviceinsight/ng-ui-basic-components";
7
+ import "react-dom";
8
+ function T({ license: t }) {
9
+ const [e, n] = c([]), [r, o] = c(!1);
10
+ return f(() => {
11
+ o(!0), N(t).then(n).catch(() => {
12
+ h(
13
+ /* @__PURE__ */ s.jsxs(a, { i18nKey: "license.roles.fetchingError", children: [
14
+ "Can't fetch the roles of the following license: ",
15
+ { license: t }
16
+ ] })
17
+ );
18
+ }).finally(() => o(!1));
19
+ }, [t]), r ? /* @__PURE__ */ s.jsx(a, { i18nKey: "general.actions.loading", children: "Loading..." }) : /* @__PURE__ */ s.jsx("span", { className: "di license-roles", children: e.map((i) => /* @__PURE__ */ s.jsx(u, { to: `/roles/${i.id}`, className: "role-link", children: i.name }, i.id)) });
20
+ }
21
+ const A = {
22
+ page: 0,
23
+ size: 15,
24
+ sort: {
25
+ property: "name",
26
+ direction: "ASC"
27
+ }
28
+ };
29
+ function K(t) {
30
+ return [
31
+ {
32
+ name: "name",
33
+ label: /* @__PURE__ */ s.jsx(a, { i18nKey: "licenses.tableHeaders.name", children: "Technical Name" }),
34
+ sortable: !0,
35
+ filterable: {
36
+ filterType: "text",
37
+ filterFn: (e, n) => e.name.toLowerCase().indexOf(n.toLowerCase()) >= 0
38
+ },
39
+ render: (e) => /* @__PURE__ */ s.jsx(u, { to: `licenses/${e.name}`, children: e.name })
40
+ },
41
+ {
42
+ name: "displayName",
43
+ label: /* @__PURE__ */ s.jsx(a, { i18nKey: "licenses.tableHeaders.displayName", children: "Display Name" }),
44
+ sortable: !0,
45
+ filterable: {
46
+ filterType: "text",
47
+ filterFn: (e, n) => e.displayName.toLowerCase().indexOf(n.toLowerCase()) >= 0
48
+ },
49
+ render: (e) => e.displayName
50
+ },
51
+ {
52
+ name: "description",
53
+ label: /* @__PURE__ */ s.jsx(a, { i18nKey: "licenses.tableHeaders.description", children: "Description" }),
54
+ render: (e) => e.description
55
+ },
56
+ {
57
+ name: "roles",
58
+ label: /* @__PURE__ */ s.jsx(a, { i18nKey: "licenses.tableHeaders.roles", children: "Roles" }),
59
+ render: (e) => /* @__PURE__ */ s.jsx(T, { license: e.name })
60
+ },
61
+ {
62
+ name: "actions",
63
+ label: "",
64
+ width: "10%",
65
+ align: "right",
66
+ render: (e) => /* @__PURE__ */ s.jsx(j, { authorities: ["MANAGE_LICENSES"], children: /* @__PURE__ */ s.jsx(
67
+ D,
68
+ {
69
+ naked: !0,
70
+ title: {
71
+ id: "licenses.tableHeaders.deleteLicense",
72
+ defaultValue: "Delete this License"
73
+ },
74
+ onClick: () => t(e),
75
+ children: /* @__PURE__ */ s.jsx(I, { del: !0 })
76
+ }
77
+ ) })
78
+ }
79
+ ];
80
+ }
81
+ function B() {
82
+ const [t, e] = c(!1), [n, r] = c([]), o = w(), { t: i } = y(), p = /* @__PURE__ */ s.jsx(a, { i18nKey: "portalAdmin.sidebarElements.licenses.create", children: "Create new license" });
83
+ f(() => {
84
+ (async () => {
85
+ try {
86
+ e(!0);
87
+ const m = await C();
88
+ r(m);
89
+ } finally {
90
+ e(!1);
91
+ }
92
+ })();
93
+ }, []);
94
+ async function L(l) {
95
+ if (await o({
96
+ title: i("licenses.confirmDeleteLicenseTitle", { defaultValue: "Delete License" }),
97
+ message: i("licenses.confirmDeleteLicenseMessage", {
98
+ defaultValue: "Do you really want to delete this License?"
99
+ })
100
+ })) {
101
+ e(!0);
102
+ try {
103
+ await E(l.name), r((d) => d.filter((x) => x.name !== l.name));
104
+ } catch (d) {
105
+ console.error("Delete license error", d), h(
106
+ i("licenses.deleteFailure", { defaultValue: "Can't delete license because it is in use" })
107
+ );
108
+ }
109
+ e(!1);
110
+ }
111
+ }
112
+ return /* @__PURE__ */ s.jsxs("div", { "data-testid": "licenses-list", children: [
113
+ /* @__PURE__ */ s.jsx(
114
+ S,
115
+ {
116
+ title: {
117
+ id: "route.label.licenses.name",
118
+ defaultValue: "Licenses"
119
+ }
120
+ }
121
+ ),
122
+ /* @__PURE__ */ s.jsx(
123
+ b,
124
+ {
125
+ tooltip: p,
126
+ authorities: "MANAGE_LICENSES",
127
+ path: "licenses/create",
128
+ dataTestId: "create-license-button"
129
+ }
130
+ ),
131
+ /* @__PURE__ */ s.jsx(
132
+ g,
133
+ {
134
+ columnDefs: K(L),
135
+ items: n,
136
+ isLoading: t,
137
+ uniqueItemKey: (l) => l.name,
138
+ paginationSettings: A,
139
+ "data-testid": "licenses-table"
140
+ }
141
+ )
142
+ ] });
143
+ }
144
+ export {
145
+ B as default
146
+ };