Skip to content

Commit

Permalink
Add cluster notification (#1291)
Browse files Browse the repository at this point in the history
* add aml link and notification for cluster

* just enable cluster notification

* specify notification element

* indent error and change notification's component name

Co-authored-by: qizhang4 <qizhang4@microsoft.com>
  • Loading branch information
zhangqilike2015 and zhadean committed Aug 17, 2020
1 parent 14d7f30 commit 0faa3e5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 32 deletions.
7 changes: 7 additions & 0 deletions src/dashboard/server/api/validator/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
"title": "Whether it supports allowed IP",
"description": "Set to true if it could be listed in allowed ip page",
"type": "boolean"
},
"notifications": {
"title": "Notifications for the cluster",
"type": "array",
"items": {
"type": "string"
}
}
}
}
Expand Down
75 changes: 43 additions & 32 deletions src/dashboard/src/Layout/NotificationBox.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import * as React from 'react';
import {
Fragment,
FunctionComponent,
useContext,
useMemo,
} from 'react';

import { get } from 'lodash';

useMemo
} from 'react'
import useFetch from 'use-http-1'
import {
Box,
BoxProps,
Divider,
Paper,
Typography,
createStyles,
makeStyles,
} from '@material-ui/core';

import { Info } from '@material-ui/icons';

import ConfigContext from '../contexts/Config';
import TeamContext from '../contexts/Team';
makeStyles
} from '@material-ui/core'
import { Info } from '@material-ui/icons'
import ClustersContext from '../contexts/Clusters'

const usePaperStyle = makeStyles(theme => createStyles({
root: {
Expand All @@ -30,29 +26,44 @@ const usePaperStyle = makeStyles(theme => createStyles({
},
}));

const NotificationBox: FunctionComponent<BoxProps> = (props) => {
const { notifications } = useContext(ConfigContext);
const { currentTeamId } = useContext(TeamContext);

const notification = useMemo(() => {
const notification = get(notifications, [currentTeamId]);
if (notification === undefined) {
return get(notifications, ['.default']);
}
return notification
}, [notifications, currentTeamId]);

const paperStyle = usePaperStyle();

if (Boolean(notification) === false) return null;
const ClusterNotifications: FunctionComponent<{ cluster: any }> = ({ cluster }) => {
const { data } = useFetch(`/api/clusters/${cluster.id}`, [cluster.id])
const notifications = useMemo(() => {
if (data === undefined) return []
if (!Array.isArray(data.notifications)) return []
return data.notifications as string[]
}, [data])
const paperStyle = usePaperStyle()
return (
<>
{
notifications.map((notification, index) => (
<Fragment key={index}>
<Paper elevation={0} classes={paperStyle}>
<Info fontSize="small" color="primary"/>
<Typography
variant="body2"
component={Box}
flex={1}
paddingLeft={1}
dangerouslySetInnerHTML={{ __html: notification }}
/>
</Paper>
<Divider/>
</Fragment>
))
}
</>
)
}

const NotificationBox: FunctionComponent<BoxProps> = (props) => {
const { clusters } = useContext(ClustersContext)
return (
<Box {...props}>
<Paper elevation={0} classes={paperStyle}>
<Info fontSize="small" color="primary"/>
<Typography variant="body2" component={Box} flex={1} paddingLeft={1}>{notification}</Typography>
</Paper>
<Divider/>
{clusters.map(cluster => (
<ClusterNotifications key={cluster.id} cluster={cluster}/>
))}
</Box>
);
};
Expand Down

0 comments on commit 0faa3e5

Please sign in to comment.