Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] [Exploratory View]added loading state for metric selector (#115748) #116588

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
});