Skip to content

Commit

Permalink
fix: remove comments and unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Jan 20, 2022
1 parent 22cb09c commit b57a388
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 102 deletions.
4 changes: 2 additions & 2 deletions src/components/Captures/CaptureGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CapturesContext } from '../../context/CapturesContext';
import { SpeciesContext } from '../../context/SpeciesContext';
import { TagsContext } from '../../context/TagsContext';

const log = require('loglevel').getLogger('../components/Verify');
const log = require('loglevel').getLogger('../components/CaptureGallery');

const useStyles = makeStyles(styles);

Expand Down Expand Up @@ -99,7 +99,7 @@ const CaptureGallery = ({
const speciesId = await speciesContext.getSpeciesId();
if (speciesId) {
approveAction.speciesId = speciesId;
console.log('species id:', speciesId);
log.debug('species id:', speciesId);
}

// create/retrieve tags
Expand Down
59 changes: 1 addition & 58 deletions src/components/Captures/CaptureGallery.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import {
act,
render,
screen,
within,
cleanup,
waitForElementToBeRemoved,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import captureApi from '../../api/treeTrackerApi';
import { act, render, screen, within, cleanup } from '@testing-library/react';
import theme from '../common/theme';
import { ThemeProvider } from '@material-ui/core/styles';
import { AppProvider } from '../../context/AppContext';
import { CapturesContext } from '../../context/CapturesContext';
import { GrowerContext } from '../../context/GrowerContext';
import { SpeciesContext } from '../../context/SpeciesContext';
import { TagsContext } from '../../context/TagsContext';
import CaptureGallery from './CaptureGallery';
import {
CAPTURE,
CAPTURES,
GROWER,
ORGS,
TAG,
TAGS,
SPECIES,
capturesValues,
growerValues,
tagsValues,
speciesValues,
} from '../tests/fixtures';
Expand All @@ -49,45 +30,10 @@ describe('Captures', () => {
return Promise.resolve({ count: 4 });
};

// mock the treeTrackerApi
// let captureApi = require('../../api/treeTrackerApi').default;

// captureApi.getCaptureById = (_id) => {
// log.debug('mock getCaptureById:');
// return Promise.resolve(CAPTURE);
// };
// captureApi.getSpecies = () => {
// log.debug('mock getSpecies:');
// return Promise.resolve(SPECIES);
// };
// captureApi.getSpeciesById = (_id) => {
// log.debug('mock getSpeciesById:');
// return Promise.resolve(SPECIES[0]);
// };
// captureApi.getCaptureCountPerSpecies = () => {
// log.debug('mock getCaptureCountPerSpecies:');
// return Promise.resolve({ count: 7 });
// };
// captureApi.getTags = () => {
// log.debug('mock getTags:');
// return Promise.resolve(TAGS);
// };
// captureApi.getTagById = (_id) => {
// log.debug('mock getTagById:');
// return Promise.resolve(TAG);
// };
// captureApi.getOrganizations = () => {
// log.debug('mock getOrganizations:');
// return Promise.resolve(ORGS);
// };

describe('with default values', () => {
beforeEach(async () => {
render(
<ThemeProvider theme={theme}>
{/* <BrowserRouter> */}
{/* <AppProvider value={{ orgList: ORGS }}> */}
{/* <GrowerContext.Provider value={growerValues}> */}
<CapturesContext.Provider value={capturesValues}>
<SpeciesContext.Provider value={speciesValues}>
<TagsContext.Provider value={tagsValues}>
Expand All @@ -99,9 +45,6 @@ describe('Captures', () => {
</TagsContext.Provider>
</SpeciesContext.Provider>
</CapturesContext.Provider>
{/* </GrowerContext.Provider> */}
{/* </AppProvider> */}
{/* </BrowserRouter> */}
</ThemeProvider>
);

Expand Down
4 changes: 0 additions & 4 deletions src/components/Captures/CaptureTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import {
import { GetApp } from '@material-ui/icons';
import IconButton from '@material-ui/core/IconButton';
import ImageIcon from '@material-ui/icons/Image';
// import Map from '@material-ui/icons/Map';
import Nature from '@material-ui/icons/Nature';
import Person from '@material-ui/icons/Person';
// import TableChartIcon from '@material-ui/icons/TableChart';
import { getDateTimeStringLocale } from '../../common/locale';
import { countToLocaleString } from '../../common/numbers';
import { getVerificationStatus } from '../../common/utils';
Expand Down Expand Up @@ -336,7 +334,6 @@ export const formatCell = (
title={`View/Edit Capture details`}
style={{ padding: '0 4px 2px' }}
>
{/* <Typography color="primary">{capture[attr]}</Typography> */}
<Nature color="primary" />
</IconButton>
<LinkToWebmap value={'Map'} type={'tree'} />
Expand All @@ -352,7 +349,6 @@ export const formatCell = (
title={`View/Edit Grower details`}
style={{ padding: '0 2px 2px 0' }}
>
{/* <Typography color="primary">{capture[attr]}</Typography> */}
<Person color="primary" />
</IconButton>
<LinkToWebmap value={'Map'} type={'user'} />
Expand Down
31 changes: 14 additions & 17 deletions src/context/CapturesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,13 @@ export function CapturesProvider(props) {

const paramString = `filter=${JSON.stringify(lbFilter)}`;
log.debug('load page with params:', paramString);
const { data } = await queryCapturesApi({ paramString }).catch((err) =>
console.error(`ERROR: Failed to get captures: ${err}`)
);
log.debug('loaded captures:', data.length);
setCaptures(data);
setIsLoading(false);
await queryCapturesApi({ paramString })
.then(({ data }) => {
log.debug('loaded captures:', data.length);
setCaptures(data);
setIsLoading(false);
})
.catch((err) => console.error(`ERROR: Failed to get captures: ${err}`));
};

const getCaptureExports = async (filterInfo = {}) => {
Expand Down Expand Up @@ -254,7 +255,6 @@ export function CapturesProvider(props) {
};

const clickCapture = (payload) => {
//{{{
const { captureId, isShift, isCmd, isCtrl } = payload;
if (!isShift && !isCmd && !isCtrl) {
setCapturesSelected([captureId]);
Expand Down Expand Up @@ -298,7 +298,6 @@ export function CapturesProvider(props) {
}
setCapturesSelected(selectedImages);
}
//}}}
};

const approve = async ({ approveAction, id }) => {
Expand Down Expand Up @@ -339,13 +338,10 @@ export function CapturesProvider(props) {
try {
for (let i = 0; i < total; i++) {
const captureId = capturesSelected[i];
const captureImage = captures.reduce((a, c) => {
if (c && c.id === captureId) {
return c;
} else {
return a;
}
}, undefined);
const captureImage = captures.reduce(
(a, c) => (c && c.id === captureId ? c : a),
undefined
);
log.debug('approve:%d', captureImage.id);
log.trace('approve:%d', captureImage.id);
await approve({
Expand Down Expand Up @@ -373,8 +369,9 @@ export function CapturesProvider(props) {

const undoneCaptureImage = (captureId) => {
//put the capture back, from undo list, sort by id
const captureUndo = capturesUndo.reduce((a, c) =>
c.id === captureId ? c : a
const captureUndo = capturesUndo.reduce(
(a, c) => (c.id === captureId ? c : a),
undefined
);
const undoneImages = capturesUndo.filter(
(capture) => capture.id !== captureId
Expand Down
1 change: 0 additions & 1 deletion src/views/CapturesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Grid } from '@material-ui/core';
import CaptureDetailDialog from '../components/CaptureDetailDialog';
import GrowerDetail from '../components/GrowerDetail';
import CaptureGallery from '../components/Captures/CaptureGallery';
// import SidePanel from '../components/SidePanel';
import CaptureTable from '../components/Captures/CaptureTable';
import { CaptureDetailProvider } from '../context/CaptureDetailContext';
import { CapturesProvider } from '../context/CapturesContext';
Expand Down
20 changes: 0 additions & 20 deletions src/views/CapturesView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ jest.mock('../api/growers');
jest.mock('../api/treeTrackerApi');

describe.skip('Captures View', () => {
//mock the growers api
// let growerApi = require('../api/growers').default;

// growerApi.getCount = () => {
// log.debug('mock getCount:');
// return Promise.resolve({ count: 2 });
// };
// growerApi.getGrower = () => {
// log.debug('mock getGrower:');
// return Promise.resolve(GROWER);
// };
// growerApi.getGrowerRegistrations = () => {
// log.debug('mock getGrowerRegistrations:');
// return Promise.resolve([]);
// };
// growerApi.getGrowerSelfies = (id) => {
// log.debug('mock getGrowerSelfies:');
// return Promise.resolve([{ planterPhotoUrl: '' }, { planterPhotoUrl: '' }]);
// };

// mock the treeTrackerApi
let captureApi = require('../api/treeTrackerApi').default;

Expand Down

0 comments on commit b57a388

Please sign in to comment.