fix map image filter bug

pull/1193/head
gabrielburnworth 2019-05-15 09:11:43 -07:00
parent c68db3475f
commit 80d24da54f
4 changed files with 32 additions and 13 deletions

View File

@ -1,6 +1,6 @@
jest.mock("../../actions", () => ({
unselectPlant: jest.fn(() => jest.fn()),
closePlantInfo: jest.fn(),
closePlantInfo: jest.fn(() => jest.fn()),
}));
import { Mode } from "../interfaces";
@ -141,6 +141,15 @@ describe("<GardenMap/>", () => {
expect.objectContaining(e));
});
it("starts drag: click-to-add mode", () => {
const wrapper = shallow(<GardenMap {...fakeProps()} />);
mockMode = Mode.clickToAdd;
const e = { pageX: 1000, pageY: 2000 };
wrapper.find(".drop-area-svg").simulate("mouseDown", e);
expect(beginPlantDrag).not.toHaveBeenCalled();
expect(getGardenCoordinates).not.toHaveBeenCalled();
});
it("drags: selecting", () => {
const wrapper = shallow(<GardenMap {...fakeProps()} />);
mockMode = Mode.boxSelect;
@ -234,7 +243,14 @@ describe("<GardenMap/>", () => {
const p = fakeProps();
p.designer.selectedPlants = undefined;
const wrapper = mount<GardenMap>(<GardenMap {...p} />);
wrapper.instance().closePanel();
wrapper.instance().closePanel()();
expect(closePlantInfo).toHaveBeenCalled();
});
it("closes panel when not in select mode", () => {
mockMode = Mode.none;
const wrapper = mount<GardenMap>(<GardenMap {...fakeProps()} />);
wrapper.instance().closePanel()();
expect(closePlantInfo).toHaveBeenCalled();
});
@ -243,7 +259,7 @@ describe("<GardenMap/>", () => {
const p = fakeProps();
p.designer.selectedPlants = [fakePlant().uuid];
const wrapper = mount<GardenMap>(<GardenMap {...p} />);
wrapper.instance().closePanel();
wrapper.instance().closePanel()();
expect(closePlantInfo).not.toHaveBeenCalled();
});

View File

@ -259,7 +259,10 @@ export class GardenMap extends
cameraCalibrationData={this.props.cameraCalibrationData}
visible={!!this.props.showImages}
mapTransformProps={this.mapTransformProps}
getConfigValue={this.props.getConfigValue} />
imageFilterBegin={
(this.props.getConfigValue("photo_filter_begin") || "").toString()}
imageFilterEnd={
(this.props.getConfigValue("photo_filter_end") || "").toString()} />
Grid = () => <Grid
onClick={this.closePanel()}
mapTransformProps={this.mapTransformProps} />

View File

@ -32,7 +32,8 @@ describe("<ImageLayer/>", () => {
scale: undefined,
calibrationZ: undefined,
},
getConfigValue: jest.fn(),
imageFilterBegin: "",
imageFilterEnd: "",
};
}
@ -54,7 +55,7 @@ describe("<ImageLayer/>", () => {
it("filters old images", () => {
const p = fakeProps();
p.images[0].body.created_at = "2018-01-22T05:00:00.000Z";
p.getConfigValue = () => "2018-01-23T05:00:00.000Z";
p.imageFilterBegin = "2018-01-23T05:00:00.000Z";
const wrapper = shallow(<ImageLayer {...p} />);
const layer = wrapper.find("#image-layer");
expect(layer.find("MapImage").length).toEqual(0);

View File

@ -4,7 +4,6 @@ import { CameraCalibrationData } from "../../../interfaces";
import { TaggedImage } from "farmbot";
import { MapImage } from "./map_image";
import { reverse, cloneDeep } from "lodash";
import { GetWebAppConfigValue } from "../../../../config_storage/actions";
import moment from "moment";
import { equals } from "../../../../util";
@ -13,7 +12,8 @@ export interface ImageLayerProps {
images: TaggedImage[];
mapTransformProps: MapTransformProps;
cameraCalibrationData: CameraCalibrationData;
getConfigValue: GetWebAppConfigValue;
imageFilterBegin: string;
imageFilterEnd: string;
}
export class ImageLayer extends React.Component<ImageLayerProps> {
@ -24,17 +24,16 @@ export class ImageLayer extends React.Component<ImageLayerProps> {
render() {
const {
visible, images, mapTransformProps, cameraCalibrationData, getConfigValue
visible, images, mapTransformProps, cameraCalibrationData,
imageFilterBegin, imageFilterEnd,
} = this.props;
const imageFilterBegin = getConfigValue("photo_filter_begin");
const imageFilterEnd = getConfigValue("photo_filter_end");
return <g id="image-layer">
{visible &&
reverse(cloneDeep(images))
.filter(x => !imageFilterEnd ||
moment(x.body.created_at).isBefore(imageFilterEnd.toString()))
moment(x.body.created_at).isBefore(imageFilterEnd))
.filter(x => !imageFilterBegin ||
moment(x.body.created_at).isAfter(imageFilterBegin.toString()))
moment(x.body.created_at).isAfter(imageFilterBegin))
.map(img =>
<MapImage
image={img}