diff --git a/src/components/Captures/CaptureGallery.js b/src/components/Captures/CaptureGallery.js index 5630d5e1e..bddce8fb1 100644 --- a/src/components/Captures/CaptureGallery.js +++ b/src/components/Captures/CaptureGallery.js @@ -6,7 +6,6 @@ import Grid from '@material-ui/core/Grid'; import LinearProgress from '@material-ui/core/LinearProgress'; import Modal from '@material-ui/core/Modal'; import Typography from '@material-ui/core/Typography'; -import Snackbar from '@material-ui/core/Snackbar'; import TablePagination from '@material-ui/core/TablePagination'; import TableChartIcon from '@material-ui/icons/TableChart'; @@ -31,10 +30,8 @@ const CaptureGallery = ({ captures, captureCount, capturesSelected, - capturesUndo, isLoading, isApproveAllProcessing, - isBulkApproving, rowsPerPage, page, approveAllComplete, @@ -42,7 +39,6 @@ const CaptureGallery = ({ clickCapture, setPage, setRowsPerPage, - undoAll, } = useContext(CapturesContext); const speciesContext = useContext(SpeciesContext); @@ -240,40 +236,17 @@ const CaptureGallery = ({ )} {isApproveAllProcessing && ( - -
+ +
+

PROCESSING ... {parseInt(complete)}% complete

+ +
)} - {false && !isApproveAllProcessing && capturesUndo.length > 0 && ( - - You have {isBulkApproving === true ? ' approved ' : ' rejected '} - {capturesUndo.length} captures - - } - color="primary" - action={ - - } - className={classes.snackbar} - /> - )} ); }; diff --git a/src/components/Captures/CaptureGallery.styles.js b/src/components/Captures/CaptureGallery.styles.js index 5dfce813b..b347b4a48 100644 --- a/src/components/Captures/CaptureGallery.styles.js +++ b/src/components/Captures/CaptureGallery.styles.js @@ -2,6 +2,7 @@ import { selectedHighlightColor, SIDE_PANEL_WIDTH, } from '../../common/variables.js'; +import { colorPrimary } from '../common/theme'; const styles = (theme) => ({ wrapper: { @@ -66,6 +67,18 @@ const styles = (theme) => ({ position: 'relative', padding: theme.spacing(2), }, + modal: { + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, + modalContent: { + width: '40%', + backgroundColor: 'white', + color: colorPrimary, + padding: '20px', + borderRadius: '4px', + }, placeholderCard: { pointerEvents: 'none', '& $card': { diff --git a/src/components/Captures/CaptureGallery.test.js b/src/components/Captures/CaptureGallery.test.js index fed795e79..90553e600 100644 --- a/src/components/Captures/CaptureGallery.test.js +++ b/src/components/Captures/CaptureGallery.test.js @@ -13,20 +13,15 @@ import { speciesValues, } from '../tests/fixtures'; -import * as loglevel from 'loglevel'; -const log = loglevel.getLogger('../tests/verify.test'); - jest.setTimeout(7000); jest.mock('../../api/treeTrackerApi'); describe('Captures', () => { // mock captures context api methods const getCaptures = () => { - log.debug('mock getCaptures:'); return Promise.resolve(CAPTURES); }; const getCaptureCount = () => { - log.debug('mock getCaptureCount:'); return Promise.resolve({ count: 4 }); }; diff --git a/src/components/Captures/CaptureTable.js b/src/components/Captures/CaptureTable.js index d495ae56c..c0f962ef1 100644 --- a/src/components/Captures/CaptureTable.js +++ b/src/components/Captures/CaptureTable.js @@ -223,7 +223,8 @@ const CaptureTable = ({ alignItems="center" > - {captureCount !== null && + {/* check captureCount is a number and not undefined */} + {!isNaN(captureCount) && `${countToLocaleString(captureCount)} capture${ captureCount === 1 ? '' : 's' }`} diff --git a/src/components/SidePanel.js b/src/components/SidePanel.js index 6a3c44838..6763d7d61 100644 --- a/src/components/SidePanel.js +++ b/src/components/SidePanel.js @@ -13,7 +13,6 @@ import TextField from '@material-ui/core/TextField'; import Checkbox from '@material-ui/core/Checkbox'; import Species from './Species'; import CaptureTags from './CaptureTags'; -// import { CapturesContext } from '../context/CapturesContext'; const SIDE_PANEL_WIDTH = 315; @@ -43,10 +42,6 @@ const useStyles = makeStyles((theme) => ({ })); function SidePanel(props) { - // console.log('render: sidepanel'); - // const { captures, capture, captureCount, setCapture } = useContext( - // CapturesContext - // ); const DEFAULT_SWITCH_APPROVE = 0; const DEFAULT_MORPHOLOGY = 'seedling'; const DEFAULT_AGE = 'new_tree'; diff --git a/src/context/CapturesContext.js b/src/context/CapturesContext.js index 1a848bd41..03eb669b2 100644 --- a/src/context/CapturesContext.js +++ b/src/context/CapturesContext.js @@ -13,7 +13,6 @@ export const CapturesContext = createContext({ captureCount: 0, capture: {}, capturesSelected: [], - capturesUndo: [], captureImageAnchor: undefined, isLoading: false, invalidateCaptureCount: false, @@ -36,7 +35,6 @@ export const CapturesContext = createContext({ getCaptureById: () => {}, getCaptureExports: () => {}, approveAll: () => {}, - undoAll: () => {}, updateFilter: () => {}, // getLocationName: () => {}, }); @@ -47,7 +45,6 @@ export function CapturesProvider(props) { const [captureCount, setCaptureCount] = useState(0); const [capture, setCapture] = useState({}); const [capturesSelected, setCapturesSelected] = useState([]); - const [capturesUndo, setCapturesUndo] = useState([]); const [captureImageAnchor, setCaptureImageAnchor] = useState(undefined); const [invalidateCaptureCount, setInvalidateCaptureCount] = useState(false); const [isApproveAllProcessing, setIsApproveAllProcessing] = useState(false); @@ -263,22 +260,16 @@ export function CapturesProvider(props) { log.debug('press shift, and there is an anchor:', captureImageAnchor); //if no anchor, then, select from beginning let indexAnchor = 0; - if (captureImageAnchor !== undefined) { - indexAnchor = captures.reduce((a, c, i) => { - if (c !== undefined && c.id === captureImageAnchor) { - return i; - } else { - return a; - } - }, -1); + if (captureImageAnchor) { + indexAnchor = captures.reduce( + (a, c, i) => (c && c.id === captureImageAnchor ? i : a), + -1 + ); } - const indexCurrent = captures.reduce((a, c, i) => { - if (c !== undefined && c.id === captureId) { - return i; - } else { - return a; - } - }, -1); + const indexCurrent = captures.reduce( + (a, c, i) => (c && c.id === captureId ? i : a), + -1 + ); const capturesSelected = captures .slice( Math.min(indexAnchor, indexCurrent), @@ -290,9 +281,9 @@ export function CapturesProvider(props) { // Toggle the selection state let selectedImages; if (capturesSelected.find((el) => el === captureId)) { - selectedImages = capturesSelected.filter(function (capture) { - return capture !== captureId; - }); + selectedImages = capturesSelected.filter( + (capture) => capture !== captureId + ); } else { selectedImages = [...capturesSelected, captureId]; } @@ -331,10 +322,8 @@ export function CapturesProvider(props) { setIsApproveAllProcessing(true); const total = capturesSelected.length; - const undo = captures.filter((capture) => - capturesSelected.some((id) => id === capture.id) - ); - log.debug('captures total:%d, undo:%d', captures.length, undo.length); + + log.debug('captures total:%d', captures.length); try { for (let i = 0; i < total; i++) { const captureId = capturesSelected[i]; @@ -356,62 +345,9 @@ export function CapturesProvider(props) { setIsApproveAllProcessing(false); return false; } - //push to undo list and set status flags - setCapturesUndo(undo), setIsLoading(false); - await getCaptures(); - setIsApproveAllProcessing(false); - setApproveAllComplete(0); - setInvalidateCaptureCount(true); - - resetSelection(); - return true; - }; - - const undoneCaptureImage = (captureId) => { - //put the capture back, from undo list, sort by id - const captureUndo = capturesUndo.reduce( - (a, c) => (c.id === captureId ? c : a), - undefined - ); - const undoneImages = capturesUndo.filter( - (capture) => capture.id !== captureId - ); - const captures = [...captures, captureUndo].sort((a, b) => a.id - b.id); - setCaptures(captures); - setCapturesUndo(undoneImages); - }; - - const undoCaptureImage = async (id) => { - await api.undoCaptureImage(id); - undoneCaptureImage(id); - return true; - }; - - const undoAll = async () => { - log.debug('undo with state:', capturesUndo); - setIsLoading(true); - setIsApproveAllProcessing(true); - - const total = capturesUndo.length; - log.debug('items:%d', captures.length); - try { - for (let i = 0; i < capturesUndo.length; i++) { - const captureImage = capturesUndo[i]; - // log.trace('undo:%d', captureImage.id); - await undoCaptureImage(captureImage.id); - setApproveAllComplete(100 * ((i + 1) / total)); - setInvalidateCaptureCount(true); - } - } catch (e) { - log.warn('get error:', e); - - // // isRejectAllProcessing: false, - setIsLoading(true); - setIsApproveAllProcessing(true); - return false; - } setIsLoading(false); + await getCaptures(); setIsApproveAllProcessing(false); setApproveAllComplete(0); setInvalidateCaptureCount(true); @@ -426,7 +362,6 @@ export function CapturesProvider(props) { capture, capturesSelected, captureImageAnchor, - capturesUndo, isLoading, isApproveAllProcessing, approveAllComplete, @@ -447,9 +382,7 @@ export function CapturesProvider(props) { getCaptureById, getCaptureExports, approveAll, - undoAll, updateFilter, - // getLocationName, }; return ( diff --git a/src/views/CapturesView.test.js b/src/views/CapturesView.test.js index 57a5beb83..2eab70265 100644 --- a/src/views/CapturesView.test.js +++ b/src/views/CapturesView.test.js @@ -36,39 +36,30 @@ describe.skip('Captures View', () => { let captureApi = require('../api/treeTrackerApi').default; const getCaptures = () => { - log.debug('mock getCaptures:'); return Promise.resolve(CAPTURES); }; const getCaptureCount = () => { - log.debug('mock getCaptureCount:'); return Promise.resolve({ count: 4 }); }; 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); }; @@ -108,7 +99,6 @@ describe.skip('Captures View', () => { name: /filter/i, }); userEvent.click(filter); - // screen.logTestingPlaygroundURL(); const verifyStatus = screen.getByLabelText(/awaiting verification/i); expect(verifyStatus).toBeInTheDocument(); @@ -123,9 +113,8 @@ describe.skip('Captures View', () => { }); userEvent.click(filter); expect(screen.getByText(/awaiting verification/i)).toBeInTheDocument(); - //data won't actually be filtered but filters should be selected - // expect(capturesValues.filter.countAppliedFilters()).toBe(1); + // data won't actually be filtered but filters should be selected let dropdown = screen.getByTestId('org-dropdown'); expect(dropdown).toBeInTheDocument(); let button = within(dropdown).getByRole('button', { @@ -142,14 +131,11 @@ describe.skip('Captures View', () => { userEvent.selectOptions(orglist, orgSelected); userEvent.click(screen.getByText(/apply/i)); - // screen.logTestingPlaygroundURL(); expect( screen.getByRole('button', { name: /filter 2/i, }) ).toBeTruthy(); - - // expect(capturesValues.filter.countAppliedFilters()).toBe(2); }); it('renders gallery view', () => { @@ -180,7 +166,6 @@ describe.skip('Captures View', () => { expect(screen.getByText(/grower identifier/i)).toBeInTheDocument(); expect(screen.getByText(/grower1@some.place/i)).toBeInTheDocument(); expect(screen.getByText(/device identifier/i)).toBeInTheDocument(); - // expect(screen.getByText(/1 - abcdef123456/i)).toBeInTheDocument(); expect(screen.getByText(/verification status/i)).toBeInTheDocument(); expect(screen.getByText(/token status/i)).toBeInTheDocument(); }); @@ -201,19 +186,6 @@ describe.skip('Captures View', () => { expect(screen.getByText(/phone number/i)).toBeInTheDocument(); expect(screen.getByText(/registered/i)).toBeInTheDocument(); }); - - // it('renders edit planter', () => { - // const planterDetails = screen.getAllByRole('button', { - // name: /planter details/i, - // }); - // userEvent.click(planterDetails[0]); - - // screen.logTestingPlaygroundURL(); - // // - // const editPlanter = screen.getByTestId(/edit-planter/i); - // expect(editPlanter).toBeInTheDocument(); - // userEvent.click(editPlanter); - // }); }); describe.skip('render view with CaptureTable', () => { @@ -243,7 +215,6 @@ describe.skip('Captures View', () => { afterEach(cleanup); it('renders table view', () => { - // screen.logTestingPlaygroundURL(); const pageSize = screen.getAllByText(/rows per page:/i); expect(pageSize).toHaveLength(2); expect(screen.getByText(/4 captures/i)); @@ -270,7 +241,6 @@ describe.skip('Captures View', () => { expect(screen.getByText(/grower identifier/i)).toBeInTheDocument(); expect(screen.getByText(/grower1@some.place/i)).toBeInTheDocument(); expect(screen.getByText(/device identifier/i)).toBeInTheDocument(); - // expect(screen.getByText(/1 - abcdef123456/i)).toBeInTheDocument(); expect(screen.getByText(/verification status/i)).toBeInTheDocument(); expect(screen.getByText(/token status/i)).toBeInTheDocument(); });