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(v2/logic): render empty and populated logic page, add mobile variant of builder sidebar #3390

Merged
merged 42 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f21b36d
refactor: use BasicField to human readable strings and icon gen fns
karrui Feb 3, 2022
4ea7b8f
feat: add initial EmptyLogic component
karrui Feb 3, 2022
9ecdc96
feat: add initial stories for logic
karrui Feb 3, 2022
71ab371
feat: add mobile variant of builder sidebar (bottom bar?)
karrui Feb 3, 2022
c4d0af1
feat: add mobile styling to builder design view
karrui Feb 3, 2022
25a2414
feat: add BuilderLogicContext to store logic state
karrui Feb 3, 2022
926279b
feat(theme): add Divider custom theme
karrui Feb 3, 2022
83d52f8
feat(NewLogicBlock): add (dumb) new logic component
karrui Feb 3, 2022
329de2a
feat: update story to be wrapped with BuilderLogicProvider
karrui Feb 7, 2022
74da140
fix(shared/types): update form_logics type to LogicDto
karrui Feb 8, 2022
630a6b7
feat: return form logics and id map in BuilderLogicContext
karrui Feb 8, 2022
b0dc971
feat: add LogicBlock and related subcomponents to render each block
karrui Feb 8, 2022
f6fb7c3
feat: render LogicBlocks in LogicContent component
karrui Feb 8, 2022
419ba9d
feat(story): update story to render logic page when there is logic
karrui Feb 8, 2022
fad9cef
feat: add non-working Add logic button
karrui Feb 8, 2022
1cf16f3
feat: add mobile styling to BuilderLogic page (and add stories)
karrui Feb 8, 2022
e664ce0
feat: add mobile styling for NewLogicBlock component
karrui Feb 8, 2022
385af7a
feat(NewLogicBlock): add mobile (and focus) styling
karrui Feb 8, 2022
e1cea35
feat: trigger new logic block on add logic button click
karrui Feb 8, 2022
47c5aba
fix(LogicBlock): add index to mapped components
karrui Feb 8, 2022
86b3f2e
fix(Footer): remove divider borderColor
karrui Feb 8, 2022
c3c5c98
style: set automatic overflowY on BuilderLogic content
karrui Feb 14, 2022
d7f8951
style(BuilderTab): update styles of mobile builder tabs, add draggable
karrui Feb 14, 2022
814e758
style(LogicContent): update spacing between blocks to 1rem
karrui Feb 14, 2022
e42130e
fix: add LogicDto to FormDtoBase instead of FormBase
karrui Feb 15, 2022
a5dd988
ref: coalesce map constants to BASICFIELD_TO_SIDEBAR_META
karrui Feb 15, 2022
317a925
feat(BuilderLogicContext): add JSDoc
karrui Feb 15, 2022
4ba9652
ref(BuilderLogicContext): remove redundant function creations
karrui Feb 15, 2022
1ca5973
fix(Logic): update floating action button to be correctly sticky
karrui Feb 21, 2022
9c5c7b6
Merge branch 'form-v2/develop' into form-v2/logic/logic-layout-1
karrui Feb 23, 2022
b537083
Merge branch 'form-v2/develop' into form-v2/logic/logic-layout-1
karrui Feb 23, 2022
8593393
fix: update logic imports to account for folder rename
karrui Feb 23, 2022
e0d2e28
feat: extract MobileCreatePageBottomBar from CreatePageSidebar
karrui Feb 23, 2022
58192c4
style: update container element styling to accommodate sticky scroll
karrui Feb 23, 2022
f27ca5b
Merge branch 'form-v2/develop' into form-v2/logic/logic-layout-1
karrui Feb 24, 2022
77f3aa1
feat(constants): update HomeNo label to Sentence case
karrui Mar 1, 2022
4558da7
ref: move BuilderLogicProvider into CreatePageLogicTab component
karrui Mar 1, 2022
a03a669
feat(BuilderLogicContext): replace context with zustand store
karrui Mar 1, 2022
1afdb43
style(EmptyLogic): add row gap to allowed logic fields display
karrui Mar 1, 2022
f232fc0
style(LogicTab): add correct styling/padding to container
karrui Mar 1, 2022
a1e8b7e
style(EmptyLogic): allow fields mobile gaps === desktop
karrui Mar 7, 2022
1f0cad7
Merge branch 'form-v2/develop' into form-v2/logic/logic-layout-1
karrui Mar 8, 2022
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/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type { BadgeProps } from './Badge'
export { Badge as default } from './Badge'
2 changes: 1 addition & 1 deletion frontend/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const Footer = ({
))}
</Wrap>
</Footer.Section>
<Divider color={`${textColorScheme}.300`} my="1.5rem" />
<Divider my="1.5rem" />
<Footer.Section>
<Box>
<Text
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/features/admin-form/create/CreatePage.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { Flex } from '@chakra-ui/react'

import { CreatePageSidebar } from './common/components/BuilderSidebar'
import {
CreatePageSidebar,
MobileCreatePageBottomBar,
} from './common/components/BuilderSidebar'
import { CreatePageContent } from './common/components/CreatePageContent'
import { CreatePageDrawerProvider } from './CreatePageDrawerContext'

