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

search-select: refactor to use React hooks #124

Merged
merged 20 commits into from Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
2 changes: 1 addition & 1 deletion devtools/runjson/localdev.json
Expand Up @@ -28,7 +28,7 @@
"Command": [
"./node_modules/.bin/webpack-dev-server",
"--inline",
"--devtool=cheap-module-source-map",
"--devtool=inline-source-map",
mastercactapus marked this conversation as resolved.
Show resolved Hide resolved
"--allowed-hosts=docker.for.mac.host.internal",
"--port=3035",
"--progress=false",
Expand Down
57 changes: 29 additions & 28 deletions web/src/app/alerts/components/AlertsListDataWrapper.js
Expand Up @@ -8,7 +8,7 @@ import Typography from '@material-ui/core/Typography'
import moment from 'moment'
import withStyles from '@material-ui/core/styles/withStyles'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { Link } from 'react-router-dom'
import { setCheckedAlerts } from '../../actions'
import { bindActionCreators } from 'redux'
import statusStyles from '../../util/statusStyles'
Expand Down Expand Up @@ -47,7 +47,6 @@ const mapDispatchToProps = dispatch =>
mapStateToProps,
mapDispatchToProps,
)
@withRouter
export default class AlertsListDataWrapper extends Component {
static propTypes = {
alert: p.object.isRequired,
Expand Down Expand Up @@ -98,7 +97,7 @@ export default class AlertsListDataWrapper extends Component {
}

render() {
const { alert, checkedAlerts, classes, history, onServicePage } = this.props
const { alert, checkedAlerts, classes, onServicePage } = this.props

const checkbox = (
<Checkbox
Expand All @@ -114,6 +113,7 @@ export default class AlertsListDataWrapper extends Component {
disableRipple
tabIndex={-1}
onChange={() => this.toggleChecked(alert.number)}
onClick={e => e.stopPropagation()}
/>
)

Expand All @@ -131,34 +131,35 @@ export default class AlertsListDataWrapper extends Component {
}

return (
<ListItem button className={statusClass}>
<ListItem
button
className={statusClass}
component={Link}
to={`/alerts/${alert.number}`}
>
{checkbox}
<div
className={classes.listItem}
onClick={() => history.push(`/alerts/${alert.number}`)}
>
<ListItemText disableTypography style={{ paddingRight: '2.75em' }}>
<Typography>
<b>{alert.number}: </b>
{alert.status.toUpperCase()}
</Typography>
{onServicePage ? null : (
<Typography variant='caption'>{alert.service.name}</Typography>
)}
<Typography variant='caption' noWrap>
{alert.summary}

<ListItemText disableTypography style={{ paddingRight: '2.75em' }}>
<Typography>
<b>{alert.number}: </b>
{alert.status.toUpperCase()}
</Typography>
{onServicePage ? null : (
<Typography variant='caption'>{alert.service.name}</Typography>
)}
<Typography variant='caption' noWrap>
{alert.summary}
</Typography>
</ListItemText>
<ListItemSecondaryAction>
<ListItemText disableTypography>
<Typography variant='caption'>
{moment(alert.created_at)
.local()
.fromNow()}
</Typography>
</ListItemText>
<ListItemSecondaryAction>
<ListItemText disableTypography>
<Typography variant='caption'>
{moment(alert.created_at)
.local()
.fromNow()}
</Typography>
</ListItemText>
</ListItemSecondaryAction>
</div>
</ListItemSecondaryAction>
</ListItem>
)
}
Expand Down
11 changes: 7 additions & 4 deletions web/src/app/dialogs/FormDialog.js
Expand Up @@ -15,6 +15,7 @@ import DialogContentError from './components/DialogContentError'
import { styles as globalStyles } from '../styles/materialStyles'
import gracefulUnmount from '../util/gracefulUnmount'
import { Form } from '../forms'
import ErrorBoundary from '../main/ErrorBoundary'

const styles = theme => {
const { cancelButton, dialogWidth } = globalStyles(theme)
Expand Down Expand Up @@ -131,10 +132,12 @@ export default class FormDialog extends React.PureComponent {
if (valid) onSubmit()
}}
>
{this.renderForm()}
{this.renderCaption()}
{this.renderErrors()}
{this.renderActions()}
<ErrorBoundary>
{this.renderForm()}
{this.renderCaption()}
{this.renderErrors()}
{this.renderActions()}
</ErrorBoundary>
</Form>
</Dialog>
)
Expand Down
14 changes: 6 additions & 8 deletions web/src/app/selection/EscalationPolicySelect.js
@@ -1,7 +1,5 @@
import React from 'react'

import gql from 'graphql-tag'
import QuerySelect from './QuerySelect'
import { makeQuerySelect } from './QuerySelect'

const query = gql`
query($input: EscalationPolicySearchOptions) {
Expand All @@ -22,8 +20,8 @@ const valueQuery = gql`
}
}
`
export class EscalationPolicySelect extends React.PureComponent {
render() {
return <QuerySelect {...this.props} query={query} valueQuery={valueQuery} />
}
}

export const EscalationPolicySelect = makeQuerySelect(
'EscalationPolicySelect',
{ query, valueQuery },
)
25 changes: 7 additions & 18 deletions web/src/app/selection/LabelKeySelect.js
@@ -1,5 +1,4 @@
import React from 'react'
import QuerySelect from './QuerySelect'
import { makeQuerySelect } from './QuerySelect'
import gql from 'graphql-tag'

const query = gql`
Expand All @@ -12,19 +11,9 @@ const query = gql`
}
`

export class LabelKeySelect extends React.PureComponent {
render() {
return (
<QuerySelect
{...this.props}
variables={{ input: { uniqueKeys: true } }}
defaultQueryVariables={{ input: { uniqueKeys: true } }}
mapDataNode={node => ({
label: node.key,
value: node.key,
})}
query={query}
/>
)
}
}
export const LabelKeySelect = makeQuerySelect('LabelKeySelect', {
variables: { uniqueKeys: true },
defaultQueryVariables: { uniqueKeys: true },
query,
mapDataNode: ({ key }) => ({ label: key, value: key }),
})