diff --git a/app/src/components/surveys/SurveysList.test.tsx b/app/src/components/surveys/SurveysList.test.tsx new file mode 100644 index 0000000000..3098165551 --- /dev/null +++ b/app/src/components/surveys/SurveysList.test.tsx @@ -0,0 +1,39 @@ +import { render } from '@testing-library/react'; +import { IGetProjectSurvey } from 'interfaces/useProjectApi.interface'; +import React from 'react'; +import SurveysList from './SurveysList'; + +describe('SurveysList', () => { + it('renders correctly with surveys', () => { + const surveysList: IGetProjectSurvey[] = [ + { + id: 1, + name: 'Moose Survey 1', + species: 'Moose', + start_date: '2021-04-09 11:53:53', + end_date: '2021-05-09 11:53:53', + status_name: 'Unpublished' + }, + { + id: 2, + name: 'Moose Survey 2', + species: 'Moose', + start_date: '2021-04-09 11:53:53', + end_date: '2021-06-10 11:53:53', + status_name: 'Published' + } + ]; + + const { getByText, queryByText } = render(); + + expect(queryByText('No Surveys')).toBeNull(); + expect(getByText('Moose Survey 1')).toBeInTheDocument(); + expect(getByText('Moose Survey 2')).toBeInTheDocument(); + }); + + it('renders correctly with no surveys', () => { + const { getByText } = render(); + + expect(getByText('No Surveys')).toBeInTheDocument(); + }); +}); diff --git a/app/src/components/surveys/SurveysList.tsx b/app/src/components/surveys/SurveysList.tsx new file mode 100644 index 0000000000..6e2a91d264 --- /dev/null +++ b/app/src/components/surveys/SurveysList.tsx @@ -0,0 +1,134 @@ +import Chip from '@material-ui/core/Chip'; +import Link from '@material-ui/core/Link'; +import Paper from '@material-ui/core/Paper'; +import Table from '@material-ui/core/Table'; +import TableBody from '@material-ui/core/TableBody'; +import TableCell from '@material-ui/core/TableCell'; +import TableContainer from '@material-ui/core/TableContainer'; +import TableHead from '@material-ui/core/TableHead'; +import TablePagination from '@material-ui/core/TablePagination'; +import TableRow from '@material-ui/core/TableRow'; +import makeStyles from '@material-ui/core/styles/makeStyles'; +import { Theme } from '@material-ui/core/styles/createMuiTheme'; +import { SurveyStatusType } from 'constants/misc'; +import clsx from 'clsx'; +import { IGetProjectSurvey } from 'interfaces/useProjectApi.interface'; +import React, { useState } from 'react'; +import { DATE_FORMAT } from 'constants/dateFormats'; +import { getFormattedDateRangeString } from 'utils/Utils'; + +const useStyles = makeStyles((theme: Theme) => ({ + table: { + minWidth: 650 + }, + heading: { + fontWeight: 'bold' + }, + tableCellBorderTop: { + borderTop: '1px solid rgba(224, 224, 224, 1)' + }, + chip: { + padding: '0px 8px', + borderRadius: '4px', + color: 'white' + }, + chipUnpublished: { + backgroundColor: theme.palette.text.secondary + }, + chipPublished: { + backgroundColor: theme.palette.success.light + } +})); + +export interface ISurveysListProps { + surveysList: IGetProjectSurvey[]; +} + +const SurveysList: React.FC = (props) => { + const classes = useStyles(); + + const [rowsPerPage, setRowsPerPage] = useState(5); + const [page, setPage] = useState(0); + + const handleChangePage = (event: unknown, newPage: number) => { + setPage(newPage); + }; + + const handleChangeRowsPerPage = (event: React.ChangeEvent) => { + setRowsPerPage(parseInt(event.target.value, 10)); + setPage(0); + }; + + const getChipIcon = (status_name: string) => { + let chipLabel; + let chipStatusClass; + + if (SurveyStatusType.UNPUBLISHED === status_name) { + chipLabel = 'UNPUBLISHED'; + chipStatusClass = classes.chipUnpublished; + } else if (SurveyStatusType.PUBLISHED === status_name) { + chipLabel = 'PUBLISHED'; + chipStatusClass = classes.chipPublished; + } + + return ; + }; + + return ( + + + + + + Name + Species + Timeline + Status + + + + {props.surveysList.length > 0 && + props.surveysList.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row, index) => ( + + + console.log('survey clicked')}> + {row.name} + + + {row.species} + + {getFormattedDateRangeString(DATE_FORMAT.ShortMediumDateFormat2, row.start_date, row.end_date)} + + {getChipIcon(row.status_name)} + + ))} + {!props.surveysList.length && ( + + + No Surveys + + + )} + +
+
+ {props.surveysList.length > 0 && ( + + )} +
+ ); +}; + +export default SurveysList; diff --git a/app/src/constants/dateFormats.ts b/app/src/constants/dateFormats.ts index bfca3f1397..6957092d9b 100644 --- a/app/src/constants/dateFormats.ts +++ b/app/src/constants/dateFormats.ts @@ -8,6 +8,7 @@ export enum DATE_FORMAT { ShortDateFormatMonthFirst = 'MM/DD/YYYY', //01/05/2020 ShortDateTimeFormat = 'YYYY-MM-DD, h:mm a', //2020-01-05, 3:30 pm ShortMediumDateFormat = 'MMM D, YYYY', //Jan 5, 2020 + ShortMediumDateFormat2 = 'MMMM DD, YYYY', //Jan 05, 2020 ShortMediumDateTimeFormat = 'MMM D, YYYY, h:mm a', //Jan 5, 2020, 3:30 pm MediumDateFormat = 'MMMM D, YYYY', //January 5, 2020 MediumDateFormat2 = 'MMMM-DD-YYYY', //January-5-2020 diff --git a/app/src/constants/misc.ts b/app/src/constants/misc.ts index f52321e41b..c1549c6c31 100644 --- a/app/src/constants/misc.ts +++ b/app/src/constants/misc.ts @@ -7,3 +7,8 @@ export enum AdministrativeActivityStatusType { ACTIONED = 'Actioned', REJECTED = 'Rejected' } + +export enum SurveyStatusType { + UNPUBLISHED = 'Unpublished', + PUBLISHED = 'Published' +} diff --git a/app/src/features/projects/view/ProjectPage.tsx b/app/src/features/projects/view/ProjectPage.tsx index 9e1b0a899f..265653396e 100644 --- a/app/src/features/projects/view/ProjectPage.tsx +++ b/app/src/features/projects/view/ProjectPage.tsx @@ -166,7 +166,7 @@ const ProjectPage: React.FC = () => { {location.pathname.includes('/details') && ( )} - {location.pathname.includes('/surveys') && } + {location.pathname.includes('/surveys') && } {location.pathname.includes('/attachments') && ( )} diff --git a/app/src/features/projects/view/ProjectSurveys.test.tsx b/app/src/features/projects/view/ProjectSurveys.test.tsx index 1bf72b1456..7837a78952 100644 --- a/app/src/features/projects/view/ProjectSurveys.test.tsx +++ b/app/src/features/projects/view/ProjectSurveys.test.tsx @@ -1,19 +1,13 @@ import { render } from '@testing-library/react'; -import { createMemoryHistory } from 'history'; import React from 'react'; -import { Router } from 'react-router'; import ProjectSurveys from './ProjectSurveys'; -const history = createMemoryHistory(); - describe('ProjectSurveys', () => { it('renders correctly', () => { - const { asFragment } = render( - - - - ); + const { getByText } = render(); - expect(asFragment()).toMatchSnapshot(); + expect(getByText('Surveys')).toBeInTheDocument(); + expect(getByText('Add Survey')).toBeInTheDocument(); + expect(getByText('Moose Survey 1')).toBeInTheDocument(); }); }); diff --git a/app/src/features/projects/view/ProjectSurveys.tsx b/app/src/features/projects/view/ProjectSurveys.tsx index 0e11d582f3..8fcca2e74d 100644 --- a/app/src/features/projects/view/ProjectSurveys.tsx +++ b/app/src/features/projects/view/ProjectSurveys.tsx @@ -1,33 +1,42 @@ import Box from '@material-ui/core/Box'; -import Paper from '@material-ui/core/Paper'; +import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; -import { IGetProjectForViewResponse } from 'interfaces/useProjectApi.interface'; +import SurveysList from 'components/surveys/SurveysList'; +import { IGetProjectSurvey } from 'interfaces/useProjectApi.interface'; import React from 'react'; -export interface IProjectSurveysProps { - projectForViewData: IGetProjectForViewResponse; -} - /** * Project surveys content for a project. * * @return {*} */ -const ProjectSurveys: React.FC = () => { +const ProjectSurveys = () => { + // TODO: Replace this with the result of an API call giving us back the surveyList data + const surveysList: IGetProjectSurvey[] = [ + { + id: 1, + name: 'Moose Survey 1', + species: 'Moose', + start_date: '2021-04-09 11:53:53', + end_date: '2021-05-09 11:53:53', + status_name: 'Unpublished' + } + ]; + return ( <> - Project Surveys - - - - Project survey component 1 placeholder - + + + Surveys + + + - - Project survey component 2 placeholder - + ); diff --git a/app/src/features/projects/view/__snapshots__/ProjectSurveys.test.tsx.snap b/app/src/features/projects/view/__snapshots__/ProjectSurveys.test.tsx.snap deleted file mode 100644 index 9d12003b0a..0000000000 --- a/app/src/features/projects/view/__snapshots__/ProjectSurveys.test.tsx.snap +++ /dev/null @@ -1,41 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ProjectSurveys renders correctly 1`] = ` - -
-

- Project Surveys -

-
-
-
-
- Project survey component 1 placeholder -
-
-
-
-
-
- Project survey component 2 placeholder -
-
-
-
-`; diff --git a/app/src/interfaces/useProjectApi.interface.ts b/app/src/interfaces/useProjectApi.interface.ts index 1228f3d366..eb2d7dde1f 100644 --- a/app/src/interfaces/useProjectApi.interface.ts +++ b/app/src/interfaces/useProjectApi.interface.ts @@ -9,6 +9,15 @@ import { IProjectPermitForm } from 'features/projects/components/ProjectPermitFo import { IProjectSpeciesForm } from 'features/projects/components/ProjectSpeciesForm'; import { Feature } from 'geojson'; +export interface IGetProjectSurvey { + id: number; + name: string; + species: string; + start_date: string; + end_date: string; + status_name: string; +} + export interface IGetProjectAttachment { id: number; fileName: string;