updated as in the field api
This commit is contained in:
parent
29902bc40b
commit
ae458c3fca
3 changed files with 17 additions and 15 deletions
|
|
@ -14,7 +14,7 @@ import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useFieldAPI } from "providers";
|
import { useFieldAPI, useGlobalState } from "providers";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useSnackbar } from "hooks";
|
import { useSnackbar } from "hooks";
|
||||||
import { Field } from "models";
|
import { Field } from "models";
|
||||||
|
|
@ -35,6 +35,7 @@ interface Props {
|
||||||
|
|
||||||
export default function FieldSettings(props: Props) {
|
export default function FieldSettings(props: Props) {
|
||||||
const { selectedField, onClose, removeField, updateFields, borders } = props;
|
const { selectedField, onClose, removeField, updateFields, borders } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [fieldName, setFieldName] = useState("");
|
const [fieldName, setFieldName] = useState("");
|
||||||
const [acres, setAcres] = useState<number>(0);
|
const [acres, setAcres] = useState<number>(0);
|
||||||
const [cropType, setCropType] = useState<pond.Grain>(pond.Grain.GRAIN_INVALID);
|
const [cropType, setCropType] = useState<pond.Grain>(pond.Grain.GRAIN_INVALID);
|
||||||
|
|
@ -89,7 +90,7 @@ export default function FieldSettings(props: Props) {
|
||||||
settings.acres = acres;
|
settings.acres = acres;
|
||||||
|
|
||||||
fieldAPI
|
fieldAPI
|
||||||
.updateField(selectedField.key(), settings)
|
.updateField(selectedField.key(), settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let newField = clone(selectedField);
|
let newField = clone(selectedField);
|
||||||
newField.settings = settings;
|
newField.settings = settings;
|
||||||
|
|
@ -121,7 +122,7 @@ export default function FieldSettings(props: Props) {
|
||||||
}
|
}
|
||||||
settings.fieldGeoData = geo;
|
settings.fieldGeoData = geo;
|
||||||
fieldAPI
|
fieldAPI
|
||||||
.addField(settings)
|
.addField(settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
updateFields && updateFields(resp.data.field, settings);
|
updateFields && updateFields(resp.data.field, settings);
|
||||||
openSnack("New Field Created");
|
openSnack("New Field Created");
|
||||||
|
|
@ -136,7 +137,7 @@ export default function FieldSettings(props: Props) {
|
||||||
const deleteField = () => {
|
const deleteField = () => {
|
||||||
if (selectedField) {
|
if (selectedField) {
|
||||||
fieldAPI
|
fieldAPI
|
||||||
.removeField(selectedField?.key())
|
.removeField(selectedField?.key(), as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Field Mapping Deleted");
|
openSnack("Field Mapping Deleted");
|
||||||
//setActiveStep(0);
|
//setActiveStep(0);
|
||||||
|
|
|
||||||
|
|
@ -1200,7 +1200,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
let newSettings = field.settings;
|
let newSettings = field.settings;
|
||||||
newSettings.fieldGeoData = geoData;
|
newSettings.fieldGeoData = geoData;
|
||||||
fieldAPI
|
fieldAPI
|
||||||
.updateField(key, newSettings)
|
.updateField(key, newSettings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let cloneGeo = clone(geoRef.current);
|
let cloneGeo = clone(geoRef.current);
|
||||||
geoData.objectKey = key;
|
geoData.objectKey = key;
|
||||||
|
|
@ -1219,7 +1219,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
let field = fieldsRef.current.get(key);
|
let field = fieldsRef.current.get(key);
|
||||||
if (field) {
|
if (field) {
|
||||||
fieldAPI
|
fieldAPI
|
||||||
.removeField(key)
|
.removeField(key, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let cloneGeo = clone(geoRef.current);
|
let cloneGeo = clone(geoRef.current);
|
||||||
cloneGeo.delete(key);
|
cloneGeo.delete(key);
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ import { or } from "utils";
|
||||||
import { pondURL } from "./pond";
|
import { pondURL } from "./pond";
|
||||||
|
|
||||||
export interface IFieldAPIContext {
|
export interface IFieldAPIContext {
|
||||||
addField: (field: pond.FieldSettings) => Promise<any>;
|
addField: (field: pond.FieldSettings, as?: string) => Promise<any>;
|
||||||
getField: (fieldId: string) => Promise<any>;
|
getField: (fieldId: string, as?: string) => Promise<any>;
|
||||||
listFields: (
|
listFields: (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -18,11 +18,12 @@ export interface IFieldAPIContext {
|
||||||
as?: string,
|
as?: string,
|
||||||
asRoot?: boolean
|
asRoot?: boolean
|
||||||
) => Promise<AxiosResponse<pond.ListFieldsResponse>>;
|
) => Promise<AxiosResponse<pond.ListFieldsResponse>>;
|
||||||
removeField: (key: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>;
|
removeField: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>;
|
||||||
updateField: (
|
updateField: (
|
||||||
key: string,
|
key: string,
|
||||||
field: pond.FieldSettings,
|
field: pond.FieldSettings,
|
||||||
asRoot?: true
|
asRoot?: true,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,19 +34,19 @@ interface Props {}
|
||||||
export default function FieldProvider(props: PropsWithChildren<Props>) {
|
export default function FieldProvider(props: PropsWithChildren<Props>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, del, post, put } = useHTTP();
|
const { get, del, post, put } = useHTTP();
|
||||||
const [{ as }] = useGlobalState();
|
//const [{ as }] = useGlobalState();
|
||||||
|
|
||||||
const addField = (field: pond.FieldSettings) => {
|
const addField = (field: pond.FieldSettings, as?: string) => {
|
||||||
if (as) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + as), field);
|
if (as) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + as), field);
|
||||||
return post(pondURL("/fields"), field);
|
return post(pondURL("/fields"), field);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getField = (fieldId: string) => {
|
const getField = (fieldId: string, as?: string) => {
|
||||||
if (as) return get(pondURL("/field/" + fieldId + "?as=" + as));
|
if (as) return get(pondURL("/field/" + fieldId + "?as=" + as));
|
||||||
return get(pondURL("/field/" + fieldId));
|
return get(pondURL("/field/" + fieldId));
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeField = (key: string) => {
|
const removeField = (key: string, as?: string) => {
|
||||||
if (as) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + as));
|
if (as) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + as));
|
||||||
return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key));
|
return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key));
|
||||||
};
|
};
|
||||||
|
|
@ -75,7 +76,7 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean) => {
|
const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, as?: string) => {
|
||||||
if (as)
|
if (as)
|
||||||
return put<pond.UpdateFieldResponse>(
|
return put<pond.UpdateFieldResponse>(
|
||||||
pondURL("/fields/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
pondURL("/fields/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue