Skip to content

Commit

Permalink
[Exploratory View]added loading state for metric selector (#115748) (#…
Browse files Browse the repository at this point in the history
…116589)

Co-authored-by: Dominique Clarke <[email protected]>

Co-authored-by: Shahzad <[email protected]>
Co-authored-by: Dominique Clarke <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2021
1 parent d3a2b4d commit f090ccb
Showing 1 changed file with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
EuiListGroup,
EuiListGroupItem,
EuiBadge,
EuiText,
EuiLoadingSpinner,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -33,7 +35,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
const [showOptions, setShowOptions] = useState(false);
const metricOptions = seriesConfig?.metricOptions;

const { indexPatterns } = useAppIndexPatternContext();
const { indexPatterns, loading } = useAppIndexPatternContext();

const onChange = (value?: string) => {
setSeries(seriesId, {
Expand Down Expand Up @@ -78,6 +80,10 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
};
});

if (!indexPattern && !loading) {
return <EuiText>{NO_DATA_AVAILABLE}</EuiText>;
}

return (
<>
{!series.selectedMetricField && (
Expand All @@ -88,6 +94,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
onClick={() => setShowOptions((prevState) => !prevState)}
fill
size="s"
isLoading={!indexPattern && loading}
>
{SELECT_REPORT_METRIC_LABEL}
</EuiButton>
Expand All @@ -107,19 +114,23 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
</EuiListGroup>
</EuiPopover>
)}
{series.selectedMetricField && (
<EuiBadge
iconType="cross"
iconSide="right"
iconOnClick={() => onChange(undefined)}
iconOnClickAriaLabel={REMOVE_REPORT_METRIC_LABEL}
>
{
seriesConfig?.metricOptions?.find((option) => option.id === series.selectedMetricField)
?.label
}
</EuiBadge>
)}
{series.selectedMetricField &&
(indexPattern && !loading ? (
<EuiBadge
iconType="cross"
iconSide="right"
iconOnClick={() => onChange(undefined)}
iconOnClickAriaLabel={REMOVE_REPORT_METRIC_LABEL}
>
{
seriesConfig?.metricOptions?.find(
(option) => option.id === series.selectedMetricField
)?.label
}
</EuiBadge>
) : (
<EuiLoadingSpinner />
))}
</>
);
}
Expand All @@ -137,3 +148,7 @@ const REMOVE_REPORT_METRIC_LABEL = i18n.translate(
defaultMessage: 'Remove report metric',
}
);

const NO_DATA_AVAILABLE = i18n.translate('xpack.observability.expView.seriesEditor.noData', {
defaultMessage: 'No data available',
});

0 comments on commit f090ccb

Please sign in to comment.