@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.
- package/CHANGELOG.md +26 -0
- package/dist/GenericCard-IWX-Bmb_.js +90 -0
- package/dist/assets/BaseView.css +1 -1
- package/dist/assets/GenericCard.css +1 -1
- package/dist/assets/GenericTable.css +1 -1
- package/dist/components/Allowed/Allowed.d.ts +5 -5
- package/dist/components/Allowed/Allowed.js +2 -2
- package/dist/components/Allowed/Allowed.test.js +3 -3
- package/dist/components/AllowedButton/AllowedButton.d.ts +3 -3
- package/dist/components/AllowedButton/AllowedButton.js +1 -1
- package/dist/components/AllowedButton/AllowedButton.test.js +32 -32
- package/dist/components/AllowedIconButton/AllowedIconButton.d.ts +3 -3
- package/dist/components/AllowedIconButton/AllowedIconButton.js +1 -1
- package/dist/components/AllowedIconButton/AllowedIconButton.test.js +17 -17
- package/dist/components/BaseView/BaseView.d.ts +1 -0
- package/dist/components/BaseView/BaseView.js +79 -79
- package/dist/components/BaseView/BaseView.test.js +58 -18
- package/dist/components/ContextMenu/ContextMenu.d.ts +5 -1
- package/dist/components/ContextMenu/ContextMenu.js +40 -35
- package/dist/components/ContextMenu/ContextMenu.test.js +74 -23
- package/dist/components/GenericTable/GenericTable.js +141 -133
- package/dist/components/GenericTable/Mobile/GenericCard.js +1 -1
- package/dist/components/GenericTable/Mobile/GenericCard.test.js +1 -1
- package/dist/components/GenericTable/Mobile/GenericCardList.js +11 -11
- package/dist/components/PermissionChecks/PermissionService.d.ts +15 -8
- package/dist/components/PermissionChecks/PermissionService.js +18 -20
- package/dist/components/PermissionChecks/PermissionService.test.js +27 -19
- package/dist/main.d.ts +1 -0
- package/dist/types/ListElement.d.ts +5 -0
- package/dist/types/Permission.d.ts +2 -2
- package/package.json +1 -1
- package/dist/GenericCard-CeqYrtLH.js +0 -89
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [2.15.0](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/compare/v2.14.0...v2.15.0) (2026-02-18)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add full-width styling for mobile table components ([af387f3](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/af387f352aecbeb4e4af5b4857a8aef13afeb461)), closes [#19352](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/issues/19352)
|
|
6
|
+
|
|
7
|
+
### Code Refactoring
|
|
8
|
+
|
|
9
|
+
* remove inline styling ([c18008b](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/c18008bda0e5ab634526156921a4e828139db90a))
|
|
10
|
+
|
|
11
|
+
## [2.14.0](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/compare/v2.13.0...v2.14.0) (2026-02-10)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add isAllowed prop to baseView elements to remove them from list when user is not allowed to access them ([ac7449e](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/ac7449e5ae0e39302f48e9178d72ee0dab725544))
|
|
16
|
+
* add isAllowed prop to contextMenu to remove items from menu when user is not allowed to trigger the action ([b071931](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/b0719310a495f68adfef9424572efa467aa519a1))
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* removed max width from base view header ([259c732](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/259c7321406cd47e5ca19e2f8bee7ed9600740ac))
|
|
21
|
+
|
|
22
|
+
### Code Refactoring
|
|
23
|
+
|
|
24
|
+
* add permission handling to BaseView and ContextMenu stories ([26b4ae5](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/26b4ae503a76c33ad57e683b5861eb2a95fa3cd6))
|
|
25
|
+
* useIsAllowed hook to check multiple entities for permissions ([f168ef5](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/commit/f168ef56c58e8cbc536a9a7451019b5c262266e1))
|
|
26
|
+
|
|
1
27
|
## [2.13.0](https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared/compare/v2.12.2...v2.13.0) (2026-02-06)
|
|
2
28
|
|
|
3
29
|
### Features
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as r, jsxs as s, Fragment as h } from "react/jsx-runtime";
|
|
2
|
+
import { C, a as y, b as T, c as g, d as v } from "./index.es-BPv5dCFQ.js";
|
|
3
|
+
import { G as m, a as u, b as l } from "./index.es-CeQB6igi.js";
|
|
4
|
+
import { d as f } from "./index.es-SjZ_-d7U.js";
|
|
5
|
+
import { useMemo as b } from "react";
|
|
6
|
+
import { OverflowTooltip as c } from "./components/OverflowTooltip/OverflowTooltip.js";
|
|
7
|
+
import './assets/GenericCard.css';const x = "_cardTitle_1w5we_1", B = "_cardBody_1w5we_5", N = "_cardContent_1w5we_10", $ = "_row_1w5we_14", G = "_font_1w5we_18", k = "_fontHeader_1w5we_23", H = "_title_1w5we_27", S = "_emptyContainer_1w5we_33", W = "_empty_1w5we_33", A = "_fullWidth_1w5we_45", i = {
|
|
8
|
+
cardTitle: x,
|
|
9
|
+
cardBody: B,
|
|
10
|
+
cardContent: N,
|
|
11
|
+
row: $,
|
|
12
|
+
font: G,
|
|
13
|
+
fontHeader: k,
|
|
14
|
+
title: H,
|
|
15
|
+
emptyContainer: S,
|
|
16
|
+
empty: W,
|
|
17
|
+
fullWidth: A
|
|
18
|
+
}, _ = {
|
|
19
|
+
desktopCol: 6,
|
|
20
|
+
phoneCol: 2,
|
|
21
|
+
tabletCol: 4,
|
|
22
|
+
verticalAlign: "bottom"
|
|
23
|
+
}, q = ({ item: e, columns: t, hiddenColumns: o }) => {
|
|
24
|
+
const d = t.find((a) => a.asCardTitle), w = t.find((a) => a.asCardSubtitle), p = b(
|
|
25
|
+
() => t.filter(
|
|
26
|
+
(a) => !a.asCardTitle && !a.asCardSubtitle && a.id !== "actions"
|
|
27
|
+
),
|
|
28
|
+
[t]
|
|
29
|
+
);
|
|
30
|
+
return /* @__PURE__ */ r(
|
|
31
|
+
C,
|
|
32
|
+
{
|
|
33
|
+
variant: "raised",
|
|
34
|
+
"data-testid": `card${d ? "-" + e[d.accessor] : ""}`,
|
|
35
|
+
children: /* @__PURE__ */ s(y, { className: i.cardContent, "data-testid": "card-content", children: [
|
|
36
|
+
/* @__PURE__ */ r(j, { item: e, titleColumn: d, subTitleColumn: w }),
|
|
37
|
+
/* @__PURE__ */ r(T, { className: i.cardBody, "data-testid": "card-body", children: /* @__PURE__ */ r(m, { fullHeight: !0, fullWidth: !0, variant: "none", children: p.map((a) => o?.includes(a.id) ? null : /* @__PURE__ */ s(u, { className: i.row, "data-testid": "row", children: [
|
|
38
|
+
/* @__PURE__ */ r(l, { horizontalAlign: "right", ..._, children: /* @__PURE__ */ s(
|
|
39
|
+
f,
|
|
40
|
+
{
|
|
41
|
+
level: 2,
|
|
42
|
+
themeColor: "text-secondary-on-background",
|
|
43
|
+
className: `${i.font} ${i.fontHeader}`,
|
|
44
|
+
tag: "div",
|
|
45
|
+
children: [
|
|
46
|
+
a.header,
|
|
47
|
+
":"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
) }),
|
|
51
|
+
/* @__PURE__ */ r(l, { horizontalAlign: "left", ..._, children: /* @__PURE__ */ r(n, { column: a, item: e }) })
|
|
52
|
+
] }, a.id)) }) })
|
|
53
|
+
] })
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}, j = ({ item: e, titleColumn: t, subTitleColumn: o }) => {
|
|
57
|
+
const d = e.actions;
|
|
58
|
+
return !t && !o && !d ? null : /* @__PURE__ */ s(h, { children: [
|
|
59
|
+
/* @__PURE__ */ r(
|
|
60
|
+
g,
|
|
61
|
+
{
|
|
62
|
+
"data-testid": "card-title",
|
|
63
|
+
className: i.cardTitle,
|
|
64
|
+
primaryText: t !== void 0 && /* @__PURE__ */ r(n, { column: t, item: e, isTitle: !0 }),
|
|
65
|
+
secondaryText: o !== void 0 && /* @__PURE__ */ r(n, { column: o, item: e, isTitle: !0 }),
|
|
66
|
+
trailingBlock: d,
|
|
67
|
+
trailingBlockType: d ? "title-actions" : void 0
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
/* @__PURE__ */ r(v, {})
|
|
71
|
+
] });
|
|
72
|
+
}, n = ({ item: e, column: t, isTitle: o = !1 }) => t.cellTemplate ? t.cellTemplate({ row: { original: e } }) : o ? /* @__PURE__ */ r(
|
|
73
|
+
c,
|
|
74
|
+
{
|
|
75
|
+
id: `tip_${t.id}_${e[t.accessor]}`,
|
|
76
|
+
text: e[t.accessor],
|
|
77
|
+
children: /* @__PURE__ */ r("span", { className: i.title, children: e[t.accessor] })
|
|
78
|
+
}
|
|
79
|
+
) : /* @__PURE__ */ r(
|
|
80
|
+
c,
|
|
81
|
+
{
|
|
82
|
+
id: `tip_${t.id}_${e[t.accessor]}`,
|
|
83
|
+
text: e[t.accessor],
|
|
84
|
+
children: /* @__PURE__ */ r(f, { level: 2, themeColor: "text-primary-on-background", className: i.font, children: e[t.accessor] })
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
export {
|
|
88
|
+
q as G,
|
|
89
|
+
i as s
|
|
90
|
+
};
|
package/dist/assets/BaseView.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._fullHeight_71rfc_1{height:100%}._fullWidth_71rfc_5{width:100%}._maxWidth_71rfc_9{background-color:var(--lmnt-theme-background)}._list_71rfc_13{box-shadow:0 8px 24px #959da533;background-color:var(--lmnt-theme-background);border-radius:.5rem;overflow-y:auto;width:100%;height:100%}._desktopList_71rfc_22{width:30%;align-self:stretch}._noRoundedCorners_71rfc_27 [class*="lmnt mdc-list-item"]{border-radius:0rem!important}._detail_71rfc_31{height:100%;box-shadow:0 8px 24px #959da533;border-radius:.5rem;background-color:var(--lmnt-theme-background);width:100%}._desktopDetail_71rfc_39{width:70%;overflow-y:auto;scrollbar-width:thin}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._cardTitle_1w5we_1{padding:.5rem!important}._cardBody_1w5we_5{padding:.25rem .5rem!important;overflow:hidden!important}._cardContent_1w5we_10{border-radius:.5rem}._row_1w5we_14{padding:.25rem 0}._font_1w5we_18{font-weight:400;align-self:end}._fontHeader_1w5we_23{text-align:right}._title_1w5we_27{display:inline-block;width:65vw;text-wrap:nowrap}._emptyContainer_1w5we_33{width:inherit;height:inherit}._empty_1w5we_33{position:relative;top:50%;left:50%;transform:translate(-50%,-25%)}._fullWidth_1w5we_45{width:100%}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._topBar_wc5ga_1 [class*=lmnt-table__top-bar__title]{display:none}._filterBar_wc5ga_5{padding:1rem;width:inherit!important}._start_wc5ga_10{padding-top:0;padding-bottom:0}._emptyTable_wc5ga_15{height:16rem}[class*=mnt-pagination][class*=mdc-data-table__pagination]{border-top:1px solid var(--lmnt-theme-on-secondary-stroke)}._elevation_wc5ga_23{border-radius:.4rem;width:100%}._table_wc5ga_28,._table_wc5ga_28 [class*=mdc-data-table__table-container]{border-radius:.4rem}._table_wc5ga_28 *[id=actions]{width:44px;padding:0 2px;position:sticky;right:0;background-color:var(--lmnt-theme-background)}._table_wc5ga_28 tr:hover td[id=actions]{background-color:var(--table-bg-color-hover)}._noBorder_wc5ga_48{border:none}._fullWidth_wc5ga_52{width:100%}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { IsAllowedProps } from '../PermissionChecks/PermissionService';
|
|
3
3
|
|
|
4
4
|
type AllowedProps = {
|
|
5
|
-
neededPermissions:
|
|
6
|
-
|
|
5
|
+
neededPermissions: IsAllowedProps['neededPermissions'];
|
|
6
|
+
entityIds: IsAllowedProps['entityIds'];
|
|
7
7
|
disclaimer?: boolean;
|
|
8
8
|
disclaimerText?: string;
|
|
9
9
|
};
|
|
@@ -11,11 +11,11 @@ type AllowedProps = {
|
|
|
11
11
|
* A component wrapper which takes permissions and an entity id (as a fallback the activeOrganization id is used) the permission is for.
|
|
12
12
|
* Returns the children if the user has the permission for the entity, nothing otherwise (or an optional disclaimer)
|
|
13
13
|
* @param children - the children to return if allowed to see it
|
|
14
|
-
* @param
|
|
14
|
+
* @param entityIds - the entity ids, the permission is for (FarmOrganizationId, VendorOrganizationId or FarmId)
|
|
15
15
|
* @param neededPermissions - the permissions needed to see the children
|
|
16
16
|
* @param disclaimer - if true a disclaimer is shown, otherwise not. (default: false)
|
|
17
17
|
* @param disclaimerText - the text to show in the disclaimer (default: 'You are not allowed to see the content of this section.')
|
|
18
18
|
* @returns
|
|
19
19
|
*/
|
|
20
|
-
export declare const Allowed: ({ children, neededPermissions,
|
|
20
|
+
export declare const Allowed: ({ children, neededPermissions, entityIds, disclaimer, disclaimerText, }: PropsWithChildren<AllowedProps>) => string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import('react').ReactNode> | null | undefined;
|
|
21
21
|
export {};
|
|
@@ -4,10 +4,10 @@ import { useIsAllowed as n } from "../PermissionChecks/PermissionService.js";
|
|
|
4
4
|
const d = ({
|
|
5
5
|
children: o,
|
|
6
6
|
neededPermissions: e,
|
|
7
|
-
|
|
7
|
+
entityIds: t,
|
|
8
8
|
disclaimer: r = !1,
|
|
9
9
|
disclaimerText: l = "You are not allowed to see the content of this section."
|
|
10
|
-
}) => n()(e, t) ? o : r ? /* @__PURE__ */ s(i, { text: l }) : null;
|
|
10
|
+
}) => n()({ neededPermissions: e, entityIds: t }) ? o : r ? /* @__PURE__ */ s(i, { text: l }) : null;
|
|
11
11
|
export {
|
|
12
12
|
d as Allowed
|
|
13
13
|
};
|
|
@@ -8,7 +8,7 @@ l("Test Allowed", () => {
|
|
|
8
8
|
d("should return the children if allowed to see them", () => {
|
|
9
9
|
const r = /* @__PURE__ */ e("div", { children: "Allowed to see children" });
|
|
10
10
|
s(
|
|
11
|
-
/* @__PURE__ */ e(i, { neededPermissions: [o.CurrentUserRead],
|
|
11
|
+
/* @__PURE__ */ e(i, { neededPermissions: [o.CurrentUserRead], entityIds: "General", children: r }),
|
|
12
12
|
{
|
|
13
13
|
userPermissions: {
|
|
14
14
|
General: [o.CurrentUserRead]
|
|
@@ -18,7 +18,7 @@ l("Test Allowed", () => {
|
|
|
18
18
|
}), d("should return empty wrapper when not allowed to see children", () => {
|
|
19
19
|
const r = /* @__PURE__ */ e("div", { children: "Allowed to see children" });
|
|
20
20
|
s(
|
|
21
|
-
/* @__PURE__ */ e(i, { neededPermissions: [o.CurrentUserRead],
|
|
21
|
+
/* @__PURE__ */ e(i, { neededPermissions: [o.CurrentUserRead], entityIds: "General", children: r }),
|
|
22
22
|
{
|
|
23
23
|
userPermissions: {
|
|
24
24
|
General: []
|
|
@@ -33,7 +33,7 @@ l("Test Allowed", () => {
|
|
|
33
33
|
{
|
|
34
34
|
disclaimer: !0,
|
|
35
35
|
neededPermissions: [o.CurrentUserRead],
|
|
36
|
-
|
|
36
|
+
entityIds: "General",
|
|
37
37
|
children: r
|
|
38
38
|
}
|
|
39
39
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ButtonProps } from '@element-public/react-button';
|
|
2
|
-
import {
|
|
2
|
+
import { IsAllowedProps } from '../PermissionChecks/PermissionService';
|
|
3
3
|
|
|
4
4
|
export type AllowedButtonProps = Omit<ButtonProps, 'buttonSize' | 'variant' | 'type' | 'label'> & {
|
|
5
5
|
/**
|
|
@@ -19,7 +19,7 @@ export type AllowedButtonProps = Omit<ButtonProps, 'buttonSize' | 'variant' | 't
|
|
|
19
19
|
/**
|
|
20
20
|
* The entity id, the permission is for (FarmOrganizationId, VendorOrganizationId or FarmLocationId).
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
entityIds: IsAllowedProps['entityIds'];
|
|
23
23
|
/**
|
|
24
24
|
* Id used for linking the button to a form.
|
|
25
25
|
*/
|
|
@@ -36,7 +36,7 @@ export type AllowedButtonProps = Omit<ButtonProps, 'buttonSize' | 'variant' | 't
|
|
|
36
36
|
/**
|
|
37
37
|
* The permissions needed to enable the button. If the array is empty, the button is always enabled.
|
|
38
38
|
*/
|
|
39
|
-
permissions:
|
|
39
|
+
permissions: IsAllowedProps['neededPermissions'];
|
|
40
40
|
/**
|
|
41
41
|
* Changes the the size of the button.
|
|
42
42
|
* Default: 'medium'
|
|
@@ -10,7 +10,7 @@ const c = ({
|
|
|
10
10
|
size: l = "medium",
|
|
11
11
|
isLoading: i = !1,
|
|
12
12
|
...t
|
|
13
|
-
}) => /* @__PURE__ */ e(s, { neededPermissions: t.permissions,
|
|
13
|
+
}) => /* @__PURE__ */ e(s, { neededPermissions: t.permissions, entityIds: t.entityIds, children: /* @__PURE__ */ e(
|
|
14
14
|
r,
|
|
15
15
|
{
|
|
16
16
|
buttonSize: l,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { s as
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { s as e, f as u } from "../../react.esm-Bm0cAgpZ.js";
|
|
3
3
|
import { renderWithPermissions as n } from "../../test-utils.js";
|
|
4
4
|
import { HVMainPermissions as i } from "../../types/Permission.js";
|
|
5
5
|
import { AllowedButton as d } from "./AllowedButton.js";
|
|
6
6
|
import { u as b } from "../../useBreakpoints-MzTZ0tCT.js";
|
|
7
|
-
import { v as l, d as m, b as c, t as r, g as
|
|
7
|
+
import { v as l, d as m, b as c, t as r, g as t } from "../../vi.bdSIJ99Y-B308Q-4w.js";
|
|
8
8
|
l.mock("../../hooks/useBreakpoints", () => ({
|
|
9
9
|
useBreakpoints: l.fn()
|
|
10
10
|
}));
|
|
@@ -18,63 +18,63 @@ m("AllowedButton Test", () => {
|
|
|
18
18
|
});
|
|
19
19
|
}), r("renders button with no permissions required", () => {
|
|
20
20
|
n(
|
|
21
|
-
/* @__PURE__ */
|
|
22
|
-
), e
|
|
21
|
+
/* @__PURE__ */ o(d, { "data-testid": "test", label: "Add", permissions: [], entityIds: "General" })
|
|
22
|
+
), t(e.getByText("Add")).toBeInTheDocument();
|
|
23
23
|
}), r("renders outlined button variant", () => {
|
|
24
24
|
n(
|
|
25
|
-
/* @__PURE__ */
|
|
25
|
+
/* @__PURE__ */ o(
|
|
26
26
|
d,
|
|
27
27
|
{
|
|
28
28
|
"data-testid": "regular-outlined-button",
|
|
29
29
|
label: "Add",
|
|
30
30
|
variant: "outlined",
|
|
31
31
|
permissions: [],
|
|
32
|
-
|
|
32
|
+
entityIds: "General"
|
|
33
33
|
}
|
|
34
34
|
)
|
|
35
35
|
);
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const s = e.getAllByRole("button")[0];
|
|
37
|
+
t(s).toHaveClass("mdc-button--outlined"), t(e.getByTestId("allowed-button-regular-outlined-button")).toBeInTheDocument();
|
|
38
38
|
}), r("renders full-width button", () => {
|
|
39
39
|
n(
|
|
40
|
-
/* @__PURE__ */
|
|
40
|
+
/* @__PURE__ */ o(
|
|
41
41
|
d,
|
|
42
42
|
{
|
|
43
43
|
"data-testid": "regular-button",
|
|
44
44
|
label: "Add",
|
|
45
45
|
fullWidth: !0,
|
|
46
46
|
permissions: [],
|
|
47
|
-
|
|
47
|
+
entityIds: "General"
|
|
48
48
|
}
|
|
49
49
|
)
|
|
50
50
|
);
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
const s = e.getAllByRole("button")[0];
|
|
52
|
+
t(s).toHaveClass("lmnt-button--full-width"), t(e.getByTestId("allowed-button-regular-button")).toBeInTheDocument();
|
|
53
53
|
}), r("calls onClick when clicked", () => {
|
|
54
|
-
const
|
|
54
|
+
const s = l.fn();
|
|
55
55
|
n(
|
|
56
|
-
/* @__PURE__ */
|
|
56
|
+
/* @__PURE__ */ o(
|
|
57
57
|
d,
|
|
58
58
|
{
|
|
59
59
|
"data-testid": "test-onclick-button",
|
|
60
60
|
label: "Add",
|
|
61
|
-
onClick:
|
|
61
|
+
onClick: s,
|
|
62
62
|
permissions: [],
|
|
63
|
-
|
|
63
|
+
entityIds: "General"
|
|
64
64
|
}
|
|
65
65
|
)
|
|
66
66
|
);
|
|
67
|
-
const a =
|
|
68
|
-
u.click(a),
|
|
67
|
+
const a = e.getAllByRole("button")[0];
|
|
68
|
+
u.click(a), t(s).toHaveBeenCalled(), t(e.getByTestId("allowed-button-test-onclick-button")).toBeInTheDocument();
|
|
69
69
|
}), r("renders disabled button when prop is used", () => {
|
|
70
70
|
n(
|
|
71
|
-
/* @__PURE__ */
|
|
71
|
+
/* @__PURE__ */ o(
|
|
72
72
|
d,
|
|
73
73
|
{
|
|
74
74
|
"data-testid": "disabled-button",
|
|
75
75
|
label: "Add",
|
|
76
76
|
permissions: [i.SuperUser],
|
|
77
|
-
|
|
77
|
+
entityIds: "farm-123",
|
|
78
78
|
disabled: !0
|
|
79
79
|
}
|
|
80
80
|
),
|
|
@@ -83,18 +83,18 @@ m("AllowedButton Test", () => {
|
|
|
83
83
|
"farm-123": [i.SuperUser]
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
), e
|
|
87
|
-
const
|
|
88
|
-
|
|
86
|
+
), t(e.getByText("Add")).toBeInTheDocument(), t(e.getByTestId("allowed-button-disabled-button")).toBeInTheDocument();
|
|
87
|
+
const s = e.getAllByRole("button")[0];
|
|
88
|
+
t(s).toHaveAttribute("disabled");
|
|
89
89
|
}), r("hides button when permission is missing", () => {
|
|
90
90
|
n(
|
|
91
|
-
/* @__PURE__ */
|
|
91
|
+
/* @__PURE__ */ o(
|
|
92
92
|
d,
|
|
93
93
|
{
|
|
94
94
|
"data-testid": "missing",
|
|
95
95
|
label: "Add",
|
|
96
96
|
permissions: [i.SuperUser],
|
|
97
|
-
|
|
97
|
+
entityIds: "farm-123"
|
|
98
98
|
}
|
|
99
99
|
),
|
|
100
100
|
{
|
|
@@ -102,16 +102,16 @@ m("AllowedButton Test", () => {
|
|
|
102
102
|
"farm-123": [i.FarmsUpdate, i.FarmsRead]
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
), e
|
|
105
|
+
), t(e.queryByText("Add")).not.toBeInTheDocument(), t(e.queryByTestId("allowed-button-missing")).not.toBeInTheDocument();
|
|
106
106
|
}), r("renders button when permission exists", () => {
|
|
107
107
|
n(
|
|
108
|
-
/* @__PURE__ */
|
|
108
|
+
/* @__PURE__ */ o(
|
|
109
109
|
d,
|
|
110
110
|
{
|
|
111
111
|
"data-testid": "enabled",
|
|
112
112
|
label: "Add",
|
|
113
113
|
permissions: [i.SuperUser],
|
|
114
|
-
|
|
114
|
+
entityIds: "farm-123"
|
|
115
115
|
}
|
|
116
116
|
),
|
|
117
117
|
{
|
|
@@ -119,8 +119,8 @@ m("AllowedButton Test", () => {
|
|
|
119
119
|
"farm-123": [i.SuperUser]
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
), e
|
|
123
|
-
const
|
|
124
|
-
|
|
122
|
+
), t(e.getByText("Add")).toBeInTheDocument(), t(e.getByTestId("allowed-button-enabled")).toBeInTheDocument();
|
|
123
|
+
const s = e.getAllByRole("button")[0];
|
|
124
|
+
t(s).not.toHaveAttribute("disabled");
|
|
125
125
|
});
|
|
126
126
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IconButtonProps } from '@element-public/react-icon-button';
|
|
2
|
-
import {
|
|
2
|
+
import { IsAllowedProps } from '../PermissionChecks/PermissionService';
|
|
3
3
|
|
|
4
4
|
export type AllowedIconButtonProps = Omit<IconButtonProps, 'variant' | 'iconType' | 'iconSize'> & {
|
|
5
5
|
/**
|
|
@@ -9,7 +9,7 @@ export type AllowedIconButtonProps = Omit<IconButtonProps, 'variant' | 'iconType
|
|
|
9
9
|
/**
|
|
10
10
|
* The entity id, the permission is for (FarmOrganizationId, VendorOrganizationId or FarmLocationId).
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
entityIds: IsAllowedProps['entityIds'];
|
|
13
13
|
/**
|
|
14
14
|
* Id used for linking the button to a form.
|
|
15
15
|
*/
|
|
@@ -28,7 +28,7 @@ export type AllowedIconButtonProps = Omit<IconButtonProps, 'variant' | 'iconType
|
|
|
28
28
|
/**
|
|
29
29
|
* The permissions needed to enable the button. If the array is empty, the button is always enabled.
|
|
30
30
|
*/
|
|
31
|
-
permissions:
|
|
31
|
+
permissions: IsAllowedProps['neededPermissions'];
|
|
32
32
|
/**
|
|
33
33
|
* Changes the the size of the icon button.
|
|
34
34
|
* Default: 'medium'
|
|
@@ -7,7 +7,7 @@ const f = ({
|
|
|
7
7
|
iconType: d = "filled",
|
|
8
8
|
size: n = "medium",
|
|
9
9
|
...t
|
|
10
|
-
}) => /* @__PURE__ */ i(l, { neededPermissions: t.permissions,
|
|
10
|
+
}) => /* @__PURE__ */ i(l, { neededPermissions: t.permissions, entityIds: t.entityIds, children: /* @__PURE__ */ i(
|
|
11
11
|
m,
|
|
12
12
|
{
|
|
13
13
|
"data-testid": `allowed-icon-button-${o}`,
|
|
@@ -4,19 +4,19 @@ import { renderWithPermissions as i } from "../../test-utils.js";
|
|
|
4
4
|
import { HVMainPermissions as n } from "../../types/Permission.js";
|
|
5
5
|
import { AllowedIconButton as r } from "./AllowedIconButton.js";
|
|
6
6
|
import { u as c } from "../../useBreakpoints-MzTZ0tCT.js";
|
|
7
|
-
import { v as
|
|
8
|
-
|
|
9
|
-
useBreakpoints:
|
|
7
|
+
import { v as d, d as m, b, t as a, g as e } from "../../vi.bdSIJ99Y-B308Q-4w.js";
|
|
8
|
+
d.mock("../../hooks/useBreakpoints", () => ({
|
|
9
|
+
useBreakpoints: d.fn()
|
|
10
10
|
}));
|
|
11
11
|
m("AllowedIconButton Test", () => {
|
|
12
12
|
b(() => {
|
|
13
|
-
|
|
13
|
+
d.mocked(c).mockReturnValue({
|
|
14
14
|
isDesktop: !0,
|
|
15
15
|
isMobile: !1,
|
|
16
16
|
isTablet: !1,
|
|
17
17
|
isDesktopNavbar: !0
|
|
18
18
|
});
|
|
19
|
-
}),
|
|
19
|
+
}), a("renders icon button with no permissions required", () => {
|
|
20
20
|
i(
|
|
21
21
|
/* @__PURE__ */ s(
|
|
22
22
|
r,
|
|
@@ -24,13 +24,13 @@ m("AllowedIconButton Test", () => {
|
|
|
24
24
|
"data-testid": "icon-button",
|
|
25
25
|
icon: "add",
|
|
26
26
|
permissions: [],
|
|
27
|
-
|
|
27
|
+
entityIds: "General"
|
|
28
28
|
}
|
|
29
29
|
)
|
|
30
30
|
);
|
|
31
31
|
const o = t.getAllByRole("button")[0];
|
|
32
32
|
e(o).toHaveClass("lmnt-icon-button"), e(t.getByTestId("allowed-icon-button-icon-button")).toBeInTheDocument();
|
|
33
|
-
}),
|
|
33
|
+
}), a("renders secondary variant icon button", () => {
|
|
34
34
|
i(
|
|
35
35
|
/* @__PURE__ */ s(
|
|
36
36
|
r,
|
|
@@ -39,14 +39,14 @@ m("AllowedIconButton Test", () => {
|
|
|
39
39
|
icon: "add",
|
|
40
40
|
variant: "filled-secondary",
|
|
41
41
|
permissions: [],
|
|
42
|
-
|
|
42
|
+
entityIds: "General"
|
|
43
43
|
}
|
|
44
44
|
)
|
|
45
45
|
);
|
|
46
46
|
const o = t.getAllByRole("button")[0];
|
|
47
47
|
e(o).toHaveClass("lmnt-icon-button--fill-secondary"), e(t.getByTestId("allowed-icon-button-secondary-button")).toBeInTheDocument();
|
|
48
|
-
}),
|
|
49
|
-
const o =
|
|
48
|
+
}), a("calls onClick when clicked", () => {
|
|
49
|
+
const o = d.fn();
|
|
50
50
|
i(
|
|
51
51
|
/* @__PURE__ */ s(
|
|
52
52
|
r,
|
|
@@ -55,13 +55,13 @@ m("AllowedIconButton Test", () => {
|
|
|
55
55
|
icon: "add",
|
|
56
56
|
onClick: o,
|
|
57
57
|
permissions: [],
|
|
58
|
-
|
|
58
|
+
entityIds: "General"
|
|
59
59
|
}
|
|
60
60
|
)
|
|
61
61
|
);
|
|
62
62
|
const l = t.getAllByRole("button")[0];
|
|
63
63
|
u.click(l), e(o).toHaveBeenCalled(), e(t.getByTestId("allowed-icon-button-test-onclick-button")).toBeInTheDocument();
|
|
64
|
-
}),
|
|
64
|
+
}), a("renders disabled icon button when prop is used", () => {
|
|
65
65
|
i(
|
|
66
66
|
/* @__PURE__ */ s(
|
|
67
67
|
r,
|
|
@@ -69,7 +69,7 @@ m("AllowedIconButton Test", () => {
|
|
|
69
69
|
"data-testid": "disabled-button",
|
|
70
70
|
icon: "add",
|
|
71
71
|
permissions: [n.SuperUser],
|
|
72
|
-
|
|
72
|
+
entityIds: "farm-123",
|
|
73
73
|
disabled: !0
|
|
74
74
|
}
|
|
75
75
|
),
|
|
@@ -81,7 +81,7 @@ m("AllowedIconButton Test", () => {
|
|
|
81
81
|
), e(t.getByTestId("allowed-icon-button-disabled-button")).toBeInTheDocument();
|
|
82
82
|
const o = t.getAllByRole("button")[0];
|
|
83
83
|
e(o).toHaveAttribute("disabled");
|
|
84
|
-
}),
|
|
84
|
+
}), a("hides icon button when permission is missing", () => {
|
|
85
85
|
i(
|
|
86
86
|
/* @__PURE__ */ s(
|
|
87
87
|
r,
|
|
@@ -89,7 +89,7 @@ m("AllowedIconButton Test", () => {
|
|
|
89
89
|
"data-testid": "missing",
|
|
90
90
|
icon: "add",
|
|
91
91
|
permissions: [n.SuperUser],
|
|
92
|
-
|
|
92
|
+
entityIds: "farm-123"
|
|
93
93
|
}
|
|
94
94
|
),
|
|
95
95
|
{
|
|
@@ -98,7 +98,7 @@ m("AllowedIconButton Test", () => {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
), e(t.queryByTestId("allowed-icon-button-missing")).not.toBeInTheDocument();
|
|
101
|
-
}),
|
|
101
|
+
}), a("renders icon button when permission exists", () => {
|
|
102
102
|
i(
|
|
103
103
|
/* @__PURE__ */ s(
|
|
104
104
|
r,
|
|
@@ -106,7 +106,7 @@ m("AllowedIconButton Test", () => {
|
|
|
106
106
|
"data-testid": "enabled",
|
|
107
107
|
icon: "add",
|
|
108
108
|
permissions: [n.SuperUser],
|
|
109
|
-
|
|
109
|
+
entityIds: "farm-123"
|
|
110
110
|
}
|
|
111
111
|
),
|
|
112
112
|
{
|
|
@@ -17,6 +17,7 @@ type BaseViewProps = {
|
|
|
17
17
|
emptyText: string;
|
|
18
18
|
/**
|
|
19
19
|
* pathname of the current route, use react-router to have the best experience (use useLocation and its pathname property)
|
|
20
|
+
* Should be used as a fallback if the user has no permissions to access any of the elements.
|
|
20
21
|
*/
|
|
21
22
|
pathname: string;
|
|
22
23
|
/**
|