-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Search] Analytics - add reusable Layout & Header + basic subrout…
…e view components (#88552) * Add AnalyticsUnavailable component * Add AnalyticsHeader component + update AnalyticsLogic to store allTags prop passed by API + convertTagsToSelectOptions util helper * Add AnalyticsLayout that all subroutes will utilize - Handles shared concerns of: - Loading state & unavailable state - Flash messages & log retention callout - Reusing the header component - Fetching data - Reloading data based on filter updates * Add very basic subroute views that utilize AnalyticsLayout * Update QueryDetail pages to set breadcrumbs * Fix QueryDetail breadcrumbs to not 404 on the 'Query' crumb Redirect to the /analytics overview since we don't actually have a /query_details overview * [PR feedback] Enforce date range defaults on the client side - instead of using coincidence to sync our client side default range & server default range - tags remain ''/undefined as default * [PR feedback] Add explicit query vs analytics view prop - to help devs more quickly distinguish at a glance whether a view will fetch analytics data or query data Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
6d1c010
commit 3168b7d
Showing
30 changed files
with
913 additions
and
17 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...rise_search/public/applications/app_search/components/analytics/analytics_layout.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import '../../../__mocks__/shallow_useeffect.mock'; | ||
import '../../../__mocks__/react_router_history.mock'; | ||
import { mockKibanaValues, setMockValues, setMockActions, rerender } from '../../../__mocks__'; | ||
|
||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { Loading } from '../../../shared/loading'; | ||
import { FlashMessages } from '../../../shared/flash_messages'; | ||
import { LogRetentionCallout } from '../log_retention'; | ||
import { AnalyticsHeader, AnalyticsUnavailable } from './components'; | ||
|
||
import { AnalyticsLayout } from './analytics_layout'; | ||
|
||
describe('AnalyticsLayout', () => { | ||
const { history } = mockKibanaValues; | ||
|
||
const values = { | ||
history, | ||
dataLoading: false, | ||
analyticsUnavailable: false, | ||
}; | ||
const actions = { | ||
loadAnalyticsData: jest.fn(), | ||
loadQueryData: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
history.location.search = ''; | ||
setMockValues(values); | ||
setMockActions(actions); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow( | ||
<AnalyticsLayout title="Hello"> | ||
<div data-test-subj="world">World!</div> | ||
</AnalyticsLayout> | ||
); | ||
|
||
expect(wrapper.find(FlashMessages)).toHaveLength(1); | ||
expect(wrapper.find(LogRetentionCallout)).toHaveLength(1); | ||
|
||
expect(wrapper.find(AnalyticsHeader).prop('title')).toEqual('Hello'); | ||
expect(wrapper.find('[data-test-subj="world"]').text()).toEqual('World!'); | ||
}); | ||
|
||
it('renders a loading component if data is not done loading', () => { | ||
setMockValues({ ...values, dataLoading: true }); | ||
const wrapper = shallow(<AnalyticsLayout title="" />); | ||
|
||
expect(wrapper.type()).toEqual(Loading); | ||
}); | ||
|
||
it('renders an unavailable component if analytics are unavailable', () => { | ||
setMockValues({ ...values, analyticsUnavailable: true }); | ||
const wrapper = shallow(<AnalyticsLayout title="" />); | ||
|
||
expect(wrapper.type()).toEqual(AnalyticsUnavailable); | ||
}); | ||
|
||
describe('data loading', () => { | ||
it('loads query data for query details pages', () => { | ||
(useParams as jest.Mock).mockReturnValueOnce({ query: 'test' }); | ||
shallow(<AnalyticsLayout isQueryView title="" />); | ||
|
||
expect(actions.loadQueryData).toHaveBeenCalledWith('test'); | ||
}); | ||
|
||
it('loads analytics data for non query details pages', () => { | ||
shallow(<AnalyticsLayout isAnalyticsView title="" />); | ||
|
||
expect(actions.loadAnalyticsData).toHaveBeenCalled(); | ||
}); | ||
|
||
it('reloads data when search params are updated (by our AnalyticsHeader filters)', () => { | ||
const wrapper = shallow(<AnalyticsLayout isAnalyticsView title="" />); | ||
expect(actions.loadAnalyticsData).toHaveBeenCalledTimes(1); | ||
|
||
history.location.search = '?tag=some-filter'; | ||
rerender(wrapper); | ||
|
||
expect(actions.loadAnalyticsData).toHaveBeenCalledTimes(2); | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...nterprise_search/public/applications/app_search/components/analytics/analytics_layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useValues, useActions } from 'kea'; | ||
|
||
import { KibanaLogic } from '../../../shared/kibana'; | ||
import { FlashMessages } from '../../../shared/flash_messages'; | ||
import { Loading } from '../../../shared/loading'; | ||
|
||
import { LogRetentionCallout, LogRetentionOptions } from '../log_retention'; | ||
|
||
import { AnalyticsLogic } from './'; | ||
import { AnalyticsHeader, AnalyticsUnavailable } from './components'; | ||
|
||
interface Props { | ||
title: string; | ||
isQueryView?: boolean; | ||
isAnalyticsView?: boolean; | ||
} | ||
export const AnalyticsLayout: React.FC<Props> = ({ | ||
title, | ||
isQueryView, | ||
isAnalyticsView, | ||
children, | ||
}) => { | ||
const { history } = useValues(KibanaLogic); | ||
const { query } = useParams() as { query: string }; | ||
const { dataLoading, analyticsUnavailable } = useValues(AnalyticsLogic); | ||
const { loadAnalyticsData, loadQueryData } = useActions(AnalyticsLogic); | ||
|
||
useEffect(() => { | ||
if (isQueryView) loadQueryData(query); | ||
if (isAnalyticsView) loadAnalyticsData(); | ||
}, [history.location.search]); | ||
|
||
if (dataLoading) return <Loading />; | ||
if (analyticsUnavailable) return <AnalyticsUnavailable />; | ||
|
||
return ( | ||
<> | ||
<AnalyticsHeader title={title} /> | ||
<FlashMessages /> | ||
<LogRetentionCallout type={LogRetentionOptions.Analytics} /> | ||
{children} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.