@ekanos/sdk 0.23.0 → 0.24.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 +15 -13
- package/api-report.md +10 -3
- package/dist/components/base-activation-dialog.js +2 -2
- package/dist/components/base-activation-dialog.js.map +1 -1
- package/dist/components/base-activation-form.js +2 -2
- package/dist/components/base-activation-form.js.map +1 -1
- package/dist/components/base-marketplace-tile.js +2 -2
- package/dist/components/base-marketplace-tile.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/widgets/ai-prompt-chip.js +2 -2
- package/dist/components/widgets/ai-prompt-chip.js.map +1 -1
- package/dist/components/widgets/widget-ask-bar.js +1 -1
- package/dist/components/widgets/widget-ask-bar.js.map +1 -1
- package/dist/components/widgets/widget-query-state.d.ts +57 -0
- package/dist/components/widgets/widget-query-state.js +44 -0
- package/dist/components/widgets/widget-query-state.js.map +1 -0
- package/dist/components/widgets/widget-state-components.js +4 -4
- package/dist/components/widgets/widget-state-components.js.map +1 -1
- package/dist/components/widgets/widget.d.ts +18 -23
- package/dist/components/widgets/widget.js +31 -32
- package/dist/components/widgets/widget.js.map +1 -1
- package/dist/experience/client.d.ts +7 -5
- package/dist/experience/client.js +7 -5
- package/dist/experience/client.js.map +1 -1
- package/dist/experience/define-experience.d.ts +13 -1
- package/dist/experience/define-experience.js +13 -1
- package/dist/experience/define-experience.js.map +1 -1
- package/dist/experience/runtime.d.ts +15 -8
- package/dist/experience/runtime.js.map +1 -1
- package/dist/experience/server.d.ts +3 -2
- package/dist/experience/server.js +3 -2
- package/dist/experience/server.js.map +1 -1
- package/dist/hooks/use-oauth-connection-status.js +3 -1
- package/dist/hooks/use-oauth-connection-status.js.map +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/types.d.ts +1 -1
- package/dist/integration/types.js.map +1 -1
- package/eslint.design-rules.mjs +35 -160
- package/package.json +3 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a widget's own read becomes its `Widget.DataState` status.
|
|
3
|
+
*
|
|
4
|
+
* Every data widget used to write this as a ternary over `isLoading` /
|
|
5
|
+
* `isError`, and every copy had the same bug: TanStack Query reports
|
|
6
|
+
* `isError` after a failed BACKGROUND refetch too, while the last good rows
|
|
7
|
+
* are still in `data`, so a card the member was reading flipped to its error
|
|
8
|
+
* view. A failed refresh with rows still on screen is not degraded: only a
|
|
9
|
+
* read that never produced rows is. The card keeps its rows and its
|
|
10
|
+
* "Updated …" footer says how old they are.
|
|
11
|
+
*
|
|
12
|
+
* No React here, so the rule is testable with plain objects.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The status, in the order a widget means it: not connected, then still
|
|
16
|
+
* loading, then a read that failed with nothing on screen, then ready.
|
|
17
|
+
*/
|
|
18
|
+
export function widgetQueryStatus(query, connection) {
|
|
19
|
+
if (connection === null || connection === void 0 ? void 0 : connection.notConnected)
|
|
20
|
+
return 'inactive';
|
|
21
|
+
if (connection === null || connection === void 0 ? void 0 : connection.connectionPending)
|
|
22
|
+
return 'loading';
|
|
23
|
+
if (connection === null || connection === void 0 ? void 0 : connection.connectionError)
|
|
24
|
+
return 'error';
|
|
25
|
+
const loading = connection
|
|
26
|
+
? connection.dataEnabled && query.isPending
|
|
27
|
+
: query.isLoading;
|
|
28
|
+
if (loading)
|
|
29
|
+
return 'loading';
|
|
30
|
+
const hasData = query.data !== undefined;
|
|
31
|
+
if (query.isError && !hasData)
|
|
32
|
+
return 'error';
|
|
33
|
+
return 'ready';
|
|
34
|
+
}
|
|
35
|
+
/** Everything `Widget.DataState` takes from one query. */
|
|
36
|
+
export function widgetQueryState(query, connection) {
|
|
37
|
+
return {
|
|
38
|
+
status: widgetQueryStatus(query, connection),
|
|
39
|
+
onRefresh: () => void query.refetch(),
|
|
40
|
+
refreshing: query.isFetching,
|
|
41
|
+
updatedAt: query.dataUpdatedAt,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=widget-query-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-query-state.js","sourceRoot":"","sources":["../../../src/components/widgets/widget-query-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA2CH;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAwE,EACxE,UAAiC;IAEjC,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,YAAY;QAAE,OAAO,UAAU,CAAC;IAChD,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,iBAAiB;QAAE,OAAO,SAAS,CAAC;IACpD,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,eAAe;QAAE,OAAO,OAAO,CAAC;IAEhD,MAAM,OAAO,GAAG,UAAU;QACxB,CAAC,CAAC,UAAU,CAAC,WAAW,IAAI,KAAK,CAAC,SAAS;QAC3C,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IACpB,IAAI,OAAO;QAAE,OAAO,SAAS,CAAC;IAE9B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,gBAAgB,CAC9B,KAAkB,EAClB,UAAiC;IAEjC,OAAO;QACL,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC;QAC5C,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE;QACrC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,SAAS,EAAE,KAAK,CAAC,aAAa;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["/**\n * How a widget's own read becomes its `Widget.DataState` status.\n *\n * Every data widget used to write this as a ternary over `isLoading` /\n * `isError`, and every copy had the same bug: TanStack Query reports\n * `isError` after a failed BACKGROUND refetch too, while the last good rows\n * are still in `data`, so a card the member was reading flipped to its error\n * view. A failed refresh with rows still on screen is not degraded: only a\n * read that never produced rows is. The card keeps its rows and its\n * \"Updated …\" footer says how old they are.\n *\n * No React here, so the rule is testable with plain objects.\n */\n\nimport type { WidgetDataStatus } from './widget';\n\n/**\n * The part of a TanStack Query result a widget's data state reads. A\n * `useQuery` result satisfies it as is.\n */\nexport interface WidgetQuery {\n data: unknown;\n /** No data yet (the query may not be fetching: see `isLoading`). */\n isPending: boolean;\n /** First load in flight: pending AND fetching. */\n isLoading: boolean;\n isError: boolean;\n isFetching: boolean;\n /** Epoch ms of the last success; `0` before the first. */\n dataUpdatedAt: number;\n refetch: () => unknown;\n}\n\n/**\n * The upstream connection a connector widget waits on before it reads,\n * as `useOAuthWidgetGate` returns it.\n */\nexport interface WidgetConnectionGate {\n /** The connection check answered: no token. */\n notConnected: boolean;\n /** The connection check has not answered yet. */\n connectionPending: boolean;\n /** The connection check failed with nothing to fall back on. */\n connectionError: boolean;\n /** Connected: the widget's own read is enabled. */\n dataEnabled: boolean;\n}\n\nexport interface WidgetQueryState {\n status: WidgetDataStatus;\n onRefresh: () => void;\n refreshing: boolean;\n updatedAt: number;\n}\n\n/**\n * The status, in the order a widget means it: not connected, then still\n * loading, then a read that failed with nothing on screen, then ready.\n */\nexport function widgetQueryStatus(\n query: Pick<WidgetQuery, 'data' | 'isPending' | 'isLoading' | 'isError'>,\n connection?: WidgetConnectionGate,\n): WidgetDataStatus {\n if (connection?.notConnected) return 'inactive';\n if (connection?.connectionPending) return 'loading';\n if (connection?.connectionError) return 'error';\n\n const loading = connection\n ? connection.dataEnabled && query.isPending\n : query.isLoading;\n if (loading) return 'loading';\n\n const hasData = query.data !== undefined;\n if (query.isError && !hasData) return 'error';\n return 'ready';\n}\n\n/** Everything `Widget.DataState` takes from one query. */\nexport function widgetQueryState(\n query: WidgetQuery,\n connection?: WidgetConnectionGate,\n): WidgetQueryState {\n return {\n status: widgetQueryStatus(query, connection),\n onRefresh: () => void query.refetch(),\n refreshing: query.isFetching,\n updatedAt: query.dataUpdatedAt,\n };\n}\n"]}
|
|
@@ -17,7 +17,7 @@ function StateAction({ action, variant = 'default', }) {
|
|
|
17
17
|
* and at most one action, left-aligned in the body's padding.
|
|
18
18
|
*/
|
|
19
19
|
function StateNote({ icon, title, description, action, actionVariant, role, testId, }) {
|
|
20
|
-
return (_jsxs("div", { role: role, className: "flex flex-1 flex-col items-start gap-3 px-5 pt-2 pb-5", "data-test": testId, children: [_jsx(Icon, { name: icon, className: "text-muted-foreground h-6 w-6", "aria-hidden": true }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-foreground text-
|
|
20
|
+
return (_jsxs("div", { role: role, className: "flex flex-1 flex-col items-start gap-3 px-5 pt-2 pb-5", "data-test": testId, children: [_jsx(Icon, { name: icon, className: "text-muted-foreground h-6 w-6", "aria-hidden": true }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-foreground text-base font-medium", children: title }), description ? (_jsx("p", { className: "text-muted-foreground max-w-prose text-sm", children: description })) : null] }), action ? _jsx(StateAction, { action: action, variant: actionVariant }) : null] }));
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* The empty state for a widget with nothing to show. Positive by default:
|
|
@@ -40,7 +40,7 @@ const INACTIVE_ICON = {
|
|
|
40
40
|
*/
|
|
41
41
|
export function WidgetInactiveState({ reason, integrationName, title, description, action, } = {}) {
|
|
42
42
|
if (!reason) {
|
|
43
|
-
return (_jsx("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: _jsx("p", { className: "text-muted-foreground text-
|
|
43
|
+
return (_jsx("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: _jsx("p", { className: "text-muted-foreground text-sm", children: title !== null && title !== void 0 ? title : (_jsx(Trans, { i18nKey: "dashboard:widgetInactive", defaults: "Widget inactive" })) }) }));
|
|
44
44
|
}
|
|
45
45
|
const name = integrationName !== null && integrationName !== void 0 ? integrationName : 'this integration';
|
|
46
46
|
const defaults = {
|
|
@@ -68,12 +68,12 @@ export function WidgetLoadingSkeleton({ variant = 'rows', }) {
|
|
|
68
68
|
return (_jsxs("div", { role: "status", "aria-busy": "true", className: "flex flex-1 flex-col", "data-test": `widget-skeleton-${variant}`, children: [_jsx("span", { className: "sr-only", children: _jsx(Trans, { i18nKey: "dashboard:widgetLoading", defaults: "Loading..." }) }), variant === 'stat' ? (_jsxs("div", { className: "space-y-2 px-5 pt-2 pb-5", children: [_jsx(Skeleton, { className: "h-3 w-24" }), _jsx(Skeleton, { className: "h-8 w-40" }), _jsx(Skeleton, { className: "h-3 w-32" })] })) : variant === 'chart' ? (_jsxs("div", { className: "space-y-3 px-5 pt-2 pb-5", children: [_jsx(Skeleton, { className: "h-8 w-40" }), _jsx(Skeleton, { className: "h-60 w-full" })] })) : (_jsx("div", { className: "divide-border divide-y", children: [0, 1, 2].map((row) => (_jsx("div", { className: cn('px-5 py-3', variant === 'schedule' ? 'flex items-start gap-3' : 'space-y-2'), children: variant === 'schedule' ? (_jsxs(_Fragment, { children: [_jsx(Skeleton, { className: "h-4 w-14 shrink-0" }), _jsxs("div", { className: "flex-1 space-y-2", children: [_jsx(Skeleton, { className: "h-4 w-2/3" }), _jsx(Skeleton, { className: "h-3 w-1/3" })] })] })) : (_jsxs(_Fragment, { children: [_jsx(Skeleton, { className: "h-4 w-2/3" }), _jsx(Skeleton, { className: "h-3 w-1/2" })] })) }, row))) }))] }));
|
|
69
69
|
}
|
|
70
70
|
export function WidgetErrorState({ title, description, onRetry, retrying = false, }) {
|
|
71
|
-
return (_jsxs("div", { role: "alert", className: "flex flex-col items-center justify-center gap-3 px-5 py-8 text-center", children: [_jsx("div", { className: "bg-destructive
|
|
71
|
+
return (_jsxs("div", { role: "alert", className: "flex flex-col items-center justify-center gap-3 px-5 py-8 text-center", children: [_jsx("div", { className: "bg-destructive-surface flex h-10 w-10 items-center justify-center rounded-full", children: _jsx(Icon, { name: "fa-circle-exclamation", className: "text-destructive h-5 w-5", "aria-hidden": true }) }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-foreground text-sm font-medium", children: title !== null && title !== void 0 ? title : (_jsx(Trans, { i18nKey: "dashboard:widgetErrorTitle", defaults: "Couldn't load this widget" })) }), _jsx("p", { className: "text-muted-foreground text-sm", children: description ? (description) : onRetry ? (_jsx(Trans, { i18nKey: "dashboard:widgetErrorBodyRetry", defaults: "Try again, or check back in a few minutes." })) : (_jsx(Trans, { i18nKey: "dashboard:widgetErrorBody", defaults: "Check back in a few minutes." })) })] }), onRetry ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: onRetry, disabled: retrying, "data-test": "widget-error-retry", children: [_jsx(Icon, { name: "fa-arrows-rotate", className: cn('h-4 w-4', retrying && 'animate-spin'), "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRetry", defaults: "Try again" })] })) : null] }));
|
|
72
72
|
}
|
|
73
73
|
export function WidgetDataLoading() {
|
|
74
74
|
return (_jsx("div", { className: "flex flex-1 items-center justify-center py-12", children: _jsx(Icon, { name: "fa-spinner-third", className: "text-muted-foreground h-8 w-8 animate-spin" }) }));
|
|
75
75
|
}
|
|
76
76
|
export function WidgetDisabledState() {
|
|
77
|
-
return (_jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: [_jsx(Icon, { name: "fa-ban", className: "text-muted-foreground mb-4 h-8 w-8" }), _jsx("p", { className: "text-muted-foreground text-
|
|
77
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center py-8 text-center", children: [_jsx(Icon, { name: "fa-ban", className: "text-muted-foreground mb-4 h-8 w-8" }), _jsx("p", { className: "text-muted-foreground text-sm", children: _jsx(Trans, { i18nKey: "dashboard:widgetDisabled", defaults: "Widget Disabled" }) })] }));
|
|
78
78
|
}
|
|
79
79
|
//# sourceMappingURL=widget-state-components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-state-components.js","sourceRoot":"","sources":["../../../src/components/widgets/widget-state-components.tsx"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AA6CtC,SAAS,WAAW,CAAC,EACnB,MAAM,EACN,OAAO,GAAG,SAAS,GAIpB;IACC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC7B,YAAG,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAC,QAAQ,EAAC,GAAG,EAAC,qBAAqB,GAAG,CACnE,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAI,CAC5B,CAAC;QAEF,OAAO,CACL,KAAC,MAAM,IAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,YAClE,MAAM,CAAC,KAAK,GACN,CACV,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,MAAM,IAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,MAAM,CAAC,OAAO,YACtE,MAAM,CAAC,KAAK,GACN,CACV,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAC,EACjB,IAAI,EACJ,KAAK,EACL,WAAW,EACX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,GACrE,IACA,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from 'react';\n\nimport Link from 'next/link.js';\n\nimport { Button } from '@ekanos/ui/button';\nimport { Icon } from '@ekanos/ui/icon';\nimport { Skeleton } from '@ekanos/ui/skeleton';\nimport { Trans } from '@ekanos/ui/trans';\nimport { cn } from '@ekanos/ui/utils';\n\n/**\n * The one action a state view offers: \"Connect QuickBooks\", \"Ask an admin\",\n * \"Create a deal\". A link with `href`, otherwise a button running `onClick`.\n */\nexport interface WidgetStateAction {\n label: ReactNode;\n href?: string;\n /** Open `href` in a new tab. */\n external?: boolean;\n onClick?: () => void;\n}\n\n/** The body shape a loading skeleton stands in for. */\nexport type WidgetSkeletonVariant = 'rows' | 'stat' | 'chart' | 'schedule';\n\n/** Why an active integration still can't show this widget's data. */\nexport type WidgetInactiveReason =\n | 'not-connected'\n | 'no-access'\n | 'setup-needed';\n\nexport interface WidgetEmptyStateProps {\n /**\n * `positive` (the default) says nothing needs the owner: \"You're all caught\n * up\". `neutral` is for an empty list that isn't good news, like a search\n * with no results.\n */\n tone?: 'positive' | 'neutral';\n title?: ReactNode;\n description?: ReactNode;\n action?: WidgetStateAction;\n}\n\nexport interface WidgetInactiveStateProps {\n reason?: WidgetInactiveReason;\n /** The integration's name, for the default copy (\"Connect QuickBooks\"). */\n integrationName?: string;\n title?: ReactNode;\n /** One sentence on what connecting or access gives the owner. */\n description?: ReactNode;\n action?: WidgetStateAction;\n}\n\nfunction StateAction({\n action,\n variant = 'default',\n}: {\n action: WidgetStateAction;\n variant?: 'default' | 'outline';\n}) {\n if (action.href) {\n const link = action.external ? (\n <a href={action.href} target=\"_blank\" rel=\"noopener noreferrer\" />\n ) : (\n <Link href={action.href} />\n );\n\n return (\n <Button size=\"sm\" variant={variant} render={link} nativeButton={false}>\n {action.label}\n </Button>\n );\n }\n\n return (\n <Button size=\"sm\" variant={variant} type=\"button\" onClick={action.onClick}>\n {action.label}\n </Button>\n );\n}\n\n/**\n * The shared shape of every non-data state: an icon, a title, one sentence\n * and at most one action, left-aligned in the body's padding.\n */\nfunction StateNote({\n icon,\n title,\n description,\n action,\n actionVariant,\n role,\n testId,\n}: {\n icon: string;\n title: ReactNode;\n description?: ReactNode;\n action?: WidgetStateAction;\n actionVariant?: 'default' | 'outline';\n role?: 'alert' | 'status';\n testId: string;\n}) {\n return (\n <div\n role={role}\n className=\"flex flex-1 flex-col items-start gap-3 px-5 pt-2 pb-5\"\n data-test={testId}\n >\n <Icon name={icon} className=\"text-muted-foreground h-6 w-6\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-foreground text-body font-medium\">{title}</p>\n {description ? (\n <p className=\"text-muted-foreground text-meta max-w-prose\">\n {description}\n </p>\n ) : null}\n </div>\n {action ? <StateAction action={action} variant={actionVariant} /> : null}\n </div>\n );\n}\n\n/**\n * The empty state for a widget with nothing to show. Positive by default:\n * an empty review queue is good news, so it reassures instead of apologizing.\n */\nexport function WidgetEmptyState({\n tone = 'positive',\n title,\n description,\n action,\n}: WidgetEmptyStateProps) {\n const positive = tone === 'positive';\n\n return (\n <StateNote\n icon={positive ? 'fa-circle-check' : 'fa-inbox'}\n title={\n title ??\n (positive ? (\n <Trans\n i18nKey=\"dashboard:widgetEmptyPositive\"\n defaults=\"You're all caught up\"\n />\n ) : (\n <Trans\n i18nKey=\"dashboard:widgetEmptyNeutral\"\n defaults=\"Nothing here yet\"\n />\n ))\n }\n description={description}\n action={action}\n actionVariant=\"outline\"\n role=\"status\"\n testId={`widget-empty-${tone}`}\n />\n );\n}\n\nconst INACTIVE_ICON: Record<WidgetInactiveReason, string> = {\n 'not-connected': 'fa-plug',\n 'no-access': 'fa-user-group',\n 'setup-needed': 'fa-sliders',\n};\n\n/**\n * Why the widget can't show data. `not-connected` offers one Connect button;\n * `no-access` is a calm note that points to an admin, never a lock screen;\n * `setup-needed` points to the integration's settings. Without a `reason` it\n * keeps the original one-line \"Widget inactive\".\n */\nexport function WidgetInactiveState({\n reason,\n integrationName,\n title,\n description,\n action,\n}: WidgetInactiveStateProps = {}) {\n if (!reason) {\n return (\n <div className=\"flex flex-col items-center justify-center py-8 text-center\">\n <p className=\"text-muted-foreground text-meta\">\n {title ?? (\n <Trans\n i18nKey=\"dashboard:widgetInactive\"\n defaults=\"Widget inactive\"\n />\n )}\n </p>\n </div>\n );\n }\n\n const name = integrationName ?? 'this integration';\n\n const defaults: Record<\n WidgetInactiveReason,\n { title: ReactNode; description: ReactNode }\n > = {\n 'not-connected': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetNotConnectedTitle\"\n defaults=\"Connect {{name}}\"\n values={{ name }}\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetNotConnectedBody\"\n defaults=\"Connect {{name}} and this card fills in with your own data.\"\n values={{ name }}\n />\n ),\n },\n 'no-access': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetNoAccessTitle\"\n defaults=\"Shared with admins for now\"\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetNoAccessBody\"\n defaults=\"Your role doesn't include this data yet. Ask an admin if you need it.\"\n />\n ),\n },\n 'setup-needed': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetSetupNeededTitle\"\n defaults=\"Finish setting up {{name}}\"\n values={{ name }}\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetSetupNeededBody\"\n defaults=\"One more step and this card starts showing data.\"\n />\n ),\n },\n };\n\n return (\n <StateNote\n icon={INACTIVE_ICON[reason]}\n title={title ?? defaults[reason].title}\n description={description ?? defaults[reason].description}\n action={action}\n actionVariant={reason === 'no-access' ? 'outline' : 'default'}\n testId={`widget-inactive-${reason}`}\n />\n );\n}\n\n/**\n * Loading, drawn as the body it stands in for so the card doesn't jump when\n * data lands. Rows suit lists and feeds, `stat` a headline figure, `chart` a\n * chart, `schedule` a day of events.\n */\nexport function WidgetLoadingSkeleton({\n variant = 'rows',\n}: {\n variant?: WidgetSkeletonVariant;\n}) {\n return (\n <div\n role=\"status\"\n aria-busy=\"true\"\n className=\"flex flex-1 flex-col\"\n data-test={`widget-skeleton-${variant}`}\n >\n <span className=\"sr-only\">\n <Trans i18nKey=\"dashboard:widgetLoading\" defaults=\"Loading...\" />\n </span>\n {variant === 'stat' ? (\n <div className=\"space-y-2 px-5 pt-2 pb-5\">\n <Skeleton className=\"h-3 w-24\" />\n <Skeleton className=\"h-8 w-40\" />\n <Skeleton className=\"h-3 w-32\" />\n </div>\n ) : variant === 'chart' ? (\n <div className=\"space-y-3 px-5 pt-2 pb-5\">\n <Skeleton className=\"h-8 w-40\" />\n <Skeleton className=\"h-60 w-full\" />\n </div>\n ) : (\n <div className=\"divide-border divide-y\">\n {[0, 1, 2].map((row) => (\n <div\n key={row}\n className={cn(\n 'px-5 py-3',\n variant === 'schedule' ? 'flex items-start gap-3' : 'space-y-2',\n )}\n >\n {variant === 'schedule' ? (\n <>\n <Skeleton className=\"h-4 w-14 shrink-0\" />\n <div className=\"flex-1 space-y-2\">\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-3 w-1/3\" />\n </div>\n </>\n ) : (\n <>\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-3 w-1/2\" />\n </>\n )}\n </div>\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport function WidgetErrorState({\n title,\n description,\n onRetry,\n retrying = false,\n}: {\n title?: ReactNode;\n description?: ReactNode;\n onRetry?: () => void;\n retrying?: boolean;\n}) {\n return (\n <div\n role=\"alert\"\n className=\"flex flex-col items-center justify-center gap-3 px-5 py-8 text-center\"\n >\n <div className=\"bg-destructive/10 flex h-10 w-10 items-center justify-center rounded-full\">\n <Icon\n name=\"fa-circle-exclamation\"\n className=\"text-destructive h-5 w-5\"\n aria-hidden\n />\n </div>\n <div className=\"space-y-1\">\n <p className=\"text-foreground text-label\">\n {title ?? (\n <Trans\n i18nKey=\"dashboard:widgetErrorTitle\"\n defaults=\"Couldn't load this widget\"\n />\n )}\n </p>\n <p className=\"text-muted-foreground text-meta\">\n {description ? (\n description\n ) : onRetry ? (\n <Trans\n i18nKey=\"dashboard:widgetErrorBodyRetry\"\n defaults=\"Try again, or check back in a few minutes.\"\n />\n ) : (\n <Trans\n i18nKey=\"dashboard:widgetErrorBody\"\n defaults=\"Check back in a few minutes.\"\n />\n )}\n </p>\n </div>\n {onRetry ? (\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={onRetry}\n disabled={retrying}\n data-test=\"widget-error-retry\"\n >\n <Icon\n name=\"fa-arrows-rotate\"\n className={cn('h-4 w-4', retrying && 'animate-spin')}\n aria-hidden\n />\n <Trans i18nKey=\"dashboard:widgetRetry\" defaults=\"Try again\" />\n </Button>\n ) : null}\n </div>\n );\n}\n\nexport function WidgetDataLoading() {\n return (\n <div className=\"flex flex-1 items-center justify-center py-12\">\n <Icon\n name=\"fa-spinner-third\"\n className=\"text-muted-foreground h-8 w-8 animate-spin\"\n />\n </div>\n );\n}\n\nexport function WidgetDisabledState() {\n return (\n <div className=\"flex flex-col items-center justify-center py-8 text-center\">\n <Icon name=\"fa-ban\" className=\"text-muted-foreground mb-4 h-8 w-8\" />\n <p className=\"text-muted-foreground text-meta\">\n <Trans i18nKey=\"dashboard:widgetDisabled\" defaults=\"Widget Disabled\" />\n </p>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"widget-state-components.js","sourceRoot":"","sources":["../../../src/components/widgets/widget-state-components.tsx"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AA6CtC,SAAS,WAAW,CAAC,EACn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AS,EACjB,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,eACR,oBAAoB,aAE9B,KAAC,IAAI,IACH,IAAI,EAAC,kBAAkB,EACvB,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,QAAQ,IAAI,cAAc,CAAC,wBAEpD,EACF,KAAC,KAAK,IAAC,OAAO,EAAC,uBAAuB,EAAC,QAAQ,EAAC,WAAW,GAAG,IACvD,CACV,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CACL,cAAK,SAAS,EAAC,+CAA+C,YAC5D,KAAC,IAAI,IACH,IAAI,EAAC,kBAAkB,EACvB,SAAS,EAAC,4CAA4C,GACtD,GACE,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,CACL,eAAK,SAAS,EAAC,4DAA4D,aACzE,KAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,oCAAoC,GAAG,EACrE,YAAG,SAAS,EAAC,+BAA+B,YAC1C,KAAC,KAAK,IAAC,OAAO,EAAC,0BAA0B,EAAC,QAAQ,EAAC,iBAAiB,GAAG,GACrE,IACA,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from 'react';\n\nimport Link from 'next/link.js';\n\nimport { Button } from '@ekanos/ui/button';\nimport { Icon } from '@ekanos/ui/icon';\nimport { Skeleton } from '@ekanos/ui/skeleton';\nimport { Trans } from '@ekanos/ui/trans';\nimport { cn } from '@ekanos/ui/utils';\n\n/**\n * The one action a state view offers: \"Connect QuickBooks\", \"Ask an admin\",\n * \"Create a deal\". A link with `href`, otherwise a button running `onClick`.\n */\nexport interface WidgetStateAction {\n label: ReactNode;\n href?: string;\n /** Open `href` in a new tab. */\n external?: boolean;\n onClick?: () => void;\n}\n\n/** The body shape a loading skeleton stands in for. */\nexport type WidgetSkeletonVariant = 'rows' | 'stat' | 'chart' | 'schedule';\n\n/** Why an active integration still can't show this widget's data. */\nexport type WidgetInactiveReason =\n | 'not-connected'\n | 'no-access'\n | 'setup-needed';\n\nexport interface WidgetEmptyStateProps {\n /**\n * `positive` (the default) says nothing needs the owner: \"You're all caught\n * up\". `neutral` is for an empty list that isn't good news, like a search\n * with no results.\n */\n tone?: 'positive' | 'neutral';\n title?: ReactNode;\n description?: ReactNode;\n action?: WidgetStateAction;\n}\n\nexport interface WidgetInactiveStateProps {\n reason?: WidgetInactiveReason;\n /** The integration's name, for the default copy (\"Connect QuickBooks\"). */\n integrationName?: string;\n title?: ReactNode;\n /** One sentence on what connecting or access gives the owner. */\n description?: ReactNode;\n action?: WidgetStateAction;\n}\n\nfunction StateAction({\n action,\n variant = 'default',\n}: {\n action: WidgetStateAction;\n variant?: 'default' | 'outline';\n}) {\n if (action.href) {\n const link = action.external ? (\n <a href={action.href} target=\"_blank\" rel=\"noopener noreferrer\" />\n ) : (\n <Link href={action.href} />\n );\n\n return (\n <Button size=\"sm\" variant={variant} render={link} nativeButton={false}>\n {action.label}\n </Button>\n );\n }\n\n return (\n <Button size=\"sm\" variant={variant} type=\"button\" onClick={action.onClick}>\n {action.label}\n </Button>\n );\n}\n\n/**\n * The shared shape of every non-data state: an icon, a title, one sentence\n * and at most one action, left-aligned in the body's padding.\n */\nfunction StateNote({\n icon,\n title,\n description,\n action,\n actionVariant,\n role,\n testId,\n}: {\n icon: string;\n title: ReactNode;\n description?: ReactNode;\n action?: WidgetStateAction;\n actionVariant?: 'default' | 'outline';\n role?: 'alert' | 'status';\n testId: string;\n}) {\n return (\n <div\n role={role}\n className=\"flex flex-1 flex-col items-start gap-3 px-5 pt-2 pb-5\"\n data-test={testId}\n >\n <Icon name={icon} className=\"text-muted-foreground h-6 w-6\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-foreground text-base font-medium\">{title}</p>\n {description ? (\n <p className=\"text-muted-foreground max-w-prose text-sm\">\n {description}\n </p>\n ) : null}\n </div>\n {action ? <StateAction action={action} variant={actionVariant} /> : null}\n </div>\n );\n}\n\n/**\n * The empty state for a widget with nothing to show. Positive by default:\n * an empty review queue is good news, so it reassures instead of apologizing.\n */\nexport function WidgetEmptyState({\n tone = 'positive',\n title,\n description,\n action,\n}: WidgetEmptyStateProps) {\n const positive = tone === 'positive';\n\n return (\n <StateNote\n icon={positive ? 'fa-circle-check' : 'fa-inbox'}\n title={\n title ??\n (positive ? (\n <Trans\n i18nKey=\"dashboard:widgetEmptyPositive\"\n defaults=\"You're all caught up\"\n />\n ) : (\n <Trans\n i18nKey=\"dashboard:widgetEmptyNeutral\"\n defaults=\"Nothing here yet\"\n />\n ))\n }\n description={description}\n action={action}\n actionVariant=\"outline\"\n role=\"status\"\n testId={`widget-empty-${tone}`}\n />\n );\n}\n\nconst INACTIVE_ICON: Record<WidgetInactiveReason, string> = {\n 'not-connected': 'fa-plug',\n 'no-access': 'fa-user-group',\n 'setup-needed': 'fa-sliders',\n};\n\n/**\n * Why the widget can't show data. `not-connected` offers one Connect button;\n * `no-access` is a calm note that points to an admin, never a lock screen;\n * `setup-needed` points to the integration's settings. Without a `reason` it\n * keeps the original one-line \"Widget inactive\".\n */\nexport function WidgetInactiveState({\n reason,\n integrationName,\n title,\n description,\n action,\n}: WidgetInactiveStateProps = {}) {\n if (!reason) {\n return (\n <div className=\"flex flex-col items-center justify-center py-8 text-center\">\n <p className=\"text-muted-foreground text-sm\">\n {title ?? (\n <Trans\n i18nKey=\"dashboard:widgetInactive\"\n defaults=\"Widget inactive\"\n />\n )}\n </p>\n </div>\n );\n }\n\n const name = integrationName ?? 'this integration';\n\n const defaults: Record<\n WidgetInactiveReason,\n { title: ReactNode; description: ReactNode }\n > = {\n 'not-connected': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetNotConnectedTitle\"\n defaults=\"Connect {{name}}\"\n values={{ name }}\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetNotConnectedBody\"\n defaults=\"Connect {{name}} and this card fills in with your own data.\"\n values={{ name }}\n />\n ),\n },\n 'no-access': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetNoAccessTitle\"\n defaults=\"Shared with admins for now\"\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetNoAccessBody\"\n defaults=\"Your role doesn't include this data yet. Ask an admin if you need it.\"\n />\n ),\n },\n 'setup-needed': {\n title: (\n <Trans\n i18nKey=\"dashboard:widgetSetupNeededTitle\"\n defaults=\"Finish setting up {{name}}\"\n values={{ name }}\n />\n ),\n description: (\n <Trans\n i18nKey=\"dashboard:widgetSetupNeededBody\"\n defaults=\"One more step and this card starts showing data.\"\n />\n ),\n },\n };\n\n return (\n <StateNote\n icon={INACTIVE_ICON[reason]}\n title={title ?? defaults[reason].title}\n description={description ?? defaults[reason].description}\n action={action}\n actionVariant={reason === 'no-access' ? 'outline' : 'default'}\n testId={`widget-inactive-${reason}`}\n />\n );\n}\n\n/**\n * Loading, drawn as the body it stands in for so the card doesn't jump when\n * data lands. Rows suit lists and feeds, `stat` a headline figure, `chart` a\n * chart, `schedule` a day of events.\n */\nexport function WidgetLoadingSkeleton({\n variant = 'rows',\n}: {\n variant?: WidgetSkeletonVariant;\n}) {\n return (\n <div\n role=\"status\"\n aria-busy=\"true\"\n className=\"flex flex-1 flex-col\"\n data-test={`widget-skeleton-${variant}`}\n >\n <span className=\"sr-only\">\n <Trans i18nKey=\"dashboard:widgetLoading\" defaults=\"Loading...\" />\n </span>\n {variant === 'stat' ? (\n <div className=\"space-y-2 px-5 pt-2 pb-5\">\n <Skeleton className=\"h-3 w-24\" />\n <Skeleton className=\"h-8 w-40\" />\n <Skeleton className=\"h-3 w-32\" />\n </div>\n ) : variant === 'chart' ? (\n <div className=\"space-y-3 px-5 pt-2 pb-5\">\n <Skeleton className=\"h-8 w-40\" />\n <Skeleton className=\"h-60 w-full\" />\n </div>\n ) : (\n <div className=\"divide-border divide-y\">\n {[0, 1, 2].map((row) => (\n <div\n key={row}\n className={cn(\n 'px-5 py-3',\n variant === 'schedule' ? 'flex items-start gap-3' : 'space-y-2',\n )}\n >\n {variant === 'schedule' ? (\n <>\n <Skeleton className=\"h-4 w-14 shrink-0\" />\n <div className=\"flex-1 space-y-2\">\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-3 w-1/3\" />\n </div>\n </>\n ) : (\n <>\n <Skeleton className=\"h-4 w-2/3\" />\n <Skeleton className=\"h-3 w-1/2\" />\n </>\n )}\n </div>\n ))}\n </div>\n )}\n </div>\n );\n}\n\nexport function WidgetErrorState({\n title,\n description,\n onRetry,\n retrying = false,\n}: {\n title?: ReactNode;\n description?: ReactNode;\n onRetry?: () => void;\n retrying?: boolean;\n}) {\n return (\n <div\n role=\"alert\"\n className=\"flex flex-col items-center justify-center gap-3 px-5 py-8 text-center\"\n >\n <div className=\"bg-destructive-surface flex h-10 w-10 items-center justify-center rounded-full\">\n <Icon\n name=\"fa-circle-exclamation\"\n className=\"text-destructive h-5 w-5\"\n aria-hidden\n />\n </div>\n <div className=\"space-y-1\">\n <p className=\"text-foreground text-sm font-medium\">\n {title ?? (\n <Trans\n i18nKey=\"dashboard:widgetErrorTitle\"\n defaults=\"Couldn't load this widget\"\n />\n )}\n </p>\n <p className=\"text-muted-foreground text-sm\">\n {description ? (\n description\n ) : onRetry ? (\n <Trans\n i18nKey=\"dashboard:widgetErrorBodyRetry\"\n defaults=\"Try again, or check back in a few minutes.\"\n />\n ) : (\n <Trans\n i18nKey=\"dashboard:widgetErrorBody\"\n defaults=\"Check back in a few minutes.\"\n />\n )}\n </p>\n </div>\n {onRetry ? (\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={onRetry}\n disabled={retrying}\n data-test=\"widget-error-retry\"\n >\n <Icon\n name=\"fa-arrows-rotate\"\n className={cn('h-4 w-4', retrying && 'animate-spin')}\n aria-hidden\n />\n <Trans i18nKey=\"dashboard:widgetRetry\" defaults=\"Try again\" />\n </Button>\n ) : null}\n </div>\n );\n}\n\nexport function WidgetDataLoading() {\n return (\n <div className=\"flex flex-1 items-center justify-center py-12\">\n <Icon\n name=\"fa-spinner-third\"\n className=\"text-muted-foreground h-8 w-8 animate-spin\"\n />\n </div>\n );\n}\n\nexport function WidgetDisabledState() {\n return (\n <div className=\"flex flex-col items-center justify-center py-8 text-center\">\n <Icon name=\"fa-ban\" className=\"text-muted-foreground mb-4 h-8 w-8\" />\n <p className=\"text-muted-foreground text-sm\">\n <Trans i18nKey=\"dashboard:widgetDisabled\" defaults=\"Widget Disabled\" />\n </p>\n </div>\n );\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { WidgetAskContext } from '../../types/widget-ask-context.js';
|
|
3
3
|
import type { WidgetVerdict } from '../../types/widget-verdict.js';
|
|
4
|
+
import { type WidgetConnectionGate, type WidgetQuery } from './widget-query-state.js';
|
|
4
5
|
import { type WidgetEmptyStateProps, type WidgetInactiveStateProps, type WidgetSkeletonVariant } from './widget-state-components.js';
|
|
5
6
|
/**
|
|
6
7
|
* The verdict the widget reported through `Widget.DataState`, for a body that
|
|
@@ -194,39 +195,33 @@ export type WidgetDataStatus = 'ready' | 'loading' | 'error' | 'inactive';
|
|
|
194
195
|
* parent state is `active` — so the integration's `inactive` / `disabled` /
|
|
195
196
|
* `loading` (initial) states still win.
|
|
196
197
|
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
198
|
+
* Pass the widget's own query as `query` and the component works out the
|
|
199
|
+
* status, the shared Refresh menu item, the Try again button on its error
|
|
200
|
+
* view and the "Updated 3 minutes ago" footer. A connector widget that waits
|
|
201
|
+
* on an upstream OAuth connection also passes `connection`, the
|
|
202
|
+
* `useOAuthWidgetGate` result:
|
|
199
203
|
*
|
|
200
204
|
* ```tsx
|
|
201
205
|
* const { state } = use(WidgetContext);
|
|
202
|
-
* const
|
|
203
|
-
* const
|
|
206
|
+
* const gate = useOAuthWidgetGate(accountId, state.state === 'active', opts);
|
|
207
|
+
* const query = useMyData(accountId, gate.dataEnabled);
|
|
204
208
|
* return (
|
|
205
|
-
* <Widget.DataState
|
|
206
|
-
* status={isLoading ? 'loading' : isError ? 'error' : 'ready'}
|
|
207
|
-
* >
|
|
209
|
+
* <Widget.DataState query={query} connection={gate}>
|
|
208
210
|
* <Widget.Card>…</Widget.Card>
|
|
209
211
|
* </Widget.DataState>
|
|
210
212
|
* );
|
|
211
213
|
* ```
|
|
212
214
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* shared Refresh menu item, a Try again button on its error view, and an
|
|
218
|
-
* "Updated 3 minutes ago" footer. With TanStack Query:
|
|
219
|
-
*
|
|
220
|
-
* ```tsx
|
|
221
|
-
* <Widget.DataState
|
|
222
|
-
* status={query.isLoading ? 'loading' : query.isError ? 'error' : 'ready'}
|
|
223
|
-
* onRefresh={() => void query.refetch()}
|
|
224
|
-
* refreshing={query.isFetching}
|
|
225
|
-
* updatedAt={query.dataUpdatedAt}
|
|
226
|
-
* >
|
|
227
|
-
* ```
|
|
215
|
+
* A failed background refresh keeps the card on its rows (`ready`); only a
|
|
216
|
+
* read that failed with nothing on screen shows the error view. The rule is
|
|
217
|
+
* `widgetQueryStatus`. `status`, `onRefresh`, `refreshing` and `updatedAt`
|
|
218
|
+
* still take explicit values and win over what `query` gives.
|
|
228
219
|
*/
|
|
229
|
-
declare function WidgetDataState({ status, loading, error, inactive, onRefresh, refreshing, updatedAt, verdict, children, }: {
|
|
220
|
+
declare function WidgetDataState({ query, connection, status: statusProp, loading, error, inactive, onRefresh: onRefreshProp, refreshing: refreshingProp, updatedAt: updatedAtProp, verdict, children, }: {
|
|
221
|
+
/** The widget's own read; a TanStack Query result fits. */
|
|
222
|
+
query?: WidgetQuery;
|
|
223
|
+
/** The upstream connection the read waits on (`useOAuthWidgetGate`). */
|
|
224
|
+
connection?: WidgetConnectionGate;
|
|
230
225
|
/**
|
|
231
226
|
* The widget's own data state. `inactive` is a widget-level "not connected"
|
|
232
227
|
* state while the integration itself is active (the product is activated
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { Component, use, useMemo, } from 'react';
|
|
14
|
+
import { Component, use, useCallback, useMemo, } from 'react';
|
|
15
15
|
import Link from 'next/link.js';
|
|
16
16
|
import { Button } from '@ekanos/ui/button';
|
|
17
17
|
import { Card, CardContent, CardFooter, CardHeader, CardTitle, } from '@ekanos/ui/card';
|
|
@@ -26,6 +26,7 @@ import { useAnimatedHeight } from './use-animated-height.js';
|
|
|
26
26
|
import { useRelativeTime } from './use-relative-time.js';
|
|
27
27
|
import { WidgetAskBar } from './widget-ask-bar.js';
|
|
28
28
|
import { WidgetContext } from './widget-context.js';
|
|
29
|
+
import { widgetQueryStatus, } from './widget-query-state.js';
|
|
29
30
|
import { WidgetDisabledState, WidgetEmptyState, WidgetErrorState, WidgetInactiveState, WidgetLoadingSkeleton, } from './widget-state-components.js';
|
|
30
31
|
// ─── Error Boundary ─────────────────────────────────────────────────────────
|
|
31
32
|
class WidgetErrorBoundary extends Component {
|
|
@@ -46,7 +47,7 @@ class WidgetErrorBoundary extends Component {
|
|
|
46
47
|
}
|
|
47
48
|
render() {
|
|
48
49
|
if (this.state.hasError) {
|
|
49
|
-
return (_jsxs("div", { role: "alert", className: "flex flex-1 flex-col items-center justify-center gap-3 px-5 py-8 text-center", children: [_jsx("div", { className: "bg-destructive
|
|
50
|
+
return (_jsxs("div", { role: "alert", className: "flex flex-1 flex-col items-center justify-center gap-3 px-5 py-8 text-center", children: [_jsx("div", { className: "bg-destructive-surface flex h-10 w-10 items-center justify-center rounded-full", children: _jsx(Icon, { name: "fa-circle-exclamation", className: "text-destructive h-5 w-5", "aria-hidden": true }) }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-foreground text-sm font-medium", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedTitle", defaults: "This widget ran into a problem" }) }), _jsx("p", { className: "text-muted-foreground max-w-xs text-sm", children: _jsx(Trans, { i18nKey: "dashboard:widgetCrashedBody", defaults: "Try again. If it keeps happening, reload the page." }) })] }), _jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: this.retry, "data-test": "widget-crash-retry", children: [_jsx(Icon, { name: "fa-arrows-rotate", className: "h-4 w-4", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRetry", defaults: "Try again" })] })] }));
|
|
50
51
|
}
|
|
51
52
|
return this.props.children;
|
|
52
53
|
}
|
|
@@ -85,7 +86,7 @@ function WidgetCard({ children }) {
|
|
|
85
86
|
tone: "verdict", className: cn(
|
|
86
87
|
// Neutralize the shadcn card's own py-6/gap-6 box model — widget
|
|
87
88
|
// chrome owns all vertical spacing via its header/content/footer.
|
|
88
|
-
'
|
|
89
|
+
'@container/widget relative flex h-full flex-col gap-0 overflow-hidden rounded-lg border-0 py-0', meta.className), "data-widget-id": meta.widgetId, children: [children, _jsx(WidgetFreshness, {})] }));
|
|
89
90
|
}
|
|
90
91
|
// ─── Header ─────────────────────────────────────────────────────────────────
|
|
91
92
|
function CollapseButton() {
|
|
@@ -127,7 +128,7 @@ const VERDICT_BADGE_PROMINENT = {
|
|
|
127
128
|
*/
|
|
128
129
|
function VerdictLine({ verdict }) {
|
|
129
130
|
if (verdict.tone === 'clear') {
|
|
130
|
-
return (_jsxs("p", { className: "text-foreground
|
|
131
|
+
return (_jsxs("p", { className: "text-foreground flex min-w-0 items-center gap-1.5 text-sm", "data-test": "widget-verdict", "data-verdict": "clear", children: [_jsx(Icon, { name: "fa-circle-check", className: "h-3.5 w-3.5 shrink-0", "aria-hidden": true }), _jsx("span", { className: "truncate", children: verdict.sentence })] }));
|
|
131
132
|
}
|
|
132
133
|
return (_jsx(StatusBadge, { tone: VERDICT_BADGE_TONE[verdict.tone], prominent: VERDICT_BADGE_PROMINENT[verdict.tone], className: "mt-0.5 max-w-full", "data-test": "widget-verdict", "data-verdict": verdict.tone, children: _jsx("span", { className: "truncate", children: verdict.sentence }) }));
|
|
133
134
|
}
|
|
@@ -150,8 +151,8 @@ function WidgetHeader({ title, subtitle, description, context, trailing, menu, c
|
|
|
150
151
|
}
|
|
151
152
|
if (!effectiveTitle)
|
|
152
153
|
return null;
|
|
153
|
-
const titleNode = effectiveDescription ? (_jsxs(_Fragment, { children: [_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(CardTitle, { className: "
|
|
154
|
-
return (_jsx(CardHeader, { className: "flex-shrink-0 px-5 pt-4 pb-3", children: _jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-start gap-2.5", children: [meta.isCollapsible ? _jsx(CollapseButton, {}) : null, _jsxs("div", { className: "min-w-0 space-y-0.5", children: [titleNode, verdict && verdict.tone !== 'clear' ? (_jsx(VerdictLine, { verdict: verdict })) : contextLine ? (_jsxs("p", { className: "text-muted-foreground text-
|
|
154
|
+
const titleNode = effectiveDescription ? (_jsxs(_Fragment, { children: [_jsx(TooltipProvider, { children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(CardTitle, { className: "cursor-help truncate" }), children: effectiveTitle }), _jsx(TooltipContent, { children: _jsx("p", { children: effectiveDescription }) })] }) }), _jsx("span", { className: "sr-only", children: effectiveDescription })] })) : (_jsx(CardTitle, { className: "truncate", children: effectiveTitle }));
|
|
155
|
+
return (_jsx(CardHeader, { className: "flex-shrink-0 px-5 pt-4 pb-3", children: _jsxs("div", { className: "flex items-start justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-start gap-2.5", children: [meta.isCollapsible ? _jsx(CollapseButton, {}) : null, _jsxs("div", { className: "min-w-0 space-y-0.5", children: [titleNode, verdict && verdict.tone !== 'clear' ? (_jsx(VerdictLine, { verdict: verdict })) : contextLine ? (_jsxs("p", { className: "text-muted-foreground truncate text-sm", "data-test": "widget-header-context", children: [contextLine, verdict ? (_jsxs(_Fragment, { children: [' · ', _jsx("span", { "data-test": "widget-verdict", "data-verdict": "clear", children: verdict.sentence })] })) : null] })) : verdict ? (_jsx(VerdictLine, { verdict: verdict })) : null] })] }), _jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [trailing ? _jsx(HeaderTrailing, { trailing: trailing }) : null, children, _jsx(WidgetMenu, { items: menu })] })] }) }));
|
|
155
156
|
}
|
|
156
157
|
/**
|
|
157
158
|
* The actions every widget shares, whatever it renders: open its full
|
|
@@ -185,7 +186,7 @@ function WidgetMenuItem({ icon, href, external = false, onSelect, disabled, chil
|
|
|
185
186
|
*/
|
|
186
187
|
function WidgetMenuChoice({ icon, label, value, options, onChange, }) {
|
|
187
188
|
const current = options.find((option) => option.value === value);
|
|
188
|
-
return (_jsxs(DropdownMenuSub, { children: [_jsxs(DropdownMenuSubTrigger, { children: [_jsx(Icon, { name: icon !== null && icon !== void 0 ? icon : 'fa-sliders', "aria-hidden": true }), _jsx("span", { className: "flex-1", children: label }), current ? (_jsx("span", { className: "text-muted-foreground text-
|
|
189
|
+
return (_jsxs(DropdownMenuSub, { children: [_jsxs(DropdownMenuSubTrigger, { children: [_jsx(Icon, { name: icon !== null && icon !== void 0 ? icon : 'fa-sliders', "aria-hidden": true }), _jsx("span", { className: "flex-1", children: label }), current ? (_jsx("span", { className: "text-muted-foreground text-xs", children: current.label })) : null] }), _jsx(DropdownMenuSubContent, { className: "min-w-44", children: _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: (next) => {
|
|
189
190
|
const match = options.find((option) => option.value === next);
|
|
190
191
|
if (match)
|
|
191
192
|
onChange(match.value);
|
|
@@ -200,7 +201,7 @@ function WidgetFreshness() {
|
|
|
200
201
|
const updated = useRelativeTime(data === null || data === void 0 ? void 0 : data.updatedAt);
|
|
201
202
|
if (state.state !== 'active' || state.collapsed || !updated)
|
|
202
203
|
return null;
|
|
203
|
-
return (_jsx("div", { className: "text-muted-foreground border-border
|
|
204
|
+
return (_jsx("div", { className: "text-muted-foreground border-border flex shrink-0 items-center gap-1.5 border-t px-5 py-2.5 text-xs", "aria-live": "polite", children: (data === null || data === void 0 ? void 0 : data.refreshing) ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: "fa-arrows-rotate", className: "h-3 w-3 animate-spin", "aria-hidden": true }), _jsx(Trans, { i18nKey: "dashboard:widgetRefreshing", defaults: "Refreshing\u2026" })] })) : (_jsx(Trans, { i18nKey: "dashboard:widgetUpdated", defaults: "Updated {{time}}", values: { time: updated } })) }));
|
|
204
205
|
}
|
|
205
206
|
// ─── State-gated content ────────────────────────────────────────────────────
|
|
206
207
|
function CollapsibleBody({ collapsed, maxContentHeight, widgetId, children, }) {
|
|
@@ -356,7 +357,7 @@ function WidgetHealthFooter() {
|
|
|
356
357
|
((_b = meta.health) === null || _b === void 0 ? void 0 : _b.status) === 'degraded';
|
|
357
358
|
if (!shouldShow)
|
|
358
359
|
return null;
|
|
359
|
-
return (_jsxs("div", { className: "text-warning border-
|
|
360
|
+
return (_jsxs("div", { className: "text-warning border-border bg-warning/5 flex items-center gap-2 border-t px-4 py-2 text-xs", children: [_jsx(Icon, { name: "fa-circle-exclamation", className: "h-4 w-4 shrink-0", "aria-hidden": true }), _jsx("span", { children: lastSynced ? (_jsx(Trans, { i18nKey: "common:integrationHealth.degradedWidgetNoticeSince", defaults: "Data may be out of date. Last synced {{time}}.", values: { time: lastSynced } })) : (_jsx(Trans, { i18nKey: "common:integrationHealth.degradedWidgetNotice", defaults: "This integration is degraded \u2014 data may be stale." })) })] }));
|
|
360
361
|
}
|
|
361
362
|
function toEpochMs(value) {
|
|
362
363
|
if (value === null || value === undefined)
|
|
@@ -370,40 +371,38 @@ function toEpochMs(value) {
|
|
|
370
371
|
* parent state is `active` — so the integration's `inactive` / `disabled` /
|
|
371
372
|
* `loading` (initial) states still win.
|
|
372
373
|
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
374
|
+
* Pass the widget's own query as `query` and the component works out the
|
|
375
|
+
* status, the shared Refresh menu item, the Try again button on its error
|
|
376
|
+
* view and the "Updated 3 minutes ago" footer. A connector widget that waits
|
|
377
|
+
* on an upstream OAuth connection also passes `connection`, the
|
|
378
|
+
* `useOAuthWidgetGate` result:
|
|
375
379
|
*
|
|
376
380
|
* ```tsx
|
|
377
381
|
* const { state } = use(WidgetContext);
|
|
378
|
-
* const
|
|
379
|
-
* const
|
|
382
|
+
* const gate = useOAuthWidgetGate(accountId, state.state === 'active', opts);
|
|
383
|
+
* const query = useMyData(accountId, gate.dataEnabled);
|
|
380
384
|
* return (
|
|
381
|
-
* <Widget.DataState
|
|
382
|
-
* status={isLoading ? 'loading' : isError ? 'error' : 'ready'}
|
|
383
|
-
* >
|
|
385
|
+
* <Widget.DataState query={query} connection={gate}>
|
|
384
386
|
* <Widget.Card>…</Widget.Card>
|
|
385
387
|
* </Widget.DataState>
|
|
386
388
|
* );
|
|
387
389
|
* ```
|
|
388
390
|
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
* shared Refresh menu item, a Try again button on its error view, and an
|
|
394
|
-
* "Updated 3 minutes ago" footer. With TanStack Query:
|
|
395
|
-
*
|
|
396
|
-
* ```tsx
|
|
397
|
-
* <Widget.DataState
|
|
398
|
-
* status={query.isLoading ? 'loading' : query.isError ? 'error' : 'ready'}
|
|
399
|
-
* onRefresh={() => void query.refetch()}
|
|
400
|
-
* refreshing={query.isFetching}
|
|
401
|
-
* updatedAt={query.dataUpdatedAt}
|
|
402
|
-
* >
|
|
403
|
-
* ```
|
|
391
|
+
* A failed background refresh keeps the card on its rows (`ready`); only a
|
|
392
|
+
* read that failed with nothing on screen shows the error view. The rule is
|
|
393
|
+
* `widgetQueryStatus`. `status`, `onRefresh`, `refreshing` and `updatedAt`
|
|
394
|
+
* still take explicit values and win over what `query` gives.
|
|
404
395
|
*/
|
|
405
|
-
function WidgetDataState({ status, loading, error, inactive, onRefresh, refreshing
|
|
396
|
+
function WidgetDataState({ query, connection, status: statusProp, loading, error, inactive, onRefresh: onRefreshProp, refreshing: refreshingProp, updatedAt: updatedAtProp, verdict, children, }) {
|
|
397
|
+
var _a;
|
|
406
398
|
const parent = useWidget();
|
|
399
|
+
const refetch = query === null || query === void 0 ? void 0 : query.refetch;
|
|
400
|
+
// `refetch` is stable across renders, so the context value is too.
|
|
401
|
+
const queryRefresh = useCallback(() => void (refetch === null || refetch === void 0 ? void 0 : refetch()), [refetch]);
|
|
402
|
+
const status = statusProp !== null && statusProp !== void 0 ? statusProp : (query ? widgetQueryStatus(query, connection) : undefined);
|
|
403
|
+
const onRefresh = onRefreshProp !== null && onRefreshProp !== void 0 ? onRefreshProp : (query ? queryRefresh : undefined);
|
|
404
|
+
const refreshing = (_a = refreshingProp !== null && refreshingProp !== void 0 ? refreshingProp : query === null || query === void 0 ? void 0 : query.isFetching) !== null && _a !== void 0 ? _a : false;
|
|
405
|
+
const updatedAt = updatedAtProp !== null && updatedAtProp !== void 0 ? updatedAtProp : query === null || query === void 0 ? void 0 : query.dataUpdatedAt;
|
|
407
406
|
const own = status !== null && status !== void 0 ? status : (inactive ? 'inactive' : loading ? 'loading' : error ? 'error' : 'ready');
|
|
408
407
|
const overrideState = parent.state.state !== 'active'
|
|
409
408
|
? parent.state.state
|