Skip to content

Commit

Permalink
Use copyBorehole from fetchApiV2 (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
danjov authored Dec 6, 2023
2 parents 5b1696d + 67dbb96 commit 28319d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
7 changes: 7 additions & 0 deletions src/client/src/api/fetchApiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export const importBoreholes = async (workgroupId, combinedFormData) => {
);
};

export const copyBorehole = async (boreholeId, workgroupId) => {
return await fetchApiV2(
`borehole/copy?id=${boreholeId}&workgroupId=${workgroupId}`,
"POST",
);
};

// layers
export const fetchLayerById = async id =>
await fetchApiV2(`layer/${id}`, "GET");
Expand Down
48 changes: 16 additions & 32 deletions src/client/src/commons/table/boreholeEditorTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DomainText from "../form/domain/domainText";
import DateText from "../form/dateText";
import TranslationText from "../form/translationText";
import { NumericFormat } from "react-number-format";
import { copyBorehole } from "../../api/fetchApiV2";

import TTable from "./table";

Expand All @@ -27,8 +28,6 @@ import {
deleteBoreholes,
} from "../../api-lib/index";
import { AlertContext } from "../alert/alertContext";
import store from "../../reducers";
import { getBasicAuthHeaderValue } from "../../api/authentication";

class BoreholeEditorTable extends TTable {
static contextType = AlertContext;
Expand Down Expand Up @@ -166,35 +165,20 @@ class BoreholeEditorTable extends TTable {
}
}
}
copyBorehole() {
const credentials = store.getState().core_user.authentication;
fetch(
`/api/v2/borehole/copy?id=${this.state.selected[0]}&workgroupId=${this.state.workgroup}`,
{
method: "POST",
cache: "no-cache",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
Authorization: getBasicAuthHeaderValue(
credentials.username,
credentials.password,
),
},
async copyBorehole() {
await copyBorehole(this.state.selected[0], this.state.workgroup).then(
boreholeId => {
this.setState(
{
copy: false,
copying: false,
},
() => {
super.handleClick({ id: boreholeId });
},
);
},
).then(r => {
this.setState(
{
copy: false,
copying: false,
},
async () => {
if (r.ok) {
super.handleClick({ id: await r.text() });
}
},
);
});
);
}
getHeaderLabel(key, disableOrdering = false) {
const { store } = this.props;
Expand Down Expand Up @@ -479,8 +463,8 @@ class BoreholeEditorTable extends TTable {
{
copying: true,
},
() => {
this.copyBorehole();
async () => {
await this.copyBorehole();
},
);
}}
Expand Down

0 comments on commit 28319d1

Please sign in to comment.