@hortiview/shared-components 2.13.0 → 2.15.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 (32) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/GenericCard-IWX-Bmb_.js +90 -0
  3. package/dist/assets/BaseView.css +1 -1
  4. package/dist/assets/GenericCard.css +1 -1
  5. package/dist/assets/GenericTable.css +1 -1
  6. package/dist/components/Allowed/Allowed.d.ts +5 -5
  7. package/dist/components/Allowed/Allowed.js +2 -2
  8. package/dist/components/Allowed/Allowed.test.js +3 -3
  9. package/dist/components/AllowedButton/AllowedButton.d.ts +3 -3
  10. package/dist/components/AllowedButton/AllowedButton.js +1 -1
  11. package/dist/components/AllowedButton/AllowedButton.test.js +32 -32
  12. package/dist/components/AllowedIconButton/AllowedIconButton.d.ts +3 -3
  13. package/dist/components/AllowedIconButton/AllowedIconButton.js +1 -1
  14. package/dist/components/AllowedIconButton/AllowedIconButton.test.js +17 -17
  15. package/dist/components/BaseView/BaseView.d.ts +1 -0
  16. package/dist/components/BaseView/BaseView.js +79 -79
  17. package/dist/components/BaseView/BaseView.test.js +58 -18
  18. package/dist/components/ContextMenu/ContextMenu.d.ts +5 -1
  19. package/dist/components/ContextMenu/ContextMenu.js +40 -35
  20. package/dist/components/ContextMenu/ContextMenu.test.js +74 -23
  21. package/dist/components/GenericTable/GenericTable.js +141 -133
  22. package/dist/components/GenericTable/Mobile/GenericCard.js +1 -1
  23. package/dist/components/GenericTable/Mobile/GenericCard.test.js +1 -1
  24. package/dist/components/GenericTable/Mobile/GenericCardList.js +11 -11
  25. package/dist/components/PermissionChecks/PermissionService.d.ts +15 -8
  26. package/dist/components/PermissionChecks/PermissionService.js +18 -20
  27. package/dist/components/PermissionChecks/PermissionService.test.js +27 -19
  28. package/dist/main.d.ts +1 -0
  29. package/dist/types/ListElement.d.ts +5 -0
  30. package/dist/types/Permission.d.ts +2 -2
  31. package/package.json +1 -1
  32. package/dist/GenericCard-CeqYrtLH.js +0 -89
@@ -4,7 +4,7 @@ import "../../../index.es-CeQB6igi.js";
4
4
  import "../../../index.es-SjZ_-d7U.js";
5
5
  import "react";
6
6
  import "../../OverflowTooltip/OverflowTooltip.js";
7
- import { G } from "../../../GenericCard-CeqYrtLH.js";
7
+ import { G } from "../../../GenericCard-IWX-Bmb_.js";
8
8
  export {
9
9
  G as GenericCard
10
10
  };
@@ -1,6 +1,6 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
2
  import { a as c, s as o } from "../../../react.esm-Bm0cAgpZ.js";
3
- import { G as i } from "../../../GenericCard-CeqYrtLH.js";
3
+ import { G as i } from "../../../GenericCard-IWX-Bmb_.js";
4
4
  import { d as m, t as s, g as e } from "../../../vi.bdSIJ99Y-B308Q-4w.js";
