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

Added error handling for Growers page #1122

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions src/api/growers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default {
offset: skip,
};

console.log('filter - ', filter);
console.log(makeQueryString(growerFilter));

const query = `${QUERY_API}/v2/growers${
growerFilter ? `?${makeQueryString(growerFilter)}` : ''
}`;
Expand Down
2 changes: 2 additions & 0 deletions src/components/CaptureFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function Filter(props) {
organization_id: organizationId,
tokenId: tokenId.trim(),
};

console.log('filter -', test);
const filter = new FilterModel(test);

props.onSubmit && props.onSubmit(filter);
Expand Down
22 changes: 20 additions & 2 deletions src/components/Growers/Growers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Grower page
*/
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useEffect } from 'react';
import { TablePagination, Typography, Tooltip, Box } from '@material-ui/core';
import Grower from './Grower';
import GrowerDetail from '../GrowerDetail';
Expand All @@ -17,6 +17,13 @@ const Growers = (props) => {
const growerContext = useContext(GrowerContext);
const [isDetailShown, setDetailShown] = useState(false);
const [growerDetail, setGrowerDetail] = useState({});
const [isError, setIsError] = useState(false);

useEffect(() => {
if (!growerContext.isLoading && growerContext.error) {
setIsError(true);
}
}, [growerContext.isLoading]);

function handlePageChange(e, page) {
growerContext.changeCurrentPage(page);
Expand Down Expand Up @@ -98,7 +105,18 @@ const Growers = (props) => {
<Box>{pagination}</Box>
</Box>

<Box className={classes.items}>{growersItems}</Box>
<Box className={classes.items}>
{isError ? (
<Box className={classes.errorBox}>
<Typography>
Sorry, there has been an Internal Server Error. Please try again
later.
</Typography>
</Box>
) : (
growersItems
)}
</Box>

<Box className={classes.pagination}>{pagination}</Box>

Expand Down
7 changes: 7 additions & 0 deletions src/components/Growers/Growers.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const useStyle = makeStyles((theme) => ({
cursor: 'pointer',
margin: '0.5rem',
},
errorBox: {
width: '100%',
height: '70vh',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
cardContent: {
padding: 0,
height: `${GROWER_IMAGE_SIZE}px`,
Expand Down
36 changes: 23 additions & 13 deletions src/context/GrowerContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function GrowerProvider(props) {
);
const [isLoading, setIsLoading] = useState(false);
const [totalGrowerCount, setTotalGrowerCount] = useState(null);
const [isError, setIsError] = useState(false);

useEffect(() => {
const abortController = new AbortController();
Expand Down Expand Up @@ -70,19 +71,27 @@ export function GrowerProvider(props) {
const pageNumber = currentPage;

//set correct values for organization_id, an array of uuids for ALL_ORGANIZATIONS or a uuid string if provided
const finalFilter = setOrganizationFilter(filter, orgId, orgList);

const { total, grower_accounts } = await api.getGrowers(
{
skip: pageNumber * pageSize,
rowsPerPage: pageSize,
filter: new FilterGrower(finalFilter),
},
abortController
);
setCount(total);
setGrowers(grower_accounts);
setIsLoading(false);
try {
const finalFilter = setOrganizationFilter(filter, orgId, orgList);

const { total, grower_accounts } = await api.getGrowers(
{
skip: pageNumber * pageSize,
rowsPerPage: pageSize,
filter: new FilterGrower(finalFilter),
},
abortController
);

setCount(total);
setGrowers(grower_accounts);
setIsLoading(false);
} catch (err) {
console.log('error status', err.status);

setIsError(true);
setIsLoading(false);
}
};

const getWallets = async (name, pageNumber) => {
Expand Down Expand Up @@ -156,6 +165,7 @@ export function GrowerProvider(props) {
};

const value = {
error: isError,
growers,
pageSize,
count,
Expand Down
Loading