Skip to content

Commit

Permalink
[UI] Style and Help text changes (#29)
Browse files Browse the repository at this point in the history
* Move new namespace input
* Help text
  • Loading branch information
saminzadeh authored and robskillington committed Feb 25, 2019
1 parent 8dbaf31 commit f329cd3
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 29 deletions.
18 changes: 18 additions & 0 deletions src/ctl/ui/src/components/HelpTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import {Popover, Icon} from 'antd';
import {getHelpText} from 'utils/helpText';

export default function HelpTooltip({helpTextKey, title, ...rest}) {
return (
<Popover
title={title}
content={<div style={{maxWidth: 200}}>{getHelpText(helpTextKey)}</div>}
trigger="click"
{...rest}>
<Icon
style={{cursor: 'pointer', color: 'rgba(0,0,0,0.3)'}}
type="question-circle-o"
/>
</Popover>
);
}
8 changes: 4 additions & 4 deletions src/ctl/ui/src/components/MappingRuleEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as util from 'utils';
import yup from 'yup';
import PoliciesEditor from './PolicyEditor';
import {filterPoliciesBasedOnTag} from 'utils';

import {getHelpText} from 'utils/helpText';
const schema = yup.object().shape({
name: yup.string('Name filter is required').required(),
filter: yup.string().required('Metric filter is required'),
Expand Down Expand Up @@ -59,7 +59,7 @@ function MappingRuleEditor({
<FormItem
required="true"
colon={false}
label="Name"
label="Rule Name"
{...formItemLayout}>
<Input
name="name"
Expand All @@ -75,7 +75,7 @@ function MappingRuleEditor({
colon={false}
label="Metric Filter"
{...formItemLayout}
help="eg. tag1:value1 tag2:value2">
help={getHelpText('metric-filter')}>
<Input
name="filter"
autoComplete="off"
Expand All @@ -97,7 +97,7 @@ function MappingRuleEditor({
required={true}
label="Policies"
{...formItemLayout}
help="eg:1m:10d = 1 min resolution for 10 days">
help={getHelpText('policy')}>
<PoliciesEditor
typeTag={typeTag}
value={values.policies}
Expand Down
20 changes: 16 additions & 4 deletions src/ctl/ui/src/components/MappingRulesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import TableActions from './TableActions';
import {compose} from 'recompose';
import {connectR2API} from 'hocs';
import {formatTimestampMilliseconds} from 'utils';

import HelpTooltip from './HelpTooltip';
const {Column} = Table;

function MappingRuleHistoryBase(props) {
Expand Down Expand Up @@ -71,12 +71,20 @@ function MappingRulesTable(props) {
locale={{emptyText: 'No mapping rules'}}>
<Column fixed="left" title="Rule Name" dataIndex="name" width={100} />
<Column
title="Metric Filter"
title={
<div>
Metric Filter <HelpTooltip helpTextKey="metric-filter" />
</div>
}
dataIndex="filter"
render={filter => <code>{filter}</code>}
/>
<Column
title="Policies"
title={
<div>
Policies <HelpTooltip helpTextKey="policy" />
</div>
}
dataIndex="policies"
render={policies => {
return _.map(policies, policy => <Tag key={policy}>{policy}</Tag>);
Expand All @@ -93,7 +101,11 @@ function MappingRulesTable(props) {
render={timestamp => formatTimestampMilliseconds(timestamp)}
/>
<Column
title="Effective Time (Local)"
title={
<div>
Effective Time (Local) <HelpTooltip helpTextKey="effective-time" />
</div>
}
dataIndex="cutoverMillis"
render={cutoverMillis => formatTimestampMilliseconds(cutoverMillis)}
/>
Expand Down
14 changes: 11 additions & 3 deletions src/ctl/ui/src/components/PolicyEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import React from 'react';
import {Select, Icon, Button} from 'antd';
import _ from 'lodash';

import HelpTooltip from './HelpTooltip';

export const AGGREGATION_FUNCTIONS = [
'Min',
'Max',
Expand Down Expand Up @@ -136,7 +138,10 @@ export function PolicyEditor(props: Props) {
</a>
)}
<div className="col col-6 px1">
<label className="block pb1">Resolution:Retention Period</label>
<label className="block pb1">
Resolution:Retention Period{' '}
<HelpTooltip helpTextKey="resolution:retention-period" />
</label>
<Select
placeholder="Select a policy"
value={policy.timePolicy}
Expand All @@ -155,7 +160,10 @@ export function PolicyEditor(props: Props) {
)}
</div>
<div className="col col-6" style={{opacity: showAggs ? 1 : 0.5}}>
<label className="block pb1">Aggregation Functions</label>
<label className="block pb1">
Aggregation Functions{' '}
<HelpTooltip helpTextKey="aggregation-function" />
</label>
{showAggs ? (
<Select
placeholder="Use default if none selected"
Expand Down Expand Up @@ -218,7 +226,7 @@ function PoliciesEditor(props) {
size="small"
type="dashed"
onClick={() => {
onChange(policies.concat(_.first(POLICIES)));
onChange((policies || []).concat(_.first(POLICIES)));
}}>
Add Policy
</Button>
Expand Down
29 changes: 22 additions & 7 deletions src/ctl/ui/src/components/RollupRuleEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {withFormik} from 'formik';
import * as util from 'utils';
import PoliciesEditor from './PolicyEditor';
import {filterPoliciesBasedOnTag} from 'utils';
import {getHelpText} from 'utils/helpText';
import HelpTooltip from './HelpTooltip';

// @TODO Move to config service
const REQUIRED_TAGS = ['dc', 'env', 'service', 'type'];
Expand Down Expand Up @@ -74,7 +76,7 @@ function RollupRuleEditor({values, handleChange, handleSubmit, setFieldValue}) {
required
colon={false}
label="Metric Filter"
help="eg. tag1:value1 tag2:value2"
help={getHelpText('metric-filter')}
{...formItemLayout}>
<Input
name="filter"
Expand All @@ -86,14 +88,22 @@ function RollupRuleEditor({values, handleChange, handleSubmit, setFieldValue}) {
...t,
policies: filterPoliciesBasedOnTag(t.policies, newTypeTag),
}));
setFieldValue('targets', targets);
setFieldValue('target', targets);
handleChange(e);
}}
/>
</FormItem>
</div>
<div className="col col-12 px1">
<FormItem required label="Targets" colon={false} {...formItemLayout}>
<FormItem
required
label={
<span>
Targets <HelpTooltip helpTextKey="target" />
</span>
}
colon={false}
{...formItemLayout}>
<TargetsEditor
typeTag={typeTag}
value={values.targets}
Expand Down Expand Up @@ -134,13 +144,16 @@ const TargetsEditorBase = props => {
<Icon type="delete" />
</a>
}>
<label>New Rollup Metric Name</label>
<label className="mb1">Rollup Metric Name</label>
<Input
className="mb2"
value={t.name}
onChange={e => handleChange(i, 'name', e.target.value)}
/>
<label>Rollup Tags</label>
<div>
<label>
Rollup Tags <HelpTooltip helpTextKey="rollup-tag" />
</label>
<div className="mb2">
{_.map(REQUIRED_TAGS, requiredTag => <Tag>{requiredTag}</Tag>)}
<Select
className="inline-block"
Expand All @@ -155,7 +168,9 @@ const TargetsEditorBase = props => {
notFoundContent={false}
/>
</div>
<label>Policies</label>
<label>
Policies <HelpTooltip helpTextKey="policy" />
</label>
<PoliciesEditor
typeTag={typeTag}
value={t.policies}
Expand Down
19 changes: 16 additions & 3 deletions src/ctl/ui/src/components/RollupRulesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import _ from 'lodash';

import RollupRuleEditor from 'components/RollupRuleEditor';
import TableActions from './TableActions';
import HelpTooltip from './HelpTooltip';
import {compose} from 'recompose';
import {connectR2API} from 'hocs';
import {formatTimestampMilliseconds} from 'utils';
Expand Down Expand Up @@ -109,12 +110,20 @@ function RollupRulesTable(props) {
locale={{emptyText: 'No rollup rules'}}>
<Column fixed="left" title="Rule Name" dataIndex="name" width={100} />
<Column
title="Metric Filter"
title={
<div>
Metric Filter <HelpTooltip helpTextKey="metric-filter" />
</div>
}
dataIndex="filter"
render={filter => <code>{filter}</code>}
/>
<Column
title="Targets"
title={
<div>
Target <HelpTooltip helpTextKey="target" />
</div>
}
dataIndex="targets"
render={targets => {
return _.map(targets, (target, i) => (
Expand All @@ -133,7 +142,11 @@ function RollupRulesTable(props) {
render={timestamp => formatTimestampMilliseconds(timestamp)}
/>
<Column
title="Effective Time (Local)"
title={
<div>
Effective Time (Local) <HelpTooltip helpTextKey="effective-time" />
</div>
}
dataIndex="cutoverMillis"
render={cutoverMillis => formatTimestampMilliseconds(cutoverMillis)}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/ctl/ui/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ body {
height: 100%
}

.ant-form-item-control {
line-height: inherit
}
13 changes: 9 additions & 4 deletions src/ctl/ui/src/pages/Namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import MappingRuleEditor from 'components/MappingRuleEditor';
import MappingRulesTable from 'components/MappingRulesTable';
import RollupRuleEditor from 'components/RollupRuleEditor';
import RollupRulesTable from 'components/RollupRulesTable';
import {getHelpText} from 'utils/helpText';

const TabPane = Tabs.TabPane;

Expand Down Expand Up @@ -66,11 +67,13 @@ function Namespace(props) {
}}>
<TabPane tab="Mapping Rules" key="mapping-rules">
<div className="mb2 clearfix">
<div className="left">
<div className="col col-9">
<h3>Mapping Rules</h3>
<p>{getHelpText('mapping-rule')}</p>
</div>
<div className="right">
<div className="col col-3">
<Button
className="right"
icon="plus"
onClick={() =>
props.setModal({
Expand Down Expand Up @@ -103,11 +106,13 @@ function Namespace(props) {
</TabPane>
<TabPane tab="Rollup Rules" key="rollup-rules">
<div className="mb2 clearfix">
<div className="left">
<div className="col col-9">
<h3>Rollup Rules</h3>
<p>{getHelpText('rollup-rule')}</p>
</div>
<div className="right">
<div className="col col-3">
<Button
className="right"
icon="plus"
onClick={() =>
props.setModal({
Expand Down
10 changes: 6 additions & 4 deletions src/ctl/ui/src/pages/Namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Button, Card, Input, Popconfirm, Table, Icon} from 'antd';
import _ from 'lodash';
import {Link} from 'react-router-dom';
import {connectR2API, withFilter} from 'hocs';

import {getHelpText} from 'utils/helpText';
const {Column} = Table;

function NamespaceTable(props) {
Expand Down Expand Up @@ -68,8 +68,9 @@ function NamespaceTable(props) {
function CreateNamespaceFormBase(props) {
const {namespace, onNamespaceChange, onSaveClick} = props;
return (
<div>
<div className="mb1">
<Input
placeholder="Namespace Name"
onPressEnter={onSaveClick}
style={{width: 200}}
className="inline-block mr1"
Expand Down Expand Up @@ -104,17 +105,18 @@ function Namespaces(props) {
<div>
<div className="mb2">
<h2>Namespaces</h2>
<p style={{color: 'gray'}}>A list of all namespaces</p>
<p style={{color: 'gray'}}>{getHelpText('namespace')}</p>
</div>
<Card>
<CreateNamespaceForm onSaveNamespace={props.saveNamespace} />

<Input
className="mb1"
value={props.nameFilter}
onChange={e => props.setNameFilter(e.target.value)}
placeholder="Namespace Filter"
/>
<NamespaceTable {...props} />
<CreateNamespaceForm onSaveNamespace={props.saveNamespace} />
</Card>
</div>
);
Expand Down
27 changes: 27 additions & 0 deletions src/ctl/ui/src/utils/helpText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const helpText = {
namespace:
'Logical grouping of rules. The namespace name must be a valid service name.',
'mapping-rule':
'Configure the resolution, retention, and optional custom aggregation functions for metrics matching the filter.',
'rollup-rule':
'Configure how to roll up metrics matching the filter and the corresponding policies. A matching metric triggers the generation of a new rollup metric whose name, tags, and policies are defined by the rollup targets. ',
'metric-filter':
' A list of tag name:glob pattern pairs identifying matching metrics.',
policy:
'Defines the resolution, retention period, and optional custom aggregation functions for given metric.',
target:
'Defines how a new rollup metric is generated and its policies. The rollup metric will use “Rollup Metric Name” as its name, “Rollup Tags” as its tags, and “Policies” as its policies. ',
'rollup-tag': 'Tags retained by the generated rollup metric.',
'resolution:retention-period':
'Describes the resolution at which the metric will be aggregated, and how long the metric will be stored for. ',
'aggregation-function':
'Defines how the given metric is aggregated. For example, an aggregation function of P99 returns the 99th percentile of the given metric.',
'effective-time': 'The time at which the rule will be in effect',
};

export function getHelpText(helpTextKey) {
if (!helpText[helpTextKey]) {
console.error(`The helpKey: ${helpTextKey} does not exist`); // eslint-disable-line
}
return helpText[helpTextKey] || '';
}

0 comments on commit f329cd3

Please sign in to comment.