@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/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G;IACH,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableData.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,KAAK,OAAO,EAAK,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"useDataTableData.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,KAAK,OAAO,EAAK,MAAM,QAAQ,CAAC;AAEjE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAMpB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,uBAAuB,CAAC,CAAC;IACxC,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,qBAAqB,CAAC,GACjD,eAAe,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAC5C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,WAAW,uBAAuB,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBA8M5C,MAAM,OAAO,SAAS,CAAC,CAAC,CAAC;qBAsB3C,MAAM,OACN,SAAS,CAAC,CAAC,CAAC,aACN,KAAK,GAAG,MAAM,GAAG,IAAI;CA0BnC,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { persistedSort, writePersisted } from "./dataTablePersistence.js";
|
|
|
2
2
|
import { paginateLocal } from "./paginateLocal.js";
|
|
3
3
|
import { z } from "alepha";
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { ActionErrorPolicy } from "alepha/react";
|
|
5
6
|
import { useForm } from "alepha/react/form";
|
|
6
7
|
//#region src/table/useDataTableData.ts
|
|
7
8
|
/**
|
|
@@ -86,7 +87,8 @@ const useDataTableData = (options) => {
|
|
|
86
87
|
alepha.events.emit("react:action:error", {
|
|
87
88
|
type: "custom",
|
|
88
89
|
id: "data-table:load",
|
|
89
|
-
error
|
|
90
|
+
error,
|
|
91
|
+
handled: ActionErrorPolicy.isHandled(error)
|
|
90
92
|
});
|
|
91
93
|
} finally {
|
|
92
94
|
if (isLatest()) setLoading(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableData.js","names":[],"sources":["../../src/table/useDataTableData.ts"],"sourcesContent":["import { type Alepha, type Page, type ZObject, z } from \"alepha\";\nimport { type FormModel, useForm } from \"alepha/react/form\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { persistedSort, writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n ColumnDef,\n SortState,\n} from \"./dataTableTypes.ts\";\nimport { paginateLocal } from \"./paginateLocal.ts\";\n\nexport interface UseDataTableDataOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n /**\n * The page size and its setter. The state is declared in `DataTable`,\n * first of all its hooks; this hook changes it from the footer's picker.\n */\n size: number;\n setSize: Dispatch<SetStateAction<number>>;\n /**\n * The key the sort is persisted under, or `undefined` when the table does\n * not store it.\n */\n sortKey: string | undefined;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The rows `DataTable` renders and the state that picks them: the page, the\n * page-size picker, the sort, and either the fetched page or the static one\n * derived from `data`.\n *\n * The setters are returned alongside the values because the refresh wiring\n * and the scope change in `DataTable` write the same state.\n */\nexport const useDataTableData = <T>(options: UseDataTableDataOptions<T>) => {\n const { props, size, setSize, sortKey, form, alepha } = options;\n\n // -- Paging / sort / data --------------------------------------------------\n\n const [page, setPage] = useState(0);\n\n /**\n * Change the page size and go back to the first page.\n *\n * The reset is the whole point: raising the size while on page 5 can put\n * the reader past the last page, which renders an empty table with no\n * visible cause. Persisted so the choice survives a reload, alongside the\n * filters, sort and columns this table already remembers.\n */\n const changeSize = (next: number) => {\n setSize(next);\n setPage(0);\n if (props.persistenceKey) {\n writePersisted(props.persistenceKey, \"size\", next);\n }\n };\n\n /**\n * The footer's page-size picker, as a form of one field.\n *\n * `Control` is form-bound and this picker is not part of any form, which is\n * why the footer stayed on a raw `<Select>` long after everything else here\n * moved. One field is the whole cost of joining, and it buys the picker the\n * same trigger, popup and keyboard handling as every other select in the\n * table. `keepDirty: false` so the re-seed below actually re-seeds: `size`\n * can move without the picker (a persisted value on mount), and a kept\n * \"edit\" would pin the trigger to a page size the table is not using.\n */\n const sizeForm = useForm({\n schema: z.object({ size: z.number() }),\n initialValues: { size },\n keepDirty: false,\n handler: async () => {},\n onChange: (_key, next) => changeSize(next as number),\n });\n\n const [sort, setSort] = useState<SortState | null>(() =>\n persistedSort(sortKey, props.defaultSort),\n );\n const [fetchedData, setData] = useState<T[]>([]);\n const [fetchedMeta, setMeta] = useState<Page<T>[\"page\"] | null>(null);\n // The filters the fetched rows answer, copied when their request left:\n // `form.currentValues` is mutated in place and already holds what the\n // reader is typing now. Read by the cells through `rowFilters`.\n const [fetchedFilters, setFetchedFilters] = useState<\n Record<string, unknown> | undefined\n >(undefined);\n const [loading, setLoading] = useState(false);\n const [refreshKey, setRefreshKey] = useState(0);\n const [isRefreshing, setIsRefreshing] = useState(false);\n\n // Alepha's pagination parser reads \"field\" as asc and \"-field\" as desc.\n // Multiple comma-separated entries are multi-column sort, so we must\n // NOT use `field,direction` syntax — that would treat \"asc\"/\"desc\" as\n // a second column name and 500 on the backend.\n const sortParam = sort\n ? sort.direction === \"desc\"\n ? `-${sort.field}`\n : sort.field\n : undefined;\n\n // Hold the latest `fetch` in a ref so it is NOT a dependency of `load`.\n // Callers pass `fetch` inline (a new function every render), and a fetcher\n // that writes a store atom the caller also subscribes to would otherwise\n // self-trigger: load → atom write → caller re-render → new `fetch` → new\n // `load` → effect re-runs → infinite loop. The ref keeps the newest closure\n // available while `load` only re-runs on actual inputs (page/size/sort/…).\n const fetchRef = useRef(props.fetch);\n fetchRef.current = props.fetch;\n\n // The newest request, so an older one that answers late cannot put its\n // rows back (#Q2517). A project switch, a filter keystroke or a refresh\n // each start one; only the last may write, and it aborts the one before.\n const latestRequest = useRef<\n { id: number; abort: AbortController } | undefined\n >(undefined);\n\n const load = useCallback(async () => {\n // Static mode owns no request. Bail before touching `loading` too, so a\n // table fed an array never flashes the skeleton over rows it already has.\n const fetcher = fetchRef.current;\n if (!fetcher) return;\n latestRequest.current?.abort.abort();\n const request = {\n id: (latestRequest.current?.id ?? 0) + 1,\n abort: new AbortController(),\n };\n latestRequest.current = request;\n const isLatest = () => latestRequest.current === request;\n setLoading(true);\n const sent = form ? { ...form.currentValues } : undefined;\n try {\n const res = await fetcher({\n page,\n size,\n sort: sortParam,\n filters: form?.currentValues,\n signal: request.abort.signal,\n });\n if (!isLatest()) return;\n setData(res.content);\n setMeta(res.page);\n setFetchedFilters(sent);\n } catch (error) {\n // A superseded request's failure (its own abort included) is nobody's\n // news: a newer one is already answering.\n if (!isLatest()) return;\n // Surface read failures through the same `react:action:error` channel\n // that useAction/useQuery use, so a mounted <ActionErrorToaster /> toasts\n // them. Keep the previous rows on screen rather than blanking the table.\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:load\",\n error: error as Error,\n });\n } finally {\n // Only the newest request clears `loading`: an older one finishing\n // first used to hide the spinner while the table still waited.\n if (isLatest()) {\n setLoading(false);\n }\n }\n }, [page, size, sortParam, refreshKey, form, alepha]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n /**\n * Static mode's equivalent of `load` — derived, not stored.\n *\n * Deliberately NOT routed through `load`: putting `props.data` in that\n * effect's dependencies reproduces the exact loop `fetchRef` exists to\n * prevent (load → setData → re-render → new inline array → new load).\n * Computed synchronously there is no state to go stale, an inline\n * `data={rows.filter(…)}` is safe, and a changed array is on screen in\n * the same render.\n */\n const staticPage = useMemo(() => {\n if (!props.data) return null;\n const sortValues: Record<string, (item: T) => unknown> = {};\n for (const [key, column] of Object.entries(props.columns)) {\n if (column.sortValue) {\n sortValues[column.sortKey ?? key] = column.sortValue;\n }\n }\n return paginateLocal(props.data, {\n page,\n size,\n sort: sortParam,\n sortValues,\n filters: form?.currentValues,\n filter: props.filter,\n });\n // `refreshKey` is what the filter-form subscriptions bump, so it is how\n // a filter change reaches this memo — `form.currentValues` is mutated in\n // place and its identity never changes.\n }, [\n props.data,\n props.columns,\n props.filter,\n page,\n size,\n sortParam,\n refreshKey,\n form,\n ]);\n\n const data = staticPage ? staticPage.content : fetchedData;\n const meta = staticPage ? staticPage.page : fetchedMeta;\n // Static rows are derived in this render from the current values, so those\n // ARE the filters they answer.\n const rowFilters = staticPage ? form?.currentValues : fetchedFilters;\n\n /**\n * Rows vanish under the reader in static mode: the caller detaches one and\n * the page they are on stops existing. Nothing fetches, so nothing else\n * would notice — the table would sit on an empty page with no visible\n * cause. Fetch mode has the same hole, but there the server round-trip\n * needed to see it makes this the wrong place to close it.\n */\n if (staticPage) {\n const totalPages = staticPage.page.totalPages ?? 0;\n if (page > 0 && page > totalPages - 1) {\n // Guarded on `page`, so it settles in one pass and does not need an\n // effect: the clamp lands before the rows render against a page that no\n // longer exists.\n setPage(Math.max(0, totalPages - 1));\n }\n }\n\n // Persist sort to localStorage on every change.\n useEffect(() => {\n if (!sortKey) return;\n writePersisted(sortKey, \"sort\", sort);\n }, [sortKey, sort]);\n\n // -- Sort ------------------------------------------------------------------\n\n const toggleSort = (col: string, def: ColumnDef<T>) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n setSort((s) => {\n const next: SortState | null =\n !s || s.field !== field\n ? { field, direction: \"asc\" }\n : s.direction === \"asc\"\n ? { field, direction: \"desc\" }\n : null;\n props.onSortChange?.(next);\n return next;\n });\n };\n\n /**\n * Sort in a named direction, or clear it.\n *\n * The header cycles; the menu states. Both write the same state, so a\n * column sorted from the menu shows the header's own arrow.\n */\n const setSortTo = (\n col: string,\n def: ColumnDef<T>,\n direction: \"asc\" | \"desc\" | null,\n ) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n const next: SortState | null = direction ? { field, direction } : null;\n setSort(next);\n props.onSortChange?.(next);\n };\n\n return {\n page,\n setPage,\n sizeForm,\n sort,\n setSort,\n data,\n meta,\n rowFilters,\n loading,\n refreshKey,\n setRefreshKey,\n isRefreshing,\n setIsRefreshing,\n toggleSort,\n setSortTo,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;AAgDA,MAAa,oBAAuB,YAAwC;CAC1E,MAAM,EAAE,OAAO,MAAM,SAAS,SAAS,MAAM,WAAW;CAIxD,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;;;;;;;;;CAUlC,MAAM,cAAc,SAAiB;EACnC,QAAQ,IAAI;EACZ,QAAQ,CAAC;EACT,IAAI,MAAM,gBACR,eAAe,MAAM,gBAAgB,QAAQ,IAAI;CAErD;;;;;;;;;;;;CAaA,MAAM,WAAW,QAAQ;EACvB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;EACrC,eAAe,EAAE,KAAK;EACtB,WAAW;E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;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,aACJ,KACA,KACA,cACG;EACH,IAAI,CAAC,IAAI,UAAU;EACnB,MAAM,QAAQ,IAAI,WAAW;EAC7B,MAAM,OAAyB,YAAY;GAAE;GAAO;EAAU,IAAI;EAClE,QAAQ,IAAI;EACZ,MAAM,eAAe,IAAI;CAC3B;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useDataTableData.js","names":[],"sources":["../../src/table/useDataTableData.ts"],"sourcesContent":["import { type Alepha, type Page, type ZObject, z } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport { type FormModel, useForm } from \"alepha/react/form\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { persistedSort, writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n ColumnDef,\n SortState,\n} from \"./dataTableTypes.ts\";\nimport { paginateLocal } from \"./paginateLocal.ts\";\n\nexport interface UseDataTableDataOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n /**\n * The page size and its setter. The state is declared in `DataTable`,\n * first of all its hooks; this hook changes it from the footer's picker.\n */\n size: number;\n setSize: Dispatch<SetStateAction<number>>;\n /**\n * The key the sort is persisted under, or `undefined` when the table does\n * not store it.\n */\n sortKey: string | undefined;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The rows `DataTable` renders and the state that picks them: the page, the\n * page-size picker, the sort, and either the fetched page or the static one\n * derived from `data`.\n *\n * The setters are returned alongside the values because the refresh wiring\n * and the scope change in `DataTable` write the same state.\n */\nexport const useDataTableData = <T>(options: UseDataTableDataOptions<T>) => {\n const { props, size, setSize, sortKey, form, alepha } = options;\n\n // -- Paging / sort / data --------------------------------------------------\n\n const [page, setPage] = useState(0);\n\n /**\n * Change the page size and go back to the first page.\n *\n * The reset is the whole point: raising the size while on page 5 can put\n * the reader past the last page, which renders an empty table with no\n * visible cause. Persisted so the choice survives a reload, alongside the\n * filters, sort and columns this table already remembers.\n */\n const changeSize = (next: number) => {\n setSize(next);\n setPage(0);\n if (props.persistenceKey) {\n writePersisted(props.persistenceKey, \"size\", next);\n }\n };\n\n /**\n * The footer's page-size picker, as a form of one field.\n *\n * `Control` is form-bound and this picker is not part of any form, which is\n * why the footer stayed on a raw `<Select>` long after everything else here\n * moved. One field is the whole cost of joining, and it buys the picker the\n * same trigger, popup and keyboard handling as every other select in the\n * table. `keepDirty: false` so the re-seed below actually re-seeds: `size`\n * can move without the picker (a persisted value on mount), and a kept\n * \"edit\" would pin the trigger to a page size the table is not using.\n */\n const sizeForm = useForm({\n schema: z.object({ size: z.number() }),\n initialValues: { size },\n keepDirty: false,\n handler: async () => {},\n onChange: (_key, next) => changeSize(next as number),\n });\n\n const [sort, setSort] = useState<SortState | null>(() =>\n persistedSort(sortKey, props.defaultSort),\n );\n const [fetchedData, setData] = useState<T[]>([]);\n const [fetchedMeta, setMeta] = useState<Page<T>[\"page\"] | null>(null);\n // The filters the fetched rows answer, copied when their request left:\n // `form.currentValues` is mutated in place and already holds what the\n // reader is typing now. Read by the cells through `rowFilters`.\n const [fetchedFilters, setFetchedFilters] = useState<\n Record<string, unknown> | undefined\n >(undefined);\n const [loading, setLoading] = useState(false);\n const [refreshKey, setRefreshKey] = useState(0);\n const [isRefreshing, setIsRefreshing] = useState(false);\n\n // Alepha's pagination parser reads \"field\" as asc and \"-field\" as desc.\n // Multiple comma-separated entries are multi-column sort, so we must\n // NOT use `field,direction` syntax — that would treat \"asc\"/\"desc\" as\n // a second column name and 500 on the backend.\n const sortParam = sort\n ? sort.direction === \"desc\"\n ? `-${sort.field}`\n : sort.field\n : undefined;\n\n // Hold the latest `fetch` in a ref so it is NOT a dependency of `load`.\n // Callers pass `fetch` inline (a new function every render), and a fetcher\n // that writes a store atom the caller also subscribes to would otherwise\n // self-trigger: load → atom write → caller re-render → new `fetch` → new\n // `load` → effect re-runs → infinite loop. The ref keeps the newest closure\n // available while `load` only re-runs on actual inputs (page/size/sort/…).\n const fetchRef = useRef(props.fetch);\n fetchRef.current = props.fetch;\n\n // The newest request, so an older one that answers late cannot put its\n // rows back (#Q2517). A project switch, a filter keystroke or a refresh\n // each start one; only the last may write, and it aborts the one before.\n const latestRequest = useRef<\n { id: number; abort: AbortController } | undefined\n >(undefined);\n\n const load = useCallback(async () => {\n // Static mode owns no request. Bail before touching `loading` too, so a\n // table fed an array never flashes the skeleton over rows it already has.\n const fetcher = fetchRef.current;\n if (!fetcher) return;\n latestRequest.current?.abort.abort();\n const request = {\n id: (latestRequest.current?.id ?? 0) + 1,\n abort: new AbortController(),\n };\n latestRequest.current = request;\n const isLatest = () => latestRequest.current === request;\n setLoading(true);\n const sent = form ? { ...form.currentValues } : undefined;\n try {\n const res = await fetcher({\n page,\n size,\n sort: sortParam,\n filters: form?.currentValues,\n signal: request.abort.signal,\n });\n if (!isLatest()) return;\n setData(res.content);\n setMeta(res.page);\n setFetchedFilters(sent);\n } catch (error) {\n // A superseded request's failure (its own abort included) is nobody's\n // news: a newer one is already answering.\n if (!isLatest()) return;\n // Surface read failures through the same `react:action:error` channel\n // that useAction/useQuery use, so a mounted <ActionErrorToaster /> toasts\n // them. Keep the previous rows on screen rather than blanking the table.\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:load\",\n error: error as Error,\n handled: ActionErrorPolicy.isHandled(error),\n });\n } finally {\n // Only the newest request clears `loading`: an older one finishing\n // first used to hide the spinner while the table still waited.\n if (isLatest()) {\n setLoading(false);\n }\n }\n }, [page, size, sortParam, refreshKey, form, alepha]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n /**\n * Static mode's equivalent of `load` — derived, not stored.\n *\n * Deliberately NOT routed through `load`: putting `props.data` in that\n * effect's dependencies reproduces the exact loop `fetchRef` exists to\n * prevent (load → setData → re-render → new inline array → new load).\n * Computed synchronously there is no state to go stale, an inline\n * `data={rows.filter(…)}` is safe, and a changed array is on screen in\n * the same render.\n */\n const staticPage = useMemo(() => {\n if (!props.data) return null;\n const sortValues: Record<string, (item: T) => unknown> = {};\n for (const [key, column] of Object.entries(props.columns)) {\n if (column.sortValue) {\n sortValues[column.sortKey ?? key] = column.sortValue;\n }\n }\n return paginateLocal(props.data, {\n page,\n size,\n sort: sortParam,\n sortValues,\n filters: form?.currentValues,\n filter: props.filter,\n });\n // `refreshKey` is what the filter-form subscriptions bump, so it is how\n // a filter change reaches this memo — `form.currentValues` is mutated in\n // place and its identity never changes.\n }, [\n props.data,\n props.columns,\n props.filter,\n page,\n size,\n sortParam,\n refreshKey,\n form,\n ]);\n\n const data = staticPage ? staticPage.content : fetchedData;\n const meta = staticPage ? staticPage.page : fetchedMeta;\n // Static rows are derived in this render from the current values, so those\n // ARE the filters they answer.\n const rowFilters = staticPage ? form?.currentValues : fetchedFilters;\n\n /**\n * Rows vanish under the reader in static mode: the caller detaches one and\n * the page they are on stops existing. Nothing fetches, so nothing else\n * would notice — the table would sit on an empty page with no visible\n * cause. Fetch mode has the same hole, but there the server round-trip\n * needed to see it makes this the wrong place to close it.\n */\n if (staticPage) {\n const totalPages = staticPage.page.totalPages ?? 0;\n if (page > 0 && page > totalPages - 1) {\n // Guarded on `page`, so it settles in one pass and does not need an\n // effect: the clamp lands before the rows render against a page that no\n // longer exists.\n setPage(Math.max(0, totalPages - 1));\n }\n }\n\n // Persist sort to localStorage on every change.\n useEffect(() => {\n if (!sortKey) return;\n writePersisted(sortKey, \"sort\", sort);\n }, [sortKey, sort]);\n\n // -- Sort ------------------------------------------------------------------\n\n const toggleSort = (col: string, def: ColumnDef<T>) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n setSort((s) => {\n const next: SortState | null =\n !s || s.field !== field\n ? { field, direction: \"asc\" }\n : s.direction === \"asc\"\n ? { field, direction: \"desc\" }\n : null;\n props.onSortChange?.(next);\n return next;\n });\n };\n\n /**\n * Sort in a named direction, or clear it.\n *\n * The header cycles; the menu states. Both write the same state, so a\n * column sorted from the menu shows the header's own arrow.\n */\n const setSortTo = (\n col: string,\n def: ColumnDef<T>,\n direction: \"asc\" | \"desc\" | null,\n ) => {\n if (!def.sortable) return;\n const field = def.sortKey ?? col;\n const next: SortState | null = direction ? { field, direction } : null;\n setSort(next);\n props.onSortChange?.(next);\n };\n\n return {\n page,\n setPage,\n sizeForm,\n sort,\n setSort,\n data,\n meta,\n rowFilters,\n loading,\n refreshKey,\n setRefreshKey,\n isRefreshing,\n setIsRefreshing,\n toggleSort,\n setSortTo,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,MAAa,oBAAuB,YAAwC;CAC1E,MAAM,EAAE,OAAO,MAAM,SAAS,SAAS,MAAM,WAAW;CAIxD,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;;;;;;;;;CAUlC,MAAM,cAAc,SAAiB;EACnC,QAAQ,IAAI;EACZ,QAAQ,CAAC;EACT,IAAI,MAAM,gBACR,eAAe,MAAM,gBAAgB,QAAQ,IAAI;CAErD;;;;;;;;;;;;CAaA,MAAM,WAAW,QAAQ;EACvB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;EACrC,eAAe,EAAE,KAAK;EACtB,WAAW;EACX,SAAS,YAAY,CAAC;EACtB,WAAW,MAAM,SAAS,WAAW,IAAc;CACrD,CAAC;CAED,MAAM,CAAC,MAAM,WAAW,eACtB,cAAc,SAAS,MAAM,WAAW,CAC1C;CACA,MAAM,CAAC,aAAa,WAAW,SAAc,CAAC,CAAC;CAC/C,MAAM,CAAC,aAAa,WAAW,SAAiC,IAAI;CAIpE,MAAM,CAAC,gBAAgB,qBAAqB,SAE1C,KAAA,CAAS;CACX,MAAM,CAAC,SAAS,c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EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -79,7 +79,7 @@ const useDataTableRefresh = (options) => {
|
|
|
79
79
|
useEffect(() => {
|
|
80
80
|
if (!form || !autoApply) return;
|
|
81
81
|
let timeout;
|
|
82
|
-
const unsub = alepha.events.on("form:
|
|
82
|
+
const unsub = alepha.events.on("form:changed", (event) => {
|
|
83
83
|
if (event.id !== form.id) return;
|
|
84
84
|
if (timeout) clearTimeout(timeout);
|
|
85
85
|
timeout = setTimeout(() => {
|
|
@@ -101,7 +101,7 @@ const useDataTableRefresh = (options) => {
|
|
|
101
101
|
const writeFilters = () => {
|
|
102
102
|
writePersisted(filtersKey, "filters", cleanFilterValues(form.currentValues ?? {}));
|
|
103
103
|
};
|
|
104
|
-
const unsubs = [alepha.events.on("form:
|
|
104
|
+
const unsubs = [alepha.events.on("form:changed", (event) => {
|
|
105
105
|
if (event.id !== form.id) return;
|
|
106
106
|
writeFilters();
|
|
107
107
|
}), alepha.events.on("form:submit:success", (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableRefresh.js","names":[],"sources":["../../src/table/useDataTableRefresh.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport type { FormModel } from \"alepha/react/form\";\nimport type { I18nProvider } from \"alepha/react/i18n\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nimport type { Toast } from \"../core/useToast.tsx\";\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n} from \"./dataTableTypes.ts\";\nimport { cleanFilterValues, shareFiltersUrl } from \"./queryFilters.ts\";\n\nexport interface UseDataTableRefreshOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n form: FormModel<ZObject> | undefined;\n /**\n * Every filter key, operator keys included, as read at mount. Reset clears\n * each of them and Share rewrites each of them.\n */\n filterKeys: readonly string[];\n /**\n * Put the bar back to its declaration. Reset filters is one act: the\n * values empty and the bar returns to what the table declares, together.\n */\n resetShownFilters: () => void;\n /**\n * The key the filter values are persisted under, or `undefined` when the\n * table does not store them.\n */\n filtersKey: string | undefined;\n alepha: Alepha;\n toast: Toast;\n tr: I18nProvider<any, any>[\"tr\"];\n setPage: Dispatch<SetStateAction<number>>;\n setRefreshKey: Dispatch<SetStateAction<number>>;\n setIsRefreshing: Dispatch<SetStateAction<boolean>>;\n}\n\n/**\n * What makes `DataTable` fetch again, and the filter actions that sit\n * beside it: the refresh button and `refreshSignal`, filter reset and share,\n * the filter form's submit and change events (with the filter persistence\n * they drive), and polling.\n *\n * It owns no row state. The page and the refresh key it writes belong to\n * `useDataTableData`.\n */\nexport const useDataTableRefresh = <T>(\n options: UseDataTableRefreshOptions<T>,\n) => {\n const {\n props,\n form,\n filterKeys,\n resetShownFilters,\n filtersKey,\n alepha,\n toast,\n tr,\n setPage,\n setRefreshKey,\n setIsRefreshing,\n } = options;\n\n // -- Refresh + reset wiring -----------------------------------------------\n\n const refresh = useCallback(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, []);\n\n const handleRefreshClick = useCallback(() => {\n setIsRefreshing(true);\n refresh();\n setTimeout(() => setIsRefreshing(false), 1000);\n }, [refresh]);\n\n // React to the external `refreshSignal` prop. The first render seeds the\n // ref without refetching (the mount effect already loads); every later\n // change triggers a refresh. Kept separate from `load`'s deps so an inline\n // `fetch` closure can't self-trigger a loop (see `fetchRef` above).\n const refreshSignalRef = useRef(props.refreshSignal);\n useEffect(() => {\n if (refreshSignalRef.current === props.refreshSignal) return;\n refreshSignalRef.current = props.refreshSignal;\n refresh();\n }, [props.refreshSignal, refresh]);\n\n const resetFilters = useCallback(() => {\n if (!form || !props.filters) return;\n // Per-field `.set(undefined)` is necessary: `setInitialValues({})`\n // doesn't emit `form:
|
|
1
|
+
{"version":3,"file":"useDataTableRefresh.js","names":[],"sources":["../../src/table/useDataTableRefresh.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport type { FormModel } from \"alepha/react/form\";\nimport type { I18nProvider } from \"alepha/react/i18n\";\nimport {\n type Dispatch,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n} from \"react\";\n\nimport type { Toast } from \"../core/useToast.tsx\";\nimport type { DataTableBaseProps } from \"./dataTableBaseProps.ts\";\nimport { writePersisted } from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableSource,\n} from \"./dataTableTypes.ts\";\nimport { cleanFilterValues, shareFiltersUrl } from \"./queryFilters.ts\";\n\nexport interface UseDataTableRefreshOptions<T> {\n props: DataTableBaseProps<T, DataTableFilterFields> &\n DataTableSource<T, DataTableFilterFields>;\n form: FormModel<ZObject> | undefined;\n /**\n * Every filter key, operator keys included, as read at mount. Reset clears\n * each of them and Share rewrites each of them.\n */\n filterKeys: readonly string[];\n /**\n * Put the bar back to its declaration. Reset filters is one act: the\n * values empty and the bar returns to what the table declares, together.\n */\n resetShownFilters: () => void;\n /**\n * The key the filter values are persisted under, or `undefined` when the\n * table does not store them.\n */\n filtersKey: string | undefined;\n alepha: Alepha;\n toast: Toast;\n tr: I18nProvider<any, any>[\"tr\"];\n setPage: Dispatch<SetStateAction<number>>;\n setRefreshKey: Dispatch<SetStateAction<number>>;\n setIsRefreshing: Dispatch<SetStateAction<boolean>>;\n}\n\n/**\n * What makes `DataTable` fetch again, and the filter actions that sit\n * beside it: the refresh button and `refreshSignal`, filter reset and share,\n * the filter form's submit and change events (with the filter persistence\n * they drive), and polling.\n *\n * It owns no row state. The page and the refresh key it writes belong to\n * `useDataTableData`.\n */\nexport const useDataTableRefresh = <T>(\n options: UseDataTableRefreshOptions<T>,\n) => {\n const {\n props,\n form,\n filterKeys,\n resetShownFilters,\n filtersKey,\n alepha,\n toast,\n tr,\n setPage,\n setRefreshKey,\n setIsRefreshing,\n } = options;\n\n // -- Refresh + reset wiring -----------------------------------------------\n\n const refresh = useCallback(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, []);\n\n const handleRefreshClick = useCallback(() => {\n setIsRefreshing(true);\n refresh();\n setTimeout(() => setIsRefreshing(false), 1000);\n }, [refresh]);\n\n // React to the external `refreshSignal` prop. The first render seeds the\n // ref without refetching (the mount effect already loads); every later\n // change triggers a refresh. Kept separate from `load`'s deps so an inline\n // `fetch` closure can't self-trigger a loop (see `fetchRef` above).\n const refreshSignalRef = useRef(props.refreshSignal);\n useEffect(() => {\n if (refreshSignalRef.current === props.refreshSignal) return;\n refreshSignalRef.current = props.refreshSignal;\n refresh();\n }, [props.refreshSignal, refresh]);\n\n const resetFilters = useCallback(() => {\n if (!form || !props.filters) return;\n // Per-field `.set(undefined)` is necessary: `setInitialValues({})`\n // doesn't emit `form:changed` for deleted keys, so inputs stay\n // visually populated and subscribers don't refetch. Explicit set\n // keeps everyone in sync.\n for (const key of filterKeys) {\n const input = (form.input as Record<string, { set?: (v: any) => void }>)[\n key\n ];\n input?.set?.(undefined);\n }\n resetShownFilters();\n }, [form, props.filters, filterKeys, resetShownFilters]);\n\n /**\n * Copy a link that opens this table with these filters.\n *\n * The write half of `fromQuery`, and the only one: nothing puts the\n * filters in the address bar as the reader types, so a link out of a\n * filtered table has to be asked for. Built on the page's own URL, so the\n * params the page owns travel with it.\n */\n /**\n * Whether a link out of this table would do anything on arrival.\n *\n * A table that does not read the query back would copy a URL whose params\n * are inert, which is worse than no Share at all: it looks like it worked.\n */\n const canShare = Boolean(props.filters?.fromQuery);\n\n const shareFilters = useCallback(async () => {\n if (!props.filters || !form) return;\n const url = shareFiltersUrl(\n window.location.href,\n filterKeys,\n cleanFilterValues(form.currentValues ?? {}),\n );\n try {\n await navigator.clipboard.writeText(url);\n toast.success(\n tr(\"dataTable.shareFiltersCopied\", { default: \"Link copied\" }),\n );\n } catch {\n // A denied clipboard permission, or an insecure origin. Nothing here\n // is worth an error toast the reader cannot act on.\n }\n }, [form, props.filters, filterKeys, toast, tr]);\n\n // -- Form event subscriptions ---------------------------------------------\n\n // Refetch on explicit submit (manual Apply, programmatic submit, etc.).\n useEffect(() => {\n if (!form) return;\n return alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n setPage(0);\n setRefreshKey((k) => k + 1);\n });\n }, [alepha, form]);\n\n // Refetch on change (debounced) when autoApplyFilters is on. Default\n // is on whenever DataTable owns the form (`filters` prop).\n const autoApply = props.autoApplyFilters ?? Boolean(props.filters);\n useEffect(() => {\n if (!form || !autoApply) return;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const unsub = alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n if (timeout) clearTimeout(timeout);\n timeout = setTimeout(() => {\n setPage(0);\n setRefreshKey((k) => k + 1);\n }, 250);\n });\n return () => {\n if (timeout) clearTimeout(timeout);\n unsub();\n };\n }, [alepha, form, autoApply]);\n\n // Persist filter values to localStorage on change.\n useEffect(() => {\n if (!filtersKey || !form || !props.filters) return;\n const writeFilters = () => {\n writePersisted(\n filtersKey,\n \"filters\",\n cleanFilterValues(form.currentValues ?? {}),\n );\n };\n const unsubs = [\n alepha.events.on(\"form:changed\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n alepha.events.on(\"form:submit:success\", (event) => {\n if (event.id !== form.id) return;\n writeFilters();\n }),\n ];\n return () => {\n for (const u of unsubs) u();\n };\n }, [alepha, form, props.filters, filtersKey]);\n\n // -- Polling ---------------------------------------------------------------\n\n useEffect(() => {\n if (!props.pollMs) return;\n const id = setInterval(() => {\n if (document.visibilityState === \"visible\") setRefreshKey((k) => k + 1);\n }, props.pollMs);\n return () => clearInterval(id);\n }, [props.pollMs]);\n\n return { refresh, handleRefreshClick, resetFilters, canShare, shareFilters };\n};\n"],"mappings":";;;;;;;;;;;;;AAwDA,MAAa,uBACX,YACG;CACH,MAAM,EACJ,OACA,MACA,YACA,mBACA,YACA,QACA,OACA,IACA,SAC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@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableSummary.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"useDataTableSummary.d.ts","sourceRoot":"","sources":["../../src/table/useDataTableSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAOnD,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAAC;IAC7D;;;OAGG;IACH,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YAAa,0BAA0B;;oBAqB5D,OAAO;sBAaqB,MAAM,GAAG,SAAS;;;CAuDxD,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { persistedSummaryOpen, writePersisted } from "./dataTablePersistence.js";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { ActionErrorPolicy } from "alepha/react";
|
|
3
4
|
//#region src/table/useDataTableSummary.ts
|
|
4
5
|
/**
|
|
5
6
|
* The state of `DataTable`'s summary panel: whether it is open, and the cards
|
|
@@ -47,7 +48,7 @@ const useDataTableSummary = (options) => {
|
|
|
47
48
|
type: "custom",
|
|
48
49
|
id: "data-table:summary",
|
|
49
50
|
error,
|
|
50
|
-
handled: onError
|
|
51
|
+
handled: ActionErrorPolicy.isHandled(error, onError)
|
|
51
52
|
});
|
|
52
53
|
onError?.(error);
|
|
53
54
|
}).finally(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataTableSummary.js","names":[],"sources":["../../src/table/useDataTableSummary.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport type { FormModel } from \"alepha/react/form\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n persistedSummaryOpen,\n writePersisted,\n} from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableStatCard,\n DataTableSummary,\n} from \"./dataTableTypes.ts\";\n\nexport interface UseDataTableSummaryOptions {\n summary: DataTableSummary<DataTableFilterFields> | undefined;\n /**\n * The key the panel's open state is stored under, or `undefined` when the\n * table stores nothing.\n */\n persistenceKey: string | undefined;\n /**\n * The table's reload counter. Every reload of the SET bumps it (a filter\n * change, Refresh, `refreshSignal`, a poll, an action's `refresh()`), and a\n * page or a sort does not, which is exactly when the figures change.\n */\n refreshKey: number;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The state of `DataTable`'s summary panel: whether it is open, and the cards\n * it shows, fetched with the table's filters when the caller gave a `fetch`.\n */\nexport const useDataTableSummary = (options: UseDataTableSummaryOptions) => {\n const { summary, persistenceKey, refreshKey, form, alepha } = options;\n\n const [open, setOpenState] = useState(() =>\n persistedSummaryOpen(persistenceKey),\n );\n // `undefined` until the first fetch lands, which is what tells the panel\n // to draw its placeholder tiles rather than nothing.\n const [fetched, setFetched] = useState<DataTableStatCard[] | undefined>();\n const [loading, setLoading] = useState(false);\n\n // Held in a ref and out of the effect's dependencies, for the reason\n // `useDataTableData` gives for `fetch`: callers write it inline, so it is a\n // new function every render, and a dependency on it refetches forever.\n const fetchRef = useRef(summary?.fetch);\n fetchRef.current = summary?.fetch;\n const onErrorRef = useRef(summary?.onError);\n onErrorRef.current = summary?.onError;\n const fetches = Boolean(summary?.fetch);\n\n const setOpen = useCallback(\n (next: boolean) => {\n setOpenState(next);\n if (persistenceKey) writePersisted(persistenceKey, \"summaryOpen\", next);\n },\n [persistenceKey],\n );\n\n /**\n * Read the open state of another scope, and forget the cards of this one.\n * Called by `DataTable` during the render where `persistenceKey` changes,\n * like the rest of the scope's state: the figures of the project just left\n * must not sit under the name of the one just opened while it loads.\n */\n const resetScope = useCallback((key: string | undefined) => {\n setOpenState(persistedSummaryOpen(key));\n setFetched(undefined);\n }, []);\n\n useEffect(() => {\n const fetcher = fetchRef.current;\n // Collapsed, nothing is on screen to be right about: opening fetches.\n if (!fetcher || !open) return;\n const controller = new AbortController();\n setLoading(true);\n fetcher({\n // A copy: `currentValues` is mutated in place as the reader types.\n filters: form ? { ...form.currentValues } : undefined,\n signal: controller.signal,\n })\n .then((cards) => {\n if (!controller.signal.aborted) setFetched(cards);\n })\n .catch((error: unknown) => {\n if (controller.signal.aborted) return;\n // The last cards stay up, like the table's rows. With none yet, the\n // placeholders go: tiles pulsing over a read that failed would say\n // it is still coming. No card is no panel, until a reload succeeds.\n setFetched((cards) => cards ?? []);\n // The table's own channel for a failed read, so a mounted\n // `ActionErrorToaster` reports it, unless the caller handles it: the\n // `onError` convention of `useQuery`, where the event still fires for\n // error reporting and the toaster skips it.\n const onError = onErrorRef.current;\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:summary\",\n error: error as Error,\n handled: onError
|
|
1
|
+
{"version":3,"file":"useDataTableSummary.js","names":[],"sources":["../../src/table/useDataTableSummary.ts"],"sourcesContent":["import type { Alepha, ZObject } from \"alepha\";\nimport { ActionErrorPolicy } from \"alepha/react\";\nimport type { FormModel } from \"alepha/react/form\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n persistedSummaryOpen,\n writePersisted,\n} from \"./dataTablePersistence.ts\";\nimport type {\n DataTableFilterFields,\n DataTableStatCard,\n DataTableSummary,\n} from \"./dataTableTypes.ts\";\n\nexport interface UseDataTableSummaryOptions {\n summary: DataTableSummary<DataTableFilterFields> | undefined;\n /**\n * The key the panel's open state is stored under, or `undefined` when the\n * table stores nothing.\n */\n persistenceKey: string | undefined;\n /**\n * The table's reload counter. Every reload of the SET bumps it (a filter\n * change, Refresh, `refreshSignal`, a poll, an action's `refresh()`), and a\n * page or a sort does not, which is exactly when the figures change.\n */\n refreshKey: number;\n form: FormModel<ZObject> | undefined;\n alepha: Alepha;\n}\n\n/**\n * The state of `DataTable`'s summary panel: whether it is open, and the cards\n * it shows, fetched with the table's filters when the caller gave a `fetch`.\n */\nexport const useDataTableSummary = (options: UseDataTableSummaryOptions) => {\n const { summary, persistenceKey, refreshKey, form, alepha } = options;\n\n const [open, setOpenState] = useState(() =>\n persistedSummaryOpen(persistenceKey),\n );\n // `undefined` until the first fetch lands, which is what tells the panel\n // to draw its placeholder tiles rather than nothing.\n const [fetched, setFetched] = useState<DataTableStatCard[] | undefined>();\n const [loading, setLoading] = useState(false);\n\n // Held in a ref and out of the effect's dependencies, for the reason\n // `useDataTableData` gives for `fetch`: callers write it inline, so it is a\n // new function every render, and a dependency on it refetches forever.\n const fetchRef = useRef(summary?.fetch);\n fetchRef.current = summary?.fetch;\n const onErrorRef = useRef(summary?.onError);\n onErrorRef.current = summary?.onError;\n const fetches = Boolean(summary?.fetch);\n\n const setOpen = useCallback(\n (next: boolean) => {\n setOpenState(next);\n if (persistenceKey) writePersisted(persistenceKey, \"summaryOpen\", next);\n },\n [persistenceKey],\n );\n\n /**\n * Read the open state of another scope, and forget the cards of this one.\n * Called by `DataTable` during the render where `persistenceKey` changes,\n * like the rest of the scope's state: the figures of the project just left\n * must not sit under the name of the one just opened while it loads.\n */\n const resetScope = useCallback((key: string | undefined) => {\n setOpenState(persistedSummaryOpen(key));\n setFetched(undefined);\n }, []);\n\n useEffect(() => {\n const fetcher = fetchRef.current;\n // Collapsed, nothing is on screen to be right about: opening fetches.\n if (!fetcher || !open) return;\n const controller = new AbortController();\n setLoading(true);\n fetcher({\n // A copy: `currentValues` is mutated in place as the reader types.\n filters: form ? { ...form.currentValues } : undefined,\n signal: controller.signal,\n })\n .then((cards) => {\n if (!controller.signal.aborted) setFetched(cards);\n })\n .catch((error: unknown) => {\n if (controller.signal.aborted) return;\n // The last cards stay up, like the table's rows. With none yet, the\n // placeholders go: tiles pulsing over a read that failed would say\n // it is still coming. No card is no panel, until a reload succeeds.\n setFetched((cards) => cards ?? []);\n // The table's own channel for a failed read, so a mounted\n // `ActionErrorToaster` reports it, unless the caller handles it: the\n // `onError` convention of `useQuery`, where the event still fires for\n // error reporting and the toaster skips it.\n const onError = onErrorRef.current;\n void alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: \"data-table:summary\",\n error: error as Error,\n handled: ActionErrorPolicy.isHandled(error, onError),\n });\n onError?.(error as Error);\n })\n .finally(() => {\n if (!controller.signal.aborted) setLoading(false);\n });\n // A newer load, a collapse or an unmount supersedes this one. Aborted\n // rather than ignored, so a fetcher that forwards the signal cancels the\n // request itself. `loading` is cleared here because the aborted load's\n // own `finally` leaves it alone, and a collapse starts no load to take\n // it over.\n return () => {\n controller.abort();\n setLoading(false);\n };\n }, [fetches, open, refreshKey, form, alepha]);\n\n const cards = summary?.fetch ? fetched : (summary?.cards ?? []);\n\n return { open, setOpen, resetScope, cards, loading };\n};\n"],"mappings":";;;;;;;;AAoCA,MAAa,uBAAuB,YAAwC;CAC1E,MAAM,EAAE,SAAS,gBAAgB,YAAY,MAAM,WAAW;CAE9D,MAAM,CAAC,MAAM,gBAAgB,eAC3B,qBAAqB,cAAc,CACrC;CAGA,MAAM,CAAC,SAAS,cAAc,SAA0C;CACxE,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAK5C,MAAM,WAAW,OAAO,SAAS,KAAK;CACtC,SAAS,UAAU,SAAS;CAC5B,MAAM,aAAa,OAAO,SAAS,OAAO;CAC1C,WAAW,UAAU,SAAS;CAC9B,MA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3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "Shared Base UI and Tailwind components for Alepha apps. Edited directly; bugfixes propagate via normal dep updates.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alepha",
|
|
@@ -188,11 +188,11 @@
|
|
|
188
188
|
"highlight.js": "^11.12.0",
|
|
189
189
|
"input-otp": "^1.5.0",
|
|
190
190
|
"lowlight": "^3.3.0",
|
|
191
|
-
"lucide-react": "^1.
|
|
191
|
+
"lucide-react": "^1.52.0",
|
|
192
192
|
"react-day-picker": "^10.0.2",
|
|
193
193
|
"react-is": "^19.3.0",
|
|
194
194
|
"react-markdown": "^10.1.0",
|
|
195
|
-
"react-resizable-panels": "^4.14.
|
|
195
|
+
"react-resizable-panels": "^4.14.2",
|
|
196
196
|
"remark-gfm": "^4.0.1",
|
|
197
197
|
"sonner": "^2.0.8",
|
|
198
198
|
"tw-animate-css": "^1.4.0",
|
|
@@ -203,9 +203,9 @@
|
|
|
203
203
|
"@testing-library/dom": "^10.4.2",
|
|
204
204
|
"@testing-library/react": "^16.3.3",
|
|
205
205
|
"@types/bun": "^1.4.2",
|
|
206
|
-
"@types/node": "^26.6.
|
|
206
|
+
"@types/node": "^26.6.4",
|
|
207
207
|
"@types/react": "^19.3.0",
|
|
208
|
-
"alepha": "0.
|
|
208
|
+
"alepha": "0.33.0",
|
|
209
209
|
"react": "^19.3.0",
|
|
210
210
|
"react-dom": "^19.3.0",
|
|
211
211
|
"recharts": "^3.10.1",
|
|
@@ -213,9 +213,9 @@
|
|
|
213
213
|
"typescript": "^7.0.2"
|
|
214
214
|
},
|
|
215
215
|
"peerDependencies": {
|
|
216
|
-
"alepha": "^0.
|
|
217
|
-
"react": "
|
|
218
|
-
"react-dom": "
|
|
216
|
+
"alepha": "^0.33.0",
|
|
217
|
+
"react": "^19.3.0",
|
|
218
|
+
"react-dom": "^19.3.0",
|
|
219
219
|
"recharts": "^3",
|
|
220
220
|
"tailwindcss": "^4"
|
|
221
221
|
},
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
}
|
|
229
229
|
},
|
|
230
230
|
"engines": {
|
|
231
|
-
"node": ">=
|
|
231
|
+
"node": ">=24.0.0"
|
|
232
232
|
},
|
|
233
233
|
"llms": "https://alepha.dev/llms.txt"
|
|
234
234
|
}
|
|
@@ -39,7 +39,7 @@ const AccountConnections = (props: AccountConnectionsProps) => {
|
|
|
39
39
|
|
|
40
40
|
const revoke = useAction<[connection: MyConnection], boolean>(
|
|
41
41
|
{
|
|
42
|
-
handler: async (connection) => {
|
|
42
|
+
handler: async (_ctx, connection) => {
|
|
43
43
|
const ok = await dialog.confirm({
|
|
44
44
|
title: tr("account.connections.revokeTitle", {
|
|
45
45
|
default: "Disconnect $1?",
|
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
MyAccountController,
|
|
3
3
|
MyProfileController,
|
|
4
4
|
} from "alepha/api/users";
|
|
5
|
-
import { useClient } from "alepha/react";
|
|
5
|
+
import { useAction, useClient } from "alepha/react";
|
|
6
6
|
import { useI18n } from "alepha/react/i18n";
|
|
7
7
|
import { type FormEvent, type ReactNode, useEffect, useState } from "react";
|
|
8
8
|
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
} from "../core/Dialog.tsx";
|
|
17
17
|
import { Input } from "../core/Input.tsx";
|
|
18
18
|
import { Label } from "../core/Label.tsx";
|
|
19
|
-
import { useToast } from "../core/useToast.tsx";
|
|
20
19
|
import { ControlPassword } from "../form/ControlPassword.tsx";
|
|
21
20
|
|
|
22
21
|
export interface AccountDeleteDialogProps {
|
|
@@ -68,13 +67,11 @@ export interface AccountDeleteDialogProps {
|
|
|
68
67
|
export const AccountDeleteDialog = (props: AccountDeleteDialogProps) => {
|
|
69
68
|
const accountApi = useClient<MyAccountController>();
|
|
70
69
|
const profileApi = useClient<MyProfileController>();
|
|
71
|
-
const toaster = useToast();
|
|
72
70
|
const { tr } = useI18n();
|
|
73
71
|
|
|
74
72
|
const [expected, setExpected] = useState<string | undefined>();
|
|
75
73
|
const [confirm, setConfirm] = useState("");
|
|
76
74
|
const [currentPassword, setCurrentPassword] = useState("");
|
|
77
|
-
const [submitting, setSubmitting] = useState(false);
|
|
78
75
|
|
|
79
76
|
useEffect(() => {
|
|
80
77
|
if (!props.open) {
|
|
@@ -104,34 +101,31 @@ export const AccountDeleteDialog = (props: AccountDeleteDialogProps) => {
|
|
|
104
101
|
props.onOpenChange(false);
|
|
105
102
|
};
|
|
106
103
|
|
|
107
|
-
|
|
104
|
+
/*
|
|
105
|
+
An application's `user:delete:before` hook refuses here ("You still own 3
|
|
106
|
+
projects") and the framework's fast-path emit delivers that message
|
|
107
|
+
unwrapped. The app's ActionErrorToaster shows it verbatim, which is the
|
|
108
|
+
entire reason the emit avoids `{ log: true }`.
|
|
109
|
+
*/
|
|
110
|
+
const remove = useAction<[]>(
|
|
111
|
+
{
|
|
112
|
+
handler: async () => {
|
|
113
|
+
await accountApi.deleteMyAccount({
|
|
114
|
+
body: {
|
|
115
|
+
confirm,
|
|
116
|
+
currentPassword: props.hasPassword ? currentPassword : undefined,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
await props.onDeleted();
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
[accountApi, confirm, currentPassword, props.hasPassword, props.onDeleted],
|
|
123
|
+
);
|
|
124
|
+
const submitting = remove.loading;
|
|
125
|
+
|
|
126
|
+
const submit = (event: FormEvent) => {
|
|
108
127
|
event.preventDefault();
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await accountApi.deleteMyAccount({
|
|
112
|
-
body: {
|
|
113
|
-
confirm,
|
|
114
|
-
currentPassword: props.hasPassword ? currentPassword : undefined,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
await props.onDeleted();
|
|
118
|
-
} catch (error: any) {
|
|
119
|
-
/*
|
|
120
|
-
An application's `user:delete:before` hook refuses here — "You still
|
|
121
|
-
own 3 projects" — and the framework's fast-path emit delivers that
|
|
122
|
-
message unwrapped. Showing it verbatim is the entire reason the emit
|
|
123
|
-
avoids `{ log: true }`; a generic "could not delete" would waste it.
|
|
124
|
-
*/
|
|
125
|
-
toaster.show(
|
|
126
|
-
error?.message ??
|
|
127
|
-
tr("account.delete.error", {
|
|
128
|
-
default: "Could not delete your account",
|
|
129
|
-
}),
|
|
130
|
-
"danger",
|
|
131
|
-
);
|
|
132
|
-
} finally {
|
|
133
|
-
setSubmitting(false);
|
|
134
|
-
}
|
|
128
|
+
void remove.run();
|
|
135
129
|
};
|
|
136
130
|
|
|
137
131
|
const ready = expected !== undefined && confirm === expected;
|
|
@@ -115,7 +115,7 @@ const AccountKeys = (props: AccountKeysProps) => {
|
|
|
115
115
|
|
|
116
116
|
const rotate = useAction<[key: ListApiKeyItem], boolean>(
|
|
117
117
|
{
|
|
118
|
-
handler: async (key) => {
|
|
118
|
+
handler: async (_ctx, key) => {
|
|
119
119
|
const ok = await dialog.confirm({
|
|
120
120
|
title: tr("account.keys.rotateTitle", {
|
|
121
121
|
default: "Rotate $1?",
|
|
@@ -144,7 +144,7 @@ const AccountKeys = (props: AccountKeysProps) => {
|
|
|
144
144
|
|
|
145
145
|
const revoke = useAction<[key: ListApiKeyItem], boolean>(
|
|
146
146
|
{
|
|
147
|
-
handler: async (key) => {
|
|
147
|
+
handler: async (_ctx, key) => {
|
|
148
148
|
const ok = await dialog.confirm({
|
|
149
149
|
title: tr("account.keys.revokeTitle", {
|
|
150
150
|
default: "Revoke $1?",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MyMfaController } from "alepha/api/users";
|
|
2
|
-
import { useClient, useQuery } from "alepha/react";
|
|
2
|
+
import { useAction, useClient, useQuery } from "alepha/react";
|
|
3
3
|
import { useI18n } from "alepha/react/i18n";
|
|
4
4
|
import { AlertTriangle } from "lucide-react";
|
|
5
5
|
import { useState } from "react";
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
DialogHeader,
|
|
13
13
|
DialogTitle,
|
|
14
14
|
} from "../core/Dialog.tsx";
|
|
15
|
-
import { useToast } from "../core/useToast.tsx";
|
|
16
15
|
import { InputOTP, InputOTPGroup, InputOTPSlot } from "../otp/InputOTP.tsx";
|
|
17
16
|
import { AccountRecoveryCodes } from "./AccountRecoveryCodes.tsx";
|
|
18
17
|
|
|
@@ -47,19 +46,23 @@ export interface AccountMfaDialogProps {
|
|
|
47
46
|
*/
|
|
48
47
|
export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
49
48
|
const api = useClient<MyMfaController>();
|
|
50
|
-
const toaster = useToast();
|
|
51
49
|
const { tr } = useI18n();
|
|
52
50
|
|
|
53
51
|
const [code, setCode] = useState("");
|
|
54
52
|
const [recoveryCodes, setRecoveryCodes] = useState<string[]>();
|
|
55
|
-
const [submitting, setSubmitting] = useState(false);
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
55
|
* A fresh enrollment is started each time the dialog opens, and the
|
|
59
56
|
* previous pending one is replaced server-side. `enabled` keys it to
|
|
60
|
-
* `props.open` so nothing is issued for a dialog nobody asked for.
|
|
57
|
+
* `props.open` so nothing is issued for a dialog nobody asked for. The
|
|
58
|
+
* previous opening's QR is not shown while the new one loads: it names a
|
|
59
|
+
* secret the server has replaced.
|
|
61
60
|
*/
|
|
62
|
-
const {
|
|
61
|
+
const {
|
|
62
|
+
data: enrollment,
|
|
63
|
+
error,
|
|
64
|
+
loading: enrolling,
|
|
65
|
+
} = useQuery<TotpEnrollment>(
|
|
63
66
|
{
|
|
64
67
|
enabled: props.open,
|
|
65
68
|
handler: () => api.enrollTotp() as Promise<TotpEnrollment>,
|
|
@@ -79,21 +82,22 @@ export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
|
79
82
|
props.onOpenChange(open);
|
|
80
83
|
};
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
// A refused code is toasted by the app's ActionErrorToaster, like any
|
|
86
|
+
// other failed action; the field is cleared for the next attempt.
|
|
87
|
+
const activate = useAction<[code: string]>(
|
|
88
|
+
{
|
|
89
|
+
handler: async (_ctx, value) => {
|
|
90
|
+
const result = await api.activateTotp({ body: { code: value } });
|
|
91
|
+
setRecoveryCodes(result.recoveryCodes);
|
|
92
|
+
await props.onDone?.();
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
[api, props.onDone],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const submit = async (value: string) => {
|
|
99
|
+
if (!(await activate.run(value)).ok) {
|
|
89
100
|
setCode("");
|
|
90
|
-
toaster.show(
|
|
91
|
-
error?.message ??
|
|
92
|
-
tr("account.mfa.invalidCode", { default: "That code is not valid" }),
|
|
93
|
-
"danger",
|
|
94
|
-
);
|
|
95
|
-
} finally {
|
|
96
|
-
setSubmitting(false);
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
|
|
@@ -105,13 +109,15 @@ export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
|
105
109
|
<Dialog
|
|
106
110
|
open={props.open}
|
|
107
111
|
onOpenChange={(open) => {
|
|
108
|
-
|
|
112
|
+
// Not while activating either: the codes it is about to return
|
|
113
|
+
// could never be shown again.
|
|
114
|
+
if (!open && (recoveryCodes || activate.loading)) {
|
|
109
115
|
return;
|
|
110
116
|
}
|
|
111
117
|
setOpen(open);
|
|
112
118
|
}}
|
|
113
119
|
>
|
|
114
|
-
<DialogContent showCloseButton={!recoveryCodes}>
|
|
120
|
+
<DialogContent showCloseButton={!recoveryCodes && !activate.loading}>
|
|
115
121
|
<DialogHeader>
|
|
116
122
|
<DialogTitle>
|
|
117
123
|
{recoveryCodes
|
|
@@ -150,7 +156,7 @@ export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
|
150
156
|
</Alert>
|
|
151
157
|
)}
|
|
152
158
|
|
|
153
|
-
{enrollment ? (
|
|
159
|
+
{enrollment && !enrolling ? (
|
|
154
160
|
<>
|
|
155
161
|
<div
|
|
156
162
|
className="mx-auto w-48 rounded-lg bg-white p-3 [&>svg]:w-full"
|
|
@@ -174,11 +180,11 @@ export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
|
174
180
|
<InputOTP
|
|
175
181
|
maxLength={6}
|
|
176
182
|
value={code}
|
|
177
|
-
disabled={
|
|
183
|
+
disabled={activate.loading}
|
|
178
184
|
onChange={(value: string) => {
|
|
179
185
|
setCode(value);
|
|
180
186
|
if (value.length === 6) {
|
|
181
|
-
void
|
|
187
|
+
void submit(value);
|
|
182
188
|
}
|
|
183
189
|
}}
|
|
184
190
|
>
|
|
@@ -191,9 +197,9 @@ export const AccountMfaDialog = (props: AccountMfaDialogProps) => {
|
|
|
191
197
|
</div>
|
|
192
198
|
|
|
193
199
|
<Button
|
|
194
|
-
loading={
|
|
200
|
+
loading={activate.loading}
|
|
195
201
|
disabled={code.length !== 6}
|
|
196
|
-
onClick={() =>
|
|
202
|
+
onClick={() => submit(code)}
|
|
197
203
|
>
|
|
198
204
|
{tr("account.mfa.turnOn", { default: "Turn on" })}
|
|
199
205
|
</Button>
|