@hortiview/shared-components 2.12.2 → 2.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.
Files changed (28) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +9 -1
  3. package/dist/assets/BaseView.css +1 -1
  4. package/dist/components/Allowed/Allowed.d.ts +5 -5
  5. package/dist/components/Allowed/Allowed.js +2 -2
  6. package/dist/components/Allowed/Allowed.test.js +3 -3
  7. package/dist/components/AllowedButton/AllowedButton.d.ts +3 -3
  8. package/dist/components/AllowedButton/AllowedButton.js +1 -1
  9. package/dist/components/AllowedButton/AllowedButton.test.js +32 -32
  10. package/dist/components/AllowedIconButton/AllowedIconButton.d.ts +3 -3
  11. package/dist/components/AllowedIconButton/AllowedIconButton.js +1 -1
  12. package/dist/components/AllowedIconButton/AllowedIconButton.test.js +17 -17
  13. package/dist/components/BaseView/BaseView.d.ts +1 -0
  14. package/dist/components/BaseView/BaseView.js +79 -79
  15. package/dist/components/BaseView/BaseView.test.js +58 -18
  16. package/dist/components/ContextMenu/ContextMenu.d.ts +5 -1
  17. package/dist/components/ContextMenu/ContextMenu.js +40 -35
  18. package/dist/components/ContextMenu/ContextMenu.test.js +74 -23
  19. package/dist/components/DeleteModal/DeleteModal.d.ts +6 -1
  20. package/dist/components/DeleteModal/DeleteModal.js +73 -58
  21. package/dist/components/DeleteModal/DeleteModal.test.js +42 -19
  22. package/dist/components/PermissionChecks/PermissionService.d.ts +15 -8
  23. package/dist/components/PermissionChecks/PermissionService.js +18 -20
  24. package/dist/components/PermissionChecks/PermissionService.test.js +27 -19
  25. package/dist/main.d.ts +1 -0
  26. package/dist/types/ListElement.d.ts +5 -0
  27. package/dist/types/Permission.d.ts +2 -2
  28. package/package.json +1 -1
@@ -1,112 +1,127 @@
1
- import { jsx as o, jsxs as f, Fragment as c } from "react/jsx-runtime";
2
- import { B as p } from "../../index.es-B8p8KCdj.js";
3
- import { G as i } from "../../index.es-oxil0uFe.js";
4
- import { I } from "../../index.es-Dgxrk6xW.js";
1
+ import { jsx as o, jsxs as b, Fragment as c } from "react/jsx-runtime";
2
+ import { B as f } from "../../index.es-B8p8KCdj.js";
3
+ import { G as m } from "../../index.es-oxil0uFe.js";
4
+ import { I as S } from "../../index.es-Dgxrk6xW.js";
5
5
  import { T as l } from "../../index.es-SjZ_-d7U.js";
6
- import { u as N } from "../../uniqueId-BNVTeImh.js";
7
- import { AvailableCustomIcons as S } from "../../enums/AvailableCustomIcons.js";
8
- import { u as x } from "../../useBreakpoints-MzTZ0tCT.js";
9
- import { Iconify as B } from "../Iconify/Iconify.js";
6
+ import { u as x } from "../../uniqueId-BNVTeImh.js";
7
+ import { AvailableCustomIcons as N } from "../../enums/AvailableCustomIcons.js";
8
+ import { u as O } from "../../useBreakpoints-MzTZ0tCT.js";
9
+ import { Iconify as z } from "../Iconify/Iconify.js";
10
+ import "react";
11
+ import "../../react-tooltip.min-CVsI--2Y.js";
12
+ import "../../orderBy-DLBJlgdL.js";
13
+ import { LoadingSpinner as B } from "../LoadingSpinner/Default/LoadingSpinner.js";
10
14
  import { Modal as M } from "../Modal/Modal.js";
