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

SIMSBIOHUB-259: General UI Fixes / Clean-up #1088

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions app/src/features/surveys/CreateSurveyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ const CreateSurveyPage = () => {
<Divider className={classes.sectionDivider} />

<HorizontalSplitFormComponent
title="Block Data"
summary="Data for Blocks"
title="Sampling Methods"
summary="Specify site selection methods, stratums and optional sampling blocks for this survey."
component={<SurveyBlockSection />}
/>
<Divider className={classes.sectionDivider} />
Expand Down
32 changes: 13 additions & 19 deletions app/src/features/surveys/components/BlockForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Typography from '@mui/material/Typography';
import { Box } from '@mui/system';
import CustomTextField from 'components/fields/CustomTextField';
import React from 'react';
Expand All @@ -12,25 +11,20 @@ export interface IBlockData {
const BlockForm: React.FC = () => {
return (
<form>
<Box>
<Box component={'fieldset'} mb={4}>
<Typography component="legend">Name and Description</Typography>
<Box mt={0.5} mb={3}>
<CustomTextField
name="name"
label="Name"
maxLength={50}
other={{ placeholder: 'Maximum 50 characters', required: true }}
/>
</Box>
<CustomTextField
name="description"
label="Description"
maxLength={250}
other={{ multiline: true, placeholder: 'Maximum 250 characters', required: true, rows: 3 }}
/>
</Box>
<Box mb={3}>
<CustomTextField
name="name"
label="Name"
maxLength={50}
other={{ placeholder: 'Maximum 50 characters', required: true }}
/>
</Box>
<CustomTextField
name="description"
label="Description"
maxLength={250}
other={{ multiline: true, placeholder: 'Maximum 250 characters', required: true, rows: 3 }}
/>
</form>
);
};
Expand Down
37 changes: 0 additions & 37 deletions app/src/features/surveys/components/CreateSurveyBlockDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import CloseIcon from '@mui/icons-material/Close';
import { Typography } from '@mui/material';
import IconButton from '@mui/material/IconButton';
import Snackbar from '@mui/material/Snackbar';
import EditDialog from 'components/dialog/EditDialog';
import { useState } from 'react';
import BlockForm from './BlockForm';
import { BlockYupSchema } from './SurveyBlockSection';
interface ICreateBlockProps {
Expand All @@ -14,15 +9,10 @@ interface ICreateBlockProps {

const CreateSurveyBlockDialog: React.FC<ICreateBlockProps> = (props) => {
const { open, onSave, onClose } = props;
const [isSnackBarOpen, setIsSnackBarOpen] = useState(false);
const [blockName, setBlockName] = useState('');
return (
<>
<EditDialog
dialogTitle={'Add Block'}
dialogText={
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at porttitor sem. Aliquam erat volutpat. Donec placerat nisl magna, et faucibus arcu condimentum sed.'
}
open={open}
dialogLoading={false}
component={{
Expand All @@ -37,36 +27,9 @@ const CreateSurveyBlockDialog: React.FC<ICreateBlockProps> = (props) => {
dialogSaveButtonLabel="Add Block"
onCancel={() => onClose()}
onSave={(formValues) => {
setBlockName(formValues.name);
setIsSnackBarOpen(true);
onSave(formValues);
}}
/>

<Snackbar
open={isSnackBarOpen}
autoHideDuration={6000}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center'
}}
onClose={() => {
setIsSnackBarOpen(false);
setBlockName('');
}}
message={
<>
<Typography variant="body2" component="div">
Block <strong>{blockName}</strong> has been added.
</Typography>
</>
}
action={
<IconButton size="small" aria-label="close" color="inherit" onClick={() => setIsSnackBarOpen(false)}>
<CloseIcon fontSize="small" />
</IconButton>
}
/>
</>
);
};
Expand Down
49 changes: 1 addition & 48 deletions app/src/features/surveys/components/EditSurveyBlockDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import CloseIcon from '@mui/icons-material/Close';
import { Typography } from '@mui/material';
import IconButton from '@mui/material/IconButton';
import Snackbar from '@mui/material/Snackbar';
import EditDialog from 'components/dialog/EditDialog';
import { useState } from 'react';
import BlockForm from './BlockForm';
import { BlockYupSchema, IEditBlock } from './SurveyBlockSection';

Expand All @@ -16,15 +11,10 @@ interface IEditBlockProps {

const EditSurveyBlockDialog: React.FC<IEditBlockProps> = (props) => {
const { open, initialData, onSave, onClose } = props;
const [isSnackBarOpen, setIsSnackBarOpen] = useState(false);
const [blockName, setBlockName] = useState('');
return (
<>
<EditDialog
dialogTitle={'Edit Block'}
dialogText={
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at porttitor sem. Aliquam erat volutpat. Donec placerat nisl magna, et faucibus arcu condimentum sed.'
}
dialogTitle={'Edit Block Details'}
open={open}
dialogLoading={false}
component={{
Expand All @@ -38,49 +28,12 @@ const EditSurveyBlockDialog: React.FC<IEditBlockProps> = (props) => {
}}
dialogSaveButtonLabel="Save"
onCancel={() => {
setBlockName('');
setIsSnackBarOpen(true);
onClose();
}}
onSave={(formValues) => {
setBlockName(formValues.name);
setIsSnackBarOpen(true);
onSave(formValues, initialData?.index);
}}
/>

<Snackbar
open={isSnackBarOpen}
autoHideDuration={6000}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'center'
}}
onClose={() => {
setIsSnackBarOpen(false);
setBlockName('');
}}
message={
<>
<Typography variant="body2" component="div">
{initialData?.block.survey_block_id ? (
<>
Block <strong>{blockName}</strong> has been updated.
</>
) : (
<>
Block <strong>{blockName}</strong> has been added.
</>
)}
</Typography>
</>
}
action={
<IconButton size="small" aria-label="close" color="inherit" onClick={() => setIsSnackBarOpen(false)}>
<CloseIcon fontSize="small" />
</IconButton>
}
/>
</>
);
};
Expand Down
72 changes: 44 additions & 28 deletions app/src/features/surveys/components/SurveyBlockSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
import Icon from '@mdi/react';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import { ListItemIcon, Menu, MenuItem, MenuProps, Typography } from '@mui/material';
import Box from '@mui/material/Box';
// import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
import Collapse from '@mui/material/Collapse';
import IconButton from '@mui/material/IconButton';
import { useFormikContext } from 'formik';
import { ICreateSurveyRequest } from 'interfaces/useSurveyApi.interface';
import React, { useState } from 'react';
import { TransitionGroup } from 'react-transition-group';
import yup from 'utils/YupSchema';
import CreateSurveyBlockDialog from './CreateSurveyBlockDialog';
import EditSurveyBlockDialog from './EditSurveyBlockDialog';
Expand All @@ -20,8 +22,8 @@

// Form validation for Block Item
export const BlockYupSchema = yup.object({
name: yup.string().required().max(50, 'Maximum 50 characters'),
description: yup.string().required().max(250, 'Maximum 250 characters')
name: yup.string().required('Name is required').max(50, 'Maximum 50 characters'),
description: yup.string().required('Description is required').max(250, 'Maximum 250 characters')
});

export const SurveyBlockYupSchema = yup.array(BlockYupSchema);
Expand Down Expand Up @@ -92,16 +94,19 @@
sx={{
marginBottom: '14px'
}}>
Define Blocks
Define Blocks{' '}
<Typography component="span" color="textSecondary" fontWeight="inherit">
(optional)
</Typography>
</Typography>
<Typography
variant="body1"
color="textSecondary"
sx={{
mb: 2,
maxWidth: '90ch'
}}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at porttitor sem. Aliquam erat volutpat. Donec
placerat nisl magna, et faucibus arcu condimentum sed.
Enter a name and description for each block used in this survey.
</Typography>
<Menu
open={Boolean(anchorEl)}
Expand Down Expand Up @@ -129,9 +134,41 @@
</MenuItem>
</Menu>
<form onSubmit={handleSubmit}>
<TransitionGroup>
{values.blocks.map((item, index) => {
return (

Check warning on line 139 in app/src/features/surveys/components/SurveyBlockSection.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/components/SurveyBlockSection.tsx#L139

Added line #L139 was not covered by tests
<Collapse key={`${item.name}-${item.description}-${index}`}>
<Card
variant="outlined"
sx={{
mt: 1,
'& .MuiCardHeader-title': {
mb: 0.5
}
}}>
<CardHeader
action={
<IconButton
onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>
handleMenuClick(event, index)

Check warning on line 153 in app/src/features/surveys/components/SurveyBlockSection.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/components/SurveyBlockSection.tsx#L153

Added line #L153 was not covered by tests
}
aria-label="settings">
<MoreVertIcon />
</IconButton>
}
title={item.name}
subheader={item.description}
/>
</Card>
</Collapse>
);
})}
</TransitionGroup>
<Button
sx={{
mt: 1
}}
data-testid="block-form-add-button"
sx={{ marginBottom: 2, marginTop: 2 }}
variant="outlined"
color="primary"
title="Add Block"
Expand All @@ -140,27 +177,6 @@
onClick={() => setIsCreateModalOpen(true)}>
Add Block
</Button>
<Box>
{values.blocks.map((item, index) => {
return (
<Card key={`${item.name}-${item.description}`} sx={{ marginTop: 1 }} variant="outlined">
<CardHeader
action={
<IconButton
onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) =>
handleMenuClick(event, index)
}
aria-label="settings">
<MoreVertIcon />
</IconButton>
}
title={item.name}
subheader={item.description}
/>
</Card>
);
})}
</Box>
</form>
</>
);
Expand Down
4 changes: 3 additions & 1 deletion app/src/features/surveys/components/SurveyUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ const SurveyUserForm: React.FC<ISurveyUser> = (props) => {
</Typography>
</Box>
{errors?.['participants'] && selectedUsers.length > 0 && (
<AlertBar severity="error" variant="standard" title={alertBarText().title} text={alertBarText().text} />
<Box mt={3}>
<AlertBar severity="error" variant="standard" title={alertBarText().title} text={alertBarText().text} />
</Box>
)}
<Box mt={3}>
<Autocomplete
Expand Down
4 changes: 2 additions & 2 deletions app/src/features/surveys/edit/EditSurveyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ const EditSurveyForm: React.FC<IEditSurveyForm> = (props) => {
<Divider className={classes.sectionDivider} />

<HorizontalSplitFormComponent
title="Block Data"
summary="Data for Blocks"
title="Sampling Methods"
summary="Specify site selection methods, stratums and optional sampling blocks for this survey."
component={<SurveyBlockSection />}
/>
<Divider className={classes.sectionDivider} />
Expand Down