Skip to content

Commit

Permalink
Remove uptime link
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Aug 23, 2023
1 parent 441db57 commit 8c1e5c7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const DecorateWithAssetDetailsStateContext: DecoratorFn = (story) => {
dateRange: {
from: '2023-04-09T11:07:49Z',
to: '2023-04-09T11:23:49Z',
mode: 'absolute',
},
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import { useEuiTheme, EuiIcon, type EuiPageHeaderProps } from '@elastic/eui';
import { css } from '@emotion/react';
import { useLinkProps } from '@kbn/observability-shared-plugin/public';
import React, { useCallback, useMemo } from 'react';
import { uptimeOverviewLocatorID } from '@kbn/observability-plugin/public';
import { capitalize } from 'lodash';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { APM_HOST_FILTER_FIELD } from '../constants';
import { LinkToAlertsRule, LinkToApmServices, LinkToNodeDetails, LinkToUptime } from '../links';
import { LinkToAlertsRule, LinkToApmServices, LinkToNodeDetails } from '../links';
import { FlyoutTabIds, type LinkOptions, type Tab, type TabIds } from '../types';
import { useAssetDetailsStateContext } from './use_asset_details_state';
import { useDateRangeProviderContext } from './use_date_range';
import { useTabSwitcherContext } from './use_tab_switcher';
import { useMetadataStateProviderContext } from './use_metadata_state';

type TabItem = NonNullable<Pick<EuiPageHeaderProps, 'tabs'>['tabs']>[number];

Expand All @@ -32,7 +29,6 @@ export const usePageHeader = (tabs: Tab[], links?: LinkOptions[]) => {
const useRightSideItems = (links?: LinkOptions[]) => {
const { getDateRangeInTimestamp } = useDateRangeProviderContext();
const { asset, assetType, overrides } = useAssetDetailsStateContext();
const { metadata } = useMetadataStateProviderContext();

const topCornerLinkComponents: Record<LinkOptions, JSX.Element> = useMemo(
() => ({
Expand All @@ -45,25 +41,8 @@ const useRightSideItems = (links?: LinkOptions[]) => {
),
alertRule: <LinkToAlertsRule onClick={overrides?.alertRule?.onCreateRuleClick} />,
apmServices: <LinkToApmServices assetName={asset.name} apmField={APM_HOST_FILTER_FIELD} />,
uptime: (
<LinkToUptime
assetName={asset.name}
assetType={assetType}
ip={
(Array.isArray(metadata?.info?.host?.ip)
? metadata?.info?.host?.ip ?? []
: [metadata?.info?.host?.ip])[0]
}
/>
),
}),
[
asset,
assetType,
getDateRangeInTimestamp,
metadata?.info?.host?.ip,
overrides?.alertRule?.onCreateRuleClick,
]
[asset, assetType, getDateRangeInTimestamp, overrides?.alertRule?.onCreateRuleClick]
);

const rightSideItems = useMemo(
Expand All @@ -76,9 +55,7 @@ const useRightSideItems = (links?: LinkOptions[]) => {

const useTabs = (tabs: Tab[]) => {
const { showTab, activeTabId } = useTabSwitcherContext();
const { asset, assetType } = useAssetDetailsStateContext();
const { metadata } = useMetadataStateProviderContext();
const { share } = useKibanaContextForPlugin().services;
const { asset } = useAssetDetailsStateContext();
const { euiTheme } = useEuiTheme();

const onTabClick = useCallback(
Expand Down Expand Up @@ -115,48 +92,11 @@ const useTabs = (tabs: Tab[]) => {
[apmTracesMenuItemLinkProps, euiTheme.size.xs]
);

const getTabToUptime = useCallback(
(name: string) => ({
'data-test-subj': 'infraAssetDetailsUptimeLinkTab',
onClick: () =>
share.url.locators.get(uptimeOverviewLocatorID)!.navigate({
[assetType]: asset.id,
ip: (Array.isArray(metadata?.info?.host?.ip)
? metadata?.info?.host?.ip ?? []
: [metadata?.info?.host?.ip])[0],
}),
label: (
<>
<EuiIcon
type="popout"
css={css`
margin-right: ${euiTheme.size.xs};
`}
/>
{name}
</>
),
}),
[asset.id, assetType, euiTheme.size.xs, metadata?.info?.host?.ip, share.url.locators]
);

const tabbedLinks = useMemo(
() => ({
[FlyoutTabIds.LINK_TO_APM]: getTabToApmTraces,
[FlyoutTabIds.LINK_TO_UPTIME]: getTabToUptime,
}),
[getTabToApmTraces, getTabToUptime]
);

const tabEntries: TabItem[] = useMemo(
() =>
tabs.map(({ name, ...tab }) => {
if (Object.keys(tabbedLinks).includes(tab.id)) {
return tabbedLinks[tab.id as keyof typeof tabbedLinks](name);
}

if (tab.id === FlyoutTabIds.LINK_TO_APM) {
return getTabToUptime(name);
return getTabToApmTraces(name);
}

return {
Expand All @@ -167,7 +107,7 @@ const useTabs = (tabs: Tab[]) => {
label: name,
};
}),
[activeTabId, getTabToUptime, onTabClick, tabbedLinks, tabs]
[activeTabId, getTabToApmTraces, onTabClick, tabs]
);

return { tabEntries };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
*/

export { LinkToApmServices } from './link_to_apm_services';
export { LinkToUptime } from './link_to_uptime';
export { LinkToAlertsRule } from './link_to_alerts';
export { LinkToNodeDetails } from './link_to_node_details';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface Tab {
name: string;
}

export type LinkOptions = 'alertRule' | 'nodeDetails' | 'apmServices' | 'uptime';
export type LinkOptions = 'alertRule' | 'nodeDetails' | 'apmServices';

export interface AssetDetailsProps {
asset: Asset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const AssetDetailPage = () => {
onTabsStateChange={handleTabStateChange}
activeTabId={FlyoutTabIds.OVERVIEW}
tabs={orderedFlyoutTabs}
links={['uptime', 'apmServices']}
links={['apmServices']}
renderMode={{
mode: 'page',
}}
Expand Down

0 comments on commit 8c1e5c7

Please sign in to comment.