import { css } from '@emotion/css'; import React, { FC, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Button, useStyles2 } from '@grafana/ui'; import { AmRouteReceiver, FormAmRoute } from '../../types/amroutes'; import { getNotificationsPermissions } from '../../utils/access-control'; import { emptyRoute } from '../../utils/amroutes'; import { Authorize } from '../Authorize'; import { AmRoutesTable } from './AmRoutesTable'; import { MuteTimingsTable } from './MuteTimingsTable'; import { getGridStyles } from './gridStyles'; export interface AmRoutesExpandedReadProps { onChange: (routes: FormAmRoute) => void; receivers: AmRouteReceiver[]; routes: FormAmRoute; readOnly?: boolean; alertManagerSourceName: string; } export const AmRoutesExpandedRead: FC = ({ onChange, receivers, routes, readOnly = false, alertManagerSourceName, }) => { const styles = useStyles2(getStyles); const gridStyles = useStyles2(getGridStyles); const permissions = getNotificationsPermissions(alertManagerSourceName); const groupWait = routes.groupWaitValue ? `${routes.groupWaitValue}${routes.groupWaitValueType}` : '-'; const groupInterval = routes.groupIntervalValue ? `${routes.groupIntervalValue}${routes.groupIntervalValueType}` : '-'; const repeatInterval = routes.repeatIntervalValue ? `${routes.repeatIntervalValue}${routes.repeatIntervalValueType}` : '-'; const [subroutes, setSubroutes] = useState(routes.routes); const [isAddMode, setIsAddMode] = useState(false); return (
Group wait
{groupWait}
Group interval
{groupInterval}
Repeat interval
{repeatInterval}
Nested policies
{!!subroutes.length ? ( { setIsAddMode(false); setSubroutes((subroutes) => { const newSubroutes = [...subroutes]; newSubroutes.pop(); return newSubroutes; }); }} onChange={(newRoutes) => { onChange({ ...routes, routes: newRoutes, }); if (isAddMode) { setIsAddMode(false); } }} receivers={receivers} routes={subroutes} alertManagerSourceName={alertManagerSourceName} /> ) : (

No nested policies configured.

)} {!isAddMode && !readOnly && ( )}
Mute timings
); }; const getStyles = (theme: GrafanaTheme2) => { return { addNestedRoutingBtn: css` margin-top: ${theme.spacing(2)}; `, }; };