export const CreatePage = (): JSX.Element => {
return (
<Flex h="100%" w="100%" overflow="auto" bg="neutral.200" direction="row">
<Flex
h="100%"
w="100%"
overflow="auto"
bg="neutral.200"
direction={{ base: 'column', md: 'row' }}
>
<CreatePageDrawerProvider>
<CreatePageSidebar />
<CreatePageContent />
<MobileCreatePageBottomBar />
</CreatePageDrawerProvider>
</Flex>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ export const BuilderAndDesignContent = ({
}, [clearActiveField, clearFieldToCreate])

return (
<Flex flex={1} bg="neutral.200">
<Flex flex={1} bg="neutral.200" overflow="auto">
<Flex
m="2rem"
m={{ base: 0, md: '2rem' }}
mb={0}
flex={1}
bg="primary.100"
p="2.5rem"
bg={{ base: 'secondary.100', md: 'primary.100' }}
p={{ base: '1.5rem', md: '2.5rem' }}
justify="center"
overflow="auto"
>
<Flex
h="fit-content"
bg="white"
p="2.5rem"
p={{ base: 0, md: '2.5rem' }}
maxW="57rem"
w="100%"
flexDir="column"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo } from 'react'
import { Flex } from '@chakra-ui/react'
import { AnimatePresence } from 'framer-motion'

import { useIsMobile } from '~hooks/useIsMobile'
import { MotionBox } from '~components/motion'

import {
Expand Down Expand Up @@ -32,7 +33,8 @@ const DRAWER_MOTION_PROPS = {
},
}

export const BuilderAndDesignDrawer = (): JSX.Element => {
export const BuilderAndDesignDrawer = (): JSX.Element | null => {
const isMobile = useIsMobile()
const { isShowDrawer, activeTab } = useCreatePageDrawer()
const activeField = useEditFieldStore(activeFieldSelector)

Expand All @@ -51,6 +53,9 @@ export const BuilderAndDesignDrawer = (): JSX.Element => {
}
}, [activeField, activeTab])

// Do not display in mobile
if (isMobile) return null

return (
<AnimatePresence>
{isShowDrawer ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, BoxProps, forwardRef, Icon, Stack, Text } from '@chakra-ui/react'

import { BasicField } from '~shared/types/field'

import { FIELDS_TO_CREATE_META } from '../../../constants'
import { BASICFIELD_TO_DRAWER_META } from '~features/admin-form/create/constants'

interface FieldOptionProps extends BoxProps {
isActive?: boolean
Expand Down Expand Up @@ -58,7 +58,10 @@ export const DraggableCreateFieldOption = ({

export const CreateFieldOption = forwardRef<FieldOptionProps, 'button'>(
({ fieldType, isDisabled, isActive, ...props }, ref) => {
const meta = useMemo(() => FIELDS_TO_CREATE_META[fieldType], [fieldType])
const meta = useMemo(
() => BASICFIELD_TO_DRAWER_META[fieldType],
[fieldType],
)

return (
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { BasicField, FormFieldDto } from '~shared/types/field'

import IconButton from '~components/IconButton'

import { BASICFIELD_TO_DRAWER_META } from '~features/admin-form/create/constants'

import {
activeFieldSelector,
clearActiveFieldSelector,
useEditFieldStore,
} from '../../../editFieldStore'
import { transformBasicFieldToText } from '../../../utils'
import { CreatePageDrawerCloseButton } from '../CreatePageDrawerCloseButton'

import { EditCheckbox } from './EditCheckbox'
Expand All @@ -22,7 +23,10 @@ export const EditFieldDrawer = (): JSX.Element | null => {
const activeField = useEditFieldStore(activeFieldSelector)

const basicFieldText = useMemo(
() => transformBasicFieldToText(activeField?.fieldType),
() =>
activeField?.fieldType
? BASICFIELD_TO_DRAWER_META[activeField.fieldType].label
: '',
[activeField?.fieldType],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { memo, useCallback, useMemo } from 'react'
import { Draggable } from 'react-beautiful-dnd'
import { FormProvider, useForm } from 'react-hook-form'
import { BiDuplicate, BiGridHorizontal, BiTrash } from 'react-icons/bi'
import { BiDuplicate, BiEdit, BiGridHorizontal, BiTrash } from 'react-icons/bi'
import { useIsMutating } from 'react-query'
import {
Box,
Expand All @@ -15,6 +15,7 @@ import {

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

import { useIsMobile } from '~hooks/useIsMobile'
import IconButton from '~components/IconButton'
import CheckboxField from '~templates/Field/Checkbox'

Expand All @@ -36,6 +37,8 @@ export const FieldRowContainer = ({
field,
index,
}: FieldRowContainerProps): JSX.Element => {
const isMobile = useIsMobile()

const updateActiveField = useEditFieldStore(updateFieldSelector)
const activeField = useEditFieldStore(activeFieldSelector)
const numFormFieldMutations = useIsMutating(adminFormFieldKeys.base)
Expand Down Expand Up @@ -74,6 +77,7 @@ export const FieldRowContainer = ({
<Box
_first={{ pt: 0 }}
_last={{ pb: 0 }}
m="0.75rem"
py="1.25rem"
{...provided.draggableProps}
ref={provided.innerRef}
Expand Down Expand Up @@ -132,7 +136,7 @@ export const FieldRowContainer = ({
</chakra.button>
</Fade>
<Box
p="1.5rem"
p={{ base: '0.75rem', md: '1.5rem' }}
pt={0}
w="100%"
pointerEvents={isActive ? undefined : 'none'}
Expand All @@ -145,11 +149,19 @@ export const FieldRowContainer = ({
</Box>
<Collapse in={isActive} style={{ width: '100%' }}>
<Flex
px="1.5rem"
px={{ base: '0.75rem', md: '1.5rem' }}
flex={1}
borderTop="1px solid var(--chakra-colors-neutral-300)"
justify="end"
justify={{ base: 'space-between', md: 'end' }}
>
{isMobile ? (
<IconButton
variant="clear"
colorScheme="secondary"
aria-label="Edit field"
icon={<BiEdit fontSize="1.25rem" />}
/>
) : null}
<ButtonGroup
variant="clear"
colorScheme="secondary"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
import {
BiAlignLeft,
BiBuilding,
BiCalculator,
BiCalendarEvent,
BiCaretDownSquare,
BiCloudUpload,
BiHash,
BiHeading,
BiImage,
BiMailSend,
BiMobile,
BiPhone,
BiRadioCircleMarked,
BiRename,
BiSelectMultiple,
BiStar,
BiTable,
BiText,
BiToggleLeft,
BiUser,
} from 'react-icons/bi'
import { As } from '@chakra-ui/react'

import { BasicField } from '~shared/types/field'

const ALL_FIELDS_ORDERED = [
Expand Down Expand Up @@ -57,108 +33,3 @@ export const CREATE_FIELD_DROP_ID = 'create-fields-field'

export const FIELD_LIST_DROP_ID = 'formFieldList'
export const PENDING_CREATE_FIELD_ID = 'FIELD-PENDING-CREATION'

export const FIELDS_TO_CREATE_META: Record<
BasicField,
{ label: string; icon: As }
> = {
[BasicField.Image]: {
label: 'Image',
icon: BiImage,
},

[BasicField.Statement]: {
label: 'Paragraph',
icon: BiText,
},

[BasicField.Section]: {
label: 'Header',
icon: BiHeading,
},

[BasicField.Attachment]: {
label: 'Attachment',
icon: BiCloudUpload,
},

[BasicField.Checkbox]: {
label: 'Checkbox',
icon: BiSelectMultiple,
},

[BasicField.Date]: {
label: 'Date',
icon: BiCalendarEvent,
},

[BasicField.Decimal]: {
label: 'Decimal',
icon: BiCalculator,
},

[BasicField.Dropdown]: {
label: 'Dropdown',
icon: BiCaretDownSquare,
},

[BasicField.Email]: {
label: 'Email',
icon: BiMailSend,
},

[BasicField.HomeNo]: {
label: 'Home Number',
icon: BiPhone,
},

[BasicField.LongText]: {
label: 'Long answer',
icon: BiAlignLeft,
},

[BasicField.Mobile]: {
label: 'Mobile number',
icon: BiMobile,
},

[BasicField.Nric]: {
label: 'NRIC',
icon: BiUser,
},

[BasicField.Number]: {
label: 'Number',
icon: BiHash,
},

[BasicField.Radio]: {
label: 'Radio',
icon: BiRadioCircleMarked,
},

[BasicField.Rating]: {
label: 'Rating',
icon: BiStar,
},

[BasicField.ShortText]: {
label: 'Short answer',
icon: BiRename,
},

[BasicField.Table]: {
label: 'Table',
icon: BiTable,
},

[BasicField.Uen]: {
label: 'UEN',
icon: BiBuilding,
},

[BasicField.YesNo]: {
label: 'Yes/No',
icon: BiToggleLeft,
},
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { BasicField } from '~shared/types/field'

import { FIELDS_TO_CREATE_META, PENDING_CREATE_FIELD_ID } from './constants'
import { BuilderContentField, PendingFormField } from './types'
import { BASICFIELD_TO_DRAWER_META } from '../constants'

/**
* Maps BasicField enums to their human-readable field type string
*/
export const transformBasicFieldToText = (basicField?: BasicField): string => {
if (!basicField) return ''
return FIELDS_TO_CREATE_META[basicField].label
}
import { PENDING_CREATE_FIELD_ID } from './constants'
import { BuilderContentField, PendingFormField } from './types'

export const isPendingFormField = (
field: BuilderContentField,
Expand All @@ -31,7 +25,7 @@ export const getFieldCreationMeta = (
description: '',
disabled: false,
required: true,
title: transformBasicFieldToText(fieldType),
title: BASICFIELD_TO_DRAWER_META[fieldType].label,
_id: PENDING_CREATE_FIELD_ID,
}

Expand Down
Loading