5
5
  m("GenericCard", () => {
6
6
  const d = {
@@ -1,25 +1,25 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { G as c } from "../../../index.es-oxil0uFe.js";
3
- import { P as l } from "../../../index.es-BanVdXEd.js";
2
+ import { G as l } from "../../../index.es-oxil0uFe.js";
3
+ import { P as c } from "../../../index.es-BanVdXEd.js";
4
4
  import { a as o } from "../../../index.es-SjZ_-d7U.js";
5
- import { s as i, G as m } from "../../../GenericCard-CeqYrtLH.js";
6
- const u = ({
5
+ import { s as e, G as m } from "../../../GenericCard-IWX-Bmb_.js";
6
+ const g = ({
7
7
  columns: n,
8
- data: e,
8
+ data: t,
9
9
  hiddenColumns: a = [],
10
- noContentText: d
11
- }) => e?.length === 0 ? /* @__PURE__ */ r("div", { "data-testid": "empty-generic-card-list", className: i.emptyContainer, children: /* @__PURE__ */ r(l, { variant: "standard", style: { textAlign: "center" }, className: i.empty, children: /* @__PURE__ */ r(o, { children: d }) }) }) : (
10
+ noContentText: s
11
+ }) => t?.length === 0 ? /* @__PURE__ */ r("div", { "data-testid": "empty-generic-card-list", className: e.emptyContainer, children: /* @__PURE__ */ r(c, { variant: "standard", style: { textAlign: "center" }, className: e.empty, children: /* @__PURE__ */ r(o, { children: s }) }) }) : (
12
12
  // needs the div to surround the Group by an element with display: block to avoid visual errors
13
- /* @__PURE__ */ r("div", { "data-testid": "generic-card-list", style: { width: "100%" }, children: /* @__PURE__ */ r(c, { fullWidth: !0, direction: "vertical", primaryAlign: "center", secondaryAlign: "center", children: e?.map((t, s) => /* @__PURE__ */ r(
13
+ /* @__PURE__ */ r("div", { className: e.fullWidth, children: /* @__PURE__ */ r(l, { fullWidth: !0, direction: "vertical", primaryAlign: "center", secondaryAlign: "center", children: t?.map((i, d) => /* @__PURE__ */ r(
14
14
  m,
15
15
  {
16
- item: t,
16
+ item: i,
17
17
  columns: n,
18
18
  hiddenColumns: a
19
19
  },
20
- t.id ?? s
20
+ i.id ?? d
21
21
  )) }) })
22
22
  );
23
23
  export {
24
- u as GenericCardList
24
+ g as GenericCardList
25
25
  };
@@ -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.13.0",
4
+ "version": "2.15.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>",
@@ -1,89 +0,0 @@
1
- import { jsx as r, jsxs as d, Fragment as C } from "react/jsx-runtime";
2
- import { C as h, a as m, b as T, c as g, d as v } from "./index.es-BPv5dCFQ.js";
3
- import { G as b, a as x, b as c } from "./index.es-CeQB6igi.js";
4
- import { d as f } from "./index.es-SjZ_-d7U.js";
5
- import { useMemo as w } from "react";
6
- import { OverflowTooltip as l } from "./components/OverflowTooltip/OverflowTooltip.js";
7
- import './assets/GenericCard.css';const u = "_cardTitle_ny9m0_1", B = "_cardBody_ny9m0_5", N = "_cardContent_ny9m0_10", $ = "_row_ny9m0_14", G = "_font_ny9m0_18", k = "_fontHeader_ny9m0_23", H = "_title_ny9m0_27", S = "_emptyContainer_ny9m0_33", A = "_empty_ny9m0_33", n = {
8
- cardTitle: u,
9
- cardBody: B,
10
- cardContent: N,
11
- row: $,
12
- font: G,
13
- fontHeader: k,
14
- title: H,
15
- emptyContainer: S,
16
- empty: A
17
- }, _ = {
18
- desktopCol: 6,
19
- phoneCol: 2,
20
- tabletCol: 4,
21
- verticalAlign: "bottom"
22
- }, W = ({ item: e, columns: t, hiddenColumns: o }) => {
23
- const i = t.find((a) => a.asCardTitle), y = t.find((a) => a.asCardSubtitle), p = w(
24
- () => t.filter(
25
- (a) => !a.asCardTitle && !a.asCardSubtitle && a.id !== "actions"
26
- ),
27
- [t]
28
- );
29
- return /* @__PURE__ */ r(
30
- h,
31
- {
32
- variant: "raised",
33
- "data-testid": `card${i ? "-" + e[i.accessor] : ""}`,
34
- children: /* @__PURE__ */ d(m, { className: n.cardContent, "data-testid": "card-content", children: [
35
- /* @__PURE__ */ r(j, { item: e, titleColumn: i, subTitleColumn: y }),
36
- /* @__PURE__ */ r(T, { className: n.cardBody, "data-testid": "card-body", children: /* @__PURE__ */ r(b, { fullHeight: !0, fullWidth: !0, variant: "none", children: p.map((a) => o?.includes(a.id) ? null : /* @__PURE__ */ d(x, { className: n.row, "data-testid": "row", children: [
37
- /* @__PURE__ */ r(c, { horizontalAlign: "right", ..._, children: /* @__PURE__ */ d(
38
- f,
39
- {
40
- level: 2,
41
- themeColor: "text-secondary-on-background",
42
- className: `${n.font} ${n.fontHeader}`,
43
- tag: "div",
44
- children: [
45
- a.header,
46
- ":"
47
- ]
48
- }
49
- ) }),
50
- /* @__PURE__ */ r(c, { horizontalAlign: "left", ..._, children: /* @__PURE__ */ r(s, { column: a, item: e }) })
51
- ] }, a.id)) }) })
52
- ] })
53
- }
54
- );
55
- }, j = ({ item: e, titleColumn: t, subTitleColumn: o }) => {
56
- const i = e.actions;
57
- return !t && !o && !i ? null : /* @__PURE__ */ d(C, { children: [
58
- /* @__PURE__ */ r(
59
- g,
60
- {
61
- "data-testid": "card-title",
62
- className: n.cardTitle,
63
- primaryText: t !== void 0 && /* @__PURE__ */ r(s, { column: t, item: e, isTitle: !0 }),
64
- secondaryText: o !== void 0 && /* @__PURE__ */ r(s, { column: o, item: e, isTitle: !0 }),
65
- trailingBlock: i,
66
- trailingBlockType: i ? "title-actions" : void 0
67
- }
68
- ),
69
- /* @__PURE__ */ r(v, {})
70
- ] });
71
- }, s = ({ item: e, column: t, isTitle: o = !1 }) => t.cellTemplate ? t.cellTemplate({ row: { original: e } }) : o ? /* @__PURE__ */ r(
72
- l,
73
- {
74
- id: `tip_${t.id}_${e[t.accessor]}`,
75
- text: e[t.accessor],
76
- children: /* @__PURE__ */ r("span", { className: n.title, children: e[t.accessor] })
77
- }
78
- ) : /* @__PURE__ */ r(
79
- l,
80
- {
81
- id: `tip_${t.id}_${e[t.accessor]}`,
82
- text: e[t.accessor],
83
- children: /* @__PURE__ */ r(f, { level: 2, themeColor: "text-primary-on-background", className: n.font, children: e[t.accessor] })
84
- }
85
- );
86
- export {
87
- W as G,
88
- n as s
89
- };