Merge pull request #1711 from FarmBot/days_ago

days => days_ago
days_ago
Rick Carlino 2020-02-24 08:52:04 -08:00 committed by GitHub
commit cd52670c0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 21 additions and 21 deletions

View File

@ -4,7 +4,7 @@ class PointGroup < ApplicationRecord
BAD_SORT = "%{value} is not valid. Valid options are: " +
SORT_TYPES.map(&:inspect).join(", ")
DEFAULT_CRITERIA = {
day: { op: "<", days: 0 },
day: { op: "<", days_ago: 0 },
string_eq: {},
number_eq: {},
number_lt: {},

View File

@ -5,7 +5,7 @@ module PointGroups
hash :criteria do
hash(:day) do
string :op, in: [">", "<"]
integer :days
integer :days_ago
end
hash(:string_eq) { array :*, class: String }
hash(:number_eq) { array :*, class: Integer }

View File

@ -460,7 +460,7 @@ export function fakePointGroup(): TaggedPointGroup {
sort_type: "xy_ascending",
point_ids: [],
criteria: {
day: { op: "<", days: 0 },
day: { op: "<", days_ago: 0 },
number_eq: {},
number_gt: {},
number_lt: {},

View File

@ -57,7 +57,7 @@ describe("selectPointsByCriteria()", () => {
it("matches age greater than 1 day old", () => {
const criteria = fakeCriteria();
criteria.day = { days: 1, op: ">" };
criteria.day = { days_ago: 1, op: ">" };
const matchingPoint = fakePoint();
matchingPoint.body.created_at = "2020-01-20T20:00:00.000Z";
const otherPoint = fakePoint();
@ -70,7 +70,7 @@ describe("selectPointsByCriteria()", () => {
it("matches age less than 1 day old", () => {
const criteria = fakeCriteria();
criteria.day = { days: 1, op: "<" };
criteria.day = { days_ago: 1, op: "<" };
const matchingPoint = fakePoint();
matchingPoint.body.created_at = "2020-02-20T20:00:00.000Z";
const otherPoint = fakePoint();
@ -83,7 +83,7 @@ describe("selectPointsByCriteria()", () => {
it("matches planted date less than 1 day old", () => {
const criteria = fakeCriteria();
criteria.day = { days: 1, op: "<" };
criteria.day = { days_ago: 1, op: "<" };
const matchingPoint = fakePlant();
matchingPoint.body.planted_at = "2020-02-20T20:00:00.000Z";
matchingPoint.body.created_at = "2020-01-20T20:00:00.000Z";

View File

@ -36,7 +36,7 @@ describe("editCriteria()", () => {
it("edits criteria: full update", () => {
const group = fakePointGroup();
const criteria: PointGroup["criteria"] = {
day: { days: 1, op: "<" },
day: { days_ago: 1, op: "<" },
string_eq: { openfarm_slug: ["slug"] },
number_eq: { x: [0] },
number_gt: { x: 0 },

View File

@ -100,7 +100,7 @@ describe("<DaySelection />", () => {
currentTarget: { value: "1" }
});
const expectedBody = cloneDeep(p.group.body);
expectedBody.criteria.day.days = 1;
expectedBody.criteria.day.days_ago = 1;
expect(overwrite).toHaveBeenCalledWith(p.group, expectedBody);
});

View File

@ -30,11 +30,11 @@ const checkCriteria =
? point.body.planted_at
: point.body.created_at);
const compareDate = moment(now)
.subtract(criteria[criteriaKey].days, "days");
.subtract(criteria[criteriaKey].days_ago, "days");
const matchesDays = criteria[criteriaKey].op == "<"
? pointDate.isAfter(compareDate)
: pointDate.isBefore(compareDate);
return matchesDays || !criteria[criteriaKey].days;
return matchesDays || !criteria[criteriaKey].days_ago;
}
};

View File

@ -2,7 +2,7 @@ import { TaggedPointGroup } from "farmbot";
import { PointGroup } from "farmbot/dist/resources/api_resources";
export const DEFAULT_CRITERIA: Readonly<PointGroup["criteria"]> = {
day: { op: "<", days: 0 },
day: { op: "<", days_ago: 0 },
number_eq: {},
number_gt: {},
number_lt: {},

View File

@ -105,16 +105,16 @@ export const DaySelection = (props: CriteriaSelectionProps) => {
selectedItem={DAY_OPERATOR_DDI_LOOKUP()[dayCriteria.op]}
onChange={ddi => dispatch(editCriteria(group, {
day: {
days: dayCriteria.days,
days_ago: dayCriteria.days_ago,
op: ddi.value as PointGroup["criteria"]["day"]["op"]
}
}))} />
</Col>
<Col xs={3}>
<input type="number" value={dayCriteria.days} onChange={e => {
<input type="number" value={dayCriteria.days_ago} onChange={e => {
const { op } = dayCriteria;
const days = parseInt(e.currentTarget.value);
dispatch(editCriteria(group, { day: { days, op } }));
const days_ago = parseInt(e.currentTarget.value);
dispatch(editCriteria(group, { day: { days_ago, op } }));
}} />
</Col>
<Col xs={4}>

View File

@ -45,7 +45,7 @@
"coveralls": "3.0.9",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.2",
"farmbot": "9.1.0",
"farmbot": "9.1.2",
"i18next": "19.0.3",
"install": "0.13.0",
"lodash": "4.17.15",

View File

@ -70,7 +70,7 @@ describe Api::PointGroupsController do
},
day: {
op: "<",
days: 0,
days_ago: 0,
},
},
}
@ -85,7 +85,7 @@ describe Api::PointGroupsController do
expect(hash.dig(:number_gt, :x)).to eq(1)
expect(hash.dig(:number_gt, :y)).to eq(1)
expect(hash.dig(:day, :op)).to eq("<")
expect(hash.dig(:day, :days)).to eq(0)
expect(hash.dig(:day, :days_ago)).to eq(0)
expect(hash.dig(:string_eq, :openfarm_slug)).to eq(["carrot"])
end
end

View File

@ -57,7 +57,7 @@ describe Api::PointGroupsController do
number_eq: { z: [24, 25, 26] },
number_lt: { x: 4, y: 4 },
number_gt: { x: 1, y: 1 },
day: { op: "<", days: 0 },
day: { op: "<", days_ago: 0 },
},
}
pg = PointGroups::Create.run!(initial_params)
@ -68,12 +68,12 @@ describe Api::PointGroupsController do
number_eq: { x: [42, 52, 62] },
number_lt: { y: 8 },
number_gt: { z: 2 },
day: { op: ">", days: 10 },
day: { op: ">", days_ago: 10 },
},
}
put :update, body: payload.to_json, format: :json, params: { id: pg.id }
expect(response.status).to eq(200)
expect(json.dig(:criteria, :day, :days)).to eq(10)
expect(json.dig(:criteria, :day, :days_ago)).to eq(10)
expect(json.dig(:criteria, :day, :op)).to eq(">")
expect(json.dig(:criteria, :number_eq, :x)).to eq([42, 52, 62])
expect(json.dig(:criteria, :number_eq, :z)).to eq(nil)