@terreno/ui 57.8.0 → 57.10.1
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 +2 -0
- package/dist/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +19 -4
- package/dist/Button.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +147 -6
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +90 -17
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/FilePickerButton.d.ts +15 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +90 -13
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts +57 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +301 -20
- package/dist/GPTChat.js.map +1 -1
- package/dist/HtmlFrame.d.ts +11 -0
- package/dist/HtmlFrame.d.ts.map +1 -0
- package/dist/HtmlFrame.js +29 -0
- package/dist/HtmlFrame.js.map +1 -0
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/Text.d.ts +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -2
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/asks/AskCard.d.ts +34 -0
- package/dist/asks/AskCard.d.ts.map +1 -0
- package/dist/asks/AskCard.js +91 -0
- package/dist/asks/AskCard.js.map +1 -0
- package/dist/asks/AskChoice.d.ts +11 -0
- package/dist/asks/AskChoice.d.ts.map +1 -0
- package/dist/asks/AskChoice.js +146 -0
- package/dist/asks/AskChoice.js.map +1 -0
- package/dist/asks/AskConfirm.d.ts +15 -0
- package/dist/asks/AskConfirm.d.ts.map +1 -0
- package/dist/asks/AskConfirm.js +17 -0
- package/dist/asks/AskConfirm.js.map +1 -0
- package/dist/asks/AskFiles.d.ts +18 -0
- package/dist/asks/AskFiles.d.ts.map +1 -0
- package/dist/asks/AskFiles.js +149 -0
- package/dist/asks/AskFiles.js.map +1 -0
- package/dist/asks/AskForm.d.ts +27 -0
- package/dist/asks/AskForm.d.ts.map +1 -0
- package/dist/asks/AskForm.js +146 -0
- package/dist/asks/AskForm.js.map +1 -0
- package/dist/asks/AskMarkdown.d.ts +25 -0
- package/dist/asks/AskMarkdown.d.ts.map +1 -0
- package/dist/asks/AskMarkdown.js +73 -0
- package/dist/asks/AskMarkdown.js.map +1 -0
- package/dist/asks/SimpleAskCard.d.ts +23 -0
- package/dist/asks/SimpleAskCard.d.ts.map +1 -0
- package/dist/asks/SimpleAskCard.js +32 -0
- package/dist/asks/SimpleAskCard.js.map +1 -0
- package/dist/asks/askControls.d.ts +33 -0
- package/dist/asks/askControls.d.ts.map +1 -0
- package/dist/asks/askControls.js +30 -0
- package/dist/asks/askControls.js.map +1 -0
- package/dist/asks/askFileRefs.d.ts +26 -0
- package/dist/asks/askFileRefs.d.ts.map +1 -0
- package/dist/asks/askFileRefs.js +75 -0
- package/dist/asks/askFileRefs.js.map +1 -0
- package/dist/asks/askFormDraft.d.ts +60 -0
- package/dist/asks/askFormDraft.d.ts.map +1 -0
- package/dist/asks/askFormDraft.js +224 -0
- package/dist/asks/askFormDraft.js.map +1 -0
- package/dist/asks/askSummary.d.ts +10 -0
- package/dist/asks/askSummary.d.ts.map +1 -0
- package/dist/asks/askSummary.js +138 -0
- package/dist/asks/askSummary.js.map +1 -0
- package/dist/asks/askTypes.d.ts +21 -0
- package/dist/asks/askTypes.d.ts.map +1 -0
- package/dist/asks/askTypes.js +2 -0
- package/dist/asks/askTypes.js.map +1 -0
- package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
- package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
- package/dist/asks/simpleCardButtonVariants.js +8 -0
- package/dist/asks/simpleCardButtonVariants.js.map +1 -0
- package/dist/blocks/BlocksError.d.ts +8 -0
- package/dist/blocks/BlocksError.d.ts.map +1 -0
- package/dist/blocks/BlocksError.js +14 -0
- package/dist/blocks/BlocksError.js.map +1 -0
- package/dist/blocks/BlocksView.d.ts +10 -0
- package/dist/blocks/BlocksView.d.ts.map +1 -0
- package/dist/blocks/BlocksView.js +90 -0
- package/dist/blocks/BlocksView.js.map +1 -0
- package/dist/blocks/blockRenderers.d.ts +25 -0
- package/dist/blocks/blockRenderers.d.ts.map +1 -0
- package/dist/blocks/blockRenderers.js +136 -0
- package/dist/blocks/blockRenderers.js.map +1 -0
- package/dist/blocks/datasetToPoints.d.ts +22 -0
- package/dist/blocks/datasetToPoints.d.ts.map +1 -0
- package/dist/blocks/datasetToPoints.js +28 -0
- package/dist/blocks/datasetToPoints.js.map +1 -0
- package/dist/blocks/useBlockSelections.d.ts +6 -0
- package/dist/blocks/useBlockSelections.d.ts.map +1 -0
- package/dist/blocks/useBlockSelections.js +10 -0
- package/dist/blocks/useBlockSelections.js.map +1 -0
- package/dist/blocks/useResolvedDatasets.d.ts +18 -0
- package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
- package/dist/blocks/useResolvedDatasets.js +59 -0
- package/dist/blocks/useResolvedDatasets.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts +15 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -0
- package/dist/blocks/useResolvedImages.js +66 -0
- package/dist/blocks/useResolvedImages.js.map +1 -0
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +2 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/Button.test.tsx +72 -0
- package/src/Button.tsx +34 -4
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +136 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DateTimeField.test.tsx +185 -2
- package/src/DateTimeField.tsx +106 -16
- package/src/DonutChart.test.tsx +78 -10
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/FilePickerButton.test.tsx +116 -9
- package/src/FilePickerButton.tsx +177 -23
- package/src/GPTChat.test.tsx +891 -8
- package/src/GPTChat.tsx +713 -45
- package/src/HtmlFrame.tsx +60 -0
- package/src/LineChart.test.tsx +109 -10
- package/src/LineChart.tsx +154 -58
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/Text.test.tsx +22 -0
- package/src/Text.tsx +10 -1
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/asks/AskCard.test.tsx +1428 -0
- package/src/asks/AskCard.tsx +240 -0
- package/src/asks/AskChoice.tsx +368 -0
- package/src/asks/AskConfirm.tsx +42 -0
- package/src/asks/AskFiles.test.tsx +347 -0
- package/src/asks/AskFiles.tsx +246 -0
- package/src/asks/AskForm.tsx +334 -0
- package/src/asks/AskMarkdown.tsx +176 -0
- package/src/asks/SimpleAskCard.test.tsx +253 -0
- package/src/asks/SimpleAskCard.tsx +82 -0
- package/src/asks/askControls.tsx +98 -0
- package/src/asks/askFileRefs.test.ts +155 -0
- package/src/asks/askFileRefs.ts +98 -0
- package/src/asks/askFormDraft.test.ts +347 -0
- package/src/asks/askFormDraft.ts +309 -0
- package/src/asks/askSummary.test.ts +255 -0
- package/src/asks/askSummary.ts +160 -0
- package/src/asks/askTypes.ts +25 -0
- package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
- package/src/asks/simpleCardButtonVariants.ts +14 -0
- package/src/blocks/BlocksError.tsx +28 -0
- package/src/blocks/BlocksView.test.tsx +607 -0
- package/src/blocks/BlocksView.tsx +125 -0
- package/src/blocks/blockRenderers.tsx +288 -0
- package/src/blocks/datasetToPoints.test.ts +31 -0
- package/src/blocks/datasetToPoints.ts +48 -0
- package/src/blocks/useBlockSelections.ts +13 -0
- package/src/blocks/useResolvedDatasets.ts +78 -0
- package/src/blocks/useResolvedImages.ts +81 -0
- package/src/bunSetup.ts +1 -0
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/index.tsx +13 -0
- package/src/isolated/HtmlFrame.isolated.tsx +54 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {type AskValidationError, validateAskInput} from "@terreno/blocks";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import {useCallback, useRef, useState} from "react";
|
|
4
|
+
import type {Text as NativeText} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {Box} from "../Box";
|
|
7
|
+
import type {IconName} from "../Common";
|
|
8
|
+
import {Heading} from "../Heading";
|
|
9
|
+
import {Icon} from "../Icon";
|
|
10
|
+
import {Text} from "../Text";
|
|
11
|
+
import {AskChoice} from "./AskChoice";
|
|
12
|
+
import {AskConfirm} from "./AskConfirm";
|
|
13
|
+
import {AskFiles} from "./AskFiles";
|
|
14
|
+
import {AskForm, AskFormAnswer} from "./AskForm";
|
|
15
|
+
import {AskMarkdown, AskMarkdownAnswer} from "./AskMarkdown";
|
|
16
|
+
import type {AskAction} from "./askControls";
|
|
17
|
+
import type {AskFilesResolver} from "./askFileRefs";
|
|
18
|
+
import {acceptedContent, askSummary, hasValidAskInput} from "./askSummary";
|
|
19
|
+
import type {AskSubmitHandler, ChatAsk} from "./askTypes";
|
|
20
|
+
|
|
21
|
+
export interface AskCardProps {
|
|
22
|
+
/** The ask to show. Pending asks are interactive; answered and cancelled asks show a summary. */
|
|
23
|
+
ask: ChatAsk;
|
|
24
|
+
/** Errors for the last answer, such as the `fields` of a 400 from the server. Shown inline. */
|
|
25
|
+
errors?: AskValidationError[];
|
|
26
|
+
/**
|
|
27
|
+
* Called with the user's answer. The pressed control shows a loading state until the returned
|
|
28
|
+
* promise settles. Without it, the card cannot be answered: buttons and the select are
|
|
29
|
+
* disabled, and radio options show as plain text.
|
|
30
|
+
*/
|
|
31
|
+
onSubmit?: AskSubmitHandler;
|
|
32
|
+
/**
|
|
33
|
+
* The pending ask's question, an accessible header. Pass it to
|
|
34
|
+
* `AccessibilityInfo.setAccessibilityFocus` to move screen reader focus to the ask.
|
|
35
|
+
*/
|
|
36
|
+
promptRef?: React.Ref<NativeText>;
|
|
37
|
+
/**
|
|
38
|
+
* Turns the files picked for a `files` ask into the answer's refs on Submit: uploads
|
|
39
|
+
* (`{fileId}`) or data URLs (`{url}`). Defaults to data URLs (`resolveAskFilesAsDataUrls`).
|
|
40
|
+
*/
|
|
41
|
+
resolveAskFiles?: AskFilesResolver;
|
|
42
|
+
testID?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const SUBMIT_ERROR = "Your answer could not be sent. Try again.";
|
|
46
|
+
|
|
47
|
+
const summaryIcon = (ask: ChatAsk): IconName => {
|
|
48
|
+
if (ask.response?.action === "accept" || (!ask.response && ask.status === "answered")) {
|
|
49
|
+
return "circle-check";
|
|
50
|
+
}
|
|
51
|
+
return "circle-minus";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const AskSummaryLine = ({ask, testID}: {ask: ChatAsk; testID: string}): React.ReactElement => (
|
|
55
|
+
<Box alignItems="center" direction="row" gap={2} testID={`${testID}-summary`}>
|
|
56
|
+
<Icon color="secondaryDark" iconName={summaryIcon(ask)} size="sm" />
|
|
57
|
+
<Text color="secondaryDark" size="sm">
|
|
58
|
+
{askSummary(ask)}
|
|
59
|
+
</Text>
|
|
60
|
+
</Box>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* What an accepted answer sent back, for kinds that show more than the summary line. A saved
|
|
65
|
+
* ask's input and answer come from the wire, so an invalid one shows only the summary line.
|
|
66
|
+
*/
|
|
67
|
+
const AnswerDetail = ({ask, testID}: {ask: ChatAsk; testID: string}): React.ReactElement | null => {
|
|
68
|
+
const content = acceptedContent(ask);
|
|
69
|
+
if (!content || !hasValidAskInput(ask)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const {markdown, values} = content;
|
|
73
|
+
if (ask.kind === "markdown" && typeof markdown === "string") {
|
|
74
|
+
return <AskMarkdownAnswer markdown={markdown} testID={testID} />;
|
|
75
|
+
}
|
|
76
|
+
if (ask.kind === "form" && values !== null && typeof values === "object") {
|
|
77
|
+
return <AskFormAnswer ask={ask} testID={testID} values={values as Record<string, unknown>} />;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const AskSummary = ({ask, testID}: {ask: ChatAsk; testID: string}): React.ReactElement => (
|
|
83
|
+
<Box gap={2}>
|
|
84
|
+
<AskSummaryLine ask={ask} testID={testID} />
|
|
85
|
+
<AnswerDetail ask={ask} testID={testID} />
|
|
86
|
+
</Box>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const AskBody = ({
|
|
90
|
+
ask,
|
|
91
|
+
errors,
|
|
92
|
+
isDisabled,
|
|
93
|
+
onAnswer,
|
|
94
|
+
pendingActionId,
|
|
95
|
+
resolveAskFiles,
|
|
96
|
+
testID,
|
|
97
|
+
}: {
|
|
98
|
+
ask: ChatAsk;
|
|
99
|
+
errors?: AskValidationError[];
|
|
100
|
+
isDisabled: boolean;
|
|
101
|
+
onAnswer: (action: AskAction) => Promise<void>;
|
|
102
|
+
pendingActionId?: string;
|
|
103
|
+
resolveAskFiles?: AskFilesResolver;
|
|
104
|
+
testID: string;
|
|
105
|
+
}): React.ReactElement => {
|
|
106
|
+
switch (ask.kind) {
|
|
107
|
+
case "choice":
|
|
108
|
+
return (
|
|
109
|
+
<AskChoice
|
|
110
|
+
ask={ask}
|
|
111
|
+
errors={errors}
|
|
112
|
+
isDisabled={isDisabled}
|
|
113
|
+
onAnswer={onAnswer}
|
|
114
|
+
pendingActionId={pendingActionId}
|
|
115
|
+
testID={testID}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
case "confirm":
|
|
119
|
+
return (
|
|
120
|
+
<AskConfirm
|
|
121
|
+
ask={ask}
|
|
122
|
+
errors={errors}
|
|
123
|
+
isDisabled={isDisabled}
|
|
124
|
+
onAnswer={onAnswer}
|
|
125
|
+
pendingActionId={pendingActionId}
|
|
126
|
+
testID={testID}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
case "markdown":
|
|
130
|
+
return (
|
|
131
|
+
<AskMarkdown
|
|
132
|
+
ask={ask}
|
|
133
|
+
errors={errors}
|
|
134
|
+
isDisabled={isDisabled}
|
|
135
|
+
onAnswer={onAnswer}
|
|
136
|
+
pendingActionId={pendingActionId}
|
|
137
|
+
testID={testID}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
case "form":
|
|
141
|
+
return (
|
|
142
|
+
<AskForm
|
|
143
|
+
ask={ask}
|
|
144
|
+
errors={errors}
|
|
145
|
+
isDisabled={isDisabled}
|
|
146
|
+
onAnswer={onAnswer}
|
|
147
|
+
pendingActionId={pendingActionId}
|
|
148
|
+
testID={testID}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
case "files":
|
|
152
|
+
return (
|
|
153
|
+
<AskFiles
|
|
154
|
+
ask={ask}
|
|
155
|
+
errors={errors}
|
|
156
|
+
isDisabled={isDisabled}
|
|
157
|
+
onAnswer={onAnswer}
|
|
158
|
+
pendingActionId={pendingActionId}
|
|
159
|
+
resolveFiles={resolveAskFiles}
|
|
160
|
+
testID={testID}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A question the agent asked, shown in the transcript. Renders the kind's controls while the ask
|
|
168
|
+
* is pending and a one-line summary of the answer afterwards.
|
|
169
|
+
*/
|
|
170
|
+
export const AskCard: React.FC<AskCardProps> = ({
|
|
171
|
+
ask,
|
|
172
|
+
errors,
|
|
173
|
+
onSubmit,
|
|
174
|
+
promptRef,
|
|
175
|
+
resolveAskFiles,
|
|
176
|
+
testID = "ask-card",
|
|
177
|
+
}) => {
|
|
178
|
+
const [pendingActionId, setPendingActionId] = useState<string | undefined>(undefined);
|
|
179
|
+
const [submitError, setSubmitError] = useState<string | undefined>(undefined);
|
|
180
|
+
const isAnsweringRef = useRef(false);
|
|
181
|
+
const {toolCallId} = ask;
|
|
182
|
+
|
|
183
|
+
const handleAnswer = useCallback(
|
|
184
|
+
async ({actionId, response}: AskAction): Promise<void> => {
|
|
185
|
+
if (!onSubmit || isAnsweringRef.current) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
isAnsweringRef.current = true;
|
|
189
|
+
setPendingActionId(actionId);
|
|
190
|
+
setSubmitError(undefined);
|
|
191
|
+
try {
|
|
192
|
+
await onSubmit({response, toolCallId});
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.warn("[AskCard] Submitting the answer failed", {error, toolCallId});
|
|
195
|
+
setSubmitError(SUBMIT_ERROR);
|
|
196
|
+
} finally {
|
|
197
|
+
isAnsweringRef.current = false;
|
|
198
|
+
setPendingActionId(undefined);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[onSubmit, toolCallId]
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (ask.status !== "pending") {
|
|
205
|
+
return <AskSummary ask={ask} testID={testID} />;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (validateAskInput({input: ask.input, kind: ask.kind}).length > 0) {
|
|
209
|
+
return (
|
|
210
|
+
<Box border="default" color="base" padding={3} rounding="md" testID={testID}>
|
|
211
|
+
<Text color="secondaryDark" size="sm" testID={`${testID}-invalid`}>
|
|
212
|
+
This question cannot be shown. Send a message to continue.
|
|
213
|
+
</Text>
|
|
214
|
+
</Box>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<Box border="default" color="base" gap={3} padding={3} rounding="md" testID={testID}>
|
|
220
|
+
{ask.input.title ? <Heading size="sm">{ask.input.title}</Heading> : null}
|
|
221
|
+
<Text accessibilityRole="header" ref={promptRef}>
|
|
222
|
+
{ask.input.prompt}
|
|
223
|
+
</Text>
|
|
224
|
+
<AskBody
|
|
225
|
+
ask={ask}
|
|
226
|
+
errors={errors}
|
|
227
|
+
isDisabled={!onSubmit}
|
|
228
|
+
onAnswer={handleAnswer}
|
|
229
|
+
pendingActionId={pendingActionId}
|
|
230
|
+
resolveAskFiles={resolveAskFiles}
|
|
231
|
+
testID={testID}
|
|
232
|
+
/>
|
|
233
|
+
{submitError ? (
|
|
234
|
+
<Text color="error" size="sm" testID={`${testID}-submit-error`}>
|
|
235
|
+
{submitError}
|
|
236
|
+
</Text>
|
|
237
|
+
) : null}
|
|
238
|
+
</Box>
|
|
239
|
+
);
|
|
240
|
+
};
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASK_LIMITS,
|
|
3
|
+
type AskResponse,
|
|
4
|
+
type AskValidationError,
|
|
5
|
+
askAllowsDecline,
|
|
6
|
+
type ChoiceAskInput,
|
|
7
|
+
type ChoiceOption,
|
|
8
|
+
choiceSelectionBounds,
|
|
9
|
+
type SimpleCard,
|
|
10
|
+
type SimpleCardButton,
|
|
11
|
+
toSimpleCard,
|
|
12
|
+
validateAskResponse,
|
|
13
|
+
} from "@terreno/blocks";
|
|
14
|
+
import type React from "react";
|
|
15
|
+
import {useCallback, useMemo, useState} from "react";
|
|
16
|
+
|
|
17
|
+
import {Box} from "../Box";
|
|
18
|
+
import {Button} from "../Button";
|
|
19
|
+
import type {FieldOption} from "../Common";
|
|
20
|
+
import {MultiselectField} from "../MultiselectField";
|
|
21
|
+
import {RadioField} from "../RadioField";
|
|
22
|
+
import {SelectField} from "../SelectField";
|
|
23
|
+
import {Text} from "../Text";
|
|
24
|
+
import {TextField} from "../TextField";
|
|
25
|
+
import {
|
|
26
|
+
type AskControlProps,
|
|
27
|
+
AskErrors,
|
|
28
|
+
SKIP_BUTTON,
|
|
29
|
+
SkipButton,
|
|
30
|
+
useAnswerButton,
|
|
31
|
+
} from "./askControls";
|
|
32
|
+
import type {ChatAsk} from "./askTypes";
|
|
33
|
+
|
|
34
|
+
/** Above this many options, the choice is a searchable select instead of radio buttons. */
|
|
35
|
+
const RADIO_OPTIONS_MAX = 8;
|
|
36
|
+
|
|
37
|
+
const SUBMIT_ACTION_ID = "submit";
|
|
38
|
+
|
|
39
|
+
export interface AskChoiceProps extends AskControlProps {
|
|
40
|
+
ask: Extract<ChatAsk, {kind: "choice"}>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The simple card's option buttons fit when the card needs no handoff and every label shows in
|
|
45
|
+
* full (D18), so a phone shows the same buttons as a watch.
|
|
46
|
+
*/
|
|
47
|
+
const fitsQuickReplies = (card: SimpleCard, input: ChoiceAskInput): boolean =>
|
|
48
|
+
!card.handoff &&
|
|
49
|
+
input.options.every(
|
|
50
|
+
(option) => option.label.length <= ASK_LIMITS.simpleCard.buttonLabelMaxLength
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const quickReplyButtons = (card: SimpleCard, input: ChoiceAskInput): SimpleCardButton[] => {
|
|
54
|
+
const hasSkip = card.buttons.some((button) => button.response.action === "decline");
|
|
55
|
+
if (hasSkip || !askAllowsDecline({input, kind: "choice"})) {
|
|
56
|
+
return card.buttons;
|
|
57
|
+
}
|
|
58
|
+
return [...card.buttons, SKIP_BUTTON];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const describedLabel = (option: ChoiceOption): string =>
|
|
62
|
+
option.description ? `${option.label} — ${option.description}` : option.label;
|
|
63
|
+
|
|
64
|
+
const toFieldOptions = (input: ChoiceAskInput, isRadio: boolean): FieldOption[] =>
|
|
65
|
+
input.options.map((option) => {
|
|
66
|
+
if (isRadio) {
|
|
67
|
+
return {key: option.id, label: describedLabel(option), value: option.id};
|
|
68
|
+
}
|
|
69
|
+
return {helperText: option.description, key: option.id, label: option.label, value: option.id};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const OptionDescriptions = ({input}: {input: ChoiceAskInput}): React.ReactElement | null => {
|
|
73
|
+
const described = input.options.filter((option) => option.description);
|
|
74
|
+
if (described.length === 0) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return (
|
|
78
|
+
<Box gap={1}>
|
|
79
|
+
{described.map((option) => (
|
|
80
|
+
<Text color="secondaryDark" key={option.id} size="sm">
|
|
81
|
+
{describedLabel(option)}
|
|
82
|
+
</Text>
|
|
83
|
+
))}
|
|
84
|
+
</Box>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** The options as plain text, for a card whose host takes no answers. */
|
|
89
|
+
const ReadOnlyOptions = ({
|
|
90
|
+
input,
|
|
91
|
+
testID,
|
|
92
|
+
}: {
|
|
93
|
+
input: ChoiceAskInput;
|
|
94
|
+
testID: string;
|
|
95
|
+
}): React.ReactElement => (
|
|
96
|
+
<Box gap={1} testID={testID}>
|
|
97
|
+
{input.options.map((option) => (
|
|
98
|
+
<Text key={option.id} size="sm">
|
|
99
|
+
{describedLabel(option)}
|
|
100
|
+
</Text>
|
|
101
|
+
))}
|
|
102
|
+
</Box>
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const otherTitle = (input: ChoiceAskInput): string => input.otherLabel ?? "Other";
|
|
106
|
+
|
|
107
|
+
/** "Choose up to 3. Other counts as one choice." from the ask's selection bounds. */
|
|
108
|
+
const selectionHint = (input: ChoiceAskInput): string => {
|
|
109
|
+
const {max, min} = choiceSelectionBounds(input);
|
|
110
|
+
const otherNote = input.allowOther === true ? ` ${otherTitle(input)} counts as one choice.` : "";
|
|
111
|
+
if (min === max) {
|
|
112
|
+
return `Choose ${min === 1 ? "one" : min}.${otherNote}`;
|
|
113
|
+
}
|
|
114
|
+
if (min === 0) {
|
|
115
|
+
return `Choose up to ${max}.${otherNote}`;
|
|
116
|
+
}
|
|
117
|
+
return `Choose ${min} to ${max}.${otherNote}`;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const otherErrorText = ({
|
|
121
|
+
errors,
|
|
122
|
+
otherText,
|
|
123
|
+
}: {
|
|
124
|
+
errors?: AskValidationError[];
|
|
125
|
+
otherText: string;
|
|
126
|
+
}): string | undefined => {
|
|
127
|
+
const {otherMaxLength} = ASK_LIMITS.choice;
|
|
128
|
+
if (otherText.trim().length > otherMaxLength) {
|
|
129
|
+
return `Keep this to ${otherMaxLength} characters or fewer.`;
|
|
130
|
+
}
|
|
131
|
+
return errors?.find((error) => error.path === "content.other")?.message;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Pick several options as checkboxes, plus an Other text field when the ask allows it. Submit is
|
|
136
|
+
* enabled once the options and the Other text together meet the ask's selection bounds.
|
|
137
|
+
*/
|
|
138
|
+
const AskChoiceMany: React.FC<AskChoiceProps> = ({
|
|
139
|
+
ask,
|
|
140
|
+
errors,
|
|
141
|
+
isDisabled,
|
|
142
|
+
onAnswer,
|
|
143
|
+
pendingActionId,
|
|
144
|
+
testID,
|
|
145
|
+
}) => {
|
|
146
|
+
const {input} = ask;
|
|
147
|
+
const [selectedIds, setSelectedIds] = useState<string[]>(input.default ?? []);
|
|
148
|
+
const [otherText, setOtherText] = useState<string>("");
|
|
149
|
+
const isAnswering = pendingActionId !== undefined;
|
|
150
|
+
const renderButton = useAnswerButton({isDisabled, onAnswer, pendingActionId, testID});
|
|
151
|
+
const fieldOptions = useMemo(
|
|
152
|
+
(): FieldOption[] =>
|
|
153
|
+
input.options.map((option) => ({
|
|
154
|
+
key: option.id,
|
|
155
|
+
label: describedLabel(option),
|
|
156
|
+
value: option.id,
|
|
157
|
+
})),
|
|
158
|
+
[input.options]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const draft = useMemo((): AskResponse => {
|
|
162
|
+
const selected = input.options
|
|
163
|
+
.map((option) => option.id)
|
|
164
|
+
.filter((id) => selectedIds.includes(id));
|
|
165
|
+
const other = otherText.trim();
|
|
166
|
+
return {action: "accept", content: other === "" ? {selected} : {other, selected}};
|
|
167
|
+
}, [input.options, otherText, selectedIds]);
|
|
168
|
+
const isDraftValid = useMemo(
|
|
169
|
+
() => validateAskResponse({input, kind: "choice", response: draft}).length === 0,
|
|
170
|
+
[draft, input]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const {max} = choiceSelectionBounds(input);
|
|
174
|
+
const choiceCount = selectedIds.length + (otherText.trim() === "" ? 0 : 1);
|
|
175
|
+
const countErrorText =
|
|
176
|
+
choiceCount > max ? `You chose ${choiceCount}. Choose at most ${max}.` : undefined;
|
|
177
|
+
|
|
178
|
+
const handleChange = useCallback(
|
|
179
|
+
(values: string[]): void => {
|
|
180
|
+
if (isDisabled || isAnswering) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
setSelectedIds(values);
|
|
184
|
+
},
|
|
185
|
+
[isAnswering, isDisabled]
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const handleOtherChange = useCallback(
|
|
189
|
+
(value: string): void => {
|
|
190
|
+
if (isDisabled || isAnswering) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
setOtherText(value);
|
|
194
|
+
},
|
|
195
|
+
[isAnswering, isDisabled]
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const handleSubmit = useCallback(
|
|
199
|
+
(): void | Promise<void> => onAnswer({actionId: SUBMIT_ACTION_ID, response: draft}),
|
|
200
|
+
[draft, onAnswer]
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<Box gap={3}>
|
|
205
|
+
{isDisabled ? (
|
|
206
|
+
<ReadOnlyOptions input={input} testID={`${testID}-options`} />
|
|
207
|
+
) : (
|
|
208
|
+
<MultiselectField
|
|
209
|
+
errorText={countErrorText}
|
|
210
|
+
helperText={selectionHint(input)}
|
|
211
|
+
onChange={handleChange}
|
|
212
|
+
options={fieldOptions}
|
|
213
|
+
testID={`${testID}-multiselect`}
|
|
214
|
+
title="Choose options"
|
|
215
|
+
value={selectedIds}
|
|
216
|
+
/>
|
|
217
|
+
)}
|
|
218
|
+
{input.allowOther === true ? (
|
|
219
|
+
<TextField
|
|
220
|
+
disabled={isDisabled || isAnswering}
|
|
221
|
+
errorText={otherErrorText({errors, otherText})}
|
|
222
|
+
onChange={handleOtherChange}
|
|
223
|
+
placeholder="Type your own answer"
|
|
224
|
+
testID={`${testID}-other`}
|
|
225
|
+
title={otherTitle(input)}
|
|
226
|
+
value={otherText}
|
|
227
|
+
/>
|
|
228
|
+
) : null}
|
|
229
|
+
<AskErrors
|
|
230
|
+
errors={errors?.filter((error) => error.path !== "content.other")}
|
|
231
|
+
testID={`${testID}-errors`}
|
|
232
|
+
/>
|
|
233
|
+
<Box direction="row" gap={2} wrap>
|
|
234
|
+
<Button
|
|
235
|
+
disabled={
|
|
236
|
+
isDisabled || !isDraftValid || (isAnswering && pendingActionId !== SUBMIT_ACTION_ID)
|
|
237
|
+
}
|
|
238
|
+
loading={pendingActionId === SUBMIT_ACTION_ID}
|
|
239
|
+
onClick={handleSubmit}
|
|
240
|
+
testID={`${testID}-submit`}
|
|
241
|
+
text={input.submitLabel ?? "Submit"}
|
|
242
|
+
wrapText
|
|
243
|
+
/>
|
|
244
|
+
<SkipButton ask={ask} renderButton={renderButton} />
|
|
245
|
+
</Box>
|
|
246
|
+
</Box>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Pick one option. Options that fit a simple card render as its buttons and answer on tap; up to
|
|
252
|
+
* eight options render as radio buttons, and more as a searchable select, each with Submit.
|
|
253
|
+
*/
|
|
254
|
+
const AskChoiceOne: React.FC<AskChoiceProps> = ({
|
|
255
|
+
ask,
|
|
256
|
+
errors,
|
|
257
|
+
isDisabled,
|
|
258
|
+
onAnswer,
|
|
259
|
+
pendingActionId,
|
|
260
|
+
testID,
|
|
261
|
+
}) => {
|
|
262
|
+
const {input, toolCallId} = ask;
|
|
263
|
+
const [selectedId, setSelectedId] = useState<string>(input.default?.[0] ?? "");
|
|
264
|
+
const isAnswering = pendingActionId !== undefined;
|
|
265
|
+
|
|
266
|
+
const card = useMemo(
|
|
267
|
+
(): SimpleCard => ask.simple ?? toSimpleCard({input, kind: "choice", toolCallId}),
|
|
268
|
+
[ask.simple, input, toolCallId]
|
|
269
|
+
);
|
|
270
|
+
const isQuickReply = fitsQuickReplies(card, input);
|
|
271
|
+
const isRadio = input.options.length <= RADIO_OPTIONS_MAX;
|
|
272
|
+
const fieldOptions = useMemo(() => toFieldOptions(input, isRadio), [input, isRadio]);
|
|
273
|
+
|
|
274
|
+
const draft = useMemo(
|
|
275
|
+
(): AskResponse => ({action: "accept", content: {selected: [selectedId]}}),
|
|
276
|
+
[selectedId]
|
|
277
|
+
);
|
|
278
|
+
const isDraftValid = useMemo(
|
|
279
|
+
() =>
|
|
280
|
+
selectedId !== "" &&
|
|
281
|
+
validateAskResponse({input, kind: "choice", response: draft}).length === 0,
|
|
282
|
+
[draft, input, selectedId]
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const handleSelect = useCallback(
|
|
286
|
+
(value: string): void => {
|
|
287
|
+
if (isDisabled || isAnswering) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
setSelectedId(value);
|
|
291
|
+
},
|
|
292
|
+
[isAnswering, isDisabled]
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const handleSubmit = useCallback(
|
|
296
|
+
(): void | Promise<void> => onAnswer({actionId: SUBMIT_ACTION_ID, response: draft}),
|
|
297
|
+
[draft, onAnswer]
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const renderButton = useAnswerButton({isDisabled, onAnswer, pendingActionId, testID});
|
|
301
|
+
|
|
302
|
+
const renderField = (): React.ReactElement => {
|
|
303
|
+
if (!isRadio) {
|
|
304
|
+
return (
|
|
305
|
+
<SelectField
|
|
306
|
+
disabled={isDisabled || isAnswering}
|
|
307
|
+
onChange={handleSelect}
|
|
308
|
+
options={fieldOptions}
|
|
309
|
+
placeholder="Choose an option"
|
|
310
|
+
testID={`${testID}-select`}
|
|
311
|
+
title="Choose one"
|
|
312
|
+
value={selectedId}
|
|
313
|
+
/>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
// RadioField has no disabled state, so a card that takes no answers lists the options instead.
|
|
317
|
+
if (isDisabled) {
|
|
318
|
+
return <ReadOnlyOptions input={input} testID={`${testID}-options`} />;
|
|
319
|
+
}
|
|
320
|
+
// RadioField takes no testID, so the wrapper carries it.
|
|
321
|
+
return (
|
|
322
|
+
<Box testID={`${testID}-radio`}>
|
|
323
|
+
<RadioField
|
|
324
|
+
onChange={handleSelect}
|
|
325
|
+
options={fieldOptions}
|
|
326
|
+
title="Choose one"
|
|
327
|
+
value={selectedId}
|
|
328
|
+
/>
|
|
329
|
+
</Box>
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
if (isQuickReply) {
|
|
334
|
+
return (
|
|
335
|
+
<Box gap={3}>
|
|
336
|
+
<OptionDescriptions input={input} />
|
|
337
|
+
<Box direction="row" gap={2} testID={`${testID}-quick-replies`} wrap>
|
|
338
|
+
{quickReplyButtons(card, input).map(renderButton)}
|
|
339
|
+
</Box>
|
|
340
|
+
<AskErrors errors={errors} testID={`${testID}-errors`} />
|
|
341
|
+
</Box>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return (
|
|
346
|
+
<Box gap={3}>
|
|
347
|
+
{renderField()}
|
|
348
|
+
<AskErrors errors={errors} testID={`${testID}-errors`} />
|
|
349
|
+
<Box direction="row" gap={2} wrap>
|
|
350
|
+
<Button
|
|
351
|
+
disabled={
|
|
352
|
+
isDisabled || !isDraftValid || (isAnswering && pendingActionId !== SUBMIT_ACTION_ID)
|
|
353
|
+
}
|
|
354
|
+
loading={pendingActionId === SUBMIT_ACTION_ID}
|
|
355
|
+
onClick={handleSubmit}
|
|
356
|
+
testID={`${testID}-submit`}
|
|
357
|
+
text={input.submitLabel ?? "Submit"}
|
|
358
|
+
wrapText
|
|
359
|
+
/>
|
|
360
|
+
<SkipButton ask={ask} renderButton={renderButton} />
|
|
361
|
+
</Box>
|
|
362
|
+
</Box>
|
|
363
|
+
);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
/** One `choice` ask: select one or select many, each with its own controls. */
|
|
367
|
+
export const AskChoice: React.FC<AskChoiceProps> = (props) =>
|
|
368
|
+
props.ask.input.select === "many" ? <AskChoiceMany {...props} /> : <AskChoiceOne {...props} />;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {type SimpleCard, toSimpleCard} from "@terreno/blocks";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import {useMemo} from "react";
|
|
4
|
+
|
|
5
|
+
import {Box} from "../Box";
|
|
6
|
+
import {type AskControlProps, AskErrors, SkipButton, useAnswerButton} from "./askControls";
|
|
7
|
+
import type {ChatAsk} from "./askTypes";
|
|
8
|
+
|
|
9
|
+
export interface AskConfirmProps extends AskControlProps {
|
|
10
|
+
ask: Extract<ChatAsk, {kind: "confirm"}>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Approve or deny one action. Renders the simple card's buttons, so the chat and a watch show the
|
|
15
|
+
* same labels, styles, and order (D26): approve first, destructive when the ask is, and deny
|
|
16
|
+
* last. Skip follows only when the ask sets `allowDecline`.
|
|
17
|
+
*/
|
|
18
|
+
export const AskConfirm: React.FC<AskConfirmProps> = ({
|
|
19
|
+
ask,
|
|
20
|
+
errors,
|
|
21
|
+
isDisabled,
|
|
22
|
+
onAnswer,
|
|
23
|
+
pendingActionId,
|
|
24
|
+
testID,
|
|
25
|
+
}) => {
|
|
26
|
+
const {input, toolCallId} = ask;
|
|
27
|
+
const card = useMemo(
|
|
28
|
+
(): SimpleCard => ask.simple ?? toSimpleCard({input, kind: "confirm", toolCallId}),
|
|
29
|
+
[ask.simple, input, toolCallId]
|
|
30
|
+
);
|
|
31
|
+
const renderButton = useAnswerButton({isDisabled, onAnswer, pendingActionId, testID});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Box gap={3}>
|
|
35
|
+
<Box direction="row" gap={2} testID={`${testID}-confirm-buttons`} wrap>
|
|
36
|
+
{card.buttons.map(renderButton)}
|
|
37
|
+
<SkipButton ask={ask} renderButton={renderButton} />
|
|
38
|
+
</Box>
|
|
39
|
+
<AskErrors errors={errors} testID={`${testID}-errors`} />
|
|
40
|
+
</Box>
|
|
41
|
+
);
|
|
42
|
+
};
|