Skip to content

Commit

Permalink
[grid-ui] Extracting small reusable components
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Feb 20, 2021
1 parent 2a28c63 commit 17e395e
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 66 deletions.
2 changes: 1 addition & 1 deletion javascript/grid-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ReactModal from "react-modal";
import {GridConfig} from "./config";
import TopBar from "./components/TopBar/TopBar";
import Overview from "./screens/Overview/Overview";
import Footer from "./components/common/Footer";
import Footer from "./components/Footer/Footer";
import Container from "@material-ui/core/Container";
import Sessions from "./screens/Sessions/Sessions";
import Help from "./screens/Help/Help";
Expand Down
12 changes: 5 additions & 7 deletions javascript/grid-ui/src/components/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
import {
Box,
Card,
CardContent, createStyles,
CardContent,
createStyles,
Grid,
Theme,
Typography,
withStyles
} from '@material-ui/core';
import React from 'react';
import NodeInfo from "../../models/node-info";
import osLogo from "../../util/os-logo";
import NodeDetailsDialog from "./NodeDetailsDialog";
import NodeLoad from "./NodeLoad";
import Stereotypes from "./Stereotypes";
import clsx from 'clsx';
import OsLogo from "../common/OsLogo";
import {Size} from "../../models/size";

const useStyles = (theme: Theme) => createStyles(
{
Expand Down Expand Up @@ -93,11 +95,7 @@ class Node extends React.Component<NodeProps, {}> {
gutterBottom
variant="h6"
>
<img
src={osLogo(node.osInfo.name)}
className={classes.osLogo}
alt="OS Logo"
/>
<OsLogo osName={node.osInfo.name}/>
<NodeDetailsDialog node={node}/>
</Typography>
</Grid>
Expand Down
17 changes: 5 additions & 12 deletions javascript/grid-ui/src/components/Node/NodeDetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ import {
Dialog,
DialogActions,
DialogContent,
DialogTitle, IconButton,
DialogTitle,
IconButton,
Theme,
Typography,
withStyles
} from '@material-ui/core';
import React from 'react';
import NodeInfo from "../../models/node-info";
import osLogo from "../../util/os-logo";
import InfoIcon from "@material-ui/icons/Info";
import OsLogo from "../common/OsLogo";
import {Size} from "../../models/size";

const useStyles = (theme: Theme) => createStyles(
{
osLogo: {
width: 32,
height: 32,
marginRight: 5,
},
buttonMargin: {
padding: 1,
},
Expand Down Expand Up @@ -81,11 +78,7 @@ class NodeDetailsDialog extends React.Component<NodeDetailsDialogProps, {}> {
</IconButton>
<Dialog onClose={this.handleDialogClose} aria-labelledby="node-info-dialog" open={open}>
<DialogTitle id="node-info-dialog">
<img
src={osLogo(nodeInfo.osInfo.name)}
className={classes.osLogo}
alt="OS Logo"
/>
<OsLogo osName={nodeInfo.osInfo.name}/>
<Box fontWeight="fontWeightBold" mr={1} display='inline'>
URI:
</Box>
Expand Down
20 changes: 3 additions & 17 deletions javascript/grid-ui/src/components/Node/Stereotypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@ 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";
import BrowserLogo from "../common/BrowserLogo";

const useStyles = (theme: Theme) => createStyles(
{
browserLogo: {
width: 24,
height: 24,
marginBottom: 5,
},
slotInfo: {
marginBottom: 10,
marginBottom: 5,
marginRight: 10,
},
});
Expand All @@ -50,21 +44,13 @@ 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"
/>
<BrowserLogo browserName={slotStereotype.browserName}/>
</Grid>
<Grid item>
<Typography className={classes.slotInfo}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import Paper from '@material-ui/core/Paper';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import {
Button, createStyles,
Button,
createStyles,
Dialog,
DialogActions,
DialogContent,
Expand All @@ -39,11 +40,12 @@ import {
withStyles
} from "@material-ui/core";
import InfoIcon from "@material-ui/icons/Info";
import browserLogo from "../../util/browser-logo";
import osLogo from "../../util/os-logo";
import browserVersion from "../../util/browser-version";
import EnhancedTableToolbar from "../EnhancedTableToolbar";
import prettyMilliseconds from "pretty-ms";
import BrowserLogo from "../common/BrowserLogo";
import OsLogo from "../common/OsLogo";
import {Size} from "../../models/size";

interface SessionData {
id: string,
Expand Down Expand Up @@ -198,12 +200,6 @@ const useStyles = (theme: Theme) => createStyles(
top: 20,
width: 1,
},
logo: {
width: 24,
height: 24,
marginBottom: 5,
marginRight: 5,
},
buttonMargin: {
padding: 1,
},
Expand Down Expand Up @@ -367,31 +363,15 @@ class RunningSessions extends React.Component<RunningSessionsProps, RunningSessi
{row.id}
</TableCell>
<TableCell align="right">
<img
src={osLogo(row.platformName as string)}
className={classes.logo}
alt="OS Logo"
/>
<img
src={browserLogo(row.browserName as string)}
className={classes.logo}
alt="Browser Logo"
/>
<OsLogo osName={row.platformName as string} size={Size.S}/>
<BrowserLogo browserName={row.browserName as string}/>
{browserVersion(row.browserVersion as string)}
{this.displaySessionInfo(row.id as string)}
<Dialog onClose={this.handleDialogClose} aria-labelledby="session-info-dialog"
open={rowOpen === row.id}>
<DialogTitle id="session-info-dialog">
<img
src={osLogo(row.platformName as string)}
className={classes.logo}
alt="OS Logo"
/>
<img
src={browserLogo(row.browserName as string)}
className={classes.logo}
alt="Browser Logo"
/>
<OsLogo osName={row.platformName as string}/>
<BrowserLogo browserName={row.browserName as string}/>
{browserVersion(row.browserVersion as string)}
</DialogTitle>
<DialogContent dividers>
Expand Down
80 changes: 80 additions & 0 deletions javascript/grid-ui/src/components/common/BrowserLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 React from "react";
import {Theme, withStyles} from "@material-ui/core/styles";
import browserLogo from "../../util/browser-logo";
import {Size} from "../../models/size";
import clsx from "clsx";

const useStyles = (theme: Theme) => (
{
logo: {
marginRight: 5,
},
small: {
width: 24,
height: 24,
},
medium: {
width: 32,
height: 32,
},
large: {
width: 48,
height: 48,
},
});

type BrowserLogoProps = {
browserName: string;
size: Size;
classes: any;
};

class BrowserLogo extends React.Component<BrowserLogoProps, {}> {

static defaultProps = {
size: Size.S
};

render() {
const {browserName, size, classes} = this.props;

function sizeMap (size) {
if (size === Size.S) {
return classes.small;
}
if (size === Size.M) {
return classes.medium;
}
if (size === Size.L) {
return classes.large;
}
}

return (
<img
src={browserLogo(browserName)}
className={clsx(classes.logo, sizeMap(size))}
alt="Browser Logo"
/>
);
}
}

export default withStyles(useStyles)(BrowserLogo)
80 changes: 80 additions & 0 deletions javascript/grid-ui/src/components/common/OsLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 React from "react";
import {Theme, withStyles} from "@material-ui/core/styles";
import {Size} from "../../models/size";
import osLogo from "../../util/os-logo";
import clsx from "clsx";

const useStyles = (theme: Theme) => (
{
logo: {
marginRight: 5,
},
small: {
width: 24,
height: 24,
},
medium: {
width: 32,
height: 32,
},
large: {
width: 48,
height: 48,
},
});

type OsLogoProps = {
osName: string;
size: Size;
classes: any;
};

class OsLogo extends React.Component<OsLogoProps, {}> {

static defaultProps = {
size: Size.S
};

render() {
const {osName, size, classes} = this.props;

function sizeMap (size) {
if (size === Size.S) {
return classes.small;
}
if (size === Size.M) {
return classes.medium;
}
if (size === Size.L) {
return classes.large;
}
}

return (
<img
src={osLogo(osName)}
className={clsx(classes.logo, sizeMap(size))}
alt="Browser Logo"
/>
);
}
}

export default withStyles(useStyles)(OsLogo)
22 changes: 22 additions & 0 deletions javascript/grid-ui/src/models/size.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

export enum Size {
S,
M,
L,
}

0 comments on commit 17e395e

Please sign in to comment.