[SecuritySolution] Hide data quality dashboard from assistant conversations (#170479)

## Summary


https://github.com/elastic/kibana/issues/166271

Traditional - with `Data quality dashboard` in assistant conversation
dropdown:
<img width="1505" alt="ess_ai_convo"
src="227aab97-b45c-451a-9c0e-7fd6dd534ff8">

Serverless - no `Data quality dashboard` in assistant conversation
dropdown:

<img width="1506" alt="serverless_ai_convo"
src="ee61c249-5cd0-40ca-b2cb-5885a32152ca">


### Checklist

Delete any items that are not applicable to this PR.


- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Angela Chuang 2023-11-03 15:53:44 +00:00 committed by GitHub
parent f7393c5480
commit 30c859206c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 3 deletions

View file

@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { renderHook } from '@testing-library/react-hooks';
import { useConversationStore } from '.';
import { useLinkAuthorized } from '../../common/links';
import { useKibana as mockUseKibana } from '../../common/lib/kibana/__mocks__';
import { DATA_QUALITY_DASHBOARD_CONVERSATION_ID } from '@kbn/ecs-data-quality-dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/translations';
import { useKibana } from '../../common/lib/kibana';
import { BASE_SECURITY_CONVERSATIONS } from '../content/conversations';
import { unset } from 'lodash/fp';
const BASE_CONVERSATIONS_WITHOUT_DATA_QUALITY = unset(
DATA_QUALITY_DASHBOARD_CONVERSATION_ID,
BASE_SECURITY_CONVERSATIONS
);
jest.mock('../../common/links', () => ({
useLinkAuthorized: jest.fn(),
}));
const mockedUseKibana = {
...mockUseKibana(),
services: {
...mockUseKibana().services,
storage: {
...mockUseKibana().services.storage,
get: jest.fn(),
set: jest.fn(),
},
},
};
jest.mock('../../common/lib/kibana', () => {
return {
useKibana: jest.fn(),
};
});
describe('useConversationStore', () => {
beforeEach(() => {
jest.clearAllMocks();
(useKibana as jest.Mock).mockReturnValue(mockedUseKibana);
});
it('should return conversations with "Data Quality dashboard" conversation', () => {
(useLinkAuthorized as jest.Mock).mockReturnValue(true);
const { result } = renderHook(() => useConversationStore());
expect(result.current.conversations).toEqual(
expect.objectContaining(BASE_SECURITY_CONVERSATIONS)
);
});
it('should return conversations Without "Data Quality dashboard" conversation', () => {
(useLinkAuthorized as jest.Mock).mockReturnValue(false);
const { result } = renderHook(() => useConversationStore());
expect(result.current.conversations).toEqual(
expect.objectContaining(BASE_CONVERSATIONS_WITHOUT_DATA_QUALITY)
);
});
});

View file

@ -7,9 +7,14 @@
import type { Conversation } from '@kbn/elastic-assistant';
import { unset } from 'lodash/fp';
import { DATA_QUALITY_DASHBOARD_CONVERSATION_ID } from '@kbn/ecs-data-quality-dashboard/impl/data_quality/data_quality_panel/tabs/summary_tab/callout_summary/translations';
import { useMemo } from 'react';
import { useLocalStorage } from '../../common/components/local_storage';
import { LOCAL_STORAGE_KEY } from '../helpers';
import { BASE_SECURITY_CONVERSATIONS } from '../content/conversations';
import { useLinkAuthorized } from '../../common/links';
import { SecurityPageName } from '../../../common';
export interface UseConversationStore {
conversations: Record<string, Conversation>;
@ -17,8 +22,16 @@ export interface UseConversationStore {
}
export const useConversationStore = (): UseConversationStore => {
const isDataQualityDashboardPageExists = useLinkAuthorized(SecurityPageName.dataQuality);
const baseConversations = useMemo(
() =>
isDataQualityDashboardPageExists
? BASE_SECURITY_CONVERSATIONS
: unset(DATA_QUALITY_DASHBOARD_CONVERSATION_ID, BASE_SECURITY_CONVERSATIONS),
[isDataQualityDashboardPageExists]
);
const [conversations, setConversations] = useLocalStorage<Record<string, Conversation>>({
defaultValue: BASE_SECURITY_CONVERSATIONS,
defaultValue: baseConversations,
key: LOCAL_STORAGE_KEY,
isInvalidDefault: (valueFromStorage) => {
return !valueFromStorage;

View file

@ -59,9 +59,9 @@ const EntityAnalyticsRoutes = () => (
const DataQualityRoutes = () => (
<PluginTemplateWrapper>
<TrackApplicationView viewId={SecurityPageName.dataQuality}>
<SecurityRoutePageWrapper pageName={SecurityPageName.dataQuality}>
<DataQuality />
</TrackApplicationView>
</SecurityRoutePageWrapper>
</PluginTemplateWrapper>
);