@protobase/ui 0.113.0 → 0.114.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/dist/account/messages.d.ts +2 -2
- package/dist/app/app.d.ts +4 -1
- package/dist/app/app.js +9 -7
- package/dist/app/change-confirm/messages.d.ts +2 -2
- package/dist/app/charts/messages.d.ts +2 -2
- package/dist/app/confirm-sign-in-messages.d.ts +2 -2
- package/dist/app/create/messages.d.ts +2 -2
- package/dist/app/delete/messages.d.ts +2 -2
- package/dist/app/displays/messages.d.ts +2 -2
- package/dist/app/displays/virtual-cards.js +1 -0
- package/dist/app/embedded-list/messages.d.ts +2 -2
- package/dist/app/export/messages.d.ts +2 -2
- package/dist/app/field-messages.d.ts +2 -2
- package/dist/app/field-types/workflow/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-status/messages.d.ts +2 -2
- package/dist/app/file-viewers/messages.d.ts +2 -2
- package/dist/app/first-frame.d.ts +13 -0
- package/dist/app/first-frame.js +23 -0
- package/dist/app/focus/messages.d.ts +2 -2
- package/dist/app/gallery/gallery-layout.d.ts +2 -2
- package/dist/app/gallery/messages.d.ts +2 -2
- package/dist/app/hand-order/messages.d.ts +2 -2
- package/dist/app/import/messages.d.ts +2 -2
- package/dist/app/index.html +0 -17
- package/dist/app/list-messages.d.ts +2 -2
- package/dist/app/main.js +19 -7
- package/dist/app/messages.d.ts +2 -2
- package/dist/app/pages/messages.d.ts +2 -2
- package/dist/app/record-chart/messages.d.ts +2 -2
- package/dist/app/record-messages.d.ts +2 -2
- package/dist/app/record-mode/shown-layout.d.ts +1 -1
- package/dist/app/record-row/messages.d.ts +2 -2
- package/dist/app/record-row/record-row.d.ts +3 -2
- package/dist/app/record-row/record-row.js +43 -27
- package/dist/app/record-row/row-window.d.ts +11 -0
- package/dist/app/record-row/row-window.js +15 -2
- package/dist/app/refresh-mark.d.ts +2 -1
- package/dist/app/refresh-mark.js +3 -1
- package/dist/app/related-cards/messages.d.ts +2 -2
- package/dist/app/reveal-when-loaded.d.ts +8 -2
- package/dist/app/reveal-when-loaded.js +12 -5
- package/dist/app/runtime/messages.d.ts +2 -2
- package/dist/app/saved/messages.d.ts +2 -2
- package/dist/app/searches/messages.d.ts +2 -2
- package/dist/app/splash-hold.d.ts +0 -1
- package/dist/app/splash-hold.js +1 -1
- package/dist/app/start-screen.d.ts +0 -9
- package/dist/app/start-screen.js +1 -10
- package/dist/app/ui-ready.d.ts +11 -0
- package/dist/app/ui-ready.js +12 -0
- package/dist/app-shell/app-shell.js +3 -1
- package/dist/app-shell/close-sidebar.d.ts +10 -0
- package/dist/app-shell/close-sidebar.js +17 -0
- package/dist/app-shell/drawer.d.ts +7 -1
- package/dist/app-shell/drawer.js +26 -7
- package/dist/app-shell/index.d.ts +2 -1
- package/dist/app-shell/index.js +2 -1
- package/dist/app-shell/messages.d.ts +2 -2
- package/dist/app-shell/top-bar.js +4 -4
- package/dist/assistant-dock/messages.d.ts +2 -2
- package/dist/auth/messages.d.ts +2 -2
- package/dist/calls/messages.d.ts +2 -2
- package/dist/compact-table/messages.d.ts +2 -2
- package/dist/data/query-keys.d.ts +6 -0
- package/dist/data/query-keys.js +10 -0
- package/dist/data/start-cache/cached-plugins.d.ts +6 -0
- package/dist/data/start-cache/cached-plugins.js +10 -0
- package/dist/data-grid/column-spec.d.ts +1 -1
- package/dist/data-grid/data-grid.js +1 -0
- package/dist/data-grid/messages.d.ts +2 -2
- package/dist/data-grid/row-source.d.ts +5 -0
- package/dist/data-grid/use-paged-rows.d.ts +5 -3
- package/dist/data-grid/use-paged-rows.js +21 -6
- package/dist/filter-panel/messages.d.ts +2 -2
- package/dist/focus-page/messages.d.ts +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/invitations/messages.d.ts +2 -2
- package/dist/live/grid-loader.d.ts +1 -0
- package/dist/live/grid-loader.js +3 -1
- package/dist/live/use-live-rows.js +1 -0
- package/dist/mailbox/messages.d.ts +2 -2
- package/dist/mocks/customers.d.ts +1 -1
- package/dist/mocks/invoices.d.ts +1 -1
- package/dist/mocks/orders.d.ts +3 -3
- package/dist/notifications/bell/messages.d.ts +2 -2
- package/dist/organizations/members-page.js +13 -7
- package/dist/organizations/messages.d.ts +2 -2
- package/dist/organizations/use-organizations.d.ts +4 -1
- package/dist/organizations/use-organizations.js +25 -19
- package/dist/package.js +1 -1
- package/dist/plugins/plugin-source.d.ts +24 -4
- package/dist/plugins/plugin-source.js +48 -14
- package/dist/plugins/use-plugin-loads.d.ts +3 -1
- package/dist/plugins/use-plugin-loads.js +24 -7
- package/dist/primitives/messages.d.ts +2 -2
- package/dist/primitives/skeleton.js +1 -0
- package/dist/record-view/messages.d.ts +2 -2
- package/dist/roles/use-active-role.d.ts +4 -1
- package/dist/roles/use-active-role.js +18 -13
- package/dist/shell/assets/api-provider-BJJrOoO4.js +2 -0
- package/dist/shell/assets/app-VoTi41IN.js +16 -0
- package/dist/shell/assets/badge-OU9hb6yQ.js +2 -0
- package/dist/shell/assets/checkbox-DFfK432Y.js +2 -0
- package/dist/shell/assets/createLucideIcon-DGm8SdFI.js +2 -0
- package/dist/shell/assets/display-value-CIH2qfgQ.js +2 -0
- package/dist/shell/assets/{field-badge-3QmjR1r3.js → field-badge-DX2Mc_fH.js} +2 -2
- package/dist/shell/assets/{graph-view-BcbWbnHO.js → graph-view-CY9LPr0B.js} +2 -2
- package/dist/shell/assets/{html-viewer-tGtSpy9M.js → html-viewer-BPGMH_GA.js} +2 -2
- package/dist/shell/assets/{in-place-form-B0EkP4B1.js → in-place-form-RWSQGEg4.js} +2 -2
- package/dist/shell/assets/index-Bzb-O7ER.js +2 -0
- package/dist/shell/assets/index-HnFovy2Q.css +2 -0
- package/dist/shell/assets/{intl-cache-bXVNV0Yq.js → intl-cache-D4doUjK1.js} +2 -2
- package/dist/shell/assets/{lib-d3-interpolate-Cl0dHO4f.js → lib-d3-interpolate-D3u38iyJ.js} +2 -2
- package/dist/shell/assets/{lib-d3-transition-DUHAGQ8z.js → lib-d3-transition-BUpPvFvt.js} +2 -2
- package/dist/shell/assets/{lib-d3-zoom-gQh2osrj.js → lib-d3-zoom-BF7SPKNh.js} +2 -2
- package/dist/shell/assets/{lib-vis.gl-react-maplibre-CU7gWYjg.js → lib-vis.gl-react-maplibre-C7-0xNFC.js} +2 -2
- package/dist/shell/assets/{lib-xyflow-react-DGg_5r7u.js → lib-xyflow-react-CKyW7szC.js} +2 -2
- package/dist/shell/assets/maplibre-9ViQO48S.js +2 -0
- package/dist/shell/assets/{markdown-content-DHKbAJjx.js → markdown-content-DTB9RQDs.js} +2 -2
- package/dist/shell/assets/{record-map-nGRmsk6x.js → record-map-CVqCWtfe.js} +2 -2
- package/dist/shell/assets/{records-map-D2flyaz3.js → records-map-ClYSxrVR.js} +2 -2
- package/dist/shell/assets/{run-trace-view-DfrAPeum.js → run-trace-view-CN16MiXg.js} +2 -2
- package/dist/shell/assets/search-picker-BGpvJQRD.js +2 -0
- package/dist/shell/assets/shared-protobase-ui-BC8LqGQB.js +2 -0
- package/dist/shell/assets/step-catalog-CZY0ZpCC.js +2 -0
- package/dist/shell/assets/step-panel-DhD80lsJ.js +2 -0
- package/dist/shell/assets/use-app-address-B4Uk3nWy.js +2 -0
- package/dist/shell/assets/{use-meta-BqEqOLNe.js → use-meta-D5kYywHm.js} +2 -2
- package/dist/shell/assets/{use-sibling-page-CiuiG-Tz.js → use-sibling-page-BJ81HcOP.js} +3 -3
- package/dist/shell/assets/value-badge-Dpd8dRqq.js +2 -0
- package/dist/shell/assets/{vendor-WWp_xlp2.js → vendor-3etemhgS.js} +4 -4
- package/dist/shell/assets/{workflow-canvas-DMP7SDWX.js → workflow-canvas-C1nGpi5w.js} +2 -2
- package/dist/shell/assets/{workflow-graph-editor-xpV8_qEl.js → workflow-graph-editor-DAJa4lq6.js} +2 -2
- package/dist/shell/assets/workflow-workbench-HramVZEJ.js +4 -0
- package/dist/shell/assets/{workflows-Bku4o2su.js → workflows-DlvOln9v.js} +2 -2
- package/dist/shell/assets/{workflows-start-kl7rSSay.js → workflows-start-QUKfwFqf.js} +2 -2
- package/dist/shell/index.html +16 -19
- package/dist/shell/protobase.shell.json +2 -2
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/api-provider-BJJrOoO4.js.map +1 -0
- package/dist/shell-source-maps/assets/app-VoTi41IN.js.map +1 -0
- package/dist/shell-source-maps/assets/{badge-ChHXC28D.js.map → badge-OU9hb6yQ.js.map} +1 -1
- package/dist/shell-source-maps/assets/{checkbox-COOOlJPG.js.map → checkbox-DFfK432Y.js.map} +1 -1
- package/dist/shell-source-maps/assets/createLucideIcon-DGm8SdFI.js.map +1 -0
- package/dist/shell-source-maps/assets/display-value-CIH2qfgQ.js.map +1 -0
- package/dist/shell-source-maps/assets/{field-badge-3QmjR1r3.js.map → field-badge-DX2Mc_fH.js.map} +1 -1
- package/dist/shell-source-maps/assets/{graph-view-BcbWbnHO.js.map → graph-view-CY9LPr0B.js.map} +1 -1
- package/dist/shell-source-maps/assets/{html-viewer-tGtSpy9M.js.map → html-viewer-BPGMH_GA.js.map} +1 -1
- package/dist/shell-source-maps/assets/{in-place-form-B0EkP4B1.js.map → in-place-form-RWSQGEg4.js.map} +1 -1
- package/dist/shell-source-maps/assets/index-Bzb-O7ER.js.map +1 -0
- package/dist/shell-source-maps/assets/{intl-cache-bXVNV0Yq.js.map → intl-cache-D4doUjK1.js.map} +1 -1
- package/dist/shell-source-maps/assets/{lib-d3-interpolate-Cl0dHO4f.js.map → lib-d3-interpolate-D3u38iyJ.js.map} +1 -1
- package/dist/shell-source-maps/assets/{lib-d3-transition-DUHAGQ8z.js.map → lib-d3-transition-BUpPvFvt.js.map} +1 -1
- package/dist/shell-source-maps/assets/{lib-d3-zoom-gQh2osrj.js.map → lib-d3-zoom-BF7SPKNh.js.map} +1 -1
- package/dist/shell-source-maps/assets/{lib-vis.gl-react-maplibre-CU7gWYjg.js.map → lib-vis.gl-react-maplibre-C7-0xNFC.js.map} +1 -1
- package/dist/shell-source-maps/assets/{lib-xyflow-react-DGg_5r7u.js.map → lib-xyflow-react-CKyW7szC.js.map} +1 -1
- package/dist/shell-source-maps/assets/{maplibre-Y7X50Jfk.js.map → maplibre-9ViQO48S.js.map} +1 -1
- package/dist/shell-source-maps/assets/{markdown-content-DHKbAJjx.js.map → markdown-content-DTB9RQDs.js.map} +1 -1
- package/dist/shell-source-maps/assets/{record-map-nGRmsk6x.js.map → record-map-CVqCWtfe.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-D2flyaz3.js.map → records-map-ClYSxrVR.js.map} +1 -1
- package/dist/shell-source-maps/assets/{run-trace-view-DfrAPeum.js.map → run-trace-view-CN16MiXg.js.map} +1 -1
- package/dist/shell-source-maps/assets/{search-picker-CJcJetBh.js.map → search-picker-BGpvJQRD.js.map} +1 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-BC8LqGQB.js.map +1 -0
- package/dist/shell-source-maps/assets/{step-catalog-ZvQOXfSh.js.map → step-catalog-CZY0ZpCC.js.map} +1 -1
- package/dist/shell-source-maps/assets/{step-panel-B1yHz7OC.js.map → step-panel-DhD80lsJ.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-app-address-B6k3dkV0.js.map → use-app-address-B4Uk3nWy.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-meta-BqEqOLNe.js.map → use-meta-D5kYywHm.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-sibling-page-CiuiG-Tz.js.map → use-sibling-page-BJ81HcOP.js.map} +1 -1
- package/dist/shell-source-maps/assets/{value-badge-BKLV4otJ.js.map → value-badge-Dpd8dRqq.js.map} +1 -1
- package/dist/shell-source-maps/assets/{vendor-WWp_xlp2.js.map → vendor-3etemhgS.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-canvas-DMP7SDWX.js.map → workflow-canvas-C1nGpi5w.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-graph-editor-xpV8_qEl.js.map → workflow-graph-editor-DAJa4lq6.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-workbench-Djdd_ODh.js.map → workflow-workbench-HramVZEJ.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflows-Bku4o2su.js.map → workflows-DlvOln9v.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflows-start-kl7rSSay.js.map → workflows-start-QUKfwFqf.js.map} +1 -1
- package/dist/status/messages.d.ts +2 -2
- package/dist/styles.css +14 -0
- package/dist/users/messages.d.ts +2 -2
- package/package.json +5 -5
- package/dist/app/hold-start-for-first-loads.d.ts +0 -12
- package/dist/app/hold-start-for-first-loads.js +0 -43
- package/dist/shell/assets/api-provider-CcDtTh0D.js +0 -2
- package/dist/shell/assets/app-DG30qs8Q.js +0 -16
- package/dist/shell/assets/badge-ChHXC28D.js +0 -2
- package/dist/shell/assets/checkbox-COOOlJPG.js +0 -2
- package/dist/shell/assets/display-value-fDiKbfJO.js +0 -2
- package/dist/shell/assets/index-BkCaPeOq.css +0 -2
- package/dist/shell/assets/index-CZ013UoE.js +0 -2
- package/dist/shell/assets/maplibre-Y7X50Jfk.js +0 -2
- package/dist/shell/assets/messages-ClKBpZlk.js +0 -2
- package/dist/shell/assets/search-picker-CJcJetBh.js +0 -2
- package/dist/shell/assets/shared-protobase-ui-CVwqj5Cp.js +0 -2
- package/dist/shell/assets/step-catalog-ZvQOXfSh.js +0 -2
- package/dist/shell/assets/step-panel-B1yHz7OC.js +0 -2
- package/dist/shell/assets/use-app-address-B6k3dkV0.js +0 -2
- package/dist/shell/assets/value-badge-BKLV4otJ.js +0 -2
- package/dist/shell/assets/workflow-workbench-Djdd_ODh.js +0 -4
- package/dist/shell-source-maps/assets/api-provider-CcDtTh0D.js.map +0 -1
- package/dist/shell-source-maps/assets/app-DG30qs8Q.js.map +0 -1
- package/dist/shell-source-maps/assets/display-value-fDiKbfJO.js.map +0 -1
- package/dist/shell-source-maps/assets/index-CZ013UoE.js.map +0 -1
- package/dist/shell-source-maps/assets/messages-ClKBpZlk.js.map +0 -1
- package/dist/shell-source-maps/assets/shared-protobase-ui-CVwqj5Cp.js.map +0 -1
|
@@ -32,5 +32,6 @@ export type LoadedPage = {
|
|
|
32
32
|
export declare const createGridLoader: ({ queryClient, client, resources, views, model, columns, filter, orderBy, related }: GridLoaderOptions) => {
|
|
33
33
|
page: (number: number) => Promise<LoadedPage>;
|
|
34
34
|
loadRows: (start: number) => Promise<GridRow[]>;
|
|
35
|
+
cachedRows: (start: number) => GridRow[] | undefined;
|
|
35
36
|
};
|
|
36
37
|
//#endregion
|
package/dist/live/grid-loader.js
CHANGED
|
@@ -89,9 +89,11 @@ const createGridLoader = ({ queryClient, client, resources, views, model, column
|
|
|
89
89
|
queryFn: () => fetchPage(number)
|
|
90
90
|
});
|
|
91
91
|
const loadRows = async (start) => (await page(Math.floor(start / 40))).rows;
|
|
92
|
+
const cachedRows = (start) => queryClient.getQueryData(pageKey(Math.floor(start / 40)))?.rows;
|
|
92
93
|
return {
|
|
93
94
|
page,
|
|
94
|
-
loadRows
|
|
95
|
+
loadRows,
|
|
96
|
+
cachedRows
|
|
95
97
|
};
|
|
96
98
|
};
|
|
97
99
|
//#endregion
|
|
@@ -57,6 +57,7 @@ const useLiveRows = ({ resources, views, model, columns, filter, orderBy, relate
|
|
|
57
57
|
source: useMemo(() => first.data ? {
|
|
58
58
|
total: first.data.total,
|
|
59
59
|
loadRows: loader.loadRows,
|
|
60
|
+
cachedRows: loader.cachedRows,
|
|
60
61
|
revision: first.dataUpdatedAt
|
|
61
62
|
} : void 0, [
|
|
62
63
|
first.data,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageValue } from "../locale/messages.js";
|
|
2
2
|
//#region src/mailbox/messages.d.ts
|
|
3
3
|
export declare const text: {
|
|
4
|
-
(id: "
|
|
5
|
-
rich(id: "
|
|
4
|
+
(id: "missing" | "expired" | "missingTitle" | "expiredTitle" | "signInOnly" | "connect" | "connectAgain", values?: Record<string, MessageValue>): string;
|
|
5
|
+
rich(id: "missing" | "expired" | "missingTitle" | "expiredTitle" | "signInOnly" | "connect" | "connectAgain", values: Record<string, MessageValue | import("react").ReactNode>): import("react").ReactNode;
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
@@ -3,7 +3,7 @@ export declare const customerCount = 480;
|
|
|
3
3
|
export declare const customerAt: (index: number) => {
|
|
4
4
|
id: string;
|
|
5
5
|
name: string;
|
|
6
|
-
country: "
|
|
6
|
+
country: "GB" | "NL" | "DE";
|
|
7
7
|
city: NonNullable<"Rotterdam" | "Eindhoven" | "Utrecht" | "Zwolle" | "Breda" | "Groningen" | "Düsseldorf" | "Köln" | "Stuttgart" | "Hamburg" | "Münster" | "Nürnberg" | "Leeds" | "Bristol" | "Birmingham" | "Manchester" | "Sheffield">;
|
|
8
8
|
};
|
|
9
9
|
export type Customer = ReturnType<typeof customerAt>;
|
package/dist/mocks/invoices.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const invoiceAt: (index: number) => {
|
|
|
18
18
|
customer: {
|
|
19
19
|
id: string;
|
|
20
20
|
name: string;
|
|
21
|
-
country: "
|
|
21
|
+
country: "GB" | "NL" | "DE";
|
|
22
22
|
city: NonNullable<"Rotterdam" | "Eindhoven" | "Utrecht" | "Zwolle" | "Breda" | "Groningen" | "Düsseldorf" | "Köln" | "Stuttgart" | "Hamburg" | "Münster" | "Nürnberg" | "Leeds" | "Bristol" | "Birmingham" | "Manchester" | "Sheffield">;
|
|
23
23
|
};
|
|
24
24
|
status: "draft" | "sent" | "paid" | "overdue";
|
package/dist/mocks/orders.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare const orderAt: (index: number) => {
|
|
|
9
9
|
id: string;
|
|
10
10
|
name: string;
|
|
11
11
|
};
|
|
12
|
-
country: "
|
|
13
|
-
status: "
|
|
12
|
+
country: "GB" | "NL" | "DE";
|
|
13
|
+
status: "cancelled" | "draft" | "confirmed" | "picking" | "shipped" | "delivered";
|
|
14
14
|
totalCents: number;
|
|
15
|
-
discount: 0 |
|
|
15
|
+
discount: 0 | 15 | 10 | 5;
|
|
16
16
|
paid: boolean;
|
|
17
17
|
createdAt: number;
|
|
18
18
|
owner: "u2" | "u5" | "u8";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageValue } from "../../locale/messages.js";
|
|
2
2
|
//#region src/notifications/bell/messages.d.ts
|
|
3
3
|
export declare const text: {
|
|
4
|
-
(id: "unread" | "empty" | "tryAgain" | "showMore" | "turnOn" | "turnOff" | "
|
|
5
|
-
rich(id: "unread" | "empty" | "tryAgain" | "showMore" | "turnOn" | "turnOff" | "
|
|
4
|
+
(id: "unread" | "empty" | "tryAgain" | "showMore" | "turnOn" | "turnOff" | "loadFailed" | "notifications" | "notificationsUnread" | "notificationsManyUnread" | "markAllRead" | "pushOff" | "pushOn" | "pushBlocked" | "pushRegistrationFailed" | "pushNoTokenApns" | "pushNoTokenFcm" | "pushRefused" | "pushFailed" | "pushOffNotStored", values?: Record<string, MessageValue>): string;
|
|
5
|
+
rich(id: "unread" | "empty" | "tryAgain" | "showMore" | "turnOn" | "turnOff" | "loadFailed" | "notifications" | "notificationsUnread" | "notificationsManyUnread" | "markAllRead" | "pushOff" | "pushOn" | "pushBlocked" | "pushRegistrationFailed" | "pushNoTokenApns" | "pushNoTokenFcm" | "pushRefused" | "pushFailed" | "pushOffNotStored", values: Record<string, MessageValue | import("react").ReactNode>): import("react").ReactNode;
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Spinner } from "../primitives/spinner.js";
|
|
2
2
|
import { Button } from "../primitives/button.js";
|
|
3
3
|
import { useAuth } from "../auth/auth-provider.js";
|
|
4
|
+
import { keys } from "../data/query-keys.js";
|
|
4
5
|
import { authMessage } from "../auth/auth-messages.js";
|
|
5
6
|
import { StatusMark } from "../status/status-mark.js";
|
|
6
7
|
import { PageHeader } from "../app-shell/page-header.js";
|
|
@@ -11,9 +12,10 @@ import { AppRolesPicker } from "./app-roles-picker.js";
|
|
|
11
12
|
import { grantableRoles, organizationRoleLabel } from "./organization-paths.js";
|
|
12
13
|
import { PersonRow } from "../people/person-row.js";
|
|
13
14
|
import { presenceOf } from "../presence/presence.js";
|
|
14
|
-
import { useCallback
|
|
15
|
+
import { useCallback } from "react";
|
|
15
16
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
16
17
|
import { AuthError } from "@protobase/client";
|
|
18
|
+
import { useQuery } from "@tanstack/react-query";
|
|
17
19
|
//#region src/organizations/members-page.tsx
|
|
18
20
|
/** The organization roles the person may set: owners every one, admins those below owner. */
|
|
19
21
|
const assignableOrganizationRoles = (current) => current?.role === "owner" ? [
|
|
@@ -83,13 +85,17 @@ const MemberRow = ({ member, current, status, presence, onChanged }) => {
|
|
|
83
85
|
*/
|
|
84
86
|
const MembersPage = ({ current, statuses, presence }) => {
|
|
85
87
|
const { session } = useAuth();
|
|
86
|
-
const [members, setMembers] = useState();
|
|
87
|
-
const [error, setError] = useState();
|
|
88
88
|
const organizationId = current?.organization?.id;
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
const query = useQuery({
|
|
90
|
+
queryKey: keys.organizationMembers(organizationId ?? ""),
|
|
91
|
+
queryFn: () => session.organizations.members(organizationId),
|
|
92
|
+
enabled: Boolean(organizationId),
|
|
93
|
+
retry: false
|
|
94
|
+
});
|
|
95
|
+
const members = query.data;
|
|
96
|
+
const error = query.error ? query.error instanceof AuthError ? authMessage(query.error) : text("couldNotReadMembers") : void 0;
|
|
97
|
+
const { refetch } = query;
|
|
98
|
+
const load = useCallback(() => void refetch(), [refetch]);
|
|
93
99
|
if (!current?.organization) return null;
|
|
94
100
|
return /* @__PURE__ */ jsxs("div", {
|
|
95
101
|
className: "mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageValue } from "../locale/messages.js";
|
|
2
2
|
//#region src/organizations/messages.d.ts
|
|
3
3
|
export declare const text: {
|
|
4
|
-
(id: "
|
|
5
|
-
rich(id: "
|
|
4
|
+
(id: "members" | "create" | "open" | "organizations" | "accept" | "join" | "leave" | "organization" | "name" | "invitations" | "remove" | "guestLinks" | "yourName" | "signOut" | "loading" | "save" | "cancel" | "until" | "current" | "password" | "delete" | "owner" | "admin" | "member" | "passwordOptional" | "invalidLink" | "manageOrganizations" | "slug" | "allOrganizations" | "allOrganizationsDescription" | "findOrganization" | "nameOrSlug" | "cannotChangeRole" | "makeAccountToJoin" | "makeAccount" | "passwordRequired" | "createAndJoin" | "createYourAccount" | "invitation" | "goToApp" | "invitesToApp" | "invitesTo" | "invitesToWith" | "hasAccount" | "signInAs" | "signInAsToJoin" | "otherAddress" | "signOutToAccept" | "inviteSomeone" | "inviteDescription" | "organizationRole" | "peopleInvited" | "notAcceptedYet" | "sendingAgain" | "nobodyWaiting" | "roleOf" | "couldNotReadMembers" | "whoWorks" | "membersDescription" | "details" | "detailsEditable" | "detailsReadOnly" | "guestLinksDescription" | "guestLinksAllowed" | "handOver" | "handOverDescription" | "newOwner" | "chooseMember" | "deleteOrganization" | "deleteDescription" | "deleteTitle" | "deleteConfirm" | "organizationName" | "leaveOwner" | "leaveMember" | "leaveName" | "noOrganization" | "youAre" | "throughGlobalRoles" | "newOrganization" | "newOrganizationDescription" | "invitationsForYou" | "invitationsForYouDescription" | "anOrganization" | "noAppRoles" | "organizationsSubtitle" | "yourOrganizations" | "memberOf" | "notMember" | "couldNotReadOrganizations", values?: Record<string, MessageValue>): string;
|
|
5
|
+
rich(id: "members" | "create" | "open" | "organizations" | "accept" | "join" | "leave" | "organization" | "name" | "invitations" | "remove" | "guestLinks" | "yourName" | "signOut" | "loading" | "save" | "cancel" | "until" | "current" | "password" | "delete" | "owner" | "admin" | "member" | "passwordOptional" | "invalidLink" | "manageOrganizations" | "slug" | "allOrganizations" | "allOrganizationsDescription" | "findOrganization" | "nameOrSlug" | "cannotChangeRole" | "makeAccountToJoin" | "makeAccount" | "passwordRequired" | "createAndJoin" | "createYourAccount" | "invitation" | "goToApp" | "invitesToApp" | "invitesTo" | "invitesToWith" | "hasAccount" | "signInAs" | "signInAsToJoin" | "otherAddress" | "signOutToAccept" | "inviteSomeone" | "inviteDescription" | "organizationRole" | "peopleInvited" | "notAcceptedYet" | "sendingAgain" | "nobodyWaiting" | "roleOf" | "couldNotReadMembers" | "whoWorks" | "membersDescription" | "details" | "detailsEditable" | "detailsReadOnly" | "guestLinksDescription" | "guestLinksAllowed" | "handOver" | "handOverDescription" | "newOwner" | "chooseMember" | "deleteOrganization" | "deleteDescription" | "deleteTitle" | "deleteConfirm" | "organizationName" | "leaveOwner" | "leaveMember" | "leaveName" | "noOrganization" | "youAre" | "throughGlobalRoles" | "newOrganization" | "newOrganizationDescription" | "invitationsForYou" | "invitationsForYouDescription" | "anOrganization" | "noAppRoles" | "organizationsSubtitle" | "yourOrganizations" | "memberOf" | "notMember" | "couldNotReadOrganizations", values: Record<string, MessageValue | import("react").ReactNode>): import("react").ReactNode;
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
@@ -8,7 +8,10 @@ export type OrganizationsState = {
|
|
|
8
8
|
error?: string;
|
|
9
9
|
reload: () => void;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The current organization and the person's organizations, read again with `reload` after a change; a query, so the
|
|
13
|
+
* start cache keeps them and the app's first frame draws them.
|
|
14
|
+
*/
|
|
12
15
|
export declare const useOrganizations: (enabled: boolean) => OrganizationsState;
|
|
13
16
|
/**
|
|
14
17
|
* Starts the app again in another organization: what it shows, the menu included, follows from the roles there, so it
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import { useAuth } from "../auth/auth-provider.js";
|
|
2
|
+
import { keys } from "../data/query-keys.js";
|
|
2
3
|
import { authMessage } from "../auth/auth-messages.js";
|
|
3
4
|
import { text } from "./messages.js";
|
|
4
|
-
import { useCallback
|
|
5
|
+
import { useCallback } from "react";
|
|
5
6
|
import { AuthError } from "@protobase/client";
|
|
7
|
+
import { useQuery } from "@tanstack/react-query";
|
|
6
8
|
//#region src/organizations/use-organizations.ts
|
|
7
|
-
|
|
9
|
+
const none = [];
|
|
10
|
+
/**
|
|
11
|
+
* The current organization and the person's organizations, read again with `reload` after a change; a query, so the
|
|
12
|
+
* start cache keeps them and the app's first frame draws them.
|
|
13
|
+
*/
|
|
8
14
|
const useOrganizations = (enabled) => {
|
|
9
15
|
const { session } = useAuth();
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setOrganizations(list);
|
|
20
|
-
}, (failure) => setError(failure instanceof AuthError ? authMessage(failure) : text("couldNotReadOrganizations")));
|
|
21
|
-
}, [
|
|
16
|
+
const query = useQuery({
|
|
17
|
+
queryKey: keys.organizations,
|
|
18
|
+
queryFn: async () => {
|
|
19
|
+
const [current, organizations] = await Promise.all([session.organizations.current(), session.organizations.list()]);
|
|
20
|
+
return {
|
|
21
|
+
current,
|
|
22
|
+
organizations
|
|
23
|
+
};
|
|
24
|
+
},
|
|
22
25
|
enabled,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
retry: false
|
|
27
|
+
});
|
|
28
|
+
const { refetch } = query;
|
|
29
|
+
const reload = useCallback(() => void refetch(), [refetch]);
|
|
30
|
+
const data = enabled ? query.data : void 0;
|
|
31
|
+
const error = enabled && query.error ? query.error instanceof AuthError ? authMessage(query.error) : text("couldNotReadOrganizations") : void 0;
|
|
26
32
|
return {
|
|
27
|
-
current,
|
|
28
|
-
organizations,
|
|
33
|
+
current: data?.current,
|
|
34
|
+
organizations: data?.organizations ?? none,
|
|
29
35
|
...error && { error },
|
|
30
36
|
reload
|
|
31
37
|
};
|
package/dist/package.js
CHANGED
|
@@ -2,15 +2,35 @@ import { PluginLoad, PluginLoader } from "./load-plugin.js";
|
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import { PluginRef } from "@protobase/client";
|
|
4
4
|
//#region src/plugins/plugin-source.d.ts
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* The event a host dispatches on `window` when the app's plugins changed where they are served, such as Protobase's
|
|
7
|
+
* official app once it has fetched a workspace's new plugin files: the app loads its plugins again and swaps them in
|
|
8
|
+
* where they draw, keeping what it shows meanwhile. Their components start afresh; the old code stays in memory.
|
|
9
|
+
*/
|
|
10
|
+
export declare const pluginsChangedEvent = "protobase:plugins-changed";
|
|
11
|
+
/**
|
|
12
|
+
* Where the app's plugins come from: each loaded once for the page, by whichever gate asks for it first, or before the
|
|
13
|
+
* app's first render; `loaded` is a plugin's load once it has settled, read at once. `forget` drops every load, so each
|
|
14
|
+
* plugin loads again, and moves `revision` on, which `subscribe` tells.
|
|
15
|
+
*/
|
|
6
16
|
export type PluginSource = {
|
|
7
17
|
load: (ref: PluginRef) => Promise<PluginLoad>;
|
|
18
|
+
loaded: (ref: PluginRef) => PluginLoad | undefined;
|
|
19
|
+
forget: () => void;
|
|
20
|
+
revision: () => number;
|
|
21
|
+
subscribe: (changed: () => void) => () => void;
|
|
8
22
|
};
|
|
9
23
|
/** A source that loads with `loader` and keeps each plugin's load, so one named before and after sign-in loads once. */
|
|
10
|
-
export declare const createPluginSource: (loader: PluginLoader) => PluginSource;
|
|
11
|
-
/**
|
|
12
|
-
|
|
24
|
+
export declare const createPluginSource: (loader: PluginLoader, base?: () => string) => PluginSource;
|
|
25
|
+
/**
|
|
26
|
+
* Loads `refs` ahead of the app's first render, such as the plugins the start cache's `/meta` names, so the plugin gate
|
|
27
|
+
* draws the app with them at once; at most `waitMs`, after which the app starts and the slow ones arrive later.
|
|
28
|
+
*/
|
|
29
|
+
export declare const preloadPlugins: (source: PluginSource, refs: readonly PluginRef[], waitMs: number) => Promise<undefined>;
|
|
30
|
+
/** The app's plugin source: `source` when the page made one before rendering, or one loading with `loader`, the page's `fetch` and `import()` by default. */
|
|
31
|
+
export declare const PluginSourceProvider: ({ loader, source: given, children }: {
|
|
13
32
|
loader?: PluginLoader;
|
|
33
|
+
source?: PluginSource;
|
|
14
34
|
children: ReactNode;
|
|
15
35
|
}) => import("react").JSX.Element;
|
|
16
36
|
export declare const usePluginSource: () => PluginSource;
|
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
import { browserLoader, loadPlugin } from "./load-plugin.js";
|
|
2
|
-
import { createContext, useContext, useMemo } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
//#region src/plugins/plugin-source.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The event a host dispatches on `window` when the app's plugins changed where they are served, such as Protobase's
|
|
7
|
+
* official app once it has fetched a workspace's new plugin files: the app loads its plugins again and swaps them in
|
|
8
|
+
* where they draw, keeping what it shows meanwhile. Their components start afresh; the old code stays in memory.
|
|
9
|
+
*/
|
|
10
|
+
const pluginsChangedEvent = "protobase:plugins-changed";
|
|
5
11
|
/** A source that loads with `loader` and keeps each plugin's load, so one named before and after sign-in loads once. */
|
|
6
|
-
const createPluginSource = (loader) => {
|
|
12
|
+
const createPluginSource = (loader, base = () => window.location.href) => {
|
|
7
13
|
const loads = /* @__PURE__ */ new Map();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const settled = /* @__PURE__ */ new Map();
|
|
15
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
16
|
+
let revision = 0;
|
|
17
|
+
return {
|
|
18
|
+
load: (ref) => {
|
|
19
|
+
const key = JSON.stringify(ref);
|
|
20
|
+
const known = loads.get(key);
|
|
21
|
+
if (known) return known;
|
|
22
|
+
const load = loadPlugin(ref, loader, base());
|
|
23
|
+
loads.set(key, load);
|
|
24
|
+
load.then((result) => settled.set(key, result));
|
|
25
|
+
return load;
|
|
26
|
+
},
|
|
27
|
+
loaded: (ref) => settled.get(JSON.stringify(ref)),
|
|
28
|
+
forget: () => {
|
|
29
|
+
loads.clear();
|
|
30
|
+
settled.clear();
|
|
31
|
+
revision += 1;
|
|
32
|
+
for (const changed of listeners) changed();
|
|
33
|
+
},
|
|
34
|
+
revision: () => revision,
|
|
35
|
+
subscribe: (changed) => {
|
|
36
|
+
listeners.add(changed);
|
|
37
|
+
return () => void listeners.delete(changed);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
16
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Loads `refs` ahead of the app's first render, such as the plugins the start cache's `/meta` names, so the plugin gate
|
|
43
|
+
* draws the app with them at once; at most `waitMs`, after which the app starts and the slow ones arrive later.
|
|
44
|
+
*/
|
|
45
|
+
const preloadPlugins = (source, refs, waitMs) => Promise.race([Promise.all(refs.map((ref) => source.load(ref))), new Promise((resolve) => setTimeout(resolve, waitMs))]).then(() => void 0);
|
|
17
46
|
const PluginSourceContext = createContext(null);
|
|
18
|
-
/** The app's plugin source, loading with `loader
|
|
19
|
-
const PluginSourceProvider = ({ loader = browserLoader, children }) => {
|
|
20
|
-
const source = useMemo(() => createPluginSource(loader), [loader]);
|
|
47
|
+
/** The app's plugin source: `source` when the page made one before rendering, or one loading with `loader`, the page's `fetch` and `import()` by default. */
|
|
48
|
+
const PluginSourceProvider = ({ loader = browserLoader, source: given, children }) => {
|
|
49
|
+
const source = useMemo(() => given ?? createPluginSource(loader), [given, loader]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const changed = () => source.forget();
|
|
52
|
+
window.addEventListener(pluginsChangedEvent, changed);
|
|
53
|
+
return () => window.removeEventListener(pluginsChangedEvent, changed);
|
|
54
|
+
}, [source]);
|
|
21
55
|
return /* @__PURE__ */ jsx(PluginSourceContext.Provider, {
|
|
22
56
|
value: source,
|
|
23
57
|
children
|
|
@@ -29,4 +63,4 @@ const usePluginSource = () => {
|
|
|
29
63
|
return source;
|
|
30
64
|
};
|
|
31
65
|
//#endregion
|
|
32
|
-
export { PluginSourceProvider, createPluginSource, usePluginSource };
|
|
66
|
+
export { PluginSourceProvider, createPluginSource, pluginsChangedEvent, preloadPlugins, usePluginSource };
|
|
@@ -6,12 +6,14 @@ import { PluginRef } from "@protobase/client";
|
|
|
6
6
|
export declare const pluginWaitMs = 10000;
|
|
7
7
|
type Loads = {
|
|
8
8
|
key: string;
|
|
9
|
+
refs?: string;
|
|
9
10
|
loads: PluginLoad[];
|
|
10
11
|
settled: boolean;
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* The plugins `refs` names, in their order, as they load. `settled` once every one has loaded or failed, or after
|
|
14
|
-
* `pluginWaitMs`, so a slow plugin delays the app only that long. Without plugins it is settled at once
|
|
15
|
+
* `pluginWaitMs`, so a slow plugin delays the app only that long. Without plugins it is settled at once, and so it is
|
|
16
|
+
* when the source has loaded every one already, as before the app's first render.
|
|
15
17
|
*/
|
|
16
18
|
export declare const usePluginLoads: (refs: readonly PluginRef[], source: PluginSource) => Loads | {
|
|
17
19
|
loads: PluginLoad[];
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
2
2
|
//#region src/plugins/use-plugin-loads.ts
|
|
3
3
|
/** How long the app waits for its plugins before it draws without the ones still loading, which arrive later. */
|
|
4
4
|
const pluginWaitMs = 1e4;
|
|
5
5
|
const none = [];
|
|
6
6
|
/**
|
|
7
7
|
* The plugins `refs` names, in their order, as they load. `settled` once every one has loaded or failed, or after
|
|
8
|
-
* `pluginWaitMs`, so a slow plugin delays the app only that long. Without plugins it is settled at once
|
|
8
|
+
* `pluginWaitMs`, so a slow plugin delays the app only that long. Without plugins it is settled at once, and so it is
|
|
9
|
+
* when the source has loaded every one already, as before the app's first render.
|
|
9
10
|
*/
|
|
10
11
|
const usePluginLoads = (refs, source) => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
12
|
+
const revision = useSyncExternalStore(source.subscribe, source.revision, source.revision);
|
|
13
|
+
const named = JSON.stringify(refs);
|
|
14
|
+
const key = `${named}#${revision}`;
|
|
15
|
+
const [state, setState] = useState(() => loadedAlready(refs, source, key) ?? {
|
|
13
16
|
key: "[]",
|
|
14
17
|
loads: none,
|
|
15
18
|
settled: true
|
|
@@ -22,10 +25,12 @@ const usePluginLoads = (refs, source) => {
|
|
|
22
25
|
const publish = () => {
|
|
23
26
|
if (!active) return;
|
|
24
27
|
const loads = results.filter((load) => load !== void 0);
|
|
25
|
-
|
|
28
|
+
const settled = waited || loads.length === refs.length;
|
|
29
|
+
setState((current) => current.refs === named && current.settled && !settled ? current : {
|
|
26
30
|
key,
|
|
31
|
+
refs: named,
|
|
27
32
|
loads,
|
|
28
|
-
settled
|
|
33
|
+
settled
|
|
29
34
|
});
|
|
30
35
|
};
|
|
31
36
|
const timer = setTimeout(() => {
|
|
@@ -47,10 +52,22 @@ const usePluginLoads = (refs, source) => {
|
|
|
47
52
|
loads: none,
|
|
48
53
|
settled: true
|
|
49
54
|
};
|
|
50
|
-
|
|
55
|
+
if (state.key === key) return state;
|
|
56
|
+
if (state.refs === named && state.settled) return state;
|
|
57
|
+
return loadedAlready(refs, source, key) ?? {
|
|
51
58
|
loads: none,
|
|
52
59
|
settled: false
|
|
53
60
|
};
|
|
54
61
|
};
|
|
62
|
+
const loadedAlready = (refs, source, key) => {
|
|
63
|
+
if (refs.length === 0) return void 0;
|
|
64
|
+
const loads = refs.map((ref) => source.loaded(ref));
|
|
65
|
+
return loads.every((load) => load !== void 0) ? {
|
|
66
|
+
key,
|
|
67
|
+
refs: JSON.stringify(refs),
|
|
68
|
+
loads,
|
|
69
|
+
settled: true
|
|
70
|
+
} : void 0;
|
|
71
|
+
};
|
|
55
72
|
//#endregion
|
|
56
73
|
export { pluginWaitMs, usePluginLoads };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageValue } from "../locale/messages.js";
|
|
2
2
|
//#region src/primitives/messages.d.ts
|
|
3
3
|
export declare const text: {
|
|
4
|
-
(id: "
|
|
5
|
-
rich(id: "
|
|
4
|
+
(id: "remove" | "close" | "loading" | "next" | "previous" | "dragToClose", values?: Record<string, MessageValue>): string;
|
|
5
|
+
rich(id: "remove" | "close" | "loading" | "next" | "previous" | "dragToClose", values: Record<string, MessageValue | import("react").ReactNode>): import("react").ReactNode;
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
@@ -6,6 +6,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
6
6
|
* load that quick shows no flash, then shimmers, or stays still when less motion is asked for.
|
|
7
7
|
*/
|
|
8
8
|
const Skeleton = ({ className, style }) => /* @__PURE__ */ jsx("span", {
|
|
9
|
+
"data-placeholder": true,
|
|
9
10
|
className: cn("block h-3 rounded bg-muted", skeletonMotion, className),
|
|
10
11
|
style
|
|
11
12
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MessageValue } from "../locale/messages.js";
|
|
2
2
|
//#region src/record-view/messages.d.ts
|
|
3
3
|
export declare const text: {
|
|
4
|
-
(id: "
|
|
5
|
-
rich(id: "
|
|
4
|
+
(id: "saving" | "actions" | "tabs" | "headingCount" | "headingCountRecords" | "savedDifferent" | "example" | "savedThis" | "keepMine" | "useTheirs" | "savedAgo" | "notSavedRetrying" | "lastEditedBy" | "lastUpdated" | "viewing", values?: Record<string, MessageValue>): string;
|
|
5
|
+
rich(id: "saving" | "actions" | "tabs" | "headingCount" | "headingCountRecords" | "savedDifferent" | "example" | "savedThis" | "keepMine" | "useTheirs" | "savedAgo" | "notSavedRetrying" | "lastEditedBy" | "lastUpdated" | "viewing", values: Record<string, MessageValue | import("react").ReactNode>): import("react").ReactNode;
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
@@ -6,6 +6,9 @@ export type ActiveRoleState = {
|
|
|
6
6
|
/** Acts with another role, then starts the app again, as a switch of organization does. */
|
|
7
7
|
switchTo: (name: string) => void;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The role the session acts with, read while `enabled` (someone is signed in) as a query, so the start cache keeps it and
|
|
11
|
+
* the app's first frame draws it; a failed read or switch shows as a toast.
|
|
12
|
+
*/
|
|
10
13
|
export declare const useActiveRole: (reopen: () => void, enabled?: boolean) => ActiveRoleState;
|
|
11
14
|
//#endregion
|
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import { useAuth } from "../auth/auth-provider.js";
|
|
2
|
+
import { keys } from "../data/query-keys.js";
|
|
2
3
|
import { useToast } from "../toasts/toast-provider.js";
|
|
3
4
|
import { authMessage } from "../auth/auth-messages.js";
|
|
4
5
|
import { text } from "./messages.js";
|
|
5
|
-
import { useCallback, useEffect
|
|
6
|
+
import { useCallback, useEffect } from "react";
|
|
6
7
|
import { AuthError } from "@protobase/client";
|
|
8
|
+
import { useQuery } from "@tanstack/react-query";
|
|
7
9
|
//#region src/roles/use-active-role.ts
|
|
8
10
|
const failureMessage = (failure, fallback) => failure instanceof AuthError ? authMessage(failure) : fallback;
|
|
9
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The role the session acts with, read while `enabled` (someone is signed in) as a query, so the start cache keeps it and
|
|
13
|
+
* the app's first frame draws it; a failed read or switch shows as a toast.
|
|
14
|
+
*/
|
|
10
15
|
const useActiveRole = (reopen, enabled = true) => {
|
|
11
16
|
const { session } = useAuth();
|
|
12
17
|
const toast = useToast();
|
|
13
|
-
const
|
|
18
|
+
const role = useQuery({
|
|
19
|
+
queryKey: keys.activeRole,
|
|
20
|
+
queryFn: () => session.roles.current(),
|
|
21
|
+
enabled,
|
|
22
|
+
retry: false
|
|
23
|
+
});
|
|
14
24
|
useEffect(() => {
|
|
15
|
-
if (
|
|
16
|
-
session.roles.current().then(setCurrent, (failure) => toast.show({
|
|
25
|
+
if (role.error) toast.show({
|
|
17
26
|
state: "error",
|
|
18
|
-
title: failureMessage(
|
|
19
|
-
})
|
|
20
|
-
}, [
|
|
21
|
-
session,
|
|
22
|
-
toast,
|
|
23
|
-
enabled
|
|
24
|
-
]);
|
|
27
|
+
title: failureMessage(role.error, text("couldNotReadRoles"))
|
|
28
|
+
});
|
|
29
|
+
}, [role.error, toast]);
|
|
25
30
|
const switchTo = useCallback((name) => void session.roles.switchTo(name).then(reopen, (failure) => toast.show({
|
|
26
31
|
state: "error",
|
|
27
32
|
title: failureMessage(failure, text("couldNotSwitch"))
|
|
@@ -31,7 +36,7 @@ const useActiveRole = (reopen, enabled = true) => {
|
|
|
31
36
|
reopen
|
|
32
37
|
]);
|
|
33
38
|
return {
|
|
34
|
-
...
|
|
39
|
+
...enabled && role.data && { current: role.data },
|
|
35
40
|
switchTo
|
|
36
41
|
};
|
|
37
42
|
};
|