Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bindings view in Hooks create page #730

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2936bca
Add Bindings view in Hooks create page
arshadkazmi42 May 12, 2019
641d42b
Create PulseBinding Component and use in PulseMessages and HookForm
arshadkazmi42 May 13, 2019
b8f864b
add static props in PulseBindings component
arshadkazmi42 May 17, 2019
f266cfc
Add binding to return from getDefinition
arshadkazmi42 May 17, 2019
5b9d224
Add bindings to payload
arshadkazmi42 May 23, 2019
f4984a0
Change routingKeyPattern to pattern for bindings in payload
arshadkazmi42 May 24, 2019
7776395
Change pattern to routingKeyPattern
arshadkazmi42 May 24, 2019
81ca99c
merge master
owlishDeveloper May 13, 2019
19a54e6
Add Create Worker Type button. Add Editor view
owlishDeveloper May 16, 2019
d623a5a
Define the workertype creation form
owlishDeveloper May 22, 2019
01ce1c8
Make the form functional
owlishDeveloper May 22, 2019
c9f2079
Cleanup
owlishDeveloper May 27, 2019
09636fd
Correct the provider config part of the component state
owlishDeveloper May 30, 2019
228f4f0
Change fetch query in webserver and change UI to render fetched values
arshadkazmi42 May 30, 2019
c9b3266
Rename worker type to worker pool
owlishDeveloper May 30, 2019
1d3da94
Implement review suggestions. Styling changes
owlishDeveloper May 31, 2019
af8de5e
More suggestions
owlishDeveloper May 31, 2019
eb645b9
Use different icon for Save button
owlishDeveloper May 31, 2019
a409b74
Change field labels. Add some useful styling
owlishDeveloper May 31, 2019
3d50fc2
Merge master
owlishDeveloper May 31, 2019
879ab4f
Finish merging master
owlishDeveloper May 31, 2019
34e753e
Finish merging master
owlishDeveloper May 31, 2019
9f06ab0
Return Dashboard. Remove button spacing for now. Remove some styles
owlishDeveloper Jun 1, 2019
bd061c2
Change imports
owlishDeveloper Jun 3, 2019
6d1929e
Replace FormLabel with ListSubheader. Ensure minimum width of the dro…
owlishDeveloper Jun 3, 2019
a9eeb15
Change name of a field. Change padding
owlishDeveloper Jun 3, 2019
6a7878e
Use vertical spacing instead of indentation to organize the form fields
owlishDeveloper Jun 3, 2019
9af784f
Add skeleton of worker-scanner tests
imbstack May 23, 2019
3f681f7
Add another check to provisioner testing
imbstack May 23, 2019
1cc3491
Add worker-scanner tests
imbstack May 28, 2019
bd28bd5
Parallelize coverage fetching
imbstack Jun 3, 2019
0936543
Add tests for reporting workerpool errors
imbstack Jun 3, 2019
3e35cea
Css cleanup, delete all bindings and save button enable fix
arshadkazmi42 Jun 4, 2019
a8980c3
Add minor changes
owlishDeveloper Jun 4, 2019
645cac1
Worker manager updates (#831)
imbstack Jun 4, 2019
9aa285d
Merge pull request #814 from owlishDeveloper/bug1542905-3
owlishDeveloper Jun 4, 2019
d28d642
Don't specify an explicit PORT for tc-web-ui
djmitche Jun 4, 2019
949fbc5
Merge pull request #836 from djmitche/no-explicit-PORT-for-web-ui
djmitche Jun 4, 2019
21fd0ef
Make setTimeout work with large timeout values (#838)
helfi92 Jun 4, 2019
989c444
Add Bindings view in Hooks create page
arshadkazmi42 May 12, 2019
3bbbb11
Create PulseBinding Component and use in PulseMessages and HookForm
arshadkazmi42 May 13, 2019
76a6f49
add static props in PulseBindings component
arshadkazmi42 May 17, 2019
019d25c
Add binding to return from getDefinition
arshadkazmi42 May 17, 2019
023761b
Add bindings to payload
arshadkazmi42 May 23, 2019
a31db51
Change routingKeyPattern to pattern for bindings in payload
arshadkazmi42 May 24, 2019
61a4307
Change pattern to routingKeyPattern
arshadkazmi42 May 24, 2019
16d71d2
Change fetch query in webserver and change UI to render fetched values
arshadkazmi42 May 30, 2019
badc0a3
Css cleanup, delete all bindings and save button enable fix
arshadkazmi42 Jun 4, 2019
bf4c6e0
Merge branch 'bindings-hook-view' of https://github.com/arshadkazmi42…
arshadkazmi42 Jun 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 51 additions & 2 deletions ui/src/components/HookForm/index.jsx
Expand Up @@ -31,6 +31,7 @@ import SpeedDialAction from '../SpeedDialAction';
import DialogAction from '../DialogAction';
import DateDistance from '../DateDistance';
import HookLastFiredTable from '../HookLastFiredTable';
import PulseBindings from '../PulseBindings';
import { hook } from '../../utils/prop-types';
import removeKeys from '../../utils/removeKeys';

Expand Down Expand Up @@ -181,6 +182,9 @@ export default class HookForm extends Component {
state = {
hook: null,
hookLastFires: null,
pattern: '#',
pulseExchange: '',
bindings: [],
// eslint-disable-next-line react/no-unused-state
previousHook: null,
taskInput: '',
Expand Down Expand Up @@ -446,6 +450,36 @@ export default class HookForm extends Component {
});
};

handleInputChange = ({ target: { name, value } }) => {
this.setState({ [name]: value });
};

handleAddBinding = () => {
const { pulseExchange, pattern } = this.state;
const bindings = this.state.bindings.concat([
{
exchange: pulseExchange,
pattern,
},
]);

this.setState({
pulseExchange: '',
pattern: '#',
bindings,
});
};

handleDeleteBinding = ({ exchange, pattern }) => {
const bindings = this.state.bindings.filter(
binding => binding.exchange !== exchange || binding.pattern !== pattern
);

this.setState({
bindings,
});
};

render() {
const {
actionLoading,
Expand All @@ -458,6 +492,9 @@ export default class HookForm extends Component {
onDialogOpen,
} = this.props;
const {
pattern,
pulseExchange,
bindings,
scheduleTextField,
taskInput,
triggerSchemaInput,
Expand Down Expand Up @@ -594,7 +631,20 @@ export default class HookForm extends Component {
</ListItem>
</Fragment>
)}
<List>
<PulseBindings
bindings={bindings}
onBindingAdd={this.handleAddBinding}
onBindingRemove={this.handleDeleteBinding}
onChange={this.handleInputChange}
pulseExchange={pulseExchange}
pattern={pattern}
/>
<List
subheader={
<ListSubheader className={classes.subheader}>
Schedule
</ListSubheader>
}>
<ListItem>
<ListItemText
primary={
Expand All @@ -611,7 +661,6 @@ export default class HookForm extends Component {
for format information. Times are in UTC.
</span>
}
label="Schedule"
name="scheduleTextField"
placeholder="* * * * * *"
fullWidth
Expand Down
149 changes: 149 additions & 0 deletions ui/src/components/PulseBindings/index.jsx
@@ -0,0 +1,149 @@
import { hot } from 'react-hot-loader';
import React, { Component, Fragment } from 'react';
import { withApollo } from 'react-apollo';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import { arrayOf, func, object, string } from 'prop-types';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import ListSubheader from '@material-ui/core/ListSubheader';
import Tooltip from '@material-ui/core/Tooltip';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
import PlusIcon from 'mdi-react/PlusIcon';
import DeleteIcon from 'mdi-react/DeleteIcon';

@hot(module)
@withApollo
@withStyles(theme => ({
iconButton: {
'& svg': {
fill: theme.palette.text.primary,
},
},
plusIcon: {
marginTop: 80,
},
deleteIcon: {
marginRight: -15,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marginRight: -theme.spacing.double,

[theme.breakpoints.down('sm')]: {
marginRight: -14,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove L31-33.

},
inputWrapper: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
inputList: {
flex: 1,
},
bindingListItem: {
paddingTop: 0,
paddingBottom: 0,
},
subheader: {
fontSize: theme.typography.pxToRem(16),
},
}))
export default class PulseBindings extends Component {
static propTypes = {
pulseExchange: string.isRequired,
pattern: string.isRequired,
bindings: arrayOf(object).isRequired,
onBindingAdd: func.isRequired,
onBindingRemove: func.isRequired,
onChange: func.isRequired,
};

render() {
const {
pulseExchange,
pattern,
bindings,
classes,
onBindingAdd,
onBindingRemove,
onChange,
} = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add static propTypes. We can also add static defaultProps if certain props are not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel all the props are required for this.
I have written static propTypes something like this.

static propTypes = {
    pulseExchange: string.isRequired,
    pattern: string.isRequired,
    bindings: arrayOf(object).isRequired,
    onBindingAdd: func.isRequired,
    onBindingRemove: func.isRequired,
    onChange: func.isRequired,
  };

Also, I am not sure if we would not need static defaultProps in this.

Let me know if there is anything missing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.


return (
<Fragment>
<div className={classes.inputWrapper}>
<List
className={classes.inputList}
subheader={
<ListSubheader className={classes.subheader}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subheader doesn't seem to be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was related to the above comment.

Bindings
</ListSubheader>
}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Bindings" and "Schedule" don't seem to have the same styling. "Bindings" seems to be smaller. Maybe we can avoid putting the title inside the component and just have it defined in the hook form view.

Screen Shot 2019-05-15 at 4 38 52 PM

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually issue was with adding the bidings inside, subheader class was missing from PulseBinding component, due to that is was not rendering with correct styles.

I have added subheader style in the component and now it looks fine.

Screen Shot 2019-05-16 at 10 02 05 PM

<ListItem>
<ListItemText
primary={
<TextField
required
label="Pulse Exchange"
name="pulseExchange"
placeholder="exchange/<username>/some-exchange-name"
onChange={onChange}
fullWidth
value={pulseExchange}
/>
}
/>
</ListItem>
<ListItem>
<ListItemText
primary={
<TextField
required
label="Routing Key Pattern"
placeholder="#.some-interesting-key.#"
name="pattern"
onChange={onChange}
fullWidth
value={pattern}
/>
}
/>
</ListItem>
</List>
<Tooltip title="Add Binding">
<IconButton
className={classNames(classes.iconButton, classes.plusIcon)}
onClick={onBindingAdd}>
<PlusIcon />
</IconButton>
</Tooltip>
</div>
<List>
{bindings.map(binding => (
<ListItem
className={classes.bindingListItem}
key={`${binding.exchange}-${binding.routingKeyPattern}`}>
<ListItemText
disableTypography
primary={
<Typography variant="body2">
<code>{binding.exchange}</code> with{' '}
<code>{binding.pattern}</code>
</Typography>
}
/>
<Tooltip title="Delete Binding">
<IconButton
className={classNames(classes.iconButton, classes.deleteIcon)}
name={binding}
onClick={() => onBindingRemove(binding)}>
<DeleteIcon />
</IconButton>
</Tooltip>
</ListItem>
))}
</List>
</Fragment>
);
}
}
102 changes: 9 additions & 93 deletions ui/src/views/PulseMessages/index.jsx
@@ -1,13 +1,10 @@
import { hot } from 'react-hot-loader';
import React, { Component, Fragment } from 'react';
import { withApollo } from 'react-apollo';
import classNames from 'classnames';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import Tooltip from '@material-ui/core/Tooltip';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
import Drawer from '@material-ui/core/Drawer';
Expand All @@ -19,9 +16,7 @@ import PlayIcon from 'mdi-react/PlayIcon';
import DownloadIcon from 'mdi-react/DownloadIcon';
import CloseIcon from 'mdi-react/CloseIcon';
import StopIcon from 'mdi-react/StopIcon';
import PlusIcon from 'mdi-react/PlusIcon';
import InformationVariantIcon from 'mdi-react/InformationVariantIcon';
import DeleteIcon from 'mdi-react/DeleteIcon';
import Code from '@mozilla-frontend-infra/components/Code';
import urls from '../../utils/urls';
import ErrorPanel from '../../components/ErrorPanel';
Expand All @@ -31,6 +26,7 @@ import Button from '../../components/Button';
import SpeedDial from '../../components/SpeedDial';
import SpeedDialAction from '../../components/SpeedDialAction';
import DataTable from '../../components/DataTable';
import PulseBindings from '../../components/PulseBindings';
import pulseMessagesQuery from './pulseMessages.graphql';
import removeKeys from '../../utils/removeKeys';

Expand All @@ -48,33 +44,12 @@ const getBindingsFromProps = props => {
fill: theme.palette.text.primary,
},
},
plusIcon: {
marginTop: 45,
},
deleteIcon: {
marginRight: -theme.spacing.triple,
[theme.breakpoints.down('sm')]: {
marginRight: -14,
},
},
playIcon: {
...theme.mixins.successIcon,
},
stopIcon: {
...theme.mixins.errorIcon,
},
inputWrapper: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
inputList: {
flex: 1,
},
bindingListItem: {
paddingTop: 0,
paddingBottom: 0,
},
infoButton: {
marginLeft: -theme.spacing.double,
marginRight: theme.spacing.unit,
Expand Down Expand Up @@ -272,74 +247,15 @@ export default class PulseMessages extends Component {
}>
<Fragment>
<ErrorPanel error={error} />
<div className={classes.inputWrapper}>
<List className={classes.inputList}>
<ListItem>
<ListItemText
primary={
<TextField
required
label="Pulse Exchange"
name="pulseExchange"
placeholder="exchange/<username>/some-exchange-name"
onChange={this.handleInputChange}
fullWidth
value={pulseExchange}
/>
}
/>
</ListItem>
<ListItem>
<ListItemText
primary={
<TextField
required
label="Routing Key Pattern"
placeholder="#.some-interesting-key.#"
name="pattern"
onChange={this.handleInputChange}
fullWidth
value={pattern}
/>
}
/>
</ListItem>
</List>
<Tooltip title="Add Binding">
<IconButton
className={classNames(classes.iconButton, classes.plusIcon)}
onClick={this.handleAddBinding}>
<PlusIcon />
</IconButton>
</Tooltip>
</div>
<PulseBindings
bindings={bindings}
onBindingAdd={this.handleAddBinding}
onBindingRemove={this.handleDeleteBinding}
onChange={this.handleInputChange}
pulseExchange={pulseExchange}
pattern={pattern}
/>
<List>
{bindings.map(binding => (
<ListItem
className={classes.bindingListItem}
key={`${binding.exchange}-${binding.routingKeyPattern}`}>
<ListItemText
disableTypography
primary={
<Typography variant="body2">
<code>{binding.exchange}</code> with{' '}
<code>{binding.pattern}</code>
</Typography>
}
/>
<Tooltip title="Delete Binding">
<IconButton
className={classNames(
classes.iconButton,
classes.deleteIcon
)}
name={binding}
onClick={() => this.handleDeleteBinding(binding)}>
<DeleteIcon />
</IconButton>
</Tooltip>
</ListItem>
))}
<Toolbar>
<Typography variant="body2" id="tableTitle">
Messages
Expand Down