forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataUsage][Serverless] Data usage metrics page enhancements (elastic…
…#195556) ## Summary This PR is a follow-up of elastic/pull/193966 and adds: 1. Datastreams filter to data usage metrics page. 2. Metrics filter (hidden for now) that lists out metric types to request. 3. Refactors to make code easier to maintain. 4. Shows a callout if no data stream is selected. ### screen ![Screenshot 2024-10-09 at 17 36 32](https://github.com/user-attachments/assets/a0779c91-25ae-4a64-819e-bc8a626f1f96) ### clip ![latest-metrics-ux](https://github.com/user-attachments/assets/0f4b1a9b-d160-435b-917b-f59c3a5cc9f8) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [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 - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
f962cdc
commit a7332ad
Showing
24 changed files
with
1,083 additions
and
230 deletions.
There are no files selected for viewing
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
150 changes: 150 additions & 0 deletions
150
x-pack/plugins/data_usage/public/app/components/data_usage_metrics.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,150 @@ | ||
/* | ||
* 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 React, { useCallback, useEffect, memo, useState } from 'react'; | ||
import { css } from '@emotion/react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiLoadingElastic, EuiCallOut } from '@elastic/eui'; | ||
import { Charts } from './charts'; | ||
import { useBreadcrumbs } from '../../utils/use_breadcrumbs'; | ||
import { useKibanaContextForPlugin } from '../../utils/use_kibana'; | ||
import { PLUGIN_NAME } from '../../../common'; | ||
import { useGetDataUsageMetrics } from '../../hooks/use_get_usage_metrics'; | ||
import { useDataUsageMetricsUrlParams } from '../hooks/use_charts_url_params'; | ||
import { DEFAULT_DATE_RANGE_OPTIONS, useDateRangePicker } from '../hooks/use_date_picker'; | ||
import { DEFAULT_METRIC_TYPES, UsageMetricsRequestBody } from '../../../common/rest_types'; | ||
import { ChartFilters } from './filters/charts_filters'; | ||
import { UX_LABELS } from '../translations'; | ||
|
||
const EuiItemCss = css` | ||
width: 100%; | ||
`; | ||
|
||
const FlexItemWithCss = memo(({ children }: { children: React.ReactNode }) => ( | ||
<EuiFlexItem css={EuiItemCss}>{children}</EuiFlexItem> | ||
)); | ||
|
||
export const DataUsageMetrics = () => { | ||
const { | ||
services: { chrome, appParams }, | ||
} = useKibanaContextForPlugin(); | ||
|
||
const { | ||
metricTypes: metricTypesFromUrl, | ||
dataStreams: dataStreamsFromUrl, | ||
startDate: startDateFromUrl, | ||
endDate: endDateFromUrl, | ||
setUrlMetricTypesFilter, | ||
setUrlDateRangeFilter, | ||
} = useDataUsageMetricsUrlParams(); | ||
|
||
const [metricsFilters, setMetricsFilters] = useState<UsageMetricsRequestBody>({ | ||
metricTypes: [...DEFAULT_METRIC_TYPES], | ||
dataStreams: [], | ||
from: DEFAULT_DATE_RANGE_OPTIONS.startDate, | ||
to: DEFAULT_DATE_RANGE_OPTIONS.endDate, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!metricTypesFromUrl) { | ||
setUrlMetricTypesFilter(metricsFilters.metricTypes.join(',')); | ||
} | ||
if (!startDateFromUrl || !endDateFromUrl) { | ||
setUrlDateRangeFilter({ startDate: metricsFilters.from, endDate: metricsFilters.to }); | ||
} | ||
}, [ | ||
endDateFromUrl, | ||
metricTypesFromUrl, | ||
metricsFilters.from, | ||
metricsFilters.metricTypes, | ||
metricsFilters.to, | ||
setUrlDateRangeFilter, | ||
setUrlMetricTypesFilter, | ||
startDateFromUrl, | ||
]); | ||
|
||
useEffect(() => { | ||
setMetricsFilters((prevState) => ({ | ||
...prevState, | ||
metricTypes: metricTypesFromUrl?.length ? metricTypesFromUrl : prevState.metricTypes, | ||
dataStreams: dataStreamsFromUrl?.length ? dataStreamsFromUrl : prevState.dataStreams, | ||
})); | ||
}, [metricTypesFromUrl, dataStreamsFromUrl]); | ||
|
||
const { dateRangePickerState, onRefreshChange, onTimeChange } = useDateRangePicker(); | ||
|
||
const { | ||
error, | ||
data, | ||
isFetching, | ||
isFetched, | ||
refetch: refetchDataUsageMetrics, | ||
} = useGetDataUsageMetrics( | ||
{ | ||
...metricsFilters, | ||
from: dateRangePickerState.startDate, | ||
to: dateRangePickerState.endDate, | ||
}, | ||
{ | ||
retry: false, | ||
} | ||
); | ||
|
||
const onRefresh = useCallback(() => { | ||
refetchDataUsageMetrics(); | ||
}, [refetchDataUsageMetrics]); | ||
|
||
const onChangeDataStreamsFilter = useCallback( | ||
(selectedDataStreams: string[]) => { | ||
setMetricsFilters((prevState) => ({ ...prevState, dataStreams: selectedDataStreams })); | ||
}, | ||
[setMetricsFilters] | ||
); | ||
|
||
const onChangeMetricTypesFilter = useCallback( | ||
(selectedMetricTypes: string[]) => { | ||
setMetricsFilters((prevState) => ({ ...prevState, metricTypes: selectedMetricTypes })); | ||
}, | ||
[setMetricsFilters] | ||
); | ||
|
||
useBreadcrumbs([{ text: PLUGIN_NAME }], appParams, chrome); | ||
|
||
return ( | ||
<EuiFlexGroup alignItems="flexStart" direction="column"> | ||
<FlexItemWithCss> | ||
<ChartFilters | ||
dateRangePickerState={dateRangePickerState} | ||
isDataLoading={isFetching} | ||
onClick={refetchDataUsageMetrics} | ||
onRefresh={onRefresh} | ||
onRefreshChange={onRefreshChange} | ||
onTimeChange={onTimeChange} | ||
onChangeDataStreamsFilter={onChangeDataStreamsFilter} | ||
onChangeMetricTypesFilter={onChangeMetricTypesFilter} | ||
showMetricsTypesFilter={false} | ||
/> | ||
</FlexItemWithCss> | ||
{!isFetching && error?.message && ( | ||
<FlexItemWithCss> | ||
<EuiCallOut | ||
size="s" | ||
title={UX_LABELS.noDataStreamsSelected} | ||
iconType="iInCircle" | ||
color="warning" | ||
/> | ||
</FlexItemWithCss> | ||
)} | ||
<FlexItemWithCss> | ||
{isFetched && data?.metrics ? ( | ||
<Charts data={data} /> | ||
) : isFetching ? ( | ||
<EuiLoadingElastic /> | ||
) : null} | ||
</FlexItemWithCss> | ||
</EuiFlexGroup> | ||
); | ||
}; |
Oops, something went wrong.