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

feat: approvals for mrf #7636

Merged
merged 47 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f82c62a
feat: add empty UT for approvals
kevin9foong Sep 2, 2024
8be24bf
feat: add approval outcome email template
kevin9foong Sep 2, 2024
d9c5143
feat: create common FormStepWithHeader component for editBlock items
kevin9foong Sep 2, 2024
e1e554c
feat: approval toggle and field in edit workflow step block
kevin9foong Sep 2, 2024
9ba9730
feat: enable saving of approval_step
kevin9foong Sep 2, 2024
d2b3603
feat: add validation of approval field selection
kevin9foong Sep 2, 2024
6e3f226
feat: add use for approvals badge for yes/no field
kevin9foong Sep 2, 2024
226746f
feat: implement sending of approval emails in BE
kevin9foong Sep 3, 2024
2ab470e
feat: validate that approval fields are yes/no on update
kevin9foong Sep 3, 2024
f78cda7
fix: out of bounds index error when re-submitting mrf via response link
kevin9foong Sep 3, 2024
1eb6969
fix: watch values needed for validation
kevin9foong Sep 5, 2024
6ef3d16
fix: add default values for sendMrfOutcomeEmails isApproval and isRej…
kevin9foong Sep 5, 2024
b5f74af
feat: validate that approval field must be in same step's edit fields
kevin9foong Sep 5, 2024
63dda46
feat: log error when checkIsStepRejected fails
kevin9foong Sep 5, 2024
e9ff39d
fix: remove duplicates in email sending using uniq
kevin9foong Sep 5, 2024
35e241c
feat: create REST api for workflow steps
kevin9foong Sep 6, 2024
40aea0d
feat: implement workflow step validation
kevin9foong Sep 6, 2024
bd645e8
feat: display field deleted state
kevin9foong Sep 6, 2024
fb054da
chore: remove stray comment
kevin9foong Sep 6, 2024
03a3919
feat: clear value if deleted
kevin9foong Sep 6, 2024
6c0abcc
feat: add joi validation for mongodb objectId of hex and 24 length st…
kevin9foong Sep 6, 2024
5a6d3dc
fix: remove workflow from updateSettings
kevin9foong Sep 6, 2024
9672df6
feat: implement mrf builder v8
kevin9foong Sep 9, 2024
784523d
feat: handle error message when admin does not select respondent type…
kevin9foong Sep 9, 2024
2c23080
chore: improve rationale comment for getValueIfNotDeleted
kevin9foong Sep 9, 2024
ce3ec38
feat: make error badge more explicit by making it red
kevin9foong Sep 10, 2024
a3309df
feat: only display use for approvals badge for mrf
kevin9foong Sep 11, 2024
4777e9a
feat: add storybook for FieldListDrawer to visual test use for approvals
kevin9foong Sep 11, 2024
6030075
feat: add chromatic stories for mrf edit step block
kevin9foong Sep 11, 2024
8dd1b2e
feat: add chromatic stories for inactive workflow builder state
kevin9foong Sep 11, 2024
a880124
feat: add BE validation that first step of MRF workflow cannot be app…
kevin9foong Sep 11, 2024
3b50321
feat: add BE unit tests for approvals
kevin9foong Sep 12, 2024
4d0d0e8
chore: add beta flags for approvals
kevin9foong Sep 12, 2024
501c3fa
fix: chromatic visual nits
kevin9foong Sep 13, 2024
538efc6
feat: add header to mrf email notif
kevin9foong Sep 13, 2024
222d777
fix: make workflow content info box 44px
kevin9foong Sep 13, 2024
7d6826c
chore: Remove capitalisations for Outcome and Notifications to comply…
kevin9foong Sep 16, 2024
66b4fea
chore: remove unused props
KenLSM Sep 16, 2024
3452dd1
chore: remove stray _ in log action
KenLSM Sep 16, 2024
e80e615
chore: remove unused imports
KenLSM Sep 16, 2024
8d13285
fix: pr comments
kevin9foong Sep 18, 2024
8247e05
fix: use edit name across form
kevin9foong Sep 19, 2024
85ea0cf
feat: refactor mrf controller to move business logic to service
kevin9foong Sep 19, 2024
0b13dfd
feat: add UT for controller and service for mrf
kevin9foong Sep 20, 2024
eb13119
fix: remove throw error in map
kevin9foong Sep 25, 2024
ff982b1
fix: allow empty lcov
KenLSM Sep 25, 2024
9dfeaff
Merge remote-tracking branch 'origin/exp/coveralls' into feat/mrf-app…
KenLSM Sep 25, 2024
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
1 change: 1 addition & 0 deletions frontend/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface BadgeProps extends ChakraBadgeProps {
* The theme of the tag to display
*/
variant?: BadgeVariants
colorScheme?: string
}

