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

user contact method edit dialog dest #3720

Merged
merged 23 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
37 changes: 36 additions & 1 deletion graphql2/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions graphql2/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions graphql2/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,13 @@ input CreateUserNotificationRuleInput {

input UpdateUserContactMethodInput {
id: ID!
type: ContactMethodType

dest: DestinationInput @experimental(flagName: "dest-types")
mastercactapus marked this conversation as resolved.
Show resolved Hide resolved

name: String

# Only value or dest should be used at a time, never both.
value: String
@deprecated(
reason: "Updating value is not supported, delete and create a new contact method instead."
Expand Down
20 changes: 19 additions & 1 deletion web/src/app/users/UserContactMethodEditDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import FormDialog from '../dialogs/FormDialog'
import UserContactMethodForm from './UserContactMethodForm'
import { pick } from 'lodash'
import { useQuery } from 'urql'
import { useExpFlag } from '../util/useExpFlag'
import { ContactMethodType, StatusUpdateState } from '../../schema'
import UserContactMethodEditDialogDest from './UserContactMethodEditDialogDest'

const query = gql`
query ($id: ID!) {
Expand All @@ -31,8 +33,12 @@ type Value = {
value: string
statusUpdates?: StatusUpdateState
}
type UserContactMethodEditDialogProps = {
onClose: () => void
contactMethodID: string
}

export default function UserContactMethodEditDialog({
function UserContactMethodEditDialog({
onClose,
contactMethodID,
}: {
Expand Down Expand Up @@ -96,3 +102,15 @@ export default function UserContactMethodEditDialog({
/>
)
}

export default function UserContactMethodEditDialogSwitch(
ethan-haynes marked this conversation as resolved.
Show resolved Hide resolved
props: UserContactMethodEditDialogProps,
): React.ReactNode {
const isDestTypesSet = useExpFlag('dest-types')

if (isDestTypesSet) {
return <UserContactMethodEditDialogDest {...props} />
ethan-haynes marked this conversation as resolved.
Show resolved Hide resolved
}

return <UserContactMethodEditDialog {...props} />
}
251 changes: 251 additions & 0 deletions web/src/app/users/UserContactMethodEditDialogDest.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import React from 'react'
import type { Meta, StoryObj } from '@storybook/react'
import UserContactMethodEditDialogDest from './UserContactMethodEditDialogDest'
import { expect, userEvent, waitFor, screen } from '@storybook/test'
import {
handleDefaultConfig,
// defaultConfig,
handleExpFlags,
} from '../storybook/graphql'
import { useArgs } from '@storybook/preview-api'
import { HttpResponse, graphql } from 'msw'
import { DestFieldValueError, InputFieldError } from '../util/errtypes'

const meta = {
title: 'users/UserContactMethodEditDialogDest',
component: UserContactMethodEditDialogDest,
tags: ['autodocs'],
parameters: {
docs: {
story: {
inline: false,
iframeHeight: 500,
},
},
msw: {
handlers: [
handleDefaultConfig,
handleExpFlags('dest-types'),
graphql.query('userCm', () => {
return HttpResponse.json({
data: {
userContactMethod: {
id: '00000000-0000-0000-0000-000000000000',
name: 'single-field contact method',
dest: {
type: 'single-field',
values: [
{
fieldID: 'phone-number',
value: '+15555555555',
label: '+1 555-555-5555',
},
],
value: 'http://localhost:8080',
},
disabled: false,
pending: false,
},
},
})
}),
graphql.mutation('updateUserContactMethod', ({ variables: vars }) => {
if (vars.input.name === 'error-test') {
return HttpResponse.json({
data: null,
errors: [
{
message: 'This is a dest field-error',
path: ['updateUserContactMethod', 'input', 'dest'],
extensions: {
code: 'INVALID_DEST_FIELD_VALUE',
fieldID: 'phone-number',
},
} satisfies DestFieldValueError,
{
message: 'This indicates an invalid destination type',
path: ['updateUserContactMethod', 'input', 'dest', 'type'],
extensions: {
code: 'INVALID_INPUT_VALUE',
},
} satisfies InputFieldError,
{
message: 'Name error',
path: ['updateUserContactMethod', 'input', 'name'],
extensions: {
code: 'INVALID_INPUT_VALUE',
},
} satisfies InputFieldError,
{
message: 'This is a generic error',
},
],
})
}
return HttpResponse.json({
data: {
updateUserContactMethod: {
id: '00000000-0000-0000-0000-000000000000',
},
},
})
}),
graphql.query('ValidateDestination', ({ variables: vars }) => {
return HttpResponse.json({
data: {
destinationFieldValidate:
vars.input.value === '@slack' ||
vars.input.value === '+12225558989' ||
vars.input.value === 'valid@email.com',
},
})
}),
],
},
},
render: function Component(args) {
const [, setArgs] = useArgs()
const onClose = (contactMethodID: string | undefined): void => {
if (args.onClose) args.onClose(contactMethodID)
setArgs({ value: contactMethodID })
}
return <UserContactMethodEditDialogDest {...args} onClose={onClose} />
},
} satisfies Meta<typeof UserContactMethodEditDialogDest>

export default meta
type Story = StoryObj<typeof meta>

export const SingleField: Story = {
args: {
contactMethodID: '00000000-0000-0000-0000-000000000000',
},
play: async () => {
await userEvent.click(await screen.findByLabelText('Destination Type'))

// incorrectly believes that the following fields are not visible
ethan-haynes marked this conversation as resolved.
Show resolved Hide resolved
expect(
await screen.findByRole('option', { hidden: true, name: 'Single Field' }),
).toBeInTheDocument()
expect(
await screen.findByRole('option', { hidden: true, name: 'Multi Field' }),
).toBeInTheDocument()
expect(
await screen.findByText('This is disabled'), // does not register as an option
).toBeInTheDocument()
expect(
await screen.findByRole('option', {
hidden: true,
name: 'Single With Status',
}),
).toBeInTheDocument()
expect(
await screen.findByRole('option', {
hidden: true,
name: 'Single With Required Status',
}),
).toBeInTheDocument()
},
}

export const MultiField: Story = {
args: {
contactMethodID: '00000000-0000-0000-0000-000000000000',
},
play: async () => {
// Select the multi-field Dest Type
await userEvent.click(await screen.findByLabelText('Destination Type'))
await userEvent.click(
await screen.findByRole('option', { hidden: true, name: 'Multi Field' }),
)

await expect(await screen.findByLabelText('Name')).toBeVisible()
await expect(await screen.findByLabelText('Destination Type')).toBeVisible()
await expect(await screen.findByLabelText('First Item')).toBeVisible()
await expect(await screen.findByLabelText('Second Item')).toBeVisible()
await expect(await screen.findByLabelText('Third Item')).toBeVisible()
},
}

export const StatusUpdates: Story = {
args: {
contactMethodID: '00000000-0000-0000-0000-000000000000',
},
play: async () => {
// Open option select
await userEvent.click(await screen.findByLabelText('Destination Type'))
await userEvent.click(
await screen.findByRole('option', { hidden: true, name: 'Single Field' }),
)
await expect(
await screen.findByLabelText(
'Send alert status updates (not supported for this type)',
),
).toBeDisabled()

await userEvent.click(await screen.findByLabelText('Destination Type'))
await userEvent.click(
await screen.findByRole('option', {
hidden: true,
name: 'Single With Status',
}),
)
await expect(
await screen.findByLabelText('Send alert status updates'),
).not.toBeDisabled()

await userEvent.click(await screen.findByLabelText('Destination Type'))
await userEvent.click(
await screen.findByRole('option', {
hidden: true,
name: 'Single With Required Status',
}),
)
await expect(
await screen.findByLabelText(
'Send alert status updates (cannot be disabled for this type)',
),
).toBeDisabled()
},
}

export const ErrorField: Story = {
args: {
contactMethodID: '00000000-0000-0000-0000-000000000000',
},

play: async () => {
await userEvent.clear(await screen.findByLabelText('Name'))
await userEvent.type(await screen.findByLabelText('Name'), 'error-test')
await userEvent.type(
await screen.findByPlaceholderText('11235550123'),
'123',
)

const submitButton = await screen.findByText('Submit')
await userEvent.click(submitButton)

// response should set error on all fields plus the generic error
await waitFor(
async () => {
await expect(await screen.findByLabelText('Name')).toBeInvalid()

await expect(await screen.findByText('Name error')).toBeVisible()

await expect(
// mui puts aria-invalid on the input, but not the combobox (which the label points to)
await screen.findByText('This indicates an invalid destination type'),
).toBeVisible()
await expect(await screen.findByLabelText('Phone Number')).toBeInvalid()
await expect(
await screen.findByText('This is a dest field-error'),
).toBeVisible()

await expect(
await screen.findByText('This is a generic error'),
).toBeVisible()
},
{ timeout: 5000 },
)
},
}
Loading
Loading