From c6422abc6459477dc96841445eb6c56bd0cb29d4 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Fri, 23 Oct 2026 16:37:32 +0200 Subject: [PATCH 01/12] [Insights] Add the Explain button and pass the Insights scope to Concierge --- src/CONST/index.ts | 1 + .../Search/SearchRouter/useAskConcierge.tsx | 4 +- src/pages/Insights/InsightsDashboard.tsx | 17 +++++- src/pages/Insights/ai/InsightsAICard.tsx | 13 +++-- src/pages/Insights/ai/InsightsAICardRow.tsx | 17 ++++-- .../Insights/ai/InsightsExplainButton.tsx | 52 +++++++++++++++++++ src/types/onyx/SidePanel.tsx | 13 ++++- src/types/onyx/index.ts | 3 +- 8 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 src/pages/Insights/ai/InsightsExplainButton.tsx diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 9d8c7a4cd827..90252d4599f7 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -10089,6 +10089,7 @@ const CONST = { CONTROL_GROUP_CURRENCY: 'Insights-ControlGroupCurrency', CONTROL_GROUP_BY: 'Insights-ControlGroupBy', CONTROL_COMPARE: 'Insights-ControlCompare', + AI_EXPLAIN: 'Insights-AIExplain', }, EXPENSE_RULES: { TABLE_ROW: 'ExpenseRules-TableRow', diff --git a/src/components/Search/SearchRouter/useAskConcierge.tsx b/src/components/Search/SearchRouter/useAskConcierge.tsx index 2f8d2360bcdf..6e2b9763a8cf 100644 --- a/src/components/Search/SearchRouter/useAskConcierge.tsx +++ b/src/components/Search/SearchRouter/useAskConcierge.tsx @@ -13,6 +13,7 @@ import {createTaskFromMarkdown} from '@userActions/Task'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {SidePanelContext} from '@src/types/onyx'; import type {FileObject} from '@src/types/utils/Attachment'; /** @@ -38,7 +39,7 @@ function useAskConcierge({forceConcierge = false}: {forceConcierge?: boolean} = const shouldRespondInThread = targetReportID === conciergeReportID && isBetaEnabled(CONST.BETAS.CONCIERGE_RESPOND_IN_THREAD); - const askConcierge = (searchQuery: string) => { + const askConcierge = (searchQuery: string, sidePanelContext?: SidePanelContext) => { const trimmedQuery = searchQuery.trim(); if (!trimmedQuery || !shouldShowAskConcierge) { return; @@ -58,6 +59,7 @@ function useAskConcierge({forceConcierge = false}: {forceConcierge?: boolean} = currentUserAccountID, shouldPlaySound: true, isInSidePanel, + sidePanelContext, delegateAccountID, conciergeReportID, conciergeThreadReportID, diff --git a/src/pages/Insights/InsightsDashboard.tsx b/src/pages/Insights/InsightsDashboard.tsx index 580765feacea..2c51d4500a01 100644 --- a/src/pages/Insights/InsightsDashboard.tsx +++ b/src/pages/Insights/InsightsDashboard.tsx @@ -27,7 +27,7 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {AIInsight, InsightsDashboardID} from '@src/types/onyx'; +import type {AIInsight, InsightsDashboardID, InsightsScope} from '@src/types/onyx'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import {useIsFocused} from '@react-navigation/native'; @@ -51,6 +51,7 @@ import useInsightsFilters from './useInsightsFilters'; type InsightsDashboardContentProps = { state: InsightsDashboardState; aiInsights: AIInsight[] | undefined; + insightsScope: InsightsScope; isLoadingAIInsights: boolean; headlineChart: InsightsDashboardChart; @@ -67,7 +68,17 @@ type InsightsDashboardContentProps = { onGroupByChange: (groupBy: InsightsFilters['groupBy']) => void; }; -function InsightsDashboardContent({state, aiInsights, isLoadingAIInsights, headlineChart, supportingCharts, filters, onRetry, onGroupByChange}: InsightsDashboardContentProps) { +function InsightsDashboardContent({ + state, + aiInsights, + insightsScope, + isLoadingAIInsights, + headlineChart, + supportingCharts, + filters, + onRetry, + onGroupByChange, +}: InsightsDashboardContentProps) { const styles = useThemeStyles(); const {pageGutter} = useLayoutSpacing(); const theme = useTheme(); @@ -152,6 +163,7 @@ function InsightsDashboardContent({state, aiInsights, isLoadingAIInsights, headl {isBetaEnabled(CONST.BETAS.INSIGHTS_AI) && ( )} @@ -273,6 +285,7 @@ function InsightsDashboard({dashboardID}: {dashboardID: InsightsDashboardID}) { + {insight.text} + ); } diff --git a/src/pages/Insights/ai/InsightsAICardRow.tsx b/src/pages/Insights/ai/InsightsAICardRow.tsx index e2521f91fcd2..09d9c39c9133 100644 --- a/src/pages/Insights/ai/InsightsAICardRow.tsx +++ b/src/pages/Insights/ai/InsightsAICardRow.tsx @@ -4,7 +4,7 @@ import useLayoutSpacing from '@hooks/useLayoutSpacing'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import type {AIInsight} from '@src/types/onyx'; +import type {AIInsight, InsightsScope} from '@src/types/onyx'; import type {ReactNode} from 'react'; @@ -19,12 +19,15 @@ const SKELETON_CARD_COUNT = 4; type InsightsAICardRowProps = { insights: AIInsight[] | undefined; + /** Dashboard filters the insights were written for, sent to Concierge when the user asks to explain. */ + insightsScope: InsightsScope; + /** Whether the dashboard has no response for the current filters yet */ isLoading: boolean; }; /** Shows the AI insights in a sideways-scrolling row, with placeholders while the dashboard loads. */ -function InsightsAICardRow({insights, isLoading}: InsightsAICardRowProps) { +function InsightsAICardRow({insights, insightsScope, isLoading}: InsightsAICardRowProps) { const styles = useThemeStyles(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const {pageGutter, pageGutterEdgeToEdge} = useLayoutSpacing(); @@ -49,7 +52,15 @@ function InsightsAICardRow({insights, isLoading}: InsightsAICardRowProps) { > {isLoading ? Array.from({length: SKELETON_CARD_COUNT}, (item, index) => renderWithDivider(, index)) - : insights?.map((insight, index) => renderWithDivider(, index))} + : insights?.map((insight, index) => + renderWithDivider( + , + index, + ), + )} ); } diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx new file mode 100644 index 000000000000..38e61fd35e3d --- /dev/null +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -0,0 +1,52 @@ +import Button from '@components/Button'; +import useAskConcierge from '@components/Search/SearchRouter/useAskConcierge'; + +import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; +import useLocalize from '@hooks/useLocalize'; +import useTheme from '@hooks/useTheme'; +import useThemeStyles from '@hooks/useThemeStyles'; + +import CONST from '@src/CONST'; +import type {InsightsScope} from '@src/types/onyx'; + +import React from 'react'; + +type InsightsExplainButtonProps = { + /** Message sent to Concierge on press */ + explainPrompt: string; + + insightsScope: InsightsScope; +}; + +/** Asks Concierge to explain an AI insight, sending along the dashboard filters it was written for. */ +function InsightsExplainButton({explainPrompt, insightsScope}: InsightsExplainButtonProps) { + const styles = useThemeStyles(); + const theme = useTheme(); + const {translate} = useLocalize(); + const icons = useMemoizedLazyExpensifyIcons(['Sparkles']); + const {askConcierge, shouldShowAskConcierge} = useAskConcierge({forceConcierge: true}); + + if (!shouldShowAskConcierge) { + return null; + } + + return ( + + ); +} + +export default InsightsExplainButton; diff --git a/src/types/onyx/SidePanel.tsx b/src/types/onyx/SidePanel.tsx index df9648f8c666..7d60c522b732 100644 --- a/src/types/onyx/SidePanel.tsx +++ b/src/types/onyx/SidePanel.tsx @@ -1,3 +1,7 @@ +import type {InsightsFilters} from '@pages/Insights/insightsFilters'; + +import type {InsightsSearchKey} from './InsightsDashboard'; + type SidePanel = { /** Whether the Side Panel is open on large screens */ open: boolean; @@ -12,11 +16,16 @@ type SidePanel = { reportID?: string; }; +/** Insights dashboard and filters the user was looking at when they asked Concierge about it */ +type InsightsScope = Pick & { + searchKey: InsightsSearchKey; +}; + /** * Describes the context of what the user was viewing when they sent a message from the Side Panel. * Sent to the backend so Concierge can tailor its response to the user's current context. */ -type SidePanelContext = {reportID?: string; selectedTransactionIDs?: string; selectedReportIDs?: string}; +type SidePanelContext = {reportID?: string; selectedTransactionIDs?: string; selectedReportIDs?: string; insightsScope?: InsightsScope}; export default SidePanel; -export type {SidePanelContext}; +export type {InsightsScope, SidePanelContext}; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index e04b5dd0d25d..47462543b5a8 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -226,7 +226,7 @@ import type Session from './Session'; import type ShareBankAccount from './ShareBankAccount'; import type ShareTempFile from './ShareTempFile'; import type SidePanel from './SidePanel'; -import type {SidePanelContext} from './SidePanel'; +import type {InsightsScope, SidePanelContext} from './SidePanel'; import type StripeCustomerID from './StripeCustomerID'; import type SuggestedAgent from './SuggestedAgent'; import type SuggestedAgentRule from './SuggestedAgentRule'; @@ -511,6 +511,7 @@ export type { CorpayPayModal, SidePanel, SidePanelContext, + InsightsScope, LastPaymentMethodType, ReportAttributesDerivedValue, LastSearchParams, From dabc5975b1e2b1cba41cd28edc43569ead5efe59 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Mon, 26 Oct 2026 10:49:44 +0100 Subject: [PATCH 02/12] Add the Explain button to charts --- src/languages/en.ts | 1 + src/pages/Insights/InsightsDashboard.tsx | 2 ++ src/pages/Insights/ai/InsightsAICard.tsx | 1 + .../Insights/ai/InsightsExplainButton.tsx | 13 ++++++++---- .../Insights/charts/InsightsChartWidget.tsx | 20 +++++++++++++++++-- tests/ui/InsightsChartWidgetTest.tsx | 1 + 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index c5de0419e292..89bc0b6c64f4 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1319,6 +1319,7 @@ const translations = { }, insightsPage: { viewOnSpend: 'View on Spend', + explainChartPrompt: (chartTitle: string) => `Explain what stands out in my ${chartTitle} data`, compare: { label: 'Compare', previousPeriod: 'Previous period', diff --git a/src/pages/Insights/InsightsDashboard.tsx b/src/pages/Insights/InsightsDashboard.tsx index 2c51d4500a01..15404fa62ce7 100644 --- a/src/pages/Insights/InsightsDashboard.tsx +++ b/src/pages/Insights/InsightsDashboard.tsx @@ -176,6 +176,7 @@ function InsightsDashboardContent({ averageQueryJSON={headlineChart.averageQueryJSON} averageSnapshot={headlineChart.averageSnapshot} filters={filters} + insightsScope={insightsScope} onRetry={onRetry} onGroupByChange={onGroupByChange} /> @@ -197,6 +198,7 @@ function InsightsDashboardContent({ averageQueryJSON={averageQueryJSON} averageSnapshot={averageSnapshot} filters={filters} + insightsScope={insightsScope} onRetry={onRetry} /> ))} diff --git a/src/pages/Insights/ai/InsightsAICard.tsx b/src/pages/Insights/ai/InsightsAICard.tsx index 8b9c2d06baaa..54224afd774c 100644 --- a/src/pages/Insights/ai/InsightsAICard.tsx +++ b/src/pages/Insights/ai/InsightsAICard.tsx @@ -28,6 +28,7 @@ function InsightsAICard({insight, insightsScope}: InsightsAICardProps) { ); diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx index 38e61fd35e3d..a76cfa6b3079 100644 --- a/src/pages/Insights/ai/InsightsExplainButton.tsx +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -16,10 +16,13 @@ type InsightsExplainButtonProps = { explainPrompt: string; insightsScope: InsightsScope; + + /** Tints the glyph and label with the link colour instead of the muted one */ + isAccented?: boolean; }; /** Asks Concierge to explain an AI insight, sending along the dashboard filters it was written for. */ -function InsightsExplainButton({explainPrompt, insightsScope}: InsightsExplainButtonProps) { +function InsightsExplainButton({explainPrompt, insightsScope, isAccented = false}: InsightsExplainButtonProps) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); @@ -30,6 +33,8 @@ function InsightsExplainButton({explainPrompt, insightsScope}: InsightsExplainBu return null; } + const glyphColor = isAccented ? theme.link : theme.icon; + return ( ); } diff --git a/src/pages/Insights/charts/InsightsChartWidget.tsx b/src/pages/Insights/charts/InsightsChartWidget.tsx index a55d7049c0c1..ad804b7e47d2 100644 --- a/src/pages/Insights/charts/InsightsChartWidget.tsx +++ b/src/pages/Insights/charts/InsightsChartWidget.tsx @@ -11,6 +11,7 @@ import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useLayoutSpacing from '@hooks/useLayoutSpacing'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; +import usePermissions from '@hooks/usePermissions'; import useThemeStyles from '@hooks/useThemeStyles'; import localFileDownload from '@libs/localFileDownload'; @@ -18,6 +19,7 @@ import Navigation from '@libs/Navigation/Navigation'; import {INSIGHTS_CHART_STATE} from '@libs/resolveInsightsChartData'; import {getDateFilterRange} from '@libs/SearchQueryUtils'; +import InsightsExplainButton from '@pages/Insights/ai/InsightsExplainButton'; import buildInsightsChartCSV from '@pages/Insights/buildInsightsChartCSV'; import InsightsGroupByDropdown from '@pages/Insights/controls/InsightsGroupByDropdown'; import type {InsightsChartSpec} from '@pages/Insights/dashboardSpecs'; @@ -27,7 +29,7 @@ import useInsightsChartData from '@pages/Insights/useInsightsChartData'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import type {SearchResults} from '@src/types/onyx'; +import type {InsightsScope, SearchResults} from '@src/types/onyx'; import type {OnyxEntry} from 'react-native-onyx'; @@ -60,6 +62,9 @@ type InsightsChartWidgetProps = { /** Page-level filters every chart on the dashboard is narrowed by */ filters: InsightsFilters; + /** Dashboard filters sent to Concierge when the user asks to explain the chart */ + insightsScope: InsightsScope; + /** Called by the retry button to request the dashboard again */ onRetry: () => void; @@ -76,11 +81,13 @@ function InsightsChartWidget({ averageQueryJSON, averageSnapshot, filters, + insightsScope, onRetry, onGroupByChange, }: InsightsChartWidgetProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const {isBetaEnabled} = usePermissions(); const {cardPaddingHorizontal, cardPaddingBottom} = useLayoutSpacing(); const icons = useMemoizedLazyExpensifyIcons(['Expand', 'Table']); const {getCurrencyDecimals} = useCurrencyListActions(); @@ -111,6 +118,14 @@ function InsightsChartWidget({ /> ) : null; + const explainButton = + isBetaEnabled(CONST.BETAS.INSIGHTS_AI) && (state === INSIGHTS_CHART_STATE.READY || isLoading) ? ( + + ) : null; + const headerMenu = !!queryJSON && (state === INSIGHTS_CHART_STATE.READY || isLoading) ? ( {groupByControl} + {explainButton} {headerMenu} ) : null diff --git a/tests/ui/InsightsChartWidgetTest.tsx b/tests/ui/InsightsChartWidgetTest.tsx index dca56c665aea..b59cc996f6f1 100644 --- a/tests/ui/InsightsChartWidgetTest.tsx +++ b/tests/ui/InsightsChartWidgetTest.tsx @@ -62,6 +62,7 @@ function renderWidget() { averageQueryJSON={undefined} averageSnapshot={undefined} filters={FILTERS} + insightsScope={{searchKey: INSIGHTS_DASHBOARD_SPECS[CONST.INSIGHTS.DASHBOARD.SPEND].searchKey, policyIDs: [], date: FILTERS.date, groupCurrency: FILTERS.groupCurrency}} onRetry={jest.fn()} /> , From fd940b1dfa76f6fef4058e8ea61b3e8e92344cc1 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Mon, 26 Oct 2026 10:54:22 +0100 Subject: [PATCH 03/12] Fix spellcheck --- src/pages/Insights/ai/InsightsExplainButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx index a76cfa6b3079..eb24304389d4 100644 --- a/src/pages/Insights/ai/InsightsExplainButton.tsx +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -17,7 +17,7 @@ type InsightsExplainButtonProps = { insightsScope: InsightsScope; - /** Tints the glyph and label with the link colour instead of the muted one */ + /** Tints the glyph and label with the link color instead of the muted one */ isAccented?: boolean; }; From 095de95d19cb82009d9bedf852d32e1272983d31 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Mon, 26 Oct 2026 14:23:30 +0100 Subject: [PATCH 04/12] Update the explainChartPrompt --- src/languages/en.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 89bc0b6c64f4..bc23365c5a55 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1319,7 +1319,7 @@ const translations = { }, insightsPage: { viewOnSpend: 'View on Spend', - explainChartPrompt: (chartTitle: string) => `Explain what stands out in my ${chartTitle} data`, + explainChartPrompt: (chartTitle: string) => `Explain the data in ${chartTitle}`, compare: { label: 'Compare', previousPeriod: 'Previous period', From 5d6a1650438174b9c22e2bc09892abd858c40284 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 10:33:01 +0100 Subject: [PATCH 05/12] Update ai card skeleton to include the button --- .../Insights/ai/InsightsAICardSkeleton.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pages/Insights/ai/InsightsAICardSkeleton.tsx b/src/pages/Insights/ai/InsightsAICardSkeleton.tsx index 307e2d66fdbf..e1bb9e3ef2e0 100644 --- a/src/pages/Insights/ai/InsightsAICardSkeleton.tsx +++ b/src/pages/Insights/ai/InsightsAICardSkeleton.tsx @@ -13,13 +13,17 @@ const LINE_HEIGHT = variables.lineHeightSizeH2; const BAR_HEIGHT = 16; const BAR_OFFSET_Y = (LINE_HEIGHT - BAR_HEIGHT) / 2; -/** Stands in for an AI card's narration while the dashboard loads. */ +const BUTTON_HEIGHT = variables.componentSizeSmall; +const BUTTON_BAR_WIDTH = 48; +const BUTTON_BAR_HEIGHT = 8; + +/** Stands in for an AI card's narration and Explain button while the dashboard loads. */ function InsightsAICardSkeleton() { const styles = useThemeStyles(); const theme = useTheme(); return ( - + + + + ); } From 3aea88fc764ca46e66f79cb1c5f1c4bcbf213c49 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 10:36:29 +0100 Subject: [PATCH 06/12] Update translation keys --- src/languages/en.ts | 3 ++- src/pages/Insights/ai/InsightsExplainButton.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 029930e97f9d..255ab6658b78 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1347,7 +1347,8 @@ const translations = { }, insightsPage: { viewOnSpend: 'View on Spend', - explainChartPrompt: (chartTitle: string) => `Explain the data in ${chartTitle}`, + explain: 'Explain', + explainChartPrompt: (chartTitle: string) => `Explain the data in ${chartTitle}.`, compliance: 'Compliance', runningTotal: 'Running total', compare: { diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx index eb24304389d4..9353f05c41c9 100644 --- a/src/pages/Insights/ai/InsightsExplainButton.tsx +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -49,7 +49,7 @@ function InsightsExplainButton({explainPrompt, insightsScope, isAccented = false fill={glyphColor} hoverFill={glyphColor} /> - {translate('reportActionContextMenu.explain')} + {translate('insightsPage.explain')} ); } From 39a4b8586739ff14c237326928b7fb524ce33e10 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 10:44:43 +0100 Subject: [PATCH 07/12] Update comments --- src/pages/Insights/ai/InsightsAICardSkeleton.tsx | 2 +- src/pages/Insights/ai/InsightsExplainButton.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/Insights/ai/InsightsAICardSkeleton.tsx b/src/pages/Insights/ai/InsightsAICardSkeleton.tsx index e1bb9e3ef2e0..93c879ccd704 100644 --- a/src/pages/Insights/ai/InsightsAICardSkeleton.tsx +++ b/src/pages/Insights/ai/InsightsAICardSkeleton.tsx @@ -17,7 +17,7 @@ const BUTTON_HEIGHT = variables.componentSizeSmall; const BUTTON_BAR_WIDTH = 48; const BUTTON_BAR_HEIGHT = 8; -/** Stands in for an AI card's narration and Explain button while the dashboard loads. */ +/** Stands in for an AI card's narration while the dashboard loads. */ function InsightsAICardSkeleton() { const styles = useThemeStyles(); const theme = useTheme(); diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx index 9353f05c41c9..4c34f6f93b44 100644 --- a/src/pages/Insights/ai/InsightsExplainButton.tsx +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -15,6 +15,7 @@ type InsightsExplainButtonProps = { /** Message sent to Concierge on press */ explainPrompt: string; + /** Dashboard and filters sent with the prompt so Concierge explains the data the user sees */ insightsScope: InsightsScope; /** Tints the glyph and label with the link color instead of the muted one */ From 2b893c78036271c1023d45b12e2f904abc8a77bf Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 10:54:42 +0100 Subject: [PATCH 08/12] Fix button position in the card --- src/pages/Insights/ai/InsightsAICard.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/Insights/ai/InsightsAICard.tsx b/src/pages/Insights/ai/InsightsAICard.tsx index 54224afd774c..588da88f34fc 100644 --- a/src/pages/Insights/ai/InsightsAICard.tsx +++ b/src/pages/Insights/ai/InsightsAICard.tsx @@ -18,10 +18,10 @@ function InsightsAICard({insight, insightsScope}: InsightsAICardProps) { const styles = useThemeStyles(); return ( - + {insight.text} From 740afaaabc22f0838c81e5c0fe790ad1c39789aa Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 11:19:15 +0100 Subject: [PATCH 09/12] Add translations --- src/languages/de.ts | 2 ++ src/languages/el.ts | 2 ++ src/languages/es.ts | 2 ++ src/languages/fr.ts | 2 ++ src/languages/it.ts | 2 ++ src/languages/ja.ts | 2 ++ src/languages/nl.ts | 2 ++ src/languages/pl.ts | 2 ++ src/languages/pt-BR.ts | 2 ++ src/languages/zh-hans.ts | 2 ++ 10 files changed, 20 insertions(+) diff --git a/src/languages/de.ts b/src/languages/de.ts index a8d78fb2deba..2804a088fb01 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -1233,6 +1233,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Compliance', runningTotal: 'Laufende Summe', + explain: 'Erklären', + explainChartPrompt: (chartTitle: string) => `Erklären Sie die Daten in ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Abonnement', diff --git a/src/languages/el.ts b/src/languages/el.ts index ba10e7d6e950..d5116735d890 100644 --- a/src/languages/el.ts +++ b/src/languages/el.ts @@ -1277,6 +1277,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Συμμόρφωση', runningTotal: 'Τρέχον σύνολο', + explain: 'Επεξήγηση', + explainChartPrompt: (chartTitle: string) => `Εξηγήστε τα δεδομένα στο ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Συνδρομή', diff --git a/src/languages/es.ts b/src/languages/es.ts index 38e74eae6a5e..5fb35bb71f3f 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1225,6 +1225,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Cumplimiento', runningTotal: 'Total acumulado', + explain: 'Explicar', + explainChartPrompt: (chartTitle: string) => `Explica los datos en ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Suscripcion', diff --git a/src/languages/fr.ts b/src/languages/fr.ts index dddf549505a4..ae648cb01c16 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -1237,6 +1237,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Conformité', runningTotal: 'Total cumulé', + explain: 'Expliquer', + explainChartPrompt: (chartTitle: string) => `Expliquez les données dans ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Abonnement', diff --git a/src/languages/it.ts b/src/languages/it.ts index 5db8994b473a..2c34b8d082d0 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -1233,6 +1233,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Conformità', runningTotal: 'Totale progressivo', + explain: 'Spiega', + explainChartPrompt: (chartTitle: string) => `Spiega i dati in ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Abbonamento', diff --git a/src/languages/ja.ts b/src/languages/ja.ts index ff6deb7d5dfa..60ec9e1223d4 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -1221,6 +1221,8 @@ const translations: TranslationDeepObject = { }, compliance: 'コンプライアンス', runningTotal: '累計合計', + explain: '説明', + explainChartPrompt: (chartTitle: string) => `${chartTitle} のデータを説明します。`, }, allSettingsScreen: { subscription: 'サブスクリプション', diff --git a/src/languages/nl.ts b/src/languages/nl.ts index 7298f782c0d0..6fd14c66d3da 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -1232,6 +1232,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Naleving', runningTotal: 'Doorlopend totaal', + explain: 'Uitleg', + explainChartPrompt: (chartTitle: string) => `Leg de gegevens in ${chartTitle} uit.`, }, allSettingsScreen: { subscription: 'Abonnement', diff --git a/src/languages/pl.ts b/src/languages/pl.ts index 6e5d686a34a7..5d5e90cbe897 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -1256,6 +1256,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Zgodność', runningTotal: 'Suma narastająco', + explain: 'Wyjaśnij', + explainChartPrompt: (chartTitle: string) => `Wyjaśnij dane w ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Subskrypcja', diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index 1c559caedc7c..e298813b8073 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -1232,6 +1232,8 @@ const translations: TranslationDeepObject = { }, compliance: 'Conformidade', runningTotal: 'Total acumulado', + explain: 'Explicar', + explainChartPrompt: (chartTitle: string) => `Explique os dados em ${chartTitle}.`, }, allSettingsScreen: { subscription: 'Assinatura', diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 010663a790cd..984a9e357232 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -1186,6 +1186,8 @@ const translations: TranslationDeepObject = { }, compliance: '合规', runningTotal: '累计总额', + explain: '解释', + explainChartPrompt: (chartTitle: string) => `解释「${chartTitle}」中的数据。`, }, allSettingsScreen: { subscription: '订阅', From e62edb30176ed0136e1889e437019259aa5df0ed Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 12:56:04 +0100 Subject: [PATCH 10/12] Add a unit test --- tests/unit/hooks/useAskConcierge.test.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/hooks/useAskConcierge.test.tsx b/tests/unit/hooks/useAskConcierge.test.tsx index 32df52a43f45..90c4d46cd999 100644 --- a/tests/unit/hooks/useAskConcierge.test.tsx +++ b/tests/unit/hooks/useAskConcierge.test.tsx @@ -5,6 +5,7 @@ import useAskConcierge from '@components/Search/SearchRouter/useAskConcierge'; import {addAttachmentWithComment, addComment} from '@userActions/Report'; import {createTaskFromMarkdown} from '@userActions/Task'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Report} from '@src/types/onyx'; import type {FileObject} from '@src/types/utils/Attachment'; @@ -161,6 +162,21 @@ describe('useAskConcierge', () => { ); }); + it('sends the side panel context with the comment, so Concierge answers about the data on screen', async () => { + // Given a loaded Concierge report and the Insights filters the user is looking at + await seedReports(); + const {result} = renderAskConcierge({forceConcierge: true}); + const sidePanelContext = { + insightsScope: {searchKey: CONST.INSIGHTS.SEARCH_KEY.SPEND, policyIDs: ['ABC123'], date: {from: '2026-01-01', to: '2026-03-31'}, groupCurrency: CONST.CURRENCY.USD}, + }; + + // When the user asks Concierge to explain an insight + result.current.askConcierge('Explain the data in Spend over time', sidePanelContext); + + // Then the filters reach addComment alongside the message + expect(mockAddComment).toHaveBeenCalledWith(expect.objectContaining({text: 'Explain the data in Spend over time', sidePanelContext})); + }); + it('creates a task instead of a comment when the message uses the `[] task` shorthand', async () => { // Given a loaded Concierge report and text that the markdown task detection claims await seedReports(); From 510f172028147188cc0a3b5f17e1d17f43d00ae7 Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 13:05:34 +0100 Subject: [PATCH 11/12] Stop rerendering Explain buttons on Concierge replies --- .../Search/SearchRouter/useAskConcierge.tsx | 6 +++-- tests/unit/hooks/useAskConcierge.test.tsx | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/Search/SearchRouter/useAskConcierge.tsx b/src/components/Search/SearchRouter/useAskConcierge.tsx index 39d725ff5772..c8ab426716df 100644 --- a/src/components/Search/SearchRouter/useAskConcierge.tsx +++ b/src/components/Search/SearchRouter/useAskConcierge.tsx @@ -17,6 +17,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {SidePanelContext} from '@src/types/onyx'; import type {FileObject} from '@src/types/utils/Attachment'; +import {getReportParentReportID} from '@selectors/Report'; + /** * Returns a callback that opens the side panel (or Concierge chat on native) * and sends the provided search query as a message. @@ -29,9 +31,9 @@ function useAskConcierge({forceConcierge = false}: {forceConcierge?: boolean} = const sidePanelReportID = useSidePanelReportID(); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const {openConciergeAnywhere, isInSidePanel} = useOpenConciergeAnywhere(); - const [sidePanelReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(sidePanelReportID)}`); + const [sidePanelParentReportID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(sidePanelReportID)}`, {selector: getReportParentReportID}); - const isSidePanelOnConciergeThread = !!conciergeReportID && sidePanelReport?.parentReportID === conciergeReportID; + const isSidePanelOnConciergeThread = !!conciergeReportID && sidePanelParentReportID === conciergeReportID; const targetReportID = !forceConcierge && isInSidePanel && sidePanelReportID && !isSidePanelOnConciergeThread ? sidePanelReportID : conciergeReportID; const [targetReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(targetReportID)}`); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); diff --git a/tests/unit/hooks/useAskConcierge.test.tsx b/tests/unit/hooks/useAskConcierge.test.tsx index 90c4d46cd999..bad56a07ee51 100644 --- a/tests/unit/hooks/useAskConcierge.test.tsx +++ b/tests/unit/hooks/useAskConcierge.test.tsx @@ -12,6 +12,8 @@ import type {FileObject} from '@src/types/utils/Attachment'; import Onyx from 'react-native-onyx'; +import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; + const ACCOUNT_ID = 1; const DELEGATE_ACCOUNT_ID = '99'; const TIMEZONE = 'Europe/Warsaw'; @@ -120,6 +122,29 @@ describe('useAskConcierge', () => { expect(result.current.conciergeTargetReportID).toBe(CONCIERGE_REPORT_ID); }); + it('does not rerender when the thread open in the side panel gets a reply', async () => { + // Given web, with the side panel showing the thread of an earlier Concierge question + mockIsInSidePanel = true; + await seedReports(); + const conciergeThread = {reportID: '300', parentReportID: CONCIERGE_REPORT_ID} as Report; + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeThread.reportID}`, conciergeThread); + mockSidePanelReportID = conciergeThread.reportID; + let renderCount = 0; + renderHook(() => { + renderCount++; + return useAskConcierge(); + }); + await waitForBatchedUpdates(); + const renderCountBeforeReply = renderCount; + + // When Concierge replies in that thread + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${conciergeThread.reportID}`, {lastMessageText: 'Spend is up because of travel.'}); + await waitForBatchedUpdates(); + + // Then the hook does not rerender, since the reply leaves the thread's parent, and so the target, unchanged + expect(renderCount).toBe(renderCountBeforeReply); + }); + it('targets Concierge on native, where there is no side panel', async () => { // Given native, which has no side panel to route through await seedReports(); From f0cdca4327e55e675cfc24912d08d4fa9ba2324e Mon Sep 17 00:00:00 2001 From: mhawryluk Date: Tue, 3 Nov 2026 13:52:28 +0100 Subject: [PATCH 12/12] Update comment in InsightsExplainButton --- src/pages/Insights/ai/InsightsExplainButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Insights/ai/InsightsExplainButton.tsx b/src/pages/Insights/ai/InsightsExplainButton.tsx index 4c34f6f93b44..63353856128e 100644 --- a/src/pages/Insights/ai/InsightsExplainButton.tsx +++ b/src/pages/Insights/ai/InsightsExplainButton.tsx @@ -22,7 +22,7 @@ type InsightsExplainButtonProps = { isAccented?: boolean; }; -/** Asks Concierge to explain an AI insight, sending along the dashboard filters it was written for. */ +/** Asks Concierge to explain an AI insight or chart, sending along the dashboard filters so the answer covers the data on screen. */ function InsightsExplainButton({explainPrompt, insightsScope, isAccented = false}: InsightsExplainButtonProps) { const styles = useThemeStyles(); const theme = useTheme();