Skip to content

Commit

Permalink
feat: only support visual editor alerts to navigate to discover (#368) (
Browse files Browse the repository at this point in the history
#370)

* feat: only support visual editor alerts to navigate to discover

Signed-off-by: tygao <[email protected]>

* doc: add changelog

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
(cherry picked from commit 50fef5c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 1e52b88 commit 2ba4853
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
53 changes: 53 additions & 0 deletions public/components/incontext_insight/generate_popover_body.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
getStartServices={getStartServices}
/>
);

await waitFor(() => {
expect(queryByText('Discover details')).not.toBeInTheDocument();
});
});
});
5 changes: 5 additions & 0 deletions public/components/incontext_insight/generate_popover_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 2ba4853

Please sign in to comment.