@alepha/ui 0.31.0 → 0.33.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/README.md +1 -1
- package/dist/account/AccountConnections.js +1 -1
- package/dist/account/AccountConnections.js.map +1 -1
- package/dist/account/AccountDeleteDialog.d.ts.map +1 -1
- package/dist/account/AccountDeleteDialog.js +17 -17
- package/dist/account/AccountDeleteDialog.js.map +1 -1
- package/dist/account/AccountKeys.js +2 -2
- package/dist/account/AccountKeys.js.map +1 -1
- package/dist/account/AccountMfaDialog.d.ts.map +1 -1
- package/dist/account/AccountMfaDialog.js +19 -25
- package/dist/account/AccountMfaDialog.js.map +1 -1
- package/dist/account/AccountPasswordDialog.d.ts.map +1 -1
- package/dist/account/AccountPasswordDialog.js +25 -24
- package/dist/account/AccountPasswordDialog.js.map +1 -1
- package/dist/account/AccountProfile.d.ts.map +1 -1
- package/dist/account/AccountProfile.js +17 -24
- package/dist/account/AccountProfile.js.map +1 -1
- package/dist/account/AccountSecurity.d.ts.map +1 -1
- package/dist/account/AccountSecurity.js +21 -19
- package/dist/account/AccountSecurity.js.map +1 -1
- package/dist/account/AccountSessions.js +1 -1
- package/dist/account/AccountSessions.js.map +1 -1
- package/dist/account/ApiKeyCreateDialog.d.ts.map +1 -1
- package/dist/account/ApiKeyCreateDialog.js +8 -12
- package/dist/account/ApiKeyCreateDialog.js.map +1 -1
- package/dist/admin/AdminFiles.js +1 -1
- package/dist/admin/AdminFiles.js.map +1 -1
- package/dist/admin/AdminJobs.js +1 -1
- package/dist/admin/AdminJobs.js.map +1 -1
- package/dist/admin/AdminKeys.js +1 -1
- package/dist/admin/AdminKeys.js.map +1 -1
- package/dist/admin/AdminParameters.d.ts.map +1 -1
- package/dist/admin/AdminParameters.js +7 -5
- package/dist/admin/AdminParameters.js.map +1 -1
- package/dist/admin/AdminParametersTreeFooterActions.d.ts +2 -2
- package/dist/admin/AdminParametersTreeFooterActions.d.ts.map +1 -1
- package/dist/admin/AdminParametersTreeFooterActions.js.map +1 -1
- package/dist/admin/AdminParametersTreePane.d.ts +2 -2
- package/dist/admin/AdminParametersTreePane.d.ts.map +1 -1
- package/dist/admin/AdminParametersTreePane.js.map +1 -1
- package/dist/admin/AdminRouter.d.ts +1 -3
- package/dist/admin/AdminRouter.d.ts.map +1 -1
- package/dist/admin/AdminRouter.js +2 -4
- package/dist/admin/AdminRouter.js.map +1 -1
- package/dist/admin/AdminSessions.js +1 -1
- package/dist/admin/AdminSessions.js.map +1 -1
- package/dist/admin/AdminUserAvatarControl.d.ts.map +1 -1
- package/dist/admin/AdminUserAvatarControl.js +9 -16
- package/dist/admin/AdminUserAvatarControl.js.map +1 -1
- package/dist/admin/AdminUserDetail.js +4 -4
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/admin/AdminUsers.d.ts.map +1 -1
- package/dist/admin/AdminUsers.js +10 -12
- package/dist/admin/AdminUsers.js.map +1 -1
- package/dist/admin/AdminUsersRolesPicker.d.ts +5 -1
- package/dist/admin/AdminUsersRolesPicker.d.ts.map +1 -1
- package/dist/admin/AdminUsersRolesPicker.js +2 -3
- package/dist/admin/AdminUsersRolesPicker.js.map +1 -1
- package/dist/admin/analytics/QueryPanel.js +1 -1
- package/dist/admin/analytics/QueryPanel.js.map +1 -1
- package/dist/admin/useConfirmedAction.d.ts +8 -2
- package/dist/admin/useConfirmedAction.d.ts.map +1 -1
- package/dist/admin/useConfirmedAction.js +15 -4
- package/dist/admin/useConfirmedAction.js.map +1 -1
- package/dist/auth/AuthLogin.d.ts.map +1 -1
- package/dist/auth/AuthLogin.js +4 -4
- package/dist/auth/AuthLogin.js.map +1 -1
- package/dist/auth/AuthRegister.js.map +1 -1
- package/dist/form/AutoForm.js +1 -1
- package/dist/form/AutoForm.js.map +1 -1
- package/dist/form/Control.d.ts.map +1 -1
- package/dist/form/Control.js +11 -1
- package/dist/form/Control.js.map +1 -1
- package/dist/form/ControlArray.js +5 -5
- package/dist/form/ControlArray.js.map +1 -1
- package/dist/form/ControlSelect.js +2 -2
- package/dist/form/ControlSelect.js.map +1 -1
- package/dist/form/ControlUpload.d.ts +1 -1
- package/dist/form/ControlUpload.js.map +1 -1
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +0 -9
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/organizations/MyOrganizationInvitations.js +2 -2
- package/dist/organizations/MyOrganizationInvitations.js.map +1 -1
- package/dist/organizations/OrganizationInviteDialog.js +1 -1
- package/dist/organizations/OrganizationInviteDialog.js.map +1 -1
- package/dist/organizations/OrganizationMembers.js +1 -1
- package/dist/organizations/OrganizationMembers.js.map +1 -1
- package/dist/organizations/OrganizationPendingInvitations.js +1 -1
- package/dist/organizations/OrganizationPendingInvitations.js.map +1 -1
- package/dist/organizations/OrganizationRanks.js +3 -3
- package/dist/organizations/OrganizationRanks.js.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts +6 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.js +13 -13
- package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
- package/dist/organizations/useRevokeOrganizationInvitation.d.ts +7 -1
- package/dist/organizations/useRevokeOrganizationInvitation.d.ts.map +1 -1
- package/dist/organizations/useRevokeOrganizationInvitation.js +13 -2
- package/dist/organizations/useRevokeOrganizationInvitation.js.map +1 -1
- package/dist/shell/ButtonUser.d.ts +1 -2
- package/dist/shell/ButtonUser.d.ts.map +1 -1
- package/dist/shell/ButtonUser.js +14 -42
- package/dist/shell/ButtonUser.js.map +1 -1
- package/dist/shell/ButtonUserContent.d.ts +13 -0
- package/dist/shell/ButtonUserContent.d.ts.map +1 -0
- package/dist/shell/ButtonUserContent.js +52 -0
- package/dist/shell/ButtonUserContent.js.map +1 -0
- package/dist/shell/ButtonUserPlaceholder.d.ts +14 -0
- package/dist/shell/ButtonUserPlaceholder.d.ts.map +1 -0
- package/dist/shell/ButtonUserPlaceholder.js +17 -0
- package/dist/shell/ButtonUserPlaceholder.js.map +1 -0
- package/dist/styles.css +94 -0
- package/dist/table/DataTable.js +1 -1
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableFilterBar.js +2 -2
- package/dist/table/DataTableFilterBar.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +1 -1
- package/dist/table/dataTableTypes.d.ts +3 -3
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +3 -1
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableRefresh.js +2 -2
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useDataTableSummary.d.ts.map +1 -1
- package/dist/table/useDataTableSummary.js +2 -1
- package/dist/table/useDataTableSummary.js.map +1 -1
- package/package.json +9 -9
- package/src/account/AccountConnections.tsx +1 -1
- package/src/account/AccountDeleteDialog.tsx +25 -31
- package/src/account/AccountKeys.tsx +2 -2
- package/src/account/AccountMfaDialog.tsx +33 -27
- package/src/account/AccountPasswordDialog.tsx +36 -39
- package/src/account/AccountProfile.tsx +29 -43
- package/src/account/AccountSecurity.tsx +57 -64
- package/src/account/AccountSessions.tsx +1 -1
- package/src/account/ApiKeyCreateDialog.tsx +12 -20
- package/src/account/__tests__/AccountRouter.spec.ts +2 -1
- package/src/admin/AdminFiles.tsx +1 -1
- package/src/admin/AdminJobs.tsx +1 -1
- package/src/admin/AdminKeys.tsx +1 -1
- package/src/admin/AdminParameters.tsx +7 -5
- package/src/admin/AdminParametersTreeFooterActions.tsx +2 -2
- package/src/admin/AdminParametersTreePane.tsx +2 -2
- package/src/admin/AdminRouter.tsx +2 -4
- package/src/admin/AdminSessions.tsx +1 -1
- package/src/admin/AdminUserAvatarControl.tsx +17 -22
- package/src/admin/AdminUserDetail.tsx +4 -4
- package/src/admin/AdminUsers.tsx +10 -12
- package/src/admin/AdminUsersRolesPicker.tsx +11 -4
- package/src/admin/__tests__/AdminRouter.spec.ts +3 -2
- package/src/admin/analytics/QueryPanel.tsx +1 -1
- package/src/admin/useConfirmedAction.tsx +24 -10
- package/src/auth/AuthLogin.tsx +10 -9
- package/src/auth/AuthRegister.tsx +2 -2
- package/src/form/AutoForm.tsx +1 -1
- package/src/form/Control.tsx +14 -1
- package/src/form/ControlArray.tsx +5 -5
- package/src/form/ControlSelect.tsx +2 -2
- package/src/form/ControlUpload.tsx +1 -1
- package/src/form/__tests__/ControlArrayChildChange.browser.spec.tsx +1 -1
- package/src/form/__tests__/ControlVerbatim.browser.spec.tsx +71 -0
- package/src/i18n/fr/uiFr.ts +0 -9
- package/src/organizations/MyOrganizationInvitations.tsx +2 -2
- package/src/organizations/OrganizationInviteDialog.tsx +1 -1
- package/src/organizations/OrganizationMembers.tsx +1 -1
- package/src/organizations/OrganizationPendingInvitations.tsx +1 -1
- package/src/organizations/OrganizationRanks.tsx +3 -3
- package/src/organizations/useInviteOrganizationMember.ts +22 -15
- package/src/organizations/useRevokeOrganizationInvitation.ts +23 -4
- package/src/shell/ButtonUser.tsx +14 -79
- package/src/shell/ButtonUserContent.tsx +92 -0
- package/src/shell/ButtonUserPlaceholder.tsx +25 -0
- package/src/shell/__tests__/ActionErrorToaster.browser.spec.tsx +1 -1
- package/src/shell/__tests__/ActionErrorToasterHandled.browser.spec.tsx +1 -2
- package/src/shell/__tests__/AppShell.pageCache.spec.tsx +67 -0
- package/src/styles.css +94 -0
- package/src/table/DataTable.tsx +1 -1
- package/src/table/DataTableFilterBar.tsx +2 -2
- package/src/table/__tests__/DataTableFilterDateRange.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableQuerySeed.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableShareFilters.browser.spec.tsx +1 -1
- package/src/table/dataTableBaseProps.ts +1 -1
- package/src/table/dataTableTypes.ts +3 -3
- package/src/table/useDataTableData.ts +2 -0
- package/src/table/useDataTableRefresh.ts +3 -3
- package/src/table/useDataTableSummary.ts +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { OrganizationInvitationController } from "alepha/api/organizations";
|
|
2
|
-
import { useAction, useClient } from "alepha/react";
|
|
2
|
+
import { type RunResult, useAction, useClient } from "alepha/react";
|
|
3
3
|
import { useI18n } from "alepha/react/i18n";
|
|
4
|
+
import { useCallback } from "react";
|
|
4
5
|
|
|
5
6
|
import { useToast } from "../core/useToast.tsx";
|
|
6
7
|
|
|
@@ -15,13 +16,17 @@ export interface InviteOrganizationMember {
|
|
|
15
16
|
* because a rank says what you may do as staff and a role says whether you
|
|
16
17
|
* are a coach, and the framework has no business knowing that club has
|
|
17
18
|
* coaches.
|
|
19
|
+
*
|
|
20
|
+
* Resolves `{ ok: true }` once sent, `{ ok: false, reason: "cancelled" }`
|
|
21
|
+
* when a local check refused it (an empty address, toasted here), and
|
|
22
|
+
* `useAction`'s other results otherwise.
|
|
18
23
|
*/
|
|
19
24
|
invite: (
|
|
20
25
|
organizationId: string,
|
|
21
26
|
email: string,
|
|
22
27
|
rank: string | undefined,
|
|
23
28
|
metadata?: Record<string, unknown>,
|
|
24
|
-
) => Promise<
|
|
29
|
+
) => Promise<RunResult<void>>;
|
|
25
30
|
loading: boolean;
|
|
26
31
|
can: boolean;
|
|
27
32
|
}
|
|
@@ -40,18 +45,7 @@ export const useInviteOrganizationMember = (): InviteOrganizationMember => {
|
|
|
40
45
|
boolean
|
|
41
46
|
>(
|
|
42
47
|
{
|
|
43
|
-
handler: async (organizationId, email, rank,
|
|
44
|
-
/**
|
|
45
|
-
* ⚠️ `useAction` appends `{ signal }` as the LAST argument to the
|
|
46
|
-
* handler, so a caller passing three arguments lands its abort signal
|
|
47
|
-
* in this fourth parameter. Reading it as metadata put an
|
|
48
|
-
* `AbortSignal` on the invitation row.
|
|
49
|
-
*
|
|
50
|
-
* Hence the shape check rather than a plain `?? undefined`: an
|
|
51
|
-
* application's metadata is its own object, and the framework's is the
|
|
52
|
-
* one carrying `signal`.
|
|
53
|
-
*/
|
|
54
|
-
const metadata = passed && !("signal" in passed) ? passed : undefined;
|
|
48
|
+
handler: async (_ctx, organizationId, email, rank, metadata) => {
|
|
55
49
|
const trimmed = email.trim();
|
|
56
50
|
if (!trimmed) {
|
|
57
51
|
toaster.error(
|
|
@@ -81,8 +75,21 @@ export const useInviteOrganizationMember = (): InviteOrganizationMember => {
|
|
|
81
75
|
[api, toaster, tr],
|
|
82
76
|
);
|
|
83
77
|
|
|
78
|
+
const invite = useCallback(
|
|
79
|
+
async (
|
|
80
|
+
...args: Parameters<typeof action.run>
|
|
81
|
+
): Promise<RunResult<void>> => {
|
|
82
|
+
const result = await action.run(...args);
|
|
83
|
+
if (!result.ok) return result;
|
|
84
|
+
return result.value
|
|
85
|
+
? { ok: true, value: undefined }
|
|
86
|
+
: { ok: false, reason: "cancelled" };
|
|
87
|
+
},
|
|
88
|
+
[action.run],
|
|
89
|
+
);
|
|
90
|
+
|
|
84
91
|
return {
|
|
85
|
-
invite
|
|
92
|
+
invite,
|
|
86
93
|
loading: action.loading,
|
|
87
94
|
can: api.createOrganizationInvitation.can(),
|
|
88
95
|
};
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import type { OrganizationInvitationController } from "alepha/api/organizations";
|
|
2
|
-
import { useAction, useClient } from "alepha/react";
|
|
2
|
+
import { type RunResult, useAction, useClient } from "alepha/react";
|
|
3
3
|
import { useI18n } from "alepha/react/i18n";
|
|
4
|
+
import { useCallback } from "react";
|
|
4
5
|
|
|
5
6
|
import { useDialog } from "../core/useDialog.tsx";
|
|
6
7
|
import { useToast } from "../core/useToast.tsx";
|
|
7
8
|
|
|
8
9
|
export interface RevokeOrganizationInvitation {
|
|
10
|
+
/**
|
|
11
|
+
* Ask, then revoke. Resolves `{ ok: true }` once revoked,
|
|
12
|
+
* `{ ok: false, reason: "cancelled" }` when the user declined the confirm,
|
|
13
|
+
* and `useAction`'s other results otherwise.
|
|
14
|
+
*/
|
|
9
15
|
revoke: (
|
|
10
16
|
organizationId: string,
|
|
11
17
|
invitationId: string,
|
|
12
18
|
email: string,
|
|
13
|
-
) => Promise<
|
|
19
|
+
) => Promise<RunResult<void>>;
|
|
14
20
|
loading: boolean;
|
|
15
21
|
can: boolean;
|
|
16
22
|
}
|
|
@@ -26,7 +32,7 @@ export const useRevokeOrganizationInvitation =
|
|
|
26
32
|
boolean
|
|
27
33
|
>(
|
|
28
34
|
{
|
|
29
|
-
handler: async (organizationId, invitationId, email) => {
|
|
35
|
+
handler: async (_ctx, organizationId, invitationId, email) => {
|
|
30
36
|
const confirmed = await dialog.confirm({
|
|
31
37
|
title: tr("organizations.invitations.revokeTitle", {
|
|
32
38
|
default: "Revoke the invitation for $1?",
|
|
@@ -58,8 +64,21 @@ export const useRevokeOrganizationInvitation =
|
|
|
58
64
|
[api, dialog, toaster, tr],
|
|
59
65
|
);
|
|
60
66
|
|
|
67
|
+
const revoke = useCallback(
|
|
68
|
+
async (
|
|
69
|
+
...args: Parameters<typeof action.run>
|
|
70
|
+
): Promise<RunResult<void>> => {
|
|
71
|
+
const result = await action.run(...args);
|
|
72
|
+
if (!result.ok) return result;
|
|
73
|
+
return result.value
|
|
74
|
+
? { ok: true, value: undefined }
|
|
75
|
+
: { ok: false, reason: "cancelled" };
|
|
76
|
+
},
|
|
77
|
+
[action.run],
|
|
78
|
+
);
|
|
79
|
+
|
|
61
80
|
return {
|
|
62
|
-
revoke
|
|
81
|
+
revoke,
|
|
63
82
|
loading: action.loading,
|
|
64
83
|
can: api.revokeOrganizationInvitation.can(),
|
|
65
84
|
};
|
package/src/shell/ButtonUser.tsx
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
void React;
|
|
4
|
-
|
|
5
|
-
import { useAuth } from "alepha/react/auth";
|
|
6
|
-
import { LogIn, User } from "lucide-react";
|
|
1
|
+
import { Personal } from "alepha/react";
|
|
7
2
|
import type { ReactNode } from "react";
|
|
8
3
|
|
|
9
|
-
import { Button } from "../core/Button.tsx";
|
|
10
|
-
import {
|
|
11
|
-
DropdownMenu,
|
|
12
|
-
DropdownMenuContent,
|
|
13
|
-
DropdownMenuTrigger,
|
|
14
|
-
} from "../core/DropdownMenu.tsx";
|
|
15
|
-
import { Tooltip, TooltipContent, TooltipTrigger } from "../core/Tooltip.tsx";
|
|
16
|
-
import { UserAvatar } from "../core/UserAvatar.tsx";
|
|
17
4
|
import { ButtonUserAccountMenuItem } from "./ButtonUserAccountMenuItem.tsx";
|
|
18
5
|
import { ButtonUserAdminMenuItem } from "./ButtonUserAdminMenuItem.tsx";
|
|
19
|
-
import {
|
|
6
|
+
import { ButtonUserContent } from "./ButtonUserContent.tsx";
|
|
20
7
|
import { ButtonUserEmail } from "./ButtonUserEmail.tsx";
|
|
21
8
|
import { ButtonUserLogoutMenuItem } from "./ButtonUserLogoutMenuItem.tsx";
|
|
9
|
+
import { ButtonUserPlaceholder } from "./ButtonUserPlaceholder.tsx";
|
|
22
10
|
|
|
23
11
|
export interface ButtonUserProps {
|
|
24
12
|
/**
|
|
@@ -105,71 +93,18 @@ export interface ButtonUserProps {
|
|
|
105
93
|
* <DropdownMenuSeparator />
|
|
106
94
|
* <ButtonUser.LogoutMenuItem />
|
|
107
95
|
* </ButtonUser>
|
|
96
|
+
*
|
|
97
|
+
* The button reads the visitor, so it is wrapped in `<Personal>`: a page
|
|
98
|
+
* showing it is still cached for everyone (#E78), with a placeholder of the
|
|
99
|
+
* same size in the shared HTML, replaced by the real button right after
|
|
100
|
+
* hydration from the visitor's own state. On a page that is personal anyway,
|
|
101
|
+
* the server renders the real button.
|
|
108
102
|
*/
|
|
109
|
-
export const ButtonUser = (props: ButtonUserProps) =>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<Tooltip>
|
|
116
|
-
<TooltipTrigger
|
|
117
|
-
render={
|
|
118
|
-
<Button
|
|
119
|
-
variant={props.variant ?? "minimal"}
|
|
120
|
-
size="icon"
|
|
121
|
-
aria-label={signInLabel}
|
|
122
|
-
disabled={!props.onSignIn}
|
|
123
|
-
onClick={props.onSignIn}
|
|
124
|
-
/>
|
|
125
|
-
}
|
|
126
|
-
>
|
|
127
|
-
<LogIn className="size-4" />
|
|
128
|
-
</TooltipTrigger>
|
|
129
|
-
<TooltipContent>{signInLabel}</TooltipContent>
|
|
130
|
-
</Tooltip>
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const menuLabel = props.menuLabel ?? "Account menu";
|
|
135
|
-
const face =
|
|
136
|
-
props.avatar ??
|
|
137
|
-
(auth.user.picture ? (
|
|
138
|
-
<UserAvatar fileId={auth.user.picture} className="size-7" />
|
|
139
|
-
) : (
|
|
140
|
-
<User className="size-4" />
|
|
141
|
-
));
|
|
142
|
-
return (
|
|
143
|
-
<DropdownMenu>
|
|
144
|
-
<Tooltip>
|
|
145
|
-
<TooltipTrigger
|
|
146
|
-
render={
|
|
147
|
-
<DropdownMenuTrigger
|
|
148
|
-
render={
|
|
149
|
-
<Button
|
|
150
|
-
variant={props.variant ?? "minimal"}
|
|
151
|
-
size="icon"
|
|
152
|
-
aria-label={menuLabel}
|
|
153
|
-
/>
|
|
154
|
-
}
|
|
155
|
-
/>
|
|
156
|
-
}
|
|
157
|
-
>
|
|
158
|
-
{/* The tooltip and `aria-label` are untouched by the avatar: a
|
|
159
|
-
face is not a label, and "Account menu" is still the accessible
|
|
160
|
-
name of the button. */}
|
|
161
|
-
{face}
|
|
162
|
-
</TooltipTrigger>
|
|
163
|
-
<TooltipContent>{menuLabel}</TooltipContent>
|
|
164
|
-
</Tooltip>
|
|
165
|
-
<DropdownMenuContent align="end" className="w-56">
|
|
166
|
-
{props.children ?? (
|
|
167
|
-
<ButtonUserDefaultMenu onAdminClick={props.onAdminClick} />
|
|
168
|
-
)}
|
|
169
|
-
</DropdownMenuContent>
|
|
170
|
-
</DropdownMenu>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
103
|
+
export const ButtonUser = (props: ButtonUserProps) => (
|
|
104
|
+
<Personal fallback={<ButtonUserPlaceholder variant={props.variant} />}>
|
|
105
|
+
<ButtonUserContent {...props} />
|
|
106
|
+
</Personal>
|
|
107
|
+
);
|
|
173
108
|
|
|
174
109
|
ButtonUser.Email = ButtonUserEmail;
|
|
175
110
|
ButtonUser.AdminMenuItem = ButtonUserAdminMenuItem;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { useAuth } from "alepha/react/auth";
|
|
6
|
+
import { LogIn, User } from "lucide-react";
|
|
7
|
+
|
|
8
|
+
import { Button } from "../core/Button.tsx";
|
|
9
|
+
import {
|
|
10
|
+
DropdownMenu,
|
|
11
|
+
DropdownMenuContent,
|
|
12
|
+
DropdownMenuTrigger,
|
|
13
|
+
} from "../core/DropdownMenu.tsx";
|
|
14
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../core/Tooltip.tsx";
|
|
15
|
+
import { UserAvatar } from "../core/UserAvatar.tsx";
|
|
16
|
+
import type { ButtonUserProps } from "./ButtonUser.tsx";
|
|
17
|
+
import { ButtonUserDefaultMenu } from "./ButtonUserDefaultMenu.tsx";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The account button itself. See {@link ButtonUserProps}.
|
|
21
|
+
*/
|
|
22
|
+
export type ButtonUserContentProps = ButtonUserProps;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What `ButtonUser` renders once it may read the visitor: the sign-in icon
|
|
26
|
+
* when logged out, the avatar and its menu when logged in. Wrapped in
|
|
27
|
+
* `<Personal>` by `ButtonUser`, so a page showing it stays shareable.
|
|
28
|
+
*/
|
|
29
|
+
export const ButtonUserContent = (props: ButtonUserContentProps) => {
|
|
30
|
+
const auth = useAuth();
|
|
31
|
+
|
|
32
|
+
if (!auth.user) {
|
|
33
|
+
const signInLabel = props.signInLabel ?? "Sign in";
|
|
34
|
+
return (
|
|
35
|
+
<Tooltip>
|
|
36
|
+
<TooltipTrigger
|
|
37
|
+
render={
|
|
38
|
+
<Button
|
|
39
|
+
variant={props.variant ?? "minimal"}
|
|
40
|
+
size="icon"
|
|
41
|
+
aria-label={signInLabel}
|
|
42
|
+
disabled={!props.onSignIn}
|
|
43
|
+
onClick={props.onSignIn}
|
|
44
|
+
/>
|
|
45
|
+
}
|
|
46
|
+
>
|
|
47
|
+
<LogIn className="size-4" />
|
|
48
|
+
</TooltipTrigger>
|
|
49
|
+
<TooltipContent>{signInLabel}</TooltipContent>
|
|
50
|
+
</Tooltip>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const menuLabel = props.menuLabel ?? "Account menu";
|
|
55
|
+
const face =
|
|
56
|
+
props.avatar ??
|
|
57
|
+
(auth.user.picture ? (
|
|
58
|
+
<UserAvatar fileId={auth.user.picture} className="size-7" />
|
|
59
|
+
) : (
|
|
60
|
+
<User className="size-4" />
|
|
61
|
+
));
|
|
62
|
+
return (
|
|
63
|
+
<DropdownMenu>
|
|
64
|
+
<Tooltip>
|
|
65
|
+
<TooltipTrigger
|
|
66
|
+
render={
|
|
67
|
+
<DropdownMenuTrigger
|
|
68
|
+
render={
|
|
69
|
+
<Button
|
|
70
|
+
variant={props.variant ?? "minimal"}
|
|
71
|
+
size="icon"
|
|
72
|
+
aria-label={menuLabel}
|
|
73
|
+
/>
|
|
74
|
+
}
|
|
75
|
+
/>
|
|
76
|
+
}
|
|
77
|
+
>
|
|
78
|
+
{/* The tooltip and `aria-label` are untouched by the avatar: a
|
|
79
|
+
face is not a label, and "Account menu" is still the accessible
|
|
80
|
+
name of the button. */}
|
|
81
|
+
{face}
|
|
82
|
+
</TooltipTrigger>
|
|
83
|
+
<TooltipContent>{menuLabel}</TooltipContent>
|
|
84
|
+
</Tooltip>
|
|
85
|
+
<DropdownMenuContent align="end" className="w-56">
|
|
86
|
+
{props.children ?? (
|
|
87
|
+
<ButtonUserDefaultMenu onAdminClick={props.onAdminClick} />
|
|
88
|
+
)}
|
|
89
|
+
</DropdownMenuContent>
|
|
90
|
+
</DropdownMenu>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cn } from "../core/utils.ts";
|
|
2
|
+
|
|
3
|
+
export interface ButtonUserPlaceholderProps {
|
|
4
|
+
/**
|
|
5
|
+
* The variant of the button it stands for: an outlined button keeps its
|
|
6
|
+
* border, so the swap moves nothing.
|
|
7
|
+
*/
|
|
8
|
+
variant?: "minimal" | "outlined";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What a shared page shows where `ButtonUser` goes, before hydration: an
|
|
13
|
+
* empty slot the size of the icon button. Neither the sign-in icon nor an
|
|
14
|
+
* avatar, since the shared page cannot know which one its visitor gets.
|
|
15
|
+
*/
|
|
16
|
+
export const ButtonUserPlaceholder = (props: ButtonUserPlaceholderProps) => (
|
|
17
|
+
<span
|
|
18
|
+
aria-hidden
|
|
19
|
+
data-slot="button-user-placeholder"
|
|
20
|
+
className={cn(
|
|
21
|
+
"inline-block size-9 shrink-0 rounded-md",
|
|
22
|
+
props.variant === "outlined" && "border",
|
|
23
|
+
)}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
@@ -228,8 +228,7 @@ describe("ActionErrorToaster and handled errors", () => {
|
|
|
228
228
|
|
|
229
229
|
// The toast would read the error's own message, which is also what the
|
|
230
230
|
// field renders here: so one element with that text means no toast.
|
|
231
|
-
const message =
|
|
232
|
-
"Invalid input: Invalid identifier or password, here at /password";
|
|
231
|
+
const message = "Invalid identifier or password, here";
|
|
233
232
|
await waitFor(() =>
|
|
234
233
|
expect(screen.getByTestId("password-error").textContent).toBe(message),
|
|
235
234
|
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Alepha } from "alepha";
|
|
2
|
+
import { AlephaReactI18n } from "alepha/react/i18n";
|
|
3
|
+
import { $page, AlephaReactRouter } from "alepha/react/router";
|
|
4
|
+
import { AlephaReactUi, uiAtom } from "alepha/react/ui";
|
|
5
|
+
import { ServerProvider } from "alepha/server";
|
|
6
|
+
import { describe, it } from "vitest";
|
|
7
|
+
|
|
8
|
+
import { AppShell } from "../AppShell.tsx";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An `AppShell` page reads no UI preference on the server (#E78): its markup
|
|
12
|
+
* is the same whatever the visitor's `alepha-ui` cookie says, so the page
|
|
13
|
+
* cache shares it between visitors who prefer different things.
|
|
14
|
+
*/
|
|
15
|
+
describe("AppShell and the page cache", () => {
|
|
16
|
+
class App {
|
|
17
|
+
layout = $page({
|
|
18
|
+
component: () => <AppShell brand="Brand" nav={[]} />,
|
|
19
|
+
children: () => [this.home],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
home = $page({
|
|
23
|
+
path: "/",
|
|
24
|
+
stream: false,
|
|
25
|
+
component: () => "home",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cookie = (ui: object) =>
|
|
30
|
+
`alepha-ui=${encodeURIComponent(JSON.stringify(ui))}`;
|
|
31
|
+
|
|
32
|
+
it("serves the same cached page to visitors with different ui cookies", async ({
|
|
33
|
+
expect,
|
|
34
|
+
}) => {
|
|
35
|
+
const alepha = Alepha.create()
|
|
36
|
+
.with(AlephaReactRouter)
|
|
37
|
+
.with(AlephaReactI18n)
|
|
38
|
+
.with(AlephaReactUi)
|
|
39
|
+
.with(App);
|
|
40
|
+
await alepha.start();
|
|
41
|
+
const base = alepha.inject(ServerProvider).hostname;
|
|
42
|
+
|
|
43
|
+
const collapsedDark = cookie({
|
|
44
|
+
...uiAtom.options.default!,
|
|
45
|
+
mode: "dark",
|
|
46
|
+
sidebar: { collapsed: true },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const first = await fetch(`${base}/`, {
|
|
50
|
+
headers: { cookie: collapsedDark },
|
|
51
|
+
});
|
|
52
|
+
const firstBody = await first.text();
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
54
|
+
const second = await fetch(`${base}/`);
|
|
55
|
+
const secondBody = await second.text();
|
|
56
|
+
|
|
57
|
+
// Variant, not shared: the shell is translated, so it reads the language,
|
|
58
|
+
// which every key carries anyway.
|
|
59
|
+
expect(first.headers.get("x-alepha-cache")).toBe("miss; verdict=variant");
|
|
60
|
+
expect(second.headers.get("x-alepha-cache")).toBe("hit; verdict=variant");
|
|
61
|
+
|
|
62
|
+
// The shared part is identical; only each visitor's private script differs.
|
|
63
|
+
const shared = (html: string) =>
|
|
64
|
+
html.replace(/<script id="__ssr_private"[^>]*>.*?<\/script>/, "");
|
|
65
|
+
expect(shared(secondBody)).toBe(shared(firstBody));
|
|
66
|
+
});
|
|
67
|
+
});
|
package/src/styles.css
CHANGED
|
@@ -87,6 +87,41 @@
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/*
|
|
91
|
+
* Safe areas, opt-in: padding that keeps content clear of a notch, the
|
|
92
|
+
* status bar and the home indicator in an edge-to-edge native shell.
|
|
93
|
+
*
|
|
94
|
+
* `--safe-area-inset-*` first: Capacitor's `SystemBars` injects them, because
|
|
95
|
+
* Android WebViews older than 140 misreport `env(safe-area-inset-*)`. Then
|
|
96
|
+
* `env()`, which is all an iPhone needs. Both resolve to 0 in a browser and
|
|
97
|
+
* in any document without `viewport-fit=cover`, so the same markup serves the
|
|
98
|
+
* website unchanged. Each sets the padding outright: put the inset on an
|
|
99
|
+
* element of its own, not on one that has a padding utility already.
|
|
100
|
+
*/
|
|
101
|
+
@utility pt-safe {
|
|
102
|
+
padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@utility pb-safe {
|
|
106
|
+
padding-bottom: var(
|
|
107
|
+
--safe-area-inset-bottom,
|
|
108
|
+
env(safe-area-inset-bottom, 0px)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@utility pl-safe {
|
|
113
|
+
padding-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@utility pr-safe {
|
|
117
|
+
padding-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@utility px-safe {
|
|
121
|
+
padding-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
|
|
122
|
+
padding-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
|
|
123
|
+
}
|
|
124
|
+
|
|
90
125
|
@theme inline {
|
|
91
126
|
--color-background: var(--background);
|
|
92
127
|
--color-foreground: var(--foreground);
|
|
@@ -435,6 +470,34 @@
|
|
|
435
470
|
@apply bg-background text-foreground;
|
|
436
471
|
}
|
|
437
472
|
|
|
473
|
+
/*
|
|
474
|
+
* Browser tells removed inside a native shell only (`data-native`, set by
|
|
475
|
+
* `@alepha/capacitor`): no grey flash on tap, no rubber band past the page,
|
|
476
|
+
* no long-press preview of links and images. Selection is never touched,
|
|
477
|
+
* and fields and editable text keep their callout, so typing, copying and
|
|
478
|
+
* assistive technology work as they do on the web.
|
|
479
|
+
*/
|
|
480
|
+
html[data-native] {
|
|
481
|
+
-webkit-tap-highlight-color: transparent;
|
|
482
|
+
overscroll-behavior: none;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
html[data-native] body {
|
|
486
|
+
-webkit-touch-callout: none;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
html[data-native]
|
|
490
|
+
:is(
|
|
491
|
+
input,
|
|
492
|
+
textarea,
|
|
493
|
+
select,
|
|
494
|
+
[contenteditable]:not([contenteditable="false"]),
|
|
495
|
+
.select-text,
|
|
496
|
+
.select-all
|
|
497
|
+
) {
|
|
498
|
+
-webkit-touch-callout: default;
|
|
499
|
+
}
|
|
500
|
+
|
|
438
501
|
/*
|
|
439
502
|
* The heading face. This rule is the whole of what makes `--font-heading`
|
|
440
503
|
* exist - see the token's own note in `:root` for the dead one it replaces.
|
|
@@ -830,3 +893,34 @@
|
|
|
830
893
|
) {
|
|
831
894
|
border-color: var(--border-hover);
|
|
832
895
|
}
|
|
896
|
+
|
|
897
|
+
/*
|
|
898
|
+
* A collapsed sidebar before hydration (#E78).
|
|
899
|
+
*
|
|
900
|
+
* The server renders the shell expanded for every visitor, so the page cache
|
|
901
|
+
* can share it; the visitor's preference reaches React only on the first
|
|
902
|
+
* commit after hydration. The boot script has already set
|
|
903
|
+
* `data-sidebar="collapsed"` on `<html>` from the `alepha-ui` cookie, so an
|
|
904
|
+
* EXPANDED sidebar under that attribute is the pre-hydration frame: it is held
|
|
905
|
+
* at the icon width, labels clipped, until React renders it collapsed. A
|
|
906
|
+
* sidebar the visitor expands again updates the attribute with it, so the rule
|
|
907
|
+
* never fights React after hydration.
|
|
908
|
+
*/
|
|
909
|
+
html[data-sidebar="collapsed"]
|
|
910
|
+
[data-slot="sidebar"][data-state="expanded"]
|
|
911
|
+
[data-slot="sidebar-gap"],
|
|
912
|
+
html[data-sidebar="collapsed"]
|
|
913
|
+
[data-slot="sidebar"][data-state="expanded"]
|
|
914
|
+
[data-slot="sidebar-container"] {
|
|
915
|
+
width: var(--sidebar-width-icon);
|
|
916
|
+
overflow: hidden;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
html[data-sidebar="collapsed"]
|
|
920
|
+
[data-slot="sidebar"][data-state="expanded"]:is(
|
|
921
|
+
[data-variant="floating"],
|
|
922
|
+
[data-variant="inset"]
|
|
923
|
+
)
|
|
924
|
+
:is([data-slot="sidebar-gap"], [data-slot="sidebar-container"]) {
|
|
925
|
+
width: calc(var(--sidebar-width-icon) + 1rem + 2px);
|
|
926
|
+
}
|
package/src/table/DataTable.tsx
CHANGED
|
@@ -287,7 +287,7 @@ export const DataTable = <
|
|
|
287
287
|
* Filter VALUES are deliberately not reset here: `useForm` captures its
|
|
288
288
|
* `initialValues` once, so resetting them is form surgery rather than a
|
|
289
289
|
* state assignment. They are also not clobbered - the filter-persist effect
|
|
290
|
-
* writes only on `form:
|
|
290
|
+
* writes only on `form:changed` / `form:submit:success`, never on mount - so
|
|
291
291
|
* the stored filters of the project you left stay its own.
|
|
292
292
|
*/
|
|
293
293
|
const scopeRef = useRef(props.persistenceKey);
|
|
@@ -188,10 +188,10 @@ export const DataTableFilterBar = (props: DataTableFilterBarProps) => {
|
|
|
188
188
|
const enumValuesOf = (field: DataTableFilterBarField): string[] => {
|
|
189
189
|
const schema = schemaOf(field);
|
|
190
190
|
if (!schema) return [];
|
|
191
|
-
if (z.schema.isEnum(schema)) return z.schema.
|
|
191
|
+
if (z.schema.isEnum(schema)) return z.schema.enumOptions(schema);
|
|
192
192
|
if (z.schema.isArray(schema)) {
|
|
193
193
|
const element = z.schema.unwrap(z.schema.element(schema));
|
|
194
|
-
if (z.schema.isEnum(element)) return z.schema.
|
|
194
|
+
if (z.schema.isEnum(element)) return z.schema.enumOptions(element);
|
|
195
195
|
}
|
|
196
196
|
return [];
|
|
197
197
|
};
|
|
@@ -91,7 +91,7 @@ describe("DataTable (a date range on the filter bar)", () => {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
const mount = async (
|
|
94
|
-
url = "/list",
|
|
94
|
+
url: `/${string}` = "/list",
|
|
95
95
|
options: { seedValues?: { createdAt?: string[] } } = {},
|
|
96
96
|
) => {
|
|
97
97
|
alepha = Alepha.create().with(AlephaReact).with(AlephaReactI18n).with(App);
|
|
@@ -73,7 +73,7 @@ describe("DataTable (filters seeded from the query)", () => {
|
|
|
73
73
|
window.history.replaceState({}, "", "/");
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
const mount = async (url: string
|
|
76
|
+
const mount = async (url: `/${string}`, ui: React.ReactNode) => {
|
|
77
77
|
alepha = Alepha.create().with(AlephaReact).with(AlephaReactI18n).with(App);
|
|
78
78
|
await alepha.start();
|
|
79
79
|
const router = alepha.inject(ReactRouter);
|
|
@@ -79,7 +79,7 @@ describe("DataTable (share filters)", () => {
|
|
|
79
79
|
window.history.replaceState({}, "", "/");
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
const mount = async (url: string
|
|
82
|
+
const mount = async (url: `/${string}`, ui: React.ReactNode) => {
|
|
83
83
|
alepha = Alepha.create().with(AlephaReact).with(AlephaReactI18n).with(App);
|
|
84
84
|
await alepha.start();
|
|
85
85
|
const router = alepha.inject(ReactRouter);
|
|
@@ -390,7 +390,7 @@ export interface DataTableBaseProps<
|
|
|
390
390
|
onSortChange?: (sort: SortState | null) => void;
|
|
391
391
|
/**
|
|
392
392
|
* When true (default when `filters` is set), the table refetches on
|
|
393
|
-
* every `form:
|
|
393
|
+
* every `form:changed` event, debounced by 250ms. Set to `false` to
|
|
394
394
|
* require an explicit submit.
|
|
395
395
|
*/
|
|
396
396
|
autoApplyFilters?: boolean;
|
|
@@ -103,7 +103,7 @@ export interface RowActionContext {
|
|
|
103
103
|
export interface RowAction<T> {
|
|
104
104
|
label: string;
|
|
105
105
|
icon?: IconType;
|
|
106
|
-
onClick: (item: T, ctx: RowActionContext) =>
|
|
106
|
+
onClick: (item: T, ctx: RowActionContext) => unknown;
|
|
107
107
|
destructive?: boolean;
|
|
108
108
|
disabled?: (item: T) => boolean;
|
|
109
109
|
/**
|
|
@@ -159,7 +159,7 @@ export interface BulkActionContext {
|
|
|
159
159
|
export interface BulkAction<T> {
|
|
160
160
|
label: string;
|
|
161
161
|
icon?: IconType;
|
|
162
|
-
onClick: (selected: T[], ctx: BulkActionContext) =>
|
|
162
|
+
onClick: (selected: T[], ctx: BulkActionContext) => unknown;
|
|
163
163
|
destructive?: boolean;
|
|
164
164
|
/**
|
|
165
165
|
* Whether the action is offered for this selection. Absent means always.
|
|
@@ -626,7 +626,7 @@ export interface DataTableFilters<
|
|
|
626
626
|
* component's `key` to re-seed on a later arrival.
|
|
627
627
|
*
|
|
628
628
|
* **Transient, and by construction.** Persistence is written from
|
|
629
|
-
* `form:
|
|
629
|
+
* `form:changed` / `form:submit:success` only, never on mount , so a seed
|
|
630
630
|
* shows in the toolbar and narrows the fetch without overwriting the
|
|
631
631
|
* filter the reader chose for themselves last time. Touch any control and
|
|
632
632
|
* the resulting values (seed included) become the stored choice, which is
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Alepha, type Page, type ZObject, z } from "alepha";
|
|
2
|
+
import { ActionErrorPolicy } from "alepha/react";
|
|
2
3
|
import { type FormModel, useForm } from "alepha/react/form";
|
|
3
4
|
import {
|
|
4
5
|
type Dispatch,
|
|
@@ -166,6 +167,7 @@ export const useDataTableData = <T>(options: UseDataTableDataOptions<T>) => {
|
|
|
166
167
|
type: "custom",
|
|
167
168
|
id: "data-table:load",
|
|
168
169
|
error: error as Error,
|
|
170
|
+
handled: ActionErrorPolicy.isHandled(error),
|
|
169
171
|
});
|
|
170
172
|
} finally {
|
|
171
173
|
// Only the newest request clears `loading`: an older one finishing
|