Skip to content

Commit

Permalink
#179: added delete all slices button on project - slice table
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxue1123 committed Apr 27, 2023
1 parent 6d48bf5 commit f027cd2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/components/Experiment/Slices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SlicesTable from "../Slice/SlicesTable";
import SpinnerWithText from "../../components/common/SpinnerWithText";
import { getProjects } from "../../services/projectService.js";
import { autoCreateTokens } from "../../utils/manageTokens";
import { getSlices } from "../../services/sliceService.js";
import { getSlices, deleteSlice } from "../../services/sliceService.js";
import { toast } from "react-toastify";
import paginate from "../../utils/paginate";
import checkPortalType from "../../utils/checkPortalType";
Expand Down Expand Up @@ -83,6 +83,16 @@ class Slices extends React.Component {
this.setState( { includeDeadSlices: !currentChoice });
}

handleDeleteAllSlices = async () => {
try {
await deleteSlice();
window.location.reload();
}
catch (err) {
toast.error("Failed to delete all slices of this project.")
}
}

getPageData = () => {
const {
pageSize,
Expand Down Expand Up @@ -263,6 +273,7 @@ class Slices extends React.Component {
sortColumn={sortColumn}
onSort={this.handleSort}
parent={this.props.parent}
onDeleteAllSlices={this.handleDeleteAllSlices}
/>
<Pagination
itemsCount={totalCount}
Expand Down
11 changes: 8 additions & 3 deletions src/components/Slice/SlicesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class SlicesTable extends Component {
),
},
{
content: (slice) => (
content: (slice) =>
<CopyButton
id={slice.slice_id}
text={"Slice ID"}
btnStyle={"btn btn-sm btn-primary"}
showCopiedValue={true}
/>
),
/>,
},
],
"projectSlices": [
Expand All @@ -57,6 +56,12 @@ class SlicesTable extends Component {
)
},
{
label: () => <button
className="btn btn-danger"
onClick={() => this.props.onDeleteAllSlices}
>
Delete All
</button>,
content: (slice) => (
<CopyButton
id={slice.slice_id}
Expand Down
12 changes: 9 additions & 3 deletions src/services/sliceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ export function createSlice(slice) {
}

export function deleteSlice(id) {
return http.delete(`${apiEndpoint}/delete/${id}`, {
headers: {'Authorization': `Bearer ${localStorage.getItem("idToken")}`}
});
if (id) {
return http.delete(`${apiEndpoint}/delete/${id}`, {
headers: {'Authorization': `Bearer ${localStorage.getItem("idToken")}`}
});
} else {
return http.delete(`${apiEndpoint}/delete`, {
headers: {'Authorization': `Bearer ${localStorage.getItem("idToken")}`}
});
}
}

export function extendSlice(id, lease_end_time) {
Expand Down

0 comments on commit f027cd2

Please sign in to comment.