export const Badge = (props: BadgeProps): JSX.Element => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const FormLabel = ({
>
<Icon
ml="0.5rem"
mb="0.1rem"
kevin9foong marked this conversation as resolved.
Show resolved Hide resolved
color="secondary.500"
as={tooltipVariant === 'info' ? BxsInfoCircle : BxsHelpCircle}
verticalAlign="middle"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export interface RadioProps
* please use the props `maxWidth` or `width` to configure
*/
isFullWidth?: boolean
/**
* If `true`, the radio children will occupy the full width of the radio container.
*/
isLabelFullWidth?: boolean
/**
* Background and shadow colors.
*/
Expand Down Expand Up @@ -121,6 +125,7 @@ export const Radio = forwardRef<RadioProps, 'input'>(
spacing = '0.5rem',
children,
isFullWidth,
isLabelFullWidth = false,
...rest
} = omitThemingProps(props)

Expand Down Expand Up @@ -203,6 +208,7 @@ export const Radio = forwardRef<RadioProps, 'input'>(
}

const labelStyles: SystemStyleObject = {
width: isLabelFullWidth ? 'full' : undefined,
userSelect: 'none',
marginStart: spacing,
...styles.label,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { DragDropContext } from 'react-beautiful-dnd'
KenLSM marked this conversation as resolved.
Show resolved Hide resolved
import { StoryFn } from '@storybook/react'

import { FormResponseMode } from '~shared/types'

import { getAdminFormView } from '~/mocks/msw/handlers/admin-form'

import { StoryRouter } from '~utils/storybook'

import { CreatePageSidebarProvider } from '~features/admin-form/create/common'

import { FieldListDrawer } from '..'

export default {
component: FieldListDrawer,
title:
'Features/AdminForm/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer',
parameters: {
msw: [getAdminFormView({ mode: FormResponseMode.Encrypt })],
},
decorators: [
StoryRouter({ initialEntries: ['/12345'], path: '/:formId' }),
(Story: StoryFn) => (
// eslint-disable-next-line @typescript-eslint/no-empty-function
<DragDropContext onDragEnd={() => {}}>
<CreatePageSidebarProvider>
<Story />
</CreatePageSidebarProvider>
</DragDropContext>
),
],
}

const encryptModeHandlers = [
getAdminFormView({ mode: FormResponseMode.Encrypt }),
]

const mrfModeHandlers = [
getAdminFormView({ mode: FormResponseMode.Multirespondent }),
]

export const EncryptMode = {
parameters: {
msw: encryptModeHandlers,
},
}

export const MrfMode = {
parameters: {
msw: mrfModeHandlers,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import {
} from 'react-beautiful-dnd'
import { Box, BoxProps, forwardRef, Icon, Stack, Text } from '@chakra-ui/react'

import { FormResponseMode } from '~shared/types'
import { BasicField, MyInfoAttribute } from '~shared/types/field'

import { useIsMobile } from '~hooks/useIsMobile'
import Badge from '~components/Badge'

import {
BASICFIELD_TO_DRAWER_META,
MYINFO_FIELD_TO_DRAWER_META,
} from '~features/admin-form/create/constants'
import { useUser } from '~features/user/queries'

import { useCreateTabForm } from '../../useCreateTabForm'
import {
Expand Down Expand Up @@ -68,7 +71,6 @@ interface DraggableMyInfoFieldOptionProps
export const DraggableBasicFieldListOption = ({
fieldType,
index,
children,
isDisabled,
...props
}: DraggableBasicFieldOptionProps): JSX.Element => {
Expand Down Expand Up @@ -111,7 +113,6 @@ export const DraggableBasicFieldListOption = ({
export const DraggableMyInfoFieldListOption = ({
fieldType,
index,
children,
isDisabled,
...props
}: DraggableMyInfoFieldOptionProps): JSX.Element => (
Expand Down Expand Up @@ -149,12 +150,16 @@ export const DraggableMyInfoFieldListOption = ({

export const BasicFieldOption = forwardRef<BasicFieldOptionProps, 'button'>(
({ fieldType, isDisabled, ...props }, ref) => {
// TODO: (MRF-email-notif) Remove isTest and useUser when approvals is out of beta
const isTest = process.env.NODE_ENV === 'test'
const { user } = useUser()
const meta = useMemo(
() => BASICFIELD_TO_DRAWER_META[fieldType],
[fieldType],
)
const { data: form } = useCreateTabForm()
const numFields = useMemo(() => form?.form_fields?.length ?? 0, [form])
const isMrf = form?.responseMode === FormResponseMode.Multirespondent
const numFields = form?.form_fields?.length ?? 0

const newFieldMeta = useMemo(
() => getFieldCreationMeta(fieldType),
Expand All @@ -178,6 +183,14 @@ export const BasicFieldOption = forwardRef<BasicFieldOptionProps, 'button'>(
>
<Icon fontSize="1.5rem" as={meta.icon} />
<Text textStyle="body-1">{meta.label}</Text>
{/* TODO: (MRF-email-notif) Remove isTest and betaFlag check when approvals is out of beta */}
{isTest || user?.betaFlags?.mrfEmailNotifications ? (
isMrf && fieldType === BasicField.YesNo ? (
<Badge maxW="100%" variant="subtle" colorScheme="secondary">
<Text noOfLines={1}>Use for approvals</Text>
</Badge>
) : null
) : null}
</FieldListOption>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ export const SaveActionGroup = ({
<Flex
justify="space-between"
align="center"
py="0.375rem"
px={{ base: '1rem', md: '2rem' }}
borderTop="1px solid"
borderColor="neutral.300"
mt="1.5rem"
px={{ base: '1.5rem', md: '2rem' }}
>
{handleDelete ? (
<IconButton
Expand All @@ -51,7 +49,7 @@ export const SaveActionGroup = ({
w="100%"
>
<Button
isLoading={isLoading}
isDisabled={isLoading}
onClick={handleSubmit}
isFullWidth={isMobile}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ interface FieldLogicBadgeProps {
*/
export const FieldLogicBadge = ({
field,
defaults = { variant: 'error', message: 'Field not found' },
defaults = {
variant: 'error',
message: 'This field was deleted and has been removed from your workflow',
},
}: FieldLogicBadgeProps) => {
const fieldMeta = useMemo(
() => (field ? BASICFIELD_TO_DRAWER_META[field.fieldType] : null),
Expand All @@ -41,6 +44,14 @@ export const FieldLogicBadge = ({
}
}, [defaults.variant, fieldMeta])

const badgeColorScheme = useMemo(() => {
if (fieldMeta) return undefined
if (defaults.variant === 'error') {
return 'danger'
}
return undefined
}, [defaults.variant, fieldMeta])

const tooltipLabel = useMemo(
() => (!fieldMeta ? defaults.message : `${fieldMeta.label} field`),
[fieldMeta, defaults.message],
Expand All @@ -57,7 +68,7 @@ export const FieldLogicBadge = ({
}, [defaults.variant, fieldMeta])

return (
<LogicBadge display="inline-flex">
<LogicBadge display="inline-flex" colorScheme={badgeColorScheme}>
<Stack direction="row" spacing="0.25rem" maxW="100%" align="center">
<Tooltip placement="top" label={tooltipLabel}>
<Box display="inline-flex" alignItems="center">
Expand Down
Loading
Loading