Skip to content

Commit

Permalink
Show service group icon when there are service groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Apr 28, 2022
1 parent eaf47ae commit f7b2066
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiFlexItem,
EuiButtonIcon,
EuiLoadingContent,
EuiLoadingSpinner,
} from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
Expand All @@ -19,7 +20,7 @@ import {
KibanaPageTemplateProps,
} from '@kbn/kibana-react-plugin/public';
import { enableServiceGroups } from '@kbn/observability-plugin/public';
import { useFetcher } from '../../../hooks/use_fetcher';
import { useFetcher, FETCH_STATUS } from '../../../hooks/use_fetcher';
import { ApmPluginStartDeps } from '../../../plugin';
import { useApmRouter } from '../../../hooks/use_apm_router';
import { useAnyOfApmParams } from '../../../hooks/use_apm_params';
Expand Down Expand Up @@ -60,8 +61,18 @@ export function ServiceGroupTemplate({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const { data: serviceGroupsData, status: serviceGroupsStatus } = useFetcher(
(callApmApi) => {
if (!serviceGroupId && isServiceGroupsEnabled) {
return callApmApi('GET /internal/apm/service-groups');
}
},
[]
);

const serviceGroupName = data?.serviceGroup.groupName;
const loadingServiceGroupName = !!serviceGroupId && !serviceGroupName;
const hasServiceGroups = !!serviceGroupsData?.serviceGroups.length;
const serviceGroupsLink = router.link('/service-groups', {
query: { ...query, serviceGroup: '' },
});
Expand All @@ -74,15 +85,22 @@ export function ServiceGroupTemplate({
justifyContent="flexStart"
responsive={false}
>
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType="layers"
color="text"
aria-label="Go to service groups"
iconSize="xl"
href={serviceGroupsLink}
/>
</EuiFlexItem>
{serviceGroupsStatus === FETCH_STATUS.LOADING && (
<EuiFlexItem grow={false}>
<EuiLoadingSpinner size="l" />
</EuiFlexItem>
)}
{(serviceGroupId || hasServiceGroups) && (
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType="layers"
color="text"
aria-label="Go to service groups"
iconSize="xl"
href={serviceGroupsLink}
/>
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
{loadingServiceGroupName ? (
<EuiLoadingContent lines={2} style={{ width: 180, height: 40 }} />
Expand Down

0 comments on commit f7b2066

Please sign in to comment.