Skip to content

Commit

Permalink
[Web UI] Check details page improvements (#2162)
Browse files Browse the repository at this point in the history
* Wrap commands, allow scrolling on env vars

Signed-off-by: Melissa P <[email protected]>

* Add buttons for publish and unpublish

Signed-off-by: Melissa P <[email protected]>

* Added check publish and unpublish actions

Signed-off-by: Melissa P <[email protected]>

* Fix syntax

Signed-off-by: Melissa P <[email protected]>

* Render single button depending on state of publish

Signed-off-by: Melissa P <[email protected]>

* update changelog

Signed-off-by: Melissa P <[email protected]>

* Review tweaks

Signed-off-by: Melissa P <[email protected]>

* Review tweaks

Signed-off-by: Melissa P <[email protected]>

* Rework Monospaced to be more clear at it's intention

Signed-off-by: Melissa P <[email protected]>

* Set DV back to table-cell and give optional scrollable prop

Signed-off-by: Melissa P <[email protected]>

* Initial implementation of code highlighting

Signed-off-by: Melissa P <[email protected]>

* Implement code highlighting

Signed-off-by: Melissa P <[email protected]>

* Update eslint rule

Signed-off-by: Melissa P <[email protected]>

* update changelog

Signed-off-by: Melissa P <[email protected]>

* Fallback theme colour re-added

Signed-off-by: Melissa P <[email protected]>
  • Loading branch information
dabria authored Oct 24, 2018
1 parent 6916639 commit 0ad392d
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Versioning](http://semver.org/spec/v2.0.0.html).
- Added a debug log message for interval timer initial offset.
- Added a privilege escalation test for RBAC.
- Web ui allows publishing and unpublishing on checks page
- Web ui allows publishing and unpublishing on check details page
- Code highlighting added

### Removed
- Staging resources and configurations have been removed from sensu-go.
Expand Down
3 changes: 3 additions & 0 deletions dashboard/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ rules:

import/prefer-default-export: 0

# Code Highlighting requirees dangerously setting
react/no-danger: 0

# https://github.com/apollographql/eslint-plugin-graphql
graphql/template-strings:
- error
Expand Down
14 changes: 14 additions & 0 deletions dashboard/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default () => {
entry: [path.resolve(root, "src/index.js")],

output: {
globalObject: "self",

path: outputPath,

publicPath: "/",
Expand Down Expand Up @@ -111,6 +113,18 @@ export default () => {
name: "static/media/[name].[hash:8].[ext]",
},
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.worker\.js$/,
loader: "worker-loader",
options: {
name: "static/[hash].worker.js",
},
},

{
test: /\.macro\.js$/,
exclude: path.resolve(root, "node_modules"),
Expand Down
6 changes: 5 additions & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"connect-history-api-fallback": "^1.5.0",
"core-js": "^2.5.6",
"cronstrue": "^1.31.0",
"css-loader": "^1.0.0",
"debounce": "^1.2.0",
"deepmerge": "^2.0.1",
"enzyme": "^3.3.0",
Expand All @@ -83,6 +84,7 @@
"graphql": "0.13.0",
"graphql-config": "^2.0.1",
"graphql-tag": "^2.9.2",
"highlight.js": "^9.13.1",
"hoist-non-react-statics": "^2.5.0",
"html-webpack-plugin": "^3.2.0",
"http-proxy-middleware": "^0.18.0",
Expand Down Expand Up @@ -121,6 +123,7 @@
"regenerator-runtime": "^0.11.1",
"source-map-loader": "bryanforbes/source-map-loader#module-context",
"stacktrace-js": "^2.0.0",
"style-loader": "^0.23.1",
"sw-precache-webpack-plugin": "^0.11.5",
"typeface-roboto": "^0.0.54",
"uglifyjs-webpack-plugin": "^1.2.5",
Expand All @@ -130,7 +133,8 @@
"warning": "^3.0.0",
"webpack": "^4.8.1",
"webpack-stats-plugin": "^0.2.1",
"whatwg-fetch": "^2.0.4"
"whatwg-fetch": "^2.0.4",
"worker-loader": "^2.0.0"
},
"jest": {
"collectCoverageFrom": [
Expand Down
13 changes: 10 additions & 3 deletions dashboard/src/components/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fade } from "@material-ui/core/styles/colorManipulator";

const styles = theme => ({
root: {
whiteSpace: "nowrap",
whiteSpace: "pre-wrap",
margin: "0 1px",
padding: `${2 / 16}em ${4 / 16}em`,
borderRadius: `${5 / 16}em`,
Expand All @@ -24,11 +24,18 @@ const styles = theme => ({
class Code extends React.PureComponent {
static propTypes = {
classes: PropTypes.object.isRequired,
children: PropTypes.node,
};

static defaultProps = { children: null };

render() {
const { classes, ...props } = this.props;
return <code {...props} className={classes.root} />;
const { classes, children, ...props } = this.props;
return (
<code {...props} className={classes.root}>
{children}
</code>
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,42 @@ import Typography from "@material-ui/core/Typography";

const styles = theme => ({
root: {
// TODO: Move into theme so that it can be overridden.
fontFamily: `"SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace`,
fontFamily: theme.typography.monospace.fontFamily,
overflowX: "scroll",
userSelect: "text",
tabSize: 2,
},
background: {
backgroundColor: emphasize(theme.palette.background.paper, 0.01875),
},
highlight: {
color:
theme.palette.type === "dark"
? theme.palette.secondary.light
: theme.palette.secondary.dark,
"& $background": {
backgroundColor: emphasize(theme.palette.text.primary, 0.05),
},
},
background: {
backgroundColor: emphasize(theme.palette.background.paper, 0.01875),
},
scaleFont: {
// Browsers tend to render monospaced fonts a little larger than intended.
// Attempt to scale accordingly.
fontSize: "0.8125rem", // TODO: Scale given fontSize from theme?
},
wrap: { whiteSpace: "pre-wrap" },
});

class Monospaced extends React.Component {
class CodeBlock extends React.Component {
static propTypes = {
background: PropTypes.bool,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
children: PropTypes.node.isRequired,
highlight: PropTypes.bool,
scaleFont: PropTypes.bool,
};

static defaultProps = {
background: false,
background: true,
component: "pre",
className: "",
highlight: false,
scaleFont: true,
highlight: null,
};

render() {
Expand All @@ -57,22 +51,21 @@ class Monospaced extends React.Component {
classes,
className: classNameProp,
children,
highlight,
scaleFont,
...props
} = this.props;

const className = classnames(classes.root, classNameProp, {
[classes.background]: background,
[classes.scaleFont]: scaleFont,
[classes.highlight]: highlight,
});

return (
<Typography className={className} {...props}>
{children}
<code className={classes.wrap}>{children}</code>
</Typography>
);
}
}

export default withStyles(styles)(Monospaced);
export default withStyles(styles)(CodeBlock);
1 change: 1 addition & 0 deletions dashboard/src/components/CodeBlock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./CodeBlock";
72 changes: 72 additions & 0 deletions dashboard/src/components/CodeHighlight/CodeHighlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import "highlight.js/styles/github-gist.css";

import React from "react";
import PropTypes from "prop-types";
import Worker from "./CodeHighlight.worker";

const worker = new Worker();
const pending = {};

worker.onmessage = event => {
const [key, data] = event.data;
pending[key].call(this, data);
};

let idx = 0;
function postMessage(msg, callback) {
const key = idx;
pending[idx] = data => {
callback(data);
delete pending[idx];
};
worker.postMessage({ key, msg });
idx += 1;
}

class CodeHighlight extends React.Component {
static propTypes = {
language: PropTypes.oneOf(["json", "bash", "properties"]).isRequired,
code: PropTypes.string.isRequired,
children: PropTypes.func.isRequired,
};

static getDerivedStateFromProps(props, state) {
if (props.code !== state.code) {
return { code: props.code, result: props.code };
}
return null;
}

state = {
code: this.props.code,
result: this.props.code,
};

componentDidMount() {
this.update();
}

componentDidUpdate() {
if (this.props.code === this.state.result) {
this.update();
}
}

componentWillUnmount() {
this.unmounted = true;
}

update = () => {
postMessage([this.props.language, this.props.code], result => {
if (!this.unmounted) {
this.setState({ result });
}
});
};

render() {
return this.props.children(this.state.result);
}
}

export default CodeHighlight;
14 changes: 14 additions & 0 deletions dashboard/src/components/CodeHighlight/CodeHighlight.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import hljs from "highlight.js/lib/highlight";
import bash from "highlight.js/lib/languages/bash";
import json from "highlight.js/lib/languages/json";
import properties from "highlight.js/lib/languages/properties";

hljs.registerLanguage("bash", bash);
hljs.registerLanguage("json", json);
hljs.registerLanguage("properties", properties);

onmessage = message => {
const [language, data] = message.data.msg;
const result = hljs.highlight(language, data);
postMessage([message.data.key, result.value]);
};
10 changes: 10 additions & 0 deletions dashboard/src/components/Dictionary/DictionaryValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const styles = theme => ({
limit: {
maxWidth: "60%",
},
scrollableContent: { display: "inline-grid" },
explicitRightMargin: { paddingRight: "24px" },
});

class DictionaryValue extends React.Component {
Expand All @@ -21,11 +23,15 @@ class DictionaryValue extends React.Component {
classes: PropTypes.object.isRequired,
className: PropTypes.string,
constrain: PropTypes.bool,
explicitRightMargin: PropTypes.bool,
scrollableContent: PropTypes.bool,
};

static defaultProps = {
className: null,
constrain: false,
explicitRightMargin: false,
scrollableContent: false,
};

render() {
Expand All @@ -34,10 +40,14 @@ class DictionaryValue extends React.Component {
classes,
children,
constrain,
explicitRightMargin,
scrollableContent,
...props
} = this.props;
const className = classnames(classes.root, classNameProp, {
[classes.limit]: constrain,
[classes.explicitRightMargin]: explicitRightMargin,
[classes.scrollableContent]: scrollableContent,
});

return (
Expand Down
1 change: 0 additions & 1 deletion dashboard/src/components/Monospaced/index.js

This file was deleted.

Loading

0 comments on commit 0ad392d

Please sign in to comment.