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

upcoming: [DI-21270] - Added the Alerts tab #11064

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ interface DesignUpdatesBannerFlag extends BaseFeatureFlag {
link: string;
}

interface AclpAlerting {
alertDefinitions: boolean;
notificationChannels: boolean;
recentActivity: boolean;
}
export interface Flags {
aclp: AclpFlag;
aclpAlerting: AclpAlerting;
aclpReadEndpoint: string;
aclpResourceTypeMap: CloudPulseResourceTypeMapFlag[];
apiMaintenance: APIMaintenance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';
import { Route, Switch } from 'react-router-dom';

import { Paper } from 'src/components/Paper';
import { Typography } from 'src/components/Typography';

export const AlertDefinitionLanding = () => {
return (
<Switch>
<Route
component={AlertDefinition}
exact
path="/monitor/cloudpulse/alerts/definitions"
/>
</Switch>
);
};

const AlertDefinition = () => {
return (
<Paper>
jaalah-akamai marked this conversation as resolved.
Show resolved Hide resolved
<Typography variant="body1">Alert Definition</Typography>
</Paper>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import * as React from 'react';
import {
Redirect,
Route,
Switch,
useLocation,
useRouteMatch,
} from 'react-router-dom';

import { Box } from 'src/components/Box';
import { Paper } from 'src/components/Paper';
import { TabLinkList } from 'src/components/Tabs/TabLinkList';
import { Tabs } from 'src/components/Tabs/Tabs';
import { useFlags } from 'src/hooks/useFlags';

import { AlertDefinitionLanding } from './AlertsDefinitionLanding';

import type { EnabledAlertTab } from '../../CloudPulseTabs';

export const AlertsLanding = React.memo(() => {
const flags = useFlags();
const { url } = useRouteMatch();
const { pathname } = useLocation();
const alertTabs = React.useMemo<EnabledAlertTab[]>(
() => [
{
isEnabled: Boolean(flags.aclpAlerting?.alertDefinitions),
tab: { routeName: `${url}/definitions`, title: 'Definitions' },
},
],
[url, flags.aclpAlerting]
);
const accessibleTabs = React.useMemo(
() =>
alertTabs
.filter((alertTab) => alertTab.isEnabled)
.map((alertTab) => alertTab.tab),
[alertTabs]
);
const activeTabIndex = React.useMemo(
() =>
Math.max(
accessibleTabs.findIndex((tab) => pathname.startsWith(tab.routeName)),
0
),
[accessibleTabs, pathname]
);
return (
<Paper sx={{ padding: 2 }}>
<Tabs index={activeTabIndex} style={{ width: '100%' }}>
<Box
sx={{
aligneItems: 'center',
display: 'flex',
justifyContent: 'space-between',
p: 1,
width: '100%',
}}
>
jaalah-akamai marked this conversation as resolved.
Show resolved Hide resolved
<TabLinkList tabs={accessibleTabs} />
</Box>
<Switch>
<Route
component={AlertDefinitionLanding}
path={'/monitor/cloudpulse/alerts/definitions'}
/>
<Redirect
from="/monitor/cloudpulse/alerts"
to="/monitor/cloudpulse/alerts/definitions"
/>
</Switch>
</Tabs>
</Paper>
);
});
115 changes: 72 additions & 43 deletions packages/manager/src/features/CloudPulse/CloudPulseTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
import { styled } from '@mui/material/styles';
import * as React from 'react';
import { matchPath } from 'react-router-dom';
import {
Redirect,
Route,
Switch,
useLocation,
useRouteMatch,
} from 'react-router-dom';

import { SuspenseLoader } from 'src/components/SuspenseLoader';
import { SafeTabPanel } from 'src/components/Tabs/SafeTabPanel';
import { TabLinkList } from 'src/components/Tabs/TabLinkList';
import { TabPanels } from 'src/components/Tabs/TabPanels';
import { Tabs } from 'src/components/Tabs/Tabs';
import { useFlags } from 'src/hooks/useFlags';

import { AlertsLanding } from './Alerts/AlertsLanding/AlertsLanding';
import { CloudPulseDashboardLanding } from './Dashboard/CloudPulseDashboardLanding';

import type { RouteComponentProps } from 'react-router-dom';
type Props = RouteComponentProps<{}>;
import type { Tab } from 'src/components/Tabs/TabLinkList';

export const CloudPulseTabs = React.memo((props: Props) => {
const tabs = [
{
routeName: `${props.match.url}/dashboards`,
title: 'Dashboards',
},
];

const matches = (p: string) => {
return Boolean(matchPath(p, { path: props.location.pathname }));
};

const navToURL = (index: number) => {
props.history.push(tabs[index].routeName);
};

return (
<StyledTabs
index={Math.max(
tabs.findIndex((tab) => matches(tab.routeName)),
export type EnabledAlertTab = {
isEnabled: boolean;
tab: Tab;
};
export const CloudPulseTabs = () => {
const flags = useFlags();
const { url } = useRouteMatch();
const { pathname } = useLocation();
const alertTabs = React.useMemo<EnabledAlertTab[]>(
() => [
{
isEnabled: true,
tab: {
routeName: `${url}/dashboards`,
title: 'Dashboards',
},
},
{
isEnabled: Boolean(
flags.aclpAlerting?.alertDefinitions ||
flags.aclpAlerting?.recentActivity ||
flags.aclpAlerting?.notificationChannels
),
tab: {
routeName: `${url}/alerts`,
title: 'Alerts',
},
},
],
[url, flags.aclpAlerting]
);
const accessibleTabs = React.useMemo(
() =>
alertTabs
.filter((alertTab) => alertTab.isEnabled)
.map((alertTab) => alertTab.tab),
[alertTabs]
);
const activeTabIndex = React.useMemo(
() =>
Math.max(
accessibleTabs.findIndex((tab) => pathname.startsWith(tab.routeName)),
0
)}
onChange={navToURL}
>
<TabLinkList tabs={tabs} />
),
[accessibleTabs, pathname]
);
return (
<Tabs index={activeTabIndex} marginTop={0}>
<TabLinkList tabs={accessibleTabs} />

<React.Suspense fallback={<SuspenseLoader />}>
<TabPanels>
<SafeTabPanel index={0}>
<CloudPulseDashboardLanding />
</SafeTabPanel>
</TabPanels>
<Switch>
<Route
component={CloudPulseDashboardLanding}
path={`${url}/dashboards`}
/>
<Route component={AlertsLanding} path={`${url}/alerts`} />
<Redirect
exact
from="/monitor/cloudpulse"
to="/monitor/cloudpulse/dashboards"
/>
</Switch>
</React.Suspense>
</StyledTabs>
</Tabs>
);
});

const StyledTabs = styled(Tabs, {
label: 'StyledTabs',
})(() => ({
marginTop: 0,
}));
};