@peers-app/peers-ui 0.34.13 → 0.34.14
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.
|
@@ -7,6 +7,7 @@ export interface IActsForYouPanelProps {
|
|
|
7
7
|
/**
|
|
8
8
|
* The package page's "Acts for you" setting, for the group the Packages screen shows. Shown when
|
|
9
9
|
* the package asks to act for the person or already has a grant here; a host without System
|
|
10
|
-
* Delegates shows nothing.
|
|
10
|
+
* Delegates shows nothing. In Personal, the person's other groups follow, each with its own
|
|
11
|
+
* grant: a package installed in Personal can act for them in any of their groups.
|
|
11
12
|
*/
|
|
12
13
|
export declare function ActsForYouPanel(props: IActsForYouPanelProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -5,14 +5,15 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const globals_1 = require("../globals");
|
|
8
|
-
const
|
|
8
|
+
const groups_client_1 = require("../groups/groups-client");
|
|
9
9
|
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
10
10
|
const acts_for_you_control_1 = require("./acts-for-you-control");
|
|
11
11
|
const delegates_ipc_1 = require("./delegates-ipc");
|
|
12
12
|
/**
|
|
13
13
|
* The package page's "Acts for you" setting, for the group the Packages screen shows. Shown when
|
|
14
14
|
* the package asks to act for the person or already has a grant here; a host without System
|
|
15
|
-
* Delegates shows nothing.
|
|
15
|
+
* Delegates shows nothing. In Personal, the person's other groups follow, each with its own
|
|
16
|
+
* grant: a package installed in Personal can act for them in any of their groups.
|
|
16
17
|
*/
|
|
17
18
|
function ActsForYouPanel(props) {
|
|
18
19
|
const [dataContextId, setDataContextId] = (0, react_1.useState)();
|
|
@@ -31,20 +32,21 @@ function ActsForYouPanel(props) {
|
|
|
31
32
|
return (0, jsx_runtime_1.jsx)(ActsForYouPanelIn, { ...props, dataContextId: dataContextId });
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
-
* live one: it reads the grant again and hears its changes.
|
|
35
|
+
* A package's grant in one context. The consumer follows the host connection, so a reconnect
|
|
36
|
+
* gives it a live one: it reads the grant again and hears its changes.
|
|
37
|
+
*
|
|
38
|
+
* @param dataContextId The group, or the personal context.
|
|
39
|
+
* @param packageId The package.
|
|
36
40
|
*/
|
|
37
|
-
function
|
|
38
|
-
const { dataContextId } = props;
|
|
39
|
-
const [groupList] = (0, hooks_1.useObservable)(globals_1.groups);
|
|
41
|
+
function useDelegateGrant(dataContextId, packageId) {
|
|
40
42
|
const { consumer } = (0, use_host_contract_1.useHostContract)((0, delegates_ipc_1.delegatesContractFor)(dataContextId));
|
|
41
43
|
const [state, setState] = (0, react_1.useState)();
|
|
42
|
-
const [
|
|
44
|
+
const [version, setVersion] = (0, react_1.useState)(0);
|
|
43
45
|
(0, react_1.useEffect)(() => {
|
|
44
46
|
if (!consumer)
|
|
45
47
|
return;
|
|
46
48
|
let cancelled = false;
|
|
47
|
-
consumer.tools.getGrant({ packageId
|
|
49
|
+
consumer.tools.getGrant({ packageId }).then((result) => {
|
|
48
50
|
if (!cancelled)
|
|
49
51
|
setState(result);
|
|
50
52
|
}, () => {
|
|
@@ -54,23 +56,50 @@ function ActsForYouPanelIn(props) {
|
|
|
54
56
|
return () => {
|
|
55
57
|
cancelled = true;
|
|
56
58
|
};
|
|
57
|
-
}, [consumer,
|
|
59
|
+
}, [consumer, packageId, version]);
|
|
58
60
|
(0, react_1.useEffect)(() => {
|
|
59
61
|
if (!consumer)
|
|
60
62
|
return;
|
|
61
63
|
const subscription = consumer.events.changed.subscribe((event) => {
|
|
62
|
-
if (event.packageId ===
|
|
63
|
-
|
|
64
|
+
if (event.packageId === packageId && event.dataContextId === dataContextId)
|
|
65
|
+
setVersion((value) => value + 1);
|
|
64
66
|
});
|
|
65
67
|
return () => {
|
|
66
68
|
subscription.unsubscribe();
|
|
67
69
|
};
|
|
68
|
-
}, [consumer,
|
|
70
|
+
}, [consumer, packageId, dataContextId]);
|
|
71
|
+
return { consumer, state, refresh: () => setVersion((value) => value + 1) };
|
|
72
|
+
}
|
|
73
|
+
/** The panel for one group. */
|
|
74
|
+
function ActsForYouPanelIn(props) {
|
|
75
|
+
const { dataContextId } = props;
|
|
76
|
+
const groupList = (0, groups_client_1.useGroups)();
|
|
77
|
+
const { consumer, state, refresh } = useDelegateGrant(dataContextId, props.packageId);
|
|
69
78
|
if (!consumer || !state || (!state.request && !state.grant))
|
|
70
79
|
return null;
|
|
71
|
-
const
|
|
72
|
-
|
|
80
|
+
const inPersonal = dataContextId === globals_1.me?.userId;
|
|
81
|
+
const group = (groupList ?? (0, globals_1.groups)()).find((entry) => entry.groupId === dataContextId);
|
|
82
|
+
const others = inPersonal ? groupList?.filter((entry) => !entry.personal) : undefined;
|
|
83
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mt-3", "data-testid": "acts-for-you-panel", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsx)("h6", { children: "Acts for you" }), state.request && ((0, jsx_runtime_1.jsxs)("p", { className: "small text-muted mb-2", children: [props.packageName, " asks: \u201C", state.request.why, "\u201D"] })), (0, jsx_runtime_1.jsx)(acts_for_you_control_1.ActsForYouControl, { packageName: props.packageName, dataContextName: inPersonal ? "Personal" : group?.name || dataContextId, grant: state.grant, userAccessLevel: state.userAccessLevel ?? 0, onChoose: async (choice) => {
|
|
73
84
|
await (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: props.packageId, dataContextId }, state.grant, choice);
|
|
74
|
-
|
|
75
|
-
} })] }));
|
|
85
|
+
refresh();
|
|
86
|
+
} }), others && others.length > 0 && ((0, jsx_runtime_1.jsx)(OtherGroups, { packageId: props.packageId, packageName: props.packageName, groups: others }))] }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The person's other groups, for a package installed in their Personal: a line each saying what
|
|
90
|
+
* the package may do there, with the group's own control behind "Change". Each starts Off.
|
|
91
|
+
*/
|
|
92
|
+
function OtherGroups(props) {
|
|
93
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mt-3", "data-testid": "acts-for-you-groups", children: [(0, jsx_runtime_1.jsx)("div", { className: "small fw-semibold mb-1", children: "In your other groups" }), (0, jsx_runtime_1.jsx)("ul", { className: "list-unstyled mb-0", children: props.groups.map((group) => ((0, jsx_runtime_1.jsx)(OtherGroupGrant, { packageId: props.packageId, packageName: props.packageName, group: group }, group.groupId))) }), (0, jsx_runtime_1.jsx)("div", { className: "form-text", children: "Each group has its own setting, and each applies on this device only." })] }));
|
|
94
|
+
}
|
|
95
|
+
/** One group's line in {@link OtherGroups}. */
|
|
96
|
+
function OtherGroupGrant(props) {
|
|
97
|
+
const { group } = props;
|
|
98
|
+
const { consumer, state, refresh } = useDelegateGrant(group.groupId, props.packageId);
|
|
99
|
+
const [open, setOpen] = (0, react_1.useState)(false);
|
|
100
|
+
const name = group.name || group.groupId;
|
|
101
|
+
return ((0, jsx_runtime_1.jsxs)("li", { className: "mb-1", "data-testid": `acts-for-you-group-${group.groupId}`, children: [(0, jsx_runtime_1.jsxs)("span", { children: [name, ": ", (0, jsx_runtime_1.jsx)("strong", { children: state ? (0, acts_for_you_control_1.actsForYouSummary)(state.grant) : "…" })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm py-0", disabled: !consumer || !state, "aria-expanded": open, onClick: () => setOpen((value) => !value), children: open ? "Done" : "Change" }), open && consumer && state && ((0, jsx_runtime_1.jsx)("div", { className: "ms-3 mt-1 mb-2", children: (0, jsx_runtime_1.jsx)(acts_for_you_control_1.ActsForYouControl, { packageName: props.packageName, dataContextName: name, grant: state.grant, userAccessLevel: state.userAccessLevel ?? 0, onChoose: async (choice) => {
|
|
102
|
+
await (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: props.packageId, dataContextId: group.groupId }, state.grant, choice);
|
|
103
|
+
refresh();
|
|
104
|
+
} }) }))] }));
|
|
76
105
|
}
|
|
@@ -10,8 +10,10 @@ export declare function DelegateRequestDialog(): import("react/jsx-runtime").JSX
|
|
|
10
10
|
/** Props for {@link DelegateRequestDialogView}. */
|
|
11
11
|
export interface IDelegateRequestDialogViewProps {
|
|
12
12
|
request: IDelegatePendingRequest;
|
|
13
|
+
/** Whether the request is for the person's Personal, whose package page lists their groups. */
|
|
14
|
+
inPersonal?: boolean;
|
|
13
15
|
onChoose: React.ComponentProps<typeof ActsForYouControl>["onChoose"];
|
|
14
16
|
onClose: () => void;
|
|
15
17
|
}
|
|
16
18
|
/** The dialog's content for one request. Focus starts on "Not now" and stays inside; Escape closes. */
|
|
17
|
-
export declare function DelegateRequestDialogView({ request, onChoose, onClose, }: IDelegateRequestDialogViewProps): React.ReactPortal;
|
|
19
|
+
export declare function DelegateRequestDialogView({ request, inPersonal, onChoose, onClose, }: IDelegateRequestDialogViewProps): React.ReactPortal;
|
|
@@ -5,6 +5,7 @@ exports.DelegateRequestDialogView = DelegateRequestDialogView;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const react_dom_1 = require("react-dom");
|
|
8
|
+
const globals_1 = require("../globals");
|
|
8
9
|
const hooks_1 = require("../hooks");
|
|
9
10
|
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
10
11
|
const global_overlays_1 = require("../root-layout/global-overlays");
|
|
@@ -20,10 +21,10 @@ function DelegateRequestDialog() {
|
|
|
20
21
|
const [request] = (0, hooks_1.useObservable)(consumer?.observables.pendingRequest ?? null);
|
|
21
22
|
if (!consumer || !request)
|
|
22
23
|
return null;
|
|
23
|
-
return ((0, jsx_runtime_1.jsx)(DelegateRequestDialogView, { request: request, onChoose: (choice) => (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: request.packageId, dataContextId: request.dataContextId }, request.grant, choice), onClose: () => void consumer.tools.dismissRequest({ requestId: request.requestId }) }, request.requestId));
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(DelegateRequestDialogView, { request: request, inPersonal: request.dataContextId === globals_1.me?.userId, onChoose: (choice) => (0, delegates_ipc_1.applyActsForYouChoice)(consumer, { packageId: request.packageId, dataContextId: request.dataContextId }, request.grant, choice), onClose: () => void consumer.tools.dismissRequest({ requestId: request.requestId }) }, request.requestId));
|
|
24
25
|
}
|
|
25
26
|
/** The dialog's content for one request. Focus starts on "Not now" and stays inside; Escape closes. */
|
|
26
|
-
function DelegateRequestDialogView({ request, onChoose, onClose, }) {
|
|
27
|
+
function DelegateRequestDialogView({ request, inPersonal = false, onChoose, onClose, }) {
|
|
27
28
|
const notNowRef = (0, react_1.useRef)(null);
|
|
28
29
|
(0, react_1.useEffect)(() => {
|
|
29
30
|
notNowRef.current?.focus();
|
|
@@ -55,6 +56,8 @@ function DelegateRequestDialogView({ request, onChoose, onClose, }) {
|
|
|
55
56
|
(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
|
|
56
57
|
if (event.target === event.currentTarget)
|
|
57
58
|
onClose();
|
|
58
|
-
}, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-delegate-request-title", onKeyDown: onKeyDown, "data-testid": "delegate-request-dialog", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-head", children: (0, jsx_runtime_1.jsxs)("h3", { id: "peers-delegate-request-title", children: ["Let ", name, " act for you in ", request.dataContextName, "?"] }) }), (0, jsx_runtime_1.jsxs)("p", { children: [name, " asks for ", (0, delegates_ipc_1.actsForYouLabel)(request.request.level), ": \u201C", request.request.why, "\u201D"] }), (0, jsx_runtime_1.jsxs)("p", { children: ["It would use the tools your other apps provide, such as Tasks, Calendar and Notes, as you, up to the level you pick. You can change it any time on ", name, "'s page in Packages
|
|
59
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-delegate-request-title", onKeyDown: onKeyDown, "data-testid": "delegate-request-dialog", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-head", children: (0, jsx_runtime_1.jsxs)("h3", { id: "peers-delegate-request-title", children: ["Let ", name, " act for you in ", request.dataContextName, "?"] }) }), (0, jsx_runtime_1.jsxs)("p", { children: [name, " asks for ", (0, delegates_ipc_1.actsForYouLabel)(request.request.level), ": \u201C", request.request.why, "\u201D"] }), (0, jsx_runtime_1.jsxs)("p", { children: ["It would use the tools your other apps provide, such as Tasks, Calendar and Notes, as you, up to the level you pick. You can change it any time on ", name, "'s page in Packages", inPersonal
|
|
60
|
+
? ", where you can also let it act for you in your other groups, each on its own."
|
|
61
|
+
: "."] }), (0, jsx_runtime_1.jsx)(acts_for_you_control_1.ActsForYouControl, { packageName: name, dataContextName: request.dataContextName, grant: request.grant, userAccessLevel: request.userAccessLevel, onChoose: onChoose }), (0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-actions mt-3", children: (0, jsx_runtime_1.jsx)("button", { ref: notNowRef, type: "button", className: "btn peers-apps-ghost", onClick: onClose, children: "Not now" }) })] }) }), document.body);
|
|
59
62
|
}
|
|
60
63
|
(0, global_overlays_1.registerGlobalOverlay)("system-delegates-request", DelegateRequestDialog);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.14",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.34.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.34.14",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.34.
|
|
50
|
+
"@peers-app/peers-sdk": "0.34.14",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|