How to use the farmbot.SpecialStatus.DIRTY function in farmbot

To help you get started, we’ve selected a few farmbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FarmBot / Farmbot-Web-App / frontend / api / __tests__ / crud_malformed_data_tests.ts View on Github external
it("rejects malformed API data", () => {
    const payload = {
      uuid: "",
      statusBeforeError: SpecialStatus.DIRTY,
      dispatch: jest.fn(),
      index: buildResourceIndex([fakePeripheral()]).index
    };
    payload.uuid = Object.keys(payload.index.all)[0];
    console.error = jest.fn();
    updateViaAjax(payload).catch(e => {
      expect("" + e).toEqual("Error: Just saved a malformed TR.");
      expect(console.error).toHaveBeenCalledTimes(1);
      expect(console.error).toHaveBeenCalledWith(
        expect.stringContaining("Peripheral"));
    });
  });
});
github FarmBot / Farmbot-Web-App / frontend / account / __tests__ / test_change_password.tsx View on Github external
it("doesn't fire maybeClearForm() if form is filled", () => {
    const { el, instance } = testCase();
    el.setState({
      status: SpecialStatus.DIRTY,
      form: { ...instance().state.form, password: "X" }
    });
    el.update();
    expect(instance().state.form.password).toEqual("X");
    expect(instance().state.status).toBe(SpecialStatus.DIRTY);
    instance().maybeClearForm();
    expect(instance().state.status).toBe(SpecialStatus.DIRTY);
    expect(instance().state.form.password).toEqual("X");
  });
github FarmBot / Farmbot-Web-App / frontend / account / __tests__ / test_change_password.tsx View on Github external
it("doesn't fire maybeClearForm() if form is filled", () => {
    const { el, instance } = testCase();
    el.setState({
      status: SpecialStatus.DIRTY,
      form: { ...instance().state.form, password: "X" }
    });
    el.update();
    expect(instance().state.form.password).toEqual("X");
    expect(instance().state.status).toBe(SpecialStatus.DIRTY);
    instance().maybeClearForm();
    expect(instance().state.status).toBe(SpecialStatus.DIRTY);
    expect(instance().state.form.password).toEqual("X");
  });
github FarmBot / Farmbot-Web-App / frontend / api / crud.ts View on Github external
export function overwrite(tr: T,
  changeset: T["body"],
  specialStatus = SpecialStatus.DIRTY):
  ReduxAction {
  return {
    type: Actions.OVERWRITE_RESOURCE,
    payload: { uuid: tr.uuid, update: changeset, specialStatus }
  };
}
github FarmBot / Farmbot-Web-App / frontend / controls / webcam / edit.tsx View on Github external
    .filter(x => x.specialStatus === SpecialStatus.DIRTY);
  return
github FarmBot / Farmbot-Web-App / webpack / ui / save_button.tsx View on Github external
export function SaveBtn(props: SaveBtnProps) {
  const STATUS_TRANSLATION: Partial> = {
    [SpecialStatus.DIRTY]: "is-dirty",
    [SpecialStatus.SAVING]: "is-saving"
  };

  const CAPTIONS: Partial> = {
    [SpecialStatus.DIRTY]: (props.dirtyText || t("Save") + " *"),
    [SpecialStatus.SAVING]: props.savingText || t("Saving")
  };

  const { savedText, onClick, hidden } = props;
  const statusClass = STATUS_TRANSLATION[props.status || ""] || "is-saved";
  const klass = `${props.color || "green"} ${statusClass} save-btn fb-button`;
  const spinnerEl = (props.status === SpecialStatus.SAVING) ?
    spinner : "";

  return <button hidden="{!!hidden}">
    {CAPTIONS[props.status] || (savedText || t("Saved") + " ✔")} {spinnerEl}
  </button>;
}
github FarmBot / Farmbot-Web-App / webpack / resources / reducer.ts View on Github external
.add(Actions.EDIT_RESOURCE, (s, { payload }) =&gt; {
      const { update } = payload;
      const target = findByUuid(s.index, payload.uuid);
      const before = defensiveClone(target.body);
      merge(target, { body: update });
      const didChange = !equals(before, target.body);
      didChange &amp;&amp; mutateSpecialStatus(target.uuid, s.index, SpecialStatus.DIRTY);
      return s;
    })
    .add(Actions.OVERWRITE_RESOURCE, (s, { payload }) =&gt; {
github FarmBot / Farmbot-Web-App / frontend / resources / actions.ts View on Github external
export const generalizedError = (payload: GeneralizedError) => {
  const badStatus = payload.statusBeforeError == SpecialStatus.SAVING;
  if (badStatus) {
    /** If, somehow, a `SAVING` status sneaks in, default it to DIRTY. */
    payload.statusBeforeError = SpecialStatus.DIRTY;
  }
  toastErrors(payload);
  stopTracking(payload.uuid);
  return { type: Actions._RESOURCE_NO, payload };
};
github FarmBot / Farmbot-Web-App / frontend / account / components / change_password.tsx View on Github external
(e: React.SyntheticEvent) =&gt; {
      const wow = {
        status: SpecialStatus.DIRTY,
        form: { ...this.state.form, [key]: e.currentTarget.value }
      };
      this.setState(wow, this.maybeClearForm);
    };
github FarmBot / Farmbot-Web-App / frontend / farm_designer / tools / add_tool.tsx View on Github external
render() {
    return 
      
      
        <label>{t("Tool Name")}</label>
        <input> this.setState({ toolName: e.currentTarget.value })} /&gt;
        
            this.props.dispatch(initSave("Tool", { name: this.state.toolName }))}
          status={SpecialStatus.DIRTY} /&gt;
      
    ;
  }
}