11
- import '../../assets/DeleteModal.css';const O = "_bulletPoint_bd412_1", j = "_modal_bd412_7", z = "_colorDanger_bd412_11", P = "_crossedOut_bd412_15", t = {
12
- bulletPoint: O,
13
- modal: j,
14
- colorDanger: z,
15
- crossedOut: P
16
- }, V = ({
15
+ import "react-hook-form";
16
+ import "../../get-D8IXqiys.js";
17
+ import "../../isArray-BjSPDQ4v.js";
18
+ import "../../isString-DVA49FEo.js";
19
+ import "../../omit-CYY_mIYv.js";
20
+ import "../../types/Time.js";
21
+ import "../../index-CuHybtft.js";
22
+ import "../SharedComponentsPermissionProvider/PermissionContext.js";
23
+ import "../../react.esm-Bm0cAgpZ.js";
24
+ import '../../assets/DeleteModal.css';const j = "_bulletPoint_bd412_1", A = "_modal_bd412_7", G = "_colorDanger_bd412_11", q = "_crossedOut_bd412_15", e = {
25
+ bulletPoint: j,
26
+ modal: A,
27
+ colorDanger: G,
28
+ crossedOut: q
29
+ }, co = ({
17
30
  title: r,
18
- confirmButtonLabel: e,
31
+ confirmButtonLabel: t,
19
32
  cancelButtonLabel: n,
20
33
  deleteHeader: a,
21
- deleteBody: s,
22
- deleteText: b,
23
- icon: g,
24
- isIconCrossedOut: h,
25
- impossibleDeleteHeader: v,
34
+ deleteBody: i,
35
+ deleteText: g,
36
+ icon: h,
37
+ isIconCrossedOut: v,
38
+ impossibleDeleteHeader: y,
26
39
  open: _,
27
40
  setOpen: d,
28
- onDelete: y,
29
- onCancel: C,
30
- isDeletePossible: m = !0,
31
- isOnline: u = !0,
32
- offlineViewProps: D
41
+ onDelete: C,
42
+ onCancel: I,
43
+ isDeletePossible: u = !0,
44
+ isDeletePending: s = !1,
45
+ isOnline: p = !0,
46
+ offlineViewProps: k
33
47
  }) => {
34
- const { isDesktop: k } = x();
48
+ const { isDesktop: D } = O();
35
49
  return /* @__PURE__ */ o(
36
50
  M,
37
51
  {
38
- isOnline: u,
39
- offlineViewProps: D,
40
- className: `${t.modal}`,
41
- modalSize: k ? "small" : "fullscreen",
52
+ isOnline: p,
53
+ offlineViewProps: k,
54
+ className: `${e.modal}`,
55
+ modalSize: D ? "small" : "fullscreen",
42
56
  open: _,
43
57
  title: r,
44
58
  onClose: () => d(!1),
45
59
  actionButton: /* @__PURE__ */ o(
46
- p,
60
+ f,
47
61
  {
48
62
  "data-testid": "delete-button",
49
63
  variant: "danger",
50
- label: e,
51
- onClick: y,
52
- disabled: !m || !u
64
+ label: s ? "" : t,
65
+ onClick: C,
66
+ disabled: !u || s || !p,
67
+ trailingIcon: s ? /* @__PURE__ */ o(B, { size: "sm", text: "", spinnerOnly: !0 }) : null
53
68
  }
54
69
  ),
55
70
  footerSupplemental: /* @__PURE__ */ o(
56
- p,
71
+ f,
57
72
  {
58
73
  "data-testid": "cancel-button",
59
74
  variant: "text",
60
75
  label: n,
61
76
  onClick: () => {
62
- C?.(), d(!1);
77
+ I?.(), d(!1);
63
78
  }
64
79
  }
65
80
  ),
66
- children: /* @__PURE__ */ f(i, { direction: "vertical", secondaryAlign: "center", children: [
67
- /* @__PURE__ */ o(A, { element: /* @__PURE__ */ o(G, { icon: g }), isCrossedOut: h }),
68
- /* @__PURE__ */ o(i, { direction: "vertical", children: m ? /* @__PURE__ */ o(
69
- q,
81
+ children: /* @__PURE__ */ b(m, { direction: "vertical", secondaryAlign: "center", children: [
82
+ /* @__PURE__ */ o(F, { element: /* @__PURE__ */ o(H, { icon: h }), isCrossedOut: v }),
83
+ /* @__PURE__ */ o(m, { direction: "vertical", children: u ? /* @__PURE__ */ o(
84
+ L,
70
85
  {
71
86
  deleteHeader: a,
72
- deleteText: b,
73
- deleteBody: s
87
+ deleteText: g,
88
+ deleteBody: i
74
89
  }
75
- ) : /* @__PURE__ */ o(F, { impossibleDeleteHeader: v }) })
90
+ ) : /* @__PURE__ */ o(P, { impossibleDeleteHeader: y }) })
76
91
  ] })
77
92
  }
78
93
  );
79
- }, A = ({
94
+ }, F = ({
80
95
  element: r,
81
- isCrossedOut: e = !1
82
- }) => e ? /* @__PURE__ */ o("span", { className: t.crossedOut, children: r }) : r, G = ({ icon: r }) => r ? typeof r != "string" ? r : Object.values(S).includes(r) ? /* @__PURE__ */ o(
83
- B,
96
+ isCrossedOut: t = !1
97
+ }) => t ? /* @__PURE__ */ o("span", { className: e.crossedOut, children: r }) : r, H = ({ icon: r }) => r ? typeof r != "string" ? r : Object.values(N).includes(r) ? /* @__PURE__ */ o(
98
+ z,
84
99
  {
85
100
  icon: r,
86
101
  iconSize: "xlarge",
87
- className: t.colorDanger
102
+ className: e.colorDanger
88
103
  }
89
- ) : /* @__PURE__ */ o(I, { icon: r, iconSize: "xlarge", className: t.colorDanger }) : /* @__PURE__ */ o(c, {}), q = ({
104
+ ) : /* @__PURE__ */ o(S, { icon: r, iconSize: "xlarge", className: e.colorDanger }) : /* @__PURE__ */ o(c, {}), L = ({
90
105
  deleteHeader: r,
91
- deleteText: e,
106
+ deleteText: t,
92
107
  deleteBody: n
93
- }) => /* @__PURE__ */ f(c, { children: [
108
+ }) => /* @__PURE__ */ b(c, { children: [
94
109
  /* @__PURE__ */ o(l, { level: 1, themeColor: "text-primary-on-background", children: r }),
95
- e && typeof e == "string" && /* @__PURE__ */ o(l, { level: 2, themeColor: "text-secondary-on-background", children: e }),
96
- e && typeof e != "string" && /* @__PURE__ */ o(c, { children: e }),
97
- n && e === void 0 && /* @__PURE__ */ o(i, { direction: "vertical", gap: "none", children: n.map((a, s) => /* @__PURE__ */ o(
110
+ t && typeof t == "string" && /* @__PURE__ */ o(l, { level: 2, themeColor: "text-secondary-on-background", children: t }),
111
+ t && typeof t != "string" && /* @__PURE__ */ o(c, { children: t }),
112
+ n && t === void 0 && /* @__PURE__ */ o(m, { direction: "vertical", gap: "none", children: n.map((a, i) => /* @__PURE__ */ o(
98
113
  l,
99
114
  {
100
115
  level: 2,
101
- className: t.bulletPoint,
116
+ className: e.bulletPoint,
102
117
  themeColor: "text-secondary-on-background",
103
118
  children: a
104
119
  },
105
- N(s.toString())
120
+ x(i.toString())
106
121
  )) })
107
- ] }), F = ({
122
+ ] }), P = ({
108
123
  impossibleDeleteHeader: r
109
124
  }) => /* @__PURE__ */ o(l, { level: 1, themeColor: "text-primary-on-background", children: r });
110
125
  export {
111
- V as DeleteModal
126
+ co as DeleteModal
112
127
  };
@@ -1,12 +1,12 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import { a as c, s as e } from "../../react.esm-Bm0cAgpZ.js";
3
- import { DeleteModal as a } from "./DeleteModal.js";
4
- import { d, t as b, a as o, g as t } from "../../vi.bdSIJ99Y-B308Q-4w.js";
5
- d("DeleteModal Test", () => {
6
- b("should render the DeleteModal properly", () => {
2
+ import { a as c, s as t } from "../../react.esm-Bm0cAgpZ.js";
3
+ import { DeleteModal as b } from "./DeleteModal.js";
4
+ import { d as a, t as s, a as o, g as e } from "../../vi.bdSIJ99Y-B308Q-4w.js";
5
+ a("DeleteModal Test", () => {
6
+ s("should render the DeleteModal properly", () => {
7
7
  c(
8
8
  /* @__PURE__ */ n(
9
- a,
9
+ b,
10
10
  {
11
11
  icon: "block",
12
12
  open: !0,
@@ -21,11 +21,11 @@ d("DeleteModal Test", () => {
21
21
  isDeletePossible: !0
22
22
  }
23
23
  )
24
- ), t(e.getByText("DELETE")).toBeInTheDocument(), t(e.getByTestId("block")).toBeInTheDocument(), t(e.getByText("block 1")).toBeInTheDocument(), t(e.getByText("block 2")).toBeInTheDocument(), t(e.getByText("block 3")).toBeInTheDocument(), t(e.getByText("Remove")).toBeInTheDocument(), t(e.getByText("Cancel")).toBeInTheDocument(), t(e.queryByText("block cant be deleted")).not.toBeInTheDocument();
25
- }), b("should render the DeleteModal properly when isDeletePossible = false", () => {
24
+ ), e(t.getByText("DELETE")).toBeInTheDocument(), e(t.getByTestId("block")).toBeInTheDocument(), e(t.getByText("block 1")).toBeInTheDocument(), e(t.getByText("block 2")).toBeInTheDocument(), e(t.getByText("block 3")).toBeInTheDocument(), e(t.getByText("Remove")).toBeInTheDocument(), e(t.getByText("Cancel")).toBeInTheDocument(), e(t.queryByText("block cant be deleted")).not.toBeInTheDocument();
25
+ }), s("should render the DeleteModal properly when isDeletePossible = false", () => {
26
26
  c(
27
27
  /* @__PURE__ */ n(
28
- a,
28
+ b,
29
29
  {
30
30
  icon: "block",
31
31
  open: !0,
@@ -40,12 +40,12 @@ d("DeleteModal Test", () => {
40
40
  isDeletePossible: !1
41
41
  }
42
42
  )
43
- ), t(e.getByText("DELETE")).toBeInTheDocument(), t(e.getByTestId("block")).toBeInTheDocument(), t(e.queryByText("block 1")).not.toBeInTheDocument(), t(e.queryByText("block 2")).not.toBeInTheDocument(), t(e.queryByText("block 3")).not.toBeInTheDocument(), t(e.getByText("Remove")).toBeInTheDocument(), t(e.getByText("Remove").parentElement).toBeDisabled(), t(e.getByText("Cancel")).toBeInTheDocument(), t(e.queryByText("block cant be deleted")).toBeInTheDocument();
44
- }), b("should call setOpen with false when clicking on cancel button", () => {
43
+ ), e(t.getByText("DELETE")).toBeInTheDocument(), e(t.getByTestId("block")).toBeInTheDocument(), e(t.queryByText("block 1")).not.toBeInTheDocument(), e(t.queryByText("block 2")).not.toBeInTheDocument(), e(t.queryByText("block 3")).not.toBeInTheDocument(), e(t.getByText("Remove")).toBeInTheDocument(), e(t.getByText("Remove").parentElement).toBeDisabled(), e(t.getByText("Cancel")).toBeInTheDocument(), e(t.queryByText("block cant be deleted")).toBeInTheDocument();
44
+ }), s("should call setOpen with false when clicking on cancel button", () => {
45
45
  const l = o.fn();
46
46
  c(
47
47
  /* @__PURE__ */ n(
48
- a,
48
+ b,
49
49
  {
50
50
  icon: "block",
51
51
  open: !0,
@@ -60,12 +60,12 @@ d("DeleteModal Test", () => {
60
60
  isDeletePossible: !0
61
61
  }
62
62
  )
63
- ), e.getByText("Cancel").click(), t(l).toHaveBeenCalledWith(!1);
64
- }), b("should call onDelete when clicking on delete button", () => {
63
+ ), t.getByText("Cancel").click(), e(l).toHaveBeenCalledWith(!1);
64
+ }), s("should call onDelete when clicking on delete button", () => {
65
65
  const l = o.fn();
66
66
  c(
67
67
  /* @__PURE__ */ n(
68
- a,
68
+ b,
69
69
  {
70
70
  icon: "block",
71
71
  open: !0,
@@ -80,12 +80,12 @@ d("DeleteModal Test", () => {
80
80
  isDeletePossible: !0
81
81
  }
82
82
  )
83
- ), e.getByText("Remove").click(), t(l).toHaveBeenCalled();
84
- }), b("render DeleteModal with OfflineView", () => {
83
+ ), t.getByText("Remove").click(), e(l).toHaveBeenCalled();
84
+ }), s("render DeleteModal with OfflineView", () => {
85
85
  const l = o.fn();
86
86
  c(
87
87
  /* @__PURE__ */ n(
88
- a,
88
+ b,
89
89
  {
90
90
  icon: "block",
91
91
  open: !0,
@@ -104,6 +104,29 @@ d("DeleteModal Test", () => {
104
104
  }
105
105
  }
106
106
  )
107
- ), e.getByText("Remove").click(), t(l).not.toHaveBeenCalled(), t(e.getByTestId("offline-test")).toBeInTheDocument();
107
+ ), t.getByText("Remove").click(), e(l).not.toHaveBeenCalled(), e(t.getByTestId("offline-test")).toBeInTheDocument();
108
+ }), s("should disable delete button when isDeletePending is true", () => {
109
+ const l = o.fn();
110
+ c(
111
+ /* @__PURE__ */ n(
112
+ b,
113
+ {
114
+ icon: "block",
115
+ open: !0,
116
+ setOpen: o.fn(),
117
+ onDelete: l,
118
+ title: "DELETE",
119
+ confirmButtonLabel: "Remove",
120
+ cancelButtonLabel: "Cancel",
121
+ deleteHeader: "Delete my block",
122
+ impossibleDeleteHeader: "block cant be deleted",
123
+ deleteBody: ["block 1", "block 2", "block 3"],
124
+ isDeletePossible: !0,
125
+ isDeletePending: !0
126
+ }
127
+ )
128
+ );
129
+ const d = t.getByTestId("delete-button");
130
+ e(d).toBeDisabled(), e(t.getByTestId("loading-spinner")).toBeInTheDocument(), d.click(), e(l).not.toHaveBeenCalled();
108
131
  });
109
132
  });
@@ -1,5 +1,11 @@
1
1
  import { HVPermissions, PermissionsByEntity } from '../../types/Permission';
2
2
 
3
+ type EntityIdType = 'General' | 'Plattform' | (string & Record<never, never>);
4
+ export type IsAllowedProps = {
5
+ neededPermissions: HVPermissions[];
6
+ entityIds: EntityIdType | EntityIdType[];
7
+ areAllPermissionsNeeded?: boolean;
8
+ };
3
9
  /**
4
10
  * Hook to check if the current user has the required permissions.
5
11
  * Must be used within a PermissionProvider.
@@ -7,18 +13,18 @@ import { HVPermissions, PermissionsByEntity } from '../../types/Permission';
7
13
  * @example
8
14
  * ```tsx
9
15
  * const isAllowed = useIsAllowed();
10
- * const canEdit = isAllowed([Permission.BlocksUpdate], farmId);
16
+ * const canEdit = isAllowed({ neededPermissions: [Permission.BlocksUpdate], entityIds: farmId });
17
+ * const canEditMultiple = isAllowed({ neededPermissions: [Permission.BlocksUpdate], entityIds: [farmId1, farmId2] });
11
18
  * ```
12
19
  *
13
- * If the given entity id not matches with an userpermissions object entry, false is returned.
14
- * Otherwise it checks the given neededPermission against the users permissions for the found entity.
15
- * @param neededPermissions the permissions needed at the point the method is called
16
- * @param entityId - the entity id, the permission is for (FarmOrganizationId, VendorOrganizationId or FarmId)
17
- * @param needAllPermissions a flag to determine if all given permissions are needed (AND) or only one of them (OR)
18
- * @param currentUserPermissions - optional parameter to pass the user permissions directly, e.g. after a permission update
20
+ * If the given entity ids do not match any user permissions object entry, false is returned.
21
+ * Otherwise it checks the given neededPermissions against the user's permissions for the found entities.
22
+ * @param neededPermissions - the permissions needed at the point the method is called
23
+ * @param entityIds - the entity id(s), the permission is for (FarmOrganizationId, VendorOrganizationId or FarmId)
24
+ * @param areAllPermissionsNeeded - a flag to determine if all given permissions are needed (AND) or only one of them (OR)
19
25
  * @returns true if the user has one of the (OR) or all (AND) needed permissions, false otherwise
20
26
  */
21
- export declare const useIsAllowed: () => (neededPermissions: HVPermissions[], entityId: string | undefined, needAllPermissions?: boolean, currentUserPermissions?: PermissionsByEntity) => boolean;
27
+ export declare const useIsAllowed: () => ({ neededPermissions, entityIds, areAllPermissionsNeeded }: IsAllowedProps) => boolean;
22
28
  /**
23
29
  * Extracts and parses permissions from a module permission token.
24
30
  *
@@ -33,3 +39,4 @@ export declare const useIsAllowed: () => (neededPermissions: HVPermissions[], en
33
39
  export declare const getPermissionsFromModulePermissionToken: ({ permissionToken, }: {
34
40
  permissionToken?: string;
35
41
  }) => PermissionsByEntity;
42
+ export {};
@@ -1,28 +1,26 @@
1
- import { j as l } from "../../index-CuHybtft.js";
2
- import { useCallback as a } from "react";
3
- import { usePermissionContext as c } from "../SharedComponentsPermissionProvider/PermissionContext.js";
4
- const y = () => {
5
- const { userPermissions: s, activeOrganizationId: e } = c();
6
- return a(
7
- (t, o, m = !1, u) => {
8
- if (t.length === 0) return !0;
9
- const r = u ?? s, n = [
10
- ...r?.[o ?? e ?? ""] ?? [],
11
- ...r?.General ?? [],
12
- ...r?.Plattform ?? []
13
- ];
14
- return n ? m ? t.every((i) => n.includes(i)) : t.some((i) => n.includes(i)) : !1;
1
+ import { j as i } from "../../index-CuHybtft.js";
2
+ import { useCallback as l } from "react";
3
+ import { usePermissionContext as u } from "../SharedComponentsPermissionProvider/PermissionContext.js";
4
+ const f = () => {
5
+ const { userPermissions: s } = u();
6
+ return l(
7
+ ({ neededPermissions: r, entityIds: e, areAllPermissionsNeeded: n = !1 }) => {
8
+ if (r.length === 0) return !0;
9
+ const t = (Array.isArray(e) ? e : [e]).flatMap(
10
+ (o) => s?.[o] ?? []
11
+ );
12
+ return t.length === 0 ? !1 : n ? r.every((o) => t.includes(o)) : r.some((o) => t.includes(o));
15
13
  },
16
- [e, s]
14
+ [s]
17
15
  );
18
- }, I = ({
16
+ }, p = ({
19
17
  permissionToken: s
20
18
  }) => {
21
19
  if (!s || s === "") return;
22
- const e = l(s), t = e.ModuleRolesAndPermissions.FarmOrganizationId, o = e.ModuleRolesAndPermissions.ExecuteEndpointPermissionNames;
23
- return { [t]: [...o] };
20
+ const r = i(s), e = r.ModuleRolesAndPermissions.FarmOrganizationId, n = r.ModuleRolesAndPermissions.ExecuteEndpointPermissionNames;
21
+ return { [e]: n };
24
22
  };
25
23
  export {
26
- I as getPermissionsFromModulePermissionToken,
27
- y as useIsAllowed
24
+ p as getPermissionsFromModulePermissionToken,
25
+ f as useIsAllowed
28
26
  };
@@ -1,10 +1,10 @@
1
- import { r as m } from "../../react.esm-Bm0cAgpZ.js";
2
- import { createPermissionWrapper as l } from "../../test-utils.js";
1
+ import { r as d } from "../../react.esm-Bm0cAgpZ.js";
2
+ import { createPermissionWrapper as m } from "../../test-utils.js";
3
3
  import { HVMainPermissions as i } from "../../types/Permission.js";
4
- import { useIsAllowed as u, getPermissionsFromModulePermissionToken as a } from "./PermissionService.js";
5
- import { d, t, g as o } from "../../vi.bdSIJ99Y-B308Q-4w.js";
6
- d("Test PermissionService", () => {
7
- d("Test isAllowed", () => {
4
+ import { useIsAllowed as l, getPermissionsFromModulePermissionToken as a } from "./PermissionService.js";
5
+ import { d as u, t, g as o } from "../../vi.bdSIJ99Y-B308Q-4w.js";
6
+ u("Test PermissionService", () => {
7
+ u("Test isAllowed", () => {
8
8
  const n = [
9
9
  i.FarmOrganizationsRead,
10
10
  i.FarmOrganizationsUpdate
@@ -12,8 +12,8 @@ d("Test PermissionService", () => {
12
12
  t("should return true if the user has all (AND) needed permissions", () => {
13
13
  const {
14
14
  result: { current: s }
15
- } = m(() => u(), {
16
- wrapper: l({
15
+ } = d(() => l(), {
16
+ wrapper: m({
17
17
  userPermissions: {
18
18
  [e]: [
19
19
  i.FarmOrganizationsRead,
@@ -21,43 +21,51 @@ d("Test PermissionService", () => {
21
21
  ]
22
22
  }
23
23
  })
24
- }), r = s(n, e, !0);
24
+ }), r = s({
25
+ neededPermissions: n,
26
+ entityIds: e,
27
+ areAllPermissionsNeeded: !0
28
+ });
25
29
  o(r).toBe(!0);
26
30
  }), t("should return true if the user has one of the (OR) needed permissions", () => {
27
31
  const {
28
32
  result: { current: s }
29
- } = m(() => u(), {
30
- wrapper: l({
33
+ } = d(() => l(), {
34
+ wrapper: m({
31
35
  userPermissions: {
32
36
  [e]: [i.BlocksCreate, i.FarmOrganizationsRead]
33
37
  }
34
38
  })
35
- }), r = s(n, e);
39
+ }), r = s({ neededPermissions: n, entityIds: e });
36
40
  o(r).toBe(!0);
37
41
  }), t("should return true if neededPermissions array is empty", () => {
38
42
  const {
39
43
  result: { current: s }
40
- } = m(() => u(), {
41
- wrapper: l({
44
+ } = d(() => l(), {
45
+ wrapper: m({
42
46
  userPermissions: {
43
47
  [e]: []
44
48
  }
45
49
  })
46
- }), r = s([], e, !0);
50
+ }), r = s({
51
+ neededPermissions: [],
52
+ entityIds: e,
53
+ areAllPermissionsNeeded: !0
54
+ });
47
55
  o(r).toBe(!0);
48
56
  }), t("should return false if given entity id not matching with any userPermissions entry", () => {
49
57
  const {
50
58
  result: { current: s }
51
- } = m(() => u(), {
52
- wrapper: l({
59
+ } = d(() => l(), {
60
+ wrapper: m({
53
61
  userPermissions: {
54
62
  456: [i.BlocksCreate]
55
63
  }
56
64
  })
57
- }), r = s(n, e);
65
+ }), r = s({ neededPermissions: n, entityIds: e });
58
66
  o(r).toBe(!1);
59
67
  });
60
- }), d("Test getPermissionsFromModulePermissionToken", () => {
68
+ }), u("Test getPermissionsFromModulePermissionToken", () => {
61
69
  const n = `
62
70
  eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJNb2R1bGVSb2xlc0FuZFBlcm1pc3Npb25zIjp7IkZhcm1Pcmdhbml6YXRpb25JZCI6IjJmZDJjMGIwLTUwNjEtNGQ0NS1hYzI1LWQxY2E0YWNkNzMzOCIsIlVzZXJJZCI6Ijc5M2IxZmFlLTg0ODItNGVkMy1hYjczLTQ1NzFhMDViYjEyYiIsIk1vZHVsZUlkIjoiMTIzNDUtNjc4OTAtYWJjZGUtZWZnaGkiLCJSb2xlTmFtZXMiOlsiRmFybSBNYW5hZ2VyIiwiRmFybSBXb3JrZXIiXSwiRXhlY3V0ZUVuZHBvaW50UGVybWlzc2lvbk5hbWVzIjpbImJsb2Nrcy1yZWFkIiwiYmxvY2tzLXVwZGF0ZSIsImZhcm1zLXJlYWQiXX19.test-signature
63
71
  `;
package/dist/main.d.ts CHANGED
@@ -62,6 +62,7 @@ export { Allowed } from './components/Allowed/Allowed';
62
62
  export { AllowedButton } from './components/AllowedButton/AllowedButton';
63
63
  export { AllowedIconButton } from './components/AllowedIconButton/AllowedIconButton';
64
64
  export { getPermissionsFromModulePermissionToken, useIsAllowed, } from './components/PermissionChecks/PermissionService';
65
+ export type { IsAllowedProps } from './components/PermissionChecks/PermissionService';
65
66
  export { SharedComponentsPermissionProvider } from './components/SharedComponentsPermissionProvider/SharedComponentsPermissionProvider';
66
67
  export { createPermissionWrapper, renderWithPermissions } from './test-utils';
67
68
  export { HVMainPermissions } from './types/Permission';
@@ -80,6 +80,7 @@ export type BaseListElement = {
80
80
  value?: string;
81
81
  /**
82
82
  * the list element is disabled if this is true
83
+ * If the user does not have the required permissions the element please use the `permissions` property instead
83
84
  */
84
85
  disabled?: boolean;
85
86
  /**
@@ -104,6 +105,10 @@ export type BaseListElement = {
104
105
  * a custom class name for the list item
105
106
  */
106
107
  listItemClassName?: string;
108
+ /**
109
+ * whether the user has the permission to view this element, if false the element will not be shown
110
+ */
111
+ isAllowed?: boolean;
107
112
  };
108
113
  /**
109
114
  * The list element to use with BaseView and ListArea, it is an extension of the BaseListElement to handle grouped lists
@@ -25,9 +25,9 @@ export type ModulePermissionTokenParsed = {
25
25
  };
26
26
  };
27
27
  /**
28
- * Type representing all possible permissions in the system.
28
+ * Type representing all possible permissions in the system.p
29
29
  */
30
- export type HVPermissions = HVMainPermissions | `${string}`;
30
+ export type HVPermissions = `${HVMainPermissions}` | (string & Record<never, never>);
31
31
  /**
32
32
  * Enum for all main permissions available in the HortiView platform.
33
33
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/shared-components",
3
3
  "description": "This is a shared component library. It should used in the HortiView platform and its modules.",
4
- "version": "2.12.2",
4
+ "version": "2.14.0",
5
5
  "type": "module",
6
6
  "repository": "https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared",
7
7
  "author": "Falk Menge <falk.menge.ext@bayer.com>",