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

Add Reef check surveys #1060

Merged
merged 39 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c5ff6ee
Add store slice and types
K-Markopoulos Nov 22, 2024
c8fadfd
Add page route
K-Markopoulos Nov 22, 2024
edd78ba
Add organism table
K-Markopoulos Nov 22, 2024
1ba373e
Add details and summary
K-Markopoulos Nov 22, 2024
21ac5cd
Suppress prettier warning
K-Markopoulos Nov 26, 2024
b8c3045
Restructure survey tables
K-Markopoulos Nov 26, 2024
a0332b2
Add substrates, skeletons & restructure tables
K-Markopoulos Nov 26, 2024
5569306
Merge branch 'master' into reef-check-survey-page
ericboucher Nov 29, 2024
1870a94
Suppress prettier warning
K-Markopoulos Nov 28, 2024
2d6aa60
Tweak styles for mobile
K-Markopoulos Nov 28, 2024
5781f20
Add tests
K-Markopoulos Nov 29, 2024
10e0e12
Temporarily hide download button
K-Markopoulos Nov 29, 2024
dcd8e59
Change tables order
K-Markopoulos Dec 2, 2024
5c74b3b
Sort by total
K-Markopoulos Dec 2, 2024
5e14dfd
Update columns
K-Markopoulos Dec 2, 2024
69012fd
Add noreferrer to external links
K-Markopoulos Dec 2, 2024
c6174f5
Encode url params
K-Markopoulos Dec 2, 2024
829d119
Clean up completed TODOs
K-Markopoulos Dec 2, 2024
a86cbc4
Merge branch 'master' into reef-check-survey-page
K-Markopoulos Dec 2, 2024
7d43ce1
Merge branch 'master' into reef-check-survey-page
ericboucher Dec 2, 2024
dec9873
Hide previous data while loading
K-Markopoulos Dec 3, 2024
5c80f07
Merge branch 'master' into reef-check-survey-page
ericboucher Dec 9, 2024
9ada832
Merge branch 'master' into reef-check-survey-page
ericboucher Dec 17, 2024
bd00680
Add Reef check surveys in Site page (#1064)
K-Markopoulos Dec 20, 2024
50d1f3b
Merge branch 'master' into reef-check-survey-page
ericboucher Jan 12, 2025
faf77b3
Fix build styles/mui updates
ericboucher Jan 12, 2025
354fbbb
Fix tests
K-Markopoulos Jan 13, 2025
a740ec4
Fix store namespace
K-Markopoulos Jan 14, 2025
f48d977
Extract segments total sort comparator
K-Markopoulos Jan 14, 2025
27de506
Add reef check available data info
K-Markopoulos Jan 14, 2025
576d592
Move the arrow icon inline
K-Markopoulos Jan 14, 2025
9eb8e7a
Add reef check map filter
K-Markopoulos Jan 14, 2025
c35a531
Test lock typeorm version
ericboucher Jan 15, 2025
6c2abe9
Address jest resolve error
K-Markopoulos Jan 15, 2025
1dc31a8
Update snapshots
K-Markopoulos Jan 15, 2025
d3739c1
Define missing global function
K-Markopoulos Jan 15, 2025
ca8e1bf
Update reef check data available link and image
K-Markopoulos Jan 15, 2025
c30c1d8
Add percentage unit in surveys table
K-Markopoulos Jan 15, 2025
12a4c48
Update typeorm to 0.3.20
ericboucher Jan 15, 2025
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
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"rxjs": "^7",
"sharp": "^0.32.6",
"ts-exif-parser": "^0.2.1",
"typeorm": "^0.3.18",
"typeorm": "0.3.19",
"typeorm-naming-strategies": "^1.1.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/sites/sites.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class SitesService {
.leftJoinAndSelect('site.region', 'region')
.leftJoinAndSelect('site.sketchFab', 'sketchFab')
.leftJoinAndSelect('site.admins', 'admins')
.leftJoinAndSelect('site.reefCheckSite', 'reefCheckSite')
.andWhere('display = true')
.getMany();

Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/time-series/time-series.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const timeSeriesTests = () => {
];

beforeAll(async () => {
// Define missing global function in test environment
global.structuredClone = (val) => JSON.parse(JSON.stringify(val));
app = await testService.getApp();
dataSource = await testService.getDataSource();
});
Expand Down
4 changes: 3 additions & 1 deletion packages/api/test/jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"globalSetup": "./test/global-setup.js",
"moduleNameMapper": {
"^csv-stringify/sync":
"<rootDir>/../../node_modules/csv-stringify/dist/cjs/sync.cjs"
"<rootDir>/../../node_modules/csv-stringify/dist/cjs/sync.cjs",
"^typeorm$": "<rootDir>/../../node_modules/typeorm",
"^uuid$": "uuid"
}
}
5 changes: 4 additions & 1 deletion packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"react-material-ui-carousel": "3.4.2",
"react-redux": "^7.2.0",
"react-router-dom": "^6.0.0",
"react-router-hash-link": "^2.4.3",
"react-slick": "^0.30.3",
"react-swipeable-bottom-sheet": "^1.1.2",
"react-swipeable-views": "^0.14.0",
Expand All @@ -76,7 +77,8 @@
"axios": "axios/dist/node/axios.cjs",
"^csv-stringify/browser/esm/sync": "<rootDir>/../../node_modules/csv-stringify/dist/cjs/sync.cjs"
},
"globalSetup": "./src/global-setup.js"
"globalSetup": "./src/global-setup.js",
"resetMocks": false
ericboucher marked this conversation as resolved.
Show resolved Hide resolved
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -110,6 +112,7 @@
"@types/react-leaflet": "^2.5.1",
"@types/react-redux": "^7.1.7",
"@types/react-router-dom": "^5.1.3",
"@types/react-router-hash-link": "^2.4.9",
"@types/react-slick": "^0.23.4",
"@types/react-swipeable-views": "^0.13.0",
"@types/redux-mock-store": "^1.0.2",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/website/src/assets/img/reef-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ exports[`Featured Media Card should render with given state from Redux store 1`]
<div
class="MuiGrid-root MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-direction-xs-column css-1qhqgqb-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-x7bhrq-MuiGrid-root"
<mock-box
alignitems="center"
classname="FeaturedMedia-noVideoCardHeaderText-4"
component="[object Object]"
display="flex"
gap="1"
to="/sites/1#surveys"
>
<img
alt="Reef Check"
src="reef-check-logo.png"
width="50"
/>
<mock-typography
classname="FeaturedMedia-noVideoCardHeaderText-4"
variant="h5"
>
SURVEY TO BE UPLOADED
REEF CHECK DATA AVAILABLE
</mock-typography>
</div>
<mock-keyboarddoublearrowdown />
</mock-box>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe('Featured Media Card', () => {
let element: HTMLElement;
beforeEach(() => {
const store = mockStore({
reefCheckSurveyList: {
list: [],
},
user: {
userInfo: mockUser,
},
Expand Down
60 changes: 46 additions & 14 deletions packages/website/src/common/SiteDetails/FeaturedMedia/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
import React from 'react';
import {
Card,
Expand All @@ -7,18 +8,23 @@ import {
Typography,
IconButton,
Theme,
Box,
} from '@mui/material';
import { WithStyles } from '@mui/styles';
import withStyles from '@mui/styles/withStyles';
import createStyles from '@mui/styles/createStyles';
import { KeyboardDoubleArrowDown } from '@mui/icons-material';
import { Link } from 'react-router-dom';
import { HashLink } from 'react-router-hash-link';
import { useSelector } from 'react-redux';

import { userInfoSelector } from 'store/User/userSlice';
import { isAdmin } from 'helpers/user';
import { convertOptionsToQueryParams } from 'helpers/video';
import { reefCheckSurveyListSelector } from 'store/ReefCheckSurveys';
import reefImage from '../../../assets/reef-image.jpg';
import uploadIcon from '../../../assets/icon_upload.svg';
import reefCheckLogo from '../../../assets/img/reef-check-logo.png';

const playerOptions = {
autoplay: 1,
Expand All @@ -35,6 +41,10 @@ const FeaturedMedia = ({
classes,
}: FeaturedMediaProps) => {
const user = useSelector(userInfoSelector);
const { list: reefCheckSurveyList } = useSelector(
reefCheckSurveyListSelector,
);
const hasReefCheckSurveys = true || reefCheckSurveyList.length > 0;
const isSiteAdmin = isAdmin(user, siteId);

if (url) {
Expand Down Expand Up @@ -71,21 +81,43 @@ const FeaturedMedia = ({
<Card className={classes.card}>
<div className={classes.noVideoCardHeader}>
<Grid container direction="column" alignItems="center" spacing={2}>
<Grid item>
{isSiteAdmin ? (
<>
<Grid item>
<Typography
className={classes.noVideoCardHeaderText}
variant="h5"
>
ADD YOUR FIRST SURVEY
</Typography>
</Grid>
<Grid item>
<IconButton
component={Link}
to={`/sites/${siteId}/new_survey`}
size="large"
>
<img src={uploadIcon} alt="upload" />
</IconButton>
</Grid>
</>
) : hasReefCheckSurveys ? (
<Box
component={HashLink}
to={`/sites/${siteId}#surveys`}
display="flex"
alignItems="center"
gap={1}
className={classes.noVideoCardHeaderText}
>
<img src={reefCheckLogo} alt="Reef Check" width={50} />
<Typography variant="h5">REEF CHECK DATA AVAILABLE</Typography>
<KeyboardDoubleArrowDown />
</Box>
) : (
<Typography className={classes.noVideoCardHeaderText} variant="h5">
{isSiteAdmin ? 'ADD YOUR FIRST SURVEY' : 'SURVEY TO BE UPLOADED'}
SURVEY TO BE UPLOADED
</Typography>
</Grid>
{isSiteAdmin && (
<Grid item>
<IconButton
component={Link}
to={`/sites/${siteId}/new_survey`}
size="large"
>
<img src={uploadIcon} alt="upload" />
</IconButton>
</Grid>
)}
</Grid>
</div>
Expand Down Expand Up @@ -118,7 +150,7 @@ const styles = (theme: Theme) => {
zIndex: 1,
},
noVideoCardHeaderText: {
opacity: 0.5,
color: 'white',
[theme.breakpoints.between('md', 1350)]: {
fontSize: 15,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { render } from '@testing-library/react';
import { mockReefCheckSurvey } from 'mocks/mockReefCheckSurvey';
import { ReefCheckSurvey } from 'store/ReefCheckSurveys';
import { BrowserRouter } from 'react-router-dom';
import { ThemeProvider } from '@mui/material';
import theme from 'layout/App/theme';
import { ReefCheckSurveyCard } from '.';

describe('ReefCheckSurveyCard', () => {
function renderReefCheckSurveyCard(overrides: Partial<ReefCheckSurvey> = {}) {
return render(
<ThemeProvider theme={theme}>
<BrowserRouter>
<ReefCheckSurveyCard
survey={{ ...mockReefCheckSurvey, ...overrides }}
/>
</BrowserRouter>
</ThemeProvider>,
);
}

it('should render date', () => {
const { getByText } = renderReefCheckSurveyCard();

expect(
getByText(`Date: ${new Date(mockReefCheckSurvey.date).toLocaleString()}`),
).toBeInTheDocument();
});

it('should render user if submittedBy is present', () => {
const { getByText } = renderReefCheckSurveyCard({
submittedBy: 'Test User',
});
expect(getByText('User: Test User')).toBeInTheDocument();
});

it('should render table with correct number of rows', () => {
const { container } = renderReefCheckSurveyCard();

expect(container.querySelectorAll('mock-tablerow').length).toBe(3);
});

it('should show correct counts in headers', () => {
const { container } = renderReefCheckSurveyCard();
const headers = [
...container.querySelectorAll('mock-tablehead mock-tablecell').values(),
].map((el) => el.textContent);
expect(headers).toEqual(
expect.arrayContaining([
'FISH (2)',
'Count',
'INVERTEBRATES (2)',
'Count',
'BLEACHING AND CORAL DIDEASES',
'YES/NO',
'IMPACT',
'YES/NO',
]),
);
});

it('should display link to survey details', () => {
const { getByRole } = renderReefCheckSurveyCard();

expect(getByRole('link', { name: 'VIEW DETAILS' })).toHaveAttribute(
'href',
`/reef_check_survey/${mockReefCheckSurvey.id}`,
);
});
});
Loading
Loading