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

alerts: create alerts for multiple services at once #173

Merged
merged 416 commits into from
Nov 27, 2019
Merged
Changes from 250 commits
Commits
Show all changes
416 commits
Select commit Hold shift + click to select a range
7259334
remove services state array
dctalbot Oct 24, 2019
ef7feac
selectedServices -> array of Ids
dctalbot Oct 24, 2019
f293420
Add all services in list
dctalbot Oct 24, 2019
87b8997
unset dev settings
dctalbot Oct 24, 2019
cf5beb7
WIP: mutation
dctalbot Oct 28, 2019
0e1a708
WIP: creates single alert
dctalbot Oct 28, 2019
9103c56
merge
dctalbot Oct 28, 2019
41f3644
WIP: multi insert
dctalbot Oct 29, 2019
81ea8eb
Merge branch 'master' into service-search-labels
Forfold Oct 29, 2019
8310f67
extract useCreateAlerts custom hook
dctalbot Oct 30, 2019
5a2b258
rm comment
dctalbot Oct 30, 2019
9785851
pass onClose handler to dialog nav
dctalbot Oct 30, 2019
a60b387
Merge branch 'master' into service-search-labels
arurao Oct 30, 2019
a7fae70
retrieve mutation repsponse
dctalbot Oct 30, 2019
fa878d6
Add confirm dialog page
dctalbot Oct 30, 2019
cdddcb8
reset state onClose
dctalbot Oct 30, 2019
72a6535
extract alertion creation logic
dctalbot Oct 30, 2019
a02e9fb
pass mutationStatus prop to StepContent
dctalbot Oct 30, 2019
a55e968
recevie mutationStatus prop
dctalbot Oct 30, 2019
23c24af
fix search on alerts list
Forfold Oct 30, 2019
398e594
fix prop types
Forfold Oct 31, 2019
9efbbe3
handle undefined
dctalbot Oct 31, 2019
e9cac11
add new specific search methods
mastercactapus Oct 31, 2019
be9f904
yeeted old search code
mastercactapus Oct 31, 2019
ede361a
map existing label query to key search
mastercactapus Oct 31, 2019
33c14dc
add new gql queries for labels
mastercactapus Oct 31, 2019
046423e
Merge branch 'master' into service-search-labels
arurao Oct 31, 2019
7da6f8a
update searchselect stuff
mastercactapus Oct 31, 2019
449b936
update container prop
mastercactapus Oct 31, 2019
9d2e1fd
Merge branch 'service-search-labels' of github.com:target/goalert int…
mastercactapus Oct 31, 2019
14f1a73
Display successful and failed alerts
dctalbot Oct 31, 2019
435e4f0
initial cy test
dctalbot Oct 31, 2019
467e77b
Merge remote-tracking branch 'origin/service-search-labels' into goal…
dctalbot Oct 31, 2019
c4f931c
Forgot to click done
dctalbot Oct 31, 2019
f4391ea
green tests
dctalbot Oct 31, 2019
4aa4c58
new speed dial names/icons
dctalbot Nov 4, 2019
3839a7b
show lines in stepper
dctalbot Nov 4, 2019
d16e7f5
Revert "show lines in stepper"
dctalbot Nov 4, 2019
b3be0f8
new step headers => also shows stepper lines
dctalbot Nov 4, 2019
3de4afb
set height of dialog, move addAll into search endAdornment
dctalbot Nov 4, 2019
4a1da85
chip container styles
dctalbot Nov 4, 2019
ddcad1d
chip container label
dctalbot Nov 4, 2019
953200f
handle empty list
dctalbot Nov 4, 2019
cc4c0b8
new empty list component message
dctalbot Nov 4, 2019
f724c46
anchor filter to search field
dctalbot Nov 4, 2019
1df07cf
simplify label select form api
mastercactapus Nov 4, 2019
c3e99ce
count selected services
dctalbot Nov 4, 2019
2e9da18
style the summary step
dctalbot Nov 4, 2019
342f191
open in new tab
dctalbot Nov 4, 2019
66bb49b
disable implicit closing on last step
dctalbot Nov 4, 2019
b58bd12
WIP styles, intiial openAll
dctalbot Nov 4, 2019
c79ae6c
add selection count
dctalbot Nov 4, 2019
a2b2ca8
move CreateAlertDialog under alerts dir
dctalbot Nov 4, 2019
63e6990
axe ye olde CreateAlertFab in favor of CreateAlertSpeedDial
dctalbot Nov 4, 2019
6b6b942
Merge remote-tracking branch 'origin/service-search-labels' into goal…
dctalbot Nov 4, 2019
515e67c
merge and refactor for new service filter container api
dctalbot Nov 4, 2019
b029657
use value for initial label key query
Forfold Nov 4, 2019
08abeec
pr comments
Forfold Nov 4, 2019
ed4d681
green tests
dctalbot Nov 4, 2019
2cd39dc
extract step0
dctalbot Nov 4, 2019
754fb17
extract step2
dctalbot Nov 4, 2019
5b30c14
extract step3
dctalbot Nov 4, 2019
1b955ae
extract step1
dctalbot Nov 4, 2019
c119c02
default to favorites only
dctalbot Nov 5, 2019
1f6a799
update key validation while searching
Forfold Nov 5, 2019
27832f6
cancel button on step0
dctalbot Nov 5, 2019
224c712
remove search var
Forfold Nov 5, 2019
d1074bc
enable default queries on search-selects
mastercactapus Nov 5, 2019
eb99cc8
Tab to next
dctalbot Nov 5, 2019
1c923a5
alert details as text area
dctalbot Nov 5, 2019
4c5a2a7
just call `makeQuerySelect` for `LabelKeySelect`
mastercactapus Nov 5, 2019
1c82af3
style step2
dctalbot Nov 5, 2019
ddb4fa6
add prop-derived variables in `makeQuerySelect`
mastercactapus Nov 5, 2019
8f721c9
recycle the Paper
dctalbot Nov 5, 2019
51b92ec
Merge remote-tracking branch 'origin/service-search-labels' into goal…
dctalbot Nov 5, 2019
a00f316
Merge branch 'master' into goal-379
dctalbot Nov 5, 2019
40cf9d6
summary -> review
dctalbot Nov 5, 2019
d156e98
textarea filles space
dctalbot Nov 5, 2019
8093b67
accessible tabbing
dctalbot Nov 5, 2019
6a39dda
rename speeddial option
dctalbot Nov 5, 2019
cfa71c3
add CREATE_ALERT_LIMIT
dctalbot Nov 5, 2019
4c916b3
hide AddAll if limit reached
dctalbot Nov 6, 2019
c214a41
OpenAll gets the axe
dctalbot Nov 6, 2019
86a31ca
alternative copy to clipboard util
dctalbot Nov 6, 2019
530006e
display url only
dctalbot Nov 6, 2019
d85ae58
nits
dctalbot Nov 6, 2019
2f29f79
match state names to graphQL field names
dctalbot Nov 6, 2019
9747d63
no message
Forfold Nov 6, 2019
c3aeabd
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
Forfold Nov 6, 2019
de3c0c3
field errors on lowercase field names
dctalbot Nov 6, 2019
e8280b3
hooks on speed-dial
dctalbot Nov 6, 2019
ac69981
optionalLabels
dctalbot Nov 6, 2019
acd8156
move CreateAlertSpeedDial out of /alerts/comonents
dctalbot Nov 6, 2019
1ec2ceb
jump to step0 if fieldErrors
dctalbot Nov 6, 2019
148584a
index as entrypoint, StepContent as main export
dctalbot Nov 6, 2019
359e9db
index as entrypoint, CreateAlertDialog as main export
dctalbot Nov 6, 2019
7ea9301
scrap the inaccessible styles on AddAll
dctalbot Nov 6, 2019
fa391f9
revert index exports
dctalbot Nov 6, 2019
2d90705
dialog height and details adjustments
Forfold Nov 6, 2019
c376e33
semantic <form with tabs submit
dctalbot Nov 6, 2019
9f0dd44
jump to step0 on field error
dctalbot Nov 6, 2019
8037bce
use Divider
dctalbot Nov 6, 2019
d32ae6d
style divider
dctalbot Nov 7, 2019
195bb9b
fix initial state on alert summary and details
Forfold Nov 7, 2019
3fe2b0d
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 7, 2019
328990c
set errorPolicy: all on mutations
dctalbot Nov 7, 2019
cc02482
display created alerts and services for failed alerts
dctalbot Nov 7, 2019
b9f5541
Display service list for failed alerts
dctalbot Nov 7, 2019
5666c75
revert to text field
Forfold Nov 7, 2019
7a3d042
require services field
Forfold Nov 7, 2019
5640bc1
rename files with title case
Forfold Nov 7, 2019
136eaae
fmt
Forfold Nov 7, 2019
b2b157d
use same primary color as icons for add all
Forfold Nov 7, 2019
3197fbc
move functions inside of export to avoid passing args
dctalbot Nov 7, 2019
807608e
return validation error for duplicate alert
arurao Nov 7, 2019
139fe85
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 7, 2019
4166d1a
fix dialog height css crashing mobile view
Forfold Nov 7, 2019
eaa9740
use same icon for copying
Forfold Nov 7, 2019
cbbcbee
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
Forfold Nov 7, 2019
e046c4e
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 7, 2019
cd30141
move useWidth src to top of comment
Forfold Nov 7, 2019
dafe56e
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 7, 2019
e689fcf
green tests
dctalbot Nov 7, 2019
0983859
create svc1 and svc2 beforeEach
dctalbot Nov 7, 2019
6375384
don't fetch service data for alert
dctalbot Nov 7, 2019
f28e498
window.open() -> <a />
dctalbot Nov 7, 2019
c52ac47
named export
dctalbot Nov 7, 2019
a570555
named export
dctalbot Nov 7, 2019
bb8ce85
named exports
dctalbot Nov 7, 2019
af8ec20
add alert tests back into services
dctalbot Nov 7, 2019
dea36b6
window.open() -> <a />
dctalbot Nov 7, 2019
89eed3b
key=index -> key=id
dctalbot Nov 7, 2019
9226ed4
key=index -> key=id
dctalbot Nov 7, 2019
4b0440e
key=index -> key=id
dctalbot Nov 7, 2019
90640b6
reversed an if
dctalbot Nov 7, 2019
369010a
show non-favs in addition to favs on mount
dctalbot Nov 7, 2019
7e3e496
refactor after realizing the first hook i ever wrote was soo weirdgit…
dctalbot Nov 7, 2019
5e9e19f
bool fn -> bool
dctalbot Nov 7, 2019
77bf44d
steps -> stepTitles
dctalbot Nov 7, 2019
2e3b2c3
handle failed query
dctalbot Nov 7, 2019
ed288db
use onExited callback to clear form
dctalbot Nov 8, 2019
e91b7aa
use .some() to break loop
dctalbot Nov 8, 2019
2daeaae
pass selectedServices through _.uniq()
dctalbot Nov 8, 2019
32cbedb
extract service key label pair parsing into util fn getServiceLabel
dctalbot Nov 8, 2019
21f242e
CREATE_ALERT_LIMIT as config var
dctalbot Nov 8, 2019
3165ad4
clear > clever
dctalbot Nov 8, 2019
6fb9d55
jump to step0 if field error onSubmit
dctalbot Nov 8, 2019
f7800f3
absURLSelector generates absolute urls
dctalbot Nov 11, 2019
e5b17f2
use absURLSelector
dctalbot Nov 11, 2019
ecc2f43
trim() details and summary onSubmit
dctalbot Nov 11, 2019
dd5a2c1
move style into makeStyles
dctalbot Nov 11, 2019
af1fdcc
name export
dctalbot Nov 11, 2019
cfbbcbe
remove comment re onError
dctalbot Nov 11, 2019
c21556b
remove url from comment
dctalbot Nov 11, 2019
e0e255c
Merge branch 'master' into goal-379
mastercactapus Nov 11, 2019
efc6d2f
dispatch push action instead of useHistory
mastercactapus Nov 11, 2019
3c4fa1e
useSelector with absURLSelector
mastercactapus Nov 11, 2019
ff9aebb
new apollo client with errors
mastercactapus Nov 11, 2019
13ac03a
add errorsByPath helper
mastercactapus Nov 11, 2019
e6ccfe7
create temp apollo client for useCreateAlerts()
dctalbot Nov 12, 2019
db0bb16
transition to use FormDialog
mastercactapus Nov 12, 2019
869aa14
Merge branch 'goal-379' of github.com:target/goalert into goal-379
mastercactapus Nov 12, 2019
a6bd608
summary->review
mastercactapus Nov 12, 2019
c3b5c3c
return alert FAB for service/alerts page
mastercactapus Nov 12, 2019
64d915c
add validation field err for service doesn't exist
arurao Nov 12, 2019
d5382e3
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
arurao Nov 12, 2019
71a2cb6
debounce service select input
mastercactapus Nov 12, 2019
60b10cc
Merge branch 'goal-379' of github.com:target/goalert into goal-379
mastercactapus Nov 12, 2019
fa368cb
error and loading messages
dctalbot Nov 12, 2019
df381a9
merge debounce
dctalbot Nov 12, 2019
870db92
check loading against disparate search/searchInput states
dctalbot Nov 12, 2019
2a9bfcd
update alerts test
mastercactapus Nov 12, 2019
ac339ab
Merge branch 'goal-379' of github.com:target/goalert into goal-379
mastercactapus Nov 12, 2019
195b6c8
don't wrap markdown in typography
mastercactapus Nov 12, 2019
8b16485
flip margin between searchInput and ChipContainer to allow for errors
dctalbot Nov 12, 2019
496d890
add ye old monitor button
Forfold Nov 12, 2019
02435c3
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
Forfold Nov 12, 2019
ab303ef
wrap markdown
mastercactapus Nov 12, 2019
5ef1d21
rm comments
dctalbot Nov 12, 2019
78a166e
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 12, 2019
54532e8
use button name according to ac
Forfold Nov 13, 2019
0a7a62d
constrain dialog height
Forfold Nov 13, 2019
ae278d2
make details optional
Forfold Nov 13, 2019
5c87824
add some margin to confirm step item content
Forfold Nov 13, 2019
6ae5012
margin for selected services text
Forfold Nov 13, 2019
bd65a55
fit key icon properly within service chip
Forfold Nov 13, 2019
4f98eb2
don't define components in render
mastercactapus Nov 13, 2019
fa17dd9
fix margin around markdown
Forfold Nov 13, 2019
184522f
add a marginal amount of margin to add all
Forfold Nov 13, 2019
a324d59
rename ss -> svcID
dctalbot Nov 14, 2019
e67496a
DRY createdAlertIDs
dctalbot Nov 14, 2019
5cf51c3
remove unused styles, shrink service form label
dctalbot Nov 14, 2019
f5adc07
Merge branch 'master' into goal-379
Forfold Nov 14, 2019
2dd398a
Merge branch 'master' into goal-379
Forfold Nov 14, 2019
dd0be96
consolidate copyToClipboard util
dctalbot Nov 14, 2019
6647c90
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 14, 2019
348f0cc
required? nah
Forfold Nov 14, 2019
aed82c0
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
Forfold Nov 14, 2019
90efea1
optional placement prop
dctalbot Nov 14, 2019
939c2d3
paint it red
dctalbot Nov 14, 2019
b461e74
new CreateAlertFab
dctalbot Nov 14, 2019
2dc44df
prepopulated service in new create alert dialog
dctalbot Nov 14, 2019
2785fc7
green tests
dctalbot Nov 14, 2019
9471420
services are no longer in a search select
dctalbot Nov 14, 2019
b1ea040
rm styles
dctalbot Nov 18, 2019
b8352e2
add optional onClick prop
dctalbot Nov 18, 2019
c95a896
add optional err prop
dctalbot Nov 18, 2019
edec02f
use Button's built-in href prop
dctalbot Nov 18, 2019
e00261d
pr tweaks
Forfold Nov 18, 2019
03535d0
Merge branch 'master' into goal-379
Forfold Nov 18, 2019
3e3c4a3
simplify search debounce
dctalbot Nov 18, 2019
24b818c
follow rules of hooks
dctalbot Nov 18, 2019
40e1b8b
update FormDialog button text
Forfold Nov 18, 2019
8d9e3e6
clean up error messaging
dctalbot Nov 18, 2019
abc39dd
reimplement transition on create alert fab to account for toast messages
Forfold Nov 18, 2019
9967a46
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 18, 2019
d6d9330
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 18, 2019
c15d36d
revert making first letter uppercase change
Forfold Nov 18, 2019
70d69df
remove unused hook
Forfold Nov 19, 2019
af2f0b3
rename FormDialog prop
Forfold Nov 19, 2019
7804be7
rm todo comments
dctalbot Nov 19, 2019
a7caf72
extract onNext function; prepopulated service will skip service selec…
dctalbot Nov 19, 2019
64a631f
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 19, 2019
8d1d56a
alert prop now implies fullscreen
dctalbot Nov 19, 2019
b641a1a
WIP recommit failing test wrt service favorites
dctalbot Nov 19, 2019
33c58af
don't use FormDialog for url-provided-error dialog
mastercactapus Nov 19, 2019
566fcd2
getServiceLabel unit test
dctalbot Nov 19, 2019
84ebe05
add additional test cases
mastercactapus Nov 19, 2019
467d312
Merge branch 'master' into goal-379
Forfold Nov 19, 2019
9e1c487
merge master
dctalbot Nov 19, 2019
d4de151
yarn
dctalbot Nov 19, 2019
760fde2
set as alert
Forfold Nov 19, 2019
718b3d1
i don't know what tense to use
Forfold Nov 19, 2019
788cc9b
omit service selection step title if serviceID provided
dctalbot Nov 21, 2019
c3cdc56
test favorites in create alert dialog
dctalbot Nov 21, 2019
0c55a13
merge master
dctalbot Nov 21, 2019
05cc59b
lint
dctalbot Nov 21, 2019
bc4959d
Merge branch 'master' into goal-379
arurao Nov 25, 2019
75c9955
Merge branch 'master' into goal-379
arurao Nov 25, 2019
334926c
pass className as prop
dctalbot Nov 25, 2019
2fb442b
use ServiceAvatar
dctalbot Nov 25, 2019
5387de7
Assume we will always get data.service, loading or error
dctalbot Nov 25, 2019
53f5d94
Use absURL to wrap all GoAlert links, as the UI won't always be mount…
dctalbot Nov 25, 2019
6f92aa4
Merge branch 'goal-379' of https://github.com/target/goalert into goa…
dctalbot Nov 25, 2019
7295d15
Merge branch 'master' into goal-379
dctalbot Nov 25, 2019
60c18bb
Merge branch 'master' into goal-379
arurao Nov 26, 2019
5f29c15
make search-select items generic
mastercactapus Nov 26, 2019
62d8e85
Merge branch 'master' into goal-379
arurao Nov 26, 2019
73a8393
Merge branch 'master' into goal-379
arurao Nov 26, 2019
f67353f
Merge branch 'master' into goal-379
mastercactapus Nov 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions util/errutil/maperror.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@ func MapDBError(err error) error {
return validation.NewFieldError("RemoveUserID", "user does not exist")
case "user_overrides_tgt_schedule_id_fkey":
return validation.NewFieldError("TargetID", "schedule does not exist")
case "alerts_services_id_fkey":
return validation.NewFieldError("ServiceID", "service does not exist")
}
case "23505": // unique constraint
if strings.HasPrefix(dbErr.ConstraintName, dbErr.TableName+"_name") || dbErr.ConstraintName == "auth_basic_users_username_key" {
@@ -41,6 +43,9 @@ func MapDBError(err error) error {
if dbErr.ConstraintName == "heartbeat_monitor_name_service_id" {
return validation.NewFieldError("Name", "heartbeat monitor already exists with that name")
}
if dbErr.ConstraintName == "idx_no_alert_duplicates" {
return validation.NewFieldError("", "duplicate alert already exists")
}
case "23514": // check constraint
newErr := mapLimitError(dbErr)
if newErr != nil {
163 changes: 163 additions & 0 deletions web/src/app/alerts/CreateAlertDialog/CreateAlertDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import React, { useState, useEffect } from 'react'
import p from 'prop-types'
import {
makeStyles,
Button,
Grid,
Stepper,
Step,
StepLabel,
Typography,
} from '@material-ui/core'
import OpenInNewIcon from '@material-ui/icons/OpenInNew'
import _ from 'lodash-es'

import { useCreateAlerts } from './useCreateAlerts'
import { fieldErrors, allErrors } from '../../util/errutil'
import FormDialog from '../../dialogs/FormDialog'
import { CreateAlertForm } from './StepContent/CreateAlertForm'
import { CreateAlertReview } from './StepContent/CreateAlertReview'

const pluralize = num => (num !== 1 ? 's' : '')

const useStyles = makeStyles(theme => ({
dialog: {
[theme.breakpoints.up('md')]: {
height: '65vh',
},
},
flexGrow: {
flexGrow: 1,
},
}))

export default function CreateAlertDialog(props) {
const classes = useStyles()
const [step, setStep] = useState(0)
const [value, setValue] = useState({
summary: '',
details: '',
serviceIDs: props.serviceID ? [props.serviceID] : [],
})
const [mutate, { data, loading, error }, getSvcID] = useCreateAlerts(value)

const fieldErrs = fieldErrors(error)
const hasValidationError = fieldErrs.some(e =>
['summary', 'details'].includes(e.field),
)

useEffect(() => {
if (hasValidationError) {
setStep(0)
}
}, [hasValidationError])

const hasCompleted = Boolean(data) && !hasValidationError
const currentStep = loading ? 2 : step

const stepTitles = props.serviceID
? ['Alert Info', 'Confirm']
: ['Alert Info', 'Service Selection', 'Confirm']

const onNext = () => {
if (currentStep === 0 && props.serviceID) {
setStep(currentStep + 2)
} else if (currentStep < 2) {
setStep(currentStep + 1)
}
}

let review, reviewTitle
if (hasCompleted) {
const createdAlertIDs = _.chain(data)
.values()
.filter()
.map(a => a.id)
.value()

const failedServices = allErrors(error).map(e => ({
id: getSvcID(e.path),
message: e.message,
}))

const failMessage = failedServices.length
? `(${failedServices.length} failed)`
: ''

const titleMessage = `Successfully created ${
createdAlertIDs.length
} alert${pluralize(createdAlertIDs.length)} ${failMessage}`

reviewTitle = (
<Grid container>
<Grid item>
<Typography>{titleMessage}</Typography>
</Grid>
<Grid item className={classes.flexGrow} />
<Grid item>
<Button
variant='contained'
color='primary'
size='small'
endIcon={<OpenInNewIcon />}
href={`/alerts?allServices=1&filter=all&search=${encodeURIComponent(
value.summary,
)}`}
target='_blank'
rel='noopener noreferrer'
>
Monitor Alerts
</Button>
</Grid>
</Grid>
)

review = (
<CreateAlertReview
createdAlertIDs={createdAlertIDs}
failedServices={failedServices}
/>
)
}

return (
<FormDialog
title='Create New Alert'
alert={hasCompleted}
primaryActionLabel={hasCompleted ? 'Done' : null}
onClose={props.onClose}
loading={loading}
subTitle={
reviewTitle || (
<Stepper activeStep={currentStep}>
{stepTitles.map((title, idx) => (
<Step key={idx}>
<StepLabel>{title}</StepLabel>
</Step>
))}
</Stepper>
)
}
form={
review || (
<CreateAlertForm
activeStep={currentStep}
value={value}
onChange={newValue => setValue(newValue)}
disabled={loading}
errors={fieldErrors(error)}
/>
)
}
PaperProps={{ className: classes.dialog }}
onSubmit={() => (hasCompleted ? props.onClose() : mutate())}
onNext={currentStep < 2 ? onNext : null}
onBack={currentStep > 0 ? () => setStep(currentStep - 1) : null}
/>
)
}

CreateAlertDialog.propTypes = {
onClose: p.func.isRequired,
serviceID: p.string,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react'
import { Typography, Grid, Divider } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import { ServiceChip } from '../../../util/Chips'
import { FormField } from '../../../forms'
import Markdown from '../../../util/Markdown'

const useStyles = makeStyles({
itemContent: {
marginTop: '0.5em',
},
itemTitle: {
paddingBottom: 0,
},
markdown: {
'& p': {
marginBlockStart: 0,
marginBlockEnd: 0,
whiteSpace: 'pre-wrap',
},
},
})

export function CreateAlertConfirm() {
const classes = useStyles()

const renderItem = ({ name, label, value, children }) => (
<Grid item xs={12}>
<Typography
variant='subtitle1'
component='h3'
className={classes.itemTitle}
>
{label}
</Typography>

<Divider />

<div className={classes.itemContent}>
{children ||
(name === 'details' ? (
<Typography
variant='body1'
className={classes.markdown}
component={Markdown}
value={value}
/>
) : (
<Typography variant='body1' component='p'>
{value}
</Typography>
))}
</div>
</Grid>
)

return (
<Grid container spacing={2}>
<FormField name='summary' label='Summary' required render={renderItem} />
<FormField name='details' label='Details' render={renderItem} />

<FormField
label='Selected Services'
name='serviceIDs'
render={({ value, ...otherProps }) =>
renderItem({
...otherProps,
label: `Selected Services (${value.length})`,
children: value.map(id => (
<ServiceChip
key={id}
clickable={false}
id={id}
style={{ margin: 3 }}
onClick={e => e.preventDefault()}
/>
)),
})
}
/>
</Grid>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import p from 'prop-types'
import { FormContainer, FormField } from '../../../forms'
import { CreateAlertInfo } from './CreateAlertInfo'
import { CreateAlertServiceSelect } from './CreateAlertServiceSelect'
import { CreateAlertConfirm } from './CreateAlertConfirm'

export function CreateAlertForm(props) {
const { activeStep, ...otherProps } = props

return (
<FormContainer optionalLabels {...otherProps}>
{activeStep === 0 && <CreateAlertInfo />}
{activeStep === 1 && (
<FormField
required
render={props => <CreateAlertServiceSelect {...props} />}
name='serviceIDs'
/>
)}
{activeStep === 2 && <CreateAlertConfirm />}
</FormContainer>
)
}

CreateAlertForm.propTypes = {
activeStep: p.number.isRequired,
value: p.shape({
summary: p.string,
details: p.string,
serviceIDs: p.arrayOf(p.string),
}),
errors: p.arrayOf(
p.shape({
field: p.oneOf(['summary', 'details', 'serviceID']).isRequired,
message: p.string.isRequired,
}),
),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { Grid, TextField } from '@material-ui/core'
import { FormField } from '../../../forms'

export function CreateAlertInfo() {
return (
<Grid container spacing={2}>
<Grid item xs={12}>
<FormField
fullWidth
label='Alert Summary'
name='summary'
required
component={TextField}
/>
</Grid>
<Grid item xs={12}>
<FormField
fullWidth
multiline
rows={7}
variant='outlined'
placeholder='Alert Details'
name='details'
component={TextField}
/>
</Grid>
</Grid>
)
}
Loading