Bug fix: Allow creation of PointGroups that contain points created during current session.
parent
9213d4f37e
commit
6b1db0c51c
|
@ -72,10 +72,9 @@ export class RawSelectPlants extends React.Component<SelectPlantsProps, {}> {
|
|||
</button>
|
||||
{DevSettings.futureFeaturesEnabled() &&
|
||||
<button className="fb-button blue"
|
||||
onClick={() => createGroup({
|
||||
points: this.props.selected,
|
||||
dispatch: this.props.dispatch
|
||||
})}>
|
||||
onClick={() => this.props.dispatch(createGroup({
|
||||
points: this.props.selected
|
||||
}))}>
|
||||
{t("Create group")}
|
||||
</button>}
|
||||
{DevSettings.futureFeaturesEnabled() &&
|
||||
|
|
|
@ -11,13 +11,16 @@ jest.mock("../../../history", () => {
|
|||
import { createGroup } from "../actions";
|
||||
import { initSave } from "../../../api/crud";
|
||||
import { history } from "../../../history";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
|
||||
describe("group action creators and thunks", () => {
|
||||
it("creates groups", async () => {
|
||||
const points: string[] =
|
||||
["Point.4.5", "Point.6.7", "Point.8.9"];
|
||||
const dispatch = jest.fn();
|
||||
|
||||
await createGroup({ points, dispatch: jest.fn(), name: "Name123" });
|
||||
const thunk = createGroup({ points, name: "Name123" });
|
||||
thunk(dispatch, fakeState);
|
||||
expect(initSave).toHaveBeenCalledWith("PointGroup", {
|
||||
name: "Name123",
|
||||
point_ids: [4, 6, 8]
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { unpackUUID, betterCompact } from "../../util";
|
||||
import { betterCompact } from "../../util";
|
||||
import { PointGroup } from "farmbot/dist/resources/api_resources";
|
||||
import { initSave } from "../../api/crud";
|
||||
import { history } from "../../history";
|
||||
import { GetState } from "../../redux/interfaces";
|
||||
|
||||
const UNTITLED = "Untitled Group";
|
||||
|
||||
|
@ -9,21 +10,21 @@ interface CreateGroupProps {
|
|||
/** TaggedPoint UUIDs */
|
||||
points: string[];
|
||||
name?: string;
|
||||
dispatch: Function;
|
||||
}
|
||||
|
||||
/** This probably won't work as a long term
|
||||
* solution because it won't add points created
|
||||
* during the current user session (localId of 0)
|
||||
*/
|
||||
export const createGroup =
|
||||
({ points, name, dispatch }: CreateGroupProps) => {
|
||||
console.warn("TODO: Handle points with a localID of 0");
|
||||
const all = points.map(x => unpackUUID(x).remoteId);
|
||||
const point_ids = betterCompact(all);
|
||||
export const createGroup = ({ points, name }: CreateGroupProps) => {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
const { references } = getState().resources.index;
|
||||
const possiblyNil = points
|
||||
.map(x => references[x])
|
||||
.map(x => x ? x.body.id : undefined);
|
||||
const point_ids = betterCompact(possiblyNil);
|
||||
const group: PointGroup = ({ name: name || UNTITLED, point_ids });
|
||||
const thunk = initSave("PointGroup", group);
|
||||
const p: Promise<{}> = thunk(dispatch);
|
||||
|
||||
return p.then(() => history.push("/app/designer/groups"));
|
||||
return thunk(dispatch).then(() => history.push("/app/designer/groups"));
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue