Skip to content

Commit

Permalink
[grid-ui] Implementing more compact layout of stereotypes and visuali…
Browse files Browse the repository at this point in the history
…zing node DOWN status with light-gray background
  • Loading branch information
barancev committed Feb 19, 2021
1 parent b2a5a41 commit 8232110
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 90 deletions.
98 changes: 13 additions & 85 deletions javascript/grid-ui/src/components/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
DialogContent,
DialogTitle,
Grid,
GridSize,
IconButton,
Theme,
Typography,
Expand All @@ -35,9 +34,9 @@ import React from 'react';
import InfoIcon from '@material-ui/icons/Info';
import NodeInfo from "../../models/node-info";
import LinearProgress, {LinearProgressProps} from '@material-ui/core/LinearProgress';
import browserLogo from "../../util/browser-logo";
import osLogo from "../../util/os-logo";
import StereotypeInfo from "../../models/stereotype-info";
import Stereotypes from "./Stereotypes";
import clsx from 'clsx';

const useStyles = (theme: Theme) => createStyles(
{
Expand All @@ -54,18 +53,14 @@ const useStyles = (theme: Theme) => createStyles(
height: 32,
marginRight: 5,
},
browserLogo: {
width: 24,
height: 24,
marginBottom: 5,
marginRight: 5,
},
buttonMargin: {
padding: 1,
},
slotInfo: {
marginBottom: 10,
marginRight: 0,
up: {

},
down: {
backgroundColor: theme.palette.grey.A100,
}
});

Expand Down Expand Up @@ -113,38 +108,12 @@ class Node extends React.Component<NodeProps, NodeState> {
const currentLoad = sessionCount === 0
? 0 :
Math.min(((sessionCount / nodeInfo.maxSession) * 100), 100).toFixed(2);
// Assuming we will put 3 stereotypes per column.
const stereotypeColumns = Math.ceil(nodeInfo.slotStereotypes.length / 3);
// Then we need to know how many columns we will display.
const columnWidth: GridSize = 12 / stereotypeColumns as any;

function CreateStereotypeGridItem(slotStereotype: StereotypeInfo, index: any) {
return (
<Grid container item alignItems='center' spacing={1} key={index}>
<Grid item>
<img
src={browserLogo(slotStereotype.browserName)}
className={classes.browserLogo}
alt="Browser Logo"
/>
</Grid>
<Grid item>
<Typography className={classes.slotInfo}>
{slotStereotype.slotCount}
</Typography>
</Grid>
<Grid item>
<Typography className={classes.slotInfo}>
{slotStereotype.browserVersion}
</Typography>
</Grid>
</Grid>
);
}
const nodeStatusClass = node.status === 'UP' ? classes.up : classes.down;

return (
<Card
className={classes.root}
className={clsx(classes.root, nodeStatusClass)}
>
<CardContent className={classes.paddingContent}>
<Grid
Expand Down Expand Up @@ -222,39 +191,9 @@ class Node extends React.Component<NodeProps, NodeState> {
</Typography>
</Grid>
<Grid item xs={12}>
<Typography
color="textPrimary"
gutterBottom
variant="h6"
>
<Box fontWeight="fontWeightBold" mr={1} display='inline'>
Stereotypes
</Box>
</Typography>
<Grid
container
justify="space-between"
spacing={2}
>
{
Array.from(Array(stereotypeColumns).keys()).map((index) => {
return (
<Grid item xs={columnWidth} key={index}>
{
nodeInfo.slotStereotypes
.sort((a, b) => a.browserName.localeCompare(b.browserName)
|| a.browserVersion.localeCompare(b.browserVersion))
.slice(index * 3, Math.min((index * 3) + 3, nodeInfo.slotStereotypes.length))
.map((slotStereotype: any, idx) => {
return (
CreateStereotypeGridItem(slotStereotype, idx)
)
})}
</Grid>
)
})
}
</Grid>
<Stereotypes stereotypes={nodeInfo.slotStereotypes}/>
</Grid>
<Grid item xs={12}>
<Grid
container
justify="space-between"
Expand All @@ -271,7 +210,7 @@ class Node extends React.Component<NodeProps, NodeState> {
</Typography>
</Box>
</Grid>
<Grid item xs={4}>
<Grid item xs={9}>
<Box pt={1} mt={2}>
<Typography
variant="body2"
Expand All @@ -281,17 +220,6 @@ class Node extends React.Component<NodeProps, NodeState> {
</Typography>
</Box>
</Grid>
<Grid item xs={5}>
<Box pt={1} mt={2}>
<Typography
color="textPrimary"
gutterBottom
variant="caption"
>
{nodeInfo.version}
</Typography>
</Box>
</Grid>
<Grid item xs={12}
>
<LinearProgressWithLabel value={Number(currentLoad)}/>
Expand Down
111 changes: 111 additions & 0 deletions javascript/grid-ui/src/components/Node/Stereotypes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import {
Box,
createStyles,
Grid,
GridSize,
Theme,
Typography,
withStyles
} from '@material-ui/core';
import React from 'react';
import browserLogo from "../../util/browser-logo";
import StereotypeInfo from "../../models/stereotype-info";

const useStyles = (theme: Theme) => createStyles(
{
browserLogo: {
width: 24,
height: 24,
marginBottom: 5,
},
slotInfo: {
marginBottom: 10,
marginRight: 10,
},
});

type StereotypesProps = {
stereotypes: StereotypeInfo[];
classes: any;
};

class Stereotypes extends React.Component<StereotypesProps, {}> {

render () {
const {stereotypes, classes} = this.props;
// Assuming we will put 3 stereotypes per column.
const stereotypeColumns = Math.ceil(stereotypes.length / 3);
// Then we need to know how many columns we will display.
const columnWidth: GridSize = 12 / stereotypeColumns as any;

function CreateStereotypeGridItem(slotStereotype: StereotypeInfo, index: any) {
return (
<Grid item key={index}>
<Grid container alignItems='center' spacing={1}>
<Grid item>
<img
src={browserLogo(slotStereotype.browserName)}
className={classes.browserLogo}
alt="Browser Logo"
/>
</Grid>
<Grid item>
<Typography className={classes.slotInfo}>
{slotStereotype.slotCount}
</Typography>
</Grid>
<Grid item>
<Typography className={classes.slotInfo}>
{slotStereotype.browserVersion}
</Typography>
</Grid>
</Grid>
</Grid>
);
}

return (
<Grid item xs={12}>
<Typography
color="textPrimary"
gutterBottom
variant="h6"
>
<Box fontWeight="fontWeightBold" mr={1} display='inline'>
Stereotypes
</Box>
</Typography>
<Grid container direction="row">
{
stereotypes
.sort((a, b) => a.browserName.localeCompare(b.browserName)
|| a.browserVersion.localeCompare(b.browserVersion))
.map((slotStereotype: any, idx) => {
return (
CreateStereotypeGridItem(slotStereotype, idx)
)
})}
</Grid>
</Grid>
);
}
}

export default withStyles(useStyles)(Stereotypes)
5 changes: 1 addition & 4 deletions javascript/grid-ui/src/screens/Overview/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ const useStyles = (theme: Theme) => createStyles(
display: 'flex',
overflow: 'auto',
flexDirection: 'column',
},
fixedHeight: {
height: 310,
},
}
});

const NODES_QUERY = loader("../../graphql/nodes.gql");
Expand Down
1 change: 0 additions & 1 deletion javascript/grid-ui/src/tests/components/Node.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const node: NodeInfo = {
it('renders basic node information', () => {
render(<Node node={node}/>);
expect(screen.getByText(node.uri)).toBeInTheDocument();
expect(screen.getByText(node.version)).toBeInTheDocument();
expect(screen.getByText(`Sessions: ${node.sessionCount}`)).toBeInTheDocument();
expect(screen.getByText(`Max. Concurrency: ${node.maxSession}`)).toBeInTheDocument();
});
Expand Down

0 comments on commit 8232110

Please sign in to comment.