From 32a8ceec43a4ab26a4632c9c37d596f4b327fc36 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 30 Oct 2024 18:20:18 +0800 Subject: [PATCH] feat: only support visual editor alerts to navigate to discover (#368) (#369) * feat: only support visual editor alerts to navigate to discover Signed-off-by: tygao * doc: add changelog Signed-off-by: tygao --------- Signed-off-by: tygao (cherry picked from commit 50fef5c06993b110367314400f857042ef646568) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] --- .../generate_popover_body.test.tsx | 53 +++++++++++++++++++ .../generate_popover_body.tsx | 5 ++ 2 files changed, 58 insertions(+) diff --git a/public/components/incontext_insight/generate_popover_body.test.tsx b/public/components/incontext_insight/generate_popover_body.test.tsx index 7c61d7f6..c6c83319 100644 --- a/public/components/incontext_insight/generate_popover_body.test.tsx +++ b/public/components/incontext_insight/generate_popover_body.test.tsx @@ -338,6 +338,7 @@ describe('GeneratePopoverBody', () => { index: 'mock_index', dataSourceId: `test-data-source-id`, monitorType: 'query_level_monitor', + isVisualEditorMonitor: true, }, }); mockPost.mockImplementation((path: string, body) => { @@ -384,4 +385,56 @@ describe('GeneratePopoverBody', () => { }); expect(window.open).toHaveBeenCalledWith('formattedUrl', '_blank'); }); + + it('should hide navigate to discover if not from visual editor monitor', async () => { + incontextInsightMock.contextProvider = jest.fn().mockResolvedValue({ + additionalInfo: { + dsl: mockDSL, + index: 'mock_index', + dataSourceId: `test-data-source-id`, + monitorType: 'query_level_monitor', + isVisualEditorMonitor: false, + }, + }); + mockPost.mockImplementation((path: string, body) => { + let value; + switch (path) { + case SUMMARY_ASSISTANT_API.SUMMARIZE: + value = { + summary: 'Generated summary content', + insightAgentIdExists: true, + }; + break; + + case SUMMARY_ASSISTANT_API.INSIGHT: + value = 'Generated insight content'; + break; + + default: + return null; + } + return Promise.resolve(value); + }); + + const coreStart = coreMock.createStart(); + const dataStart = dataPluginMock.createStartContract(); + const getStartServices = jest.fn().mockResolvedValue([ + coreStart, + { + data: dataStart, + }, + ]); + const { queryByText } = render( + + ); + + await waitFor(() => { + expect(queryByText('Discover details')).not.toBeInTheDocument(); + }); + }); }); diff --git a/public/components/incontext_insight/generate_popover_body.tsx b/public/components/incontext_insight/generate_popover_body.tsx index a161e4a8..ede3a119 100644 --- a/public/components/incontext_insight/generate_popover_body.tsx +++ b/public/components/incontext_insight/generate_popover_body.tsx @@ -58,6 +58,11 @@ export const GeneratePopoverBody: React.FC<{ if (!contextObject) return; const monitorType = contextObject?.additionalInfo?.monitorType; const dsl = contextObject?.additionalInfo?.dsl; + const isVisualEditorMonitor = contextObject?.additionalInfo?.isVisualEditorMonitor; + // Only alerts from visual editor monitor support to navigate to discover. + if (!isVisualEditorMonitor) { + return; + } // Only this two types from alerting contain DSL and index. const isSupportedMonitorType = monitorType === 'query_level_monitor' || monitorType === 'bucket_level_monitor';