feat: Loading and error states for metrics dropdown (#161)

Loading state:

![Screenshot 2023-12-21 at 10 25 59 PM](https://github.com/hyperdxio/hyperdx/assets/149748269/7005a6e0-2c59-4a5d-a8d5-325dd2bb16f2)


Error state:

![Screenshot 2023-12-21 at 10 30 45 PM](https://github.com/hyperdxio/hyperdx/assets/149748269/434119cd-a8ce-4a9d-a638-4b8c0c744271)
This commit is contained in:
Shorpo 2023-12-22 10:59:12 -07:00 committed by GitHub
parent 060089d3ee
commit f65dd9bc1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---
Loading and error states for metrics dropdown

View file

@ -176,7 +176,7 @@ export function MetricSelect({
setMetricName: (value: string | undefined) => void;
}) {
// TODO: Dedup with metric rate checkbox
const { data: metricTagsData } = api.useMetricsTags();
const { data: metricTagsData, isLoading, isError } = api.useMetricsTags();
const aggFnWithMaybeRate = (aggFn: AggFn, isRate: boolean) => {
if (isRate) {
@ -198,6 +198,8 @@ export function MetricSelect({
<>
<div className="ms-3 flex-grow-1">
<MetricNameSelect
isLoading={isLoading}
isError={isError}
value={metricName}
setValue={name => {
const metricType = metricTagsData?.data?.find(
@ -259,9 +261,13 @@ export function MetricRateSelect({
export function MetricNameSelect({
value,
setValue,
isLoading,
isError,
}: {
value: string | undefined | null;
setValue: (value: string | undefined) => void;
isLoading?: boolean;
isError?: boolean;
}) {
const { data: metricTagsData } = api.useMetricsTags();
@ -276,6 +282,15 @@ export function MetricNameSelect({
return (
<AsyncSelect
isLoading={isLoading}
isDisabled={isError}
placeholder={
isLoading
? 'Loading...'
: isError
? 'Unable to load metrics'
: 'Select a metric...'
}
loadOptions={input => {
return Promise.resolve(
options.filter(v =>