Skip to content

Commit 71e582a

Browse files
committed
implement snapshot delete
1 parent 2010733 commit 71e582a

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/packages/frontend/project/explorer/action-bar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ export function ActionBar({
166166
}
167167

168168
function render_action_button(name: FileAction) {
169-
if (isSnapshotPath(current_path) && isDisabledSnapshots(name)) {
170-
return null;
169+
if (isSnapshotPath(current_path)) {
170+
if (isDisabledSnapshots(name)) {
171+
return null;
172+
}
173+
if (current_path != SNAPSHOTS && name == "delete") {
174+
return null;
175+
}
171176
}
172177
const obj = file_actions[name];
173178
const handle_click = (_e: React.MouseEvent) => {

src/packages/frontend/project/snapshots.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function CreateSnapshot() {
105105
}}
106106
footer={[
107107
<Button
108+
key="cancel"
108109
onClick={() => {
109110
setOpen(false);
110111
setName("");
@@ -113,6 +114,7 @@ function CreateSnapshot() {
113114
Cancel
114115
</Button>,
115116
<Button
117+
key="create"
116118
type="primary"
117119
onClick={createSnapshot}
118120
disabled={!name.trim()}
@@ -229,6 +231,7 @@ function EditSchedule() {
229231
}}
230232
footer={[
231233
<Button
234+
key="cancel"
232235
onClick={() => {
233236
setOpen(false);
234237
setName("");
@@ -237,6 +240,7 @@ function EditSchedule() {
237240
Cancel
238241
</Button>,
239242
<Button
243+
key="create"
240244
type="primary"
241245
onClick={createSnapshot}
242246
disabled={!name.trim()}

src/packages/frontend/project_actions.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ import {
111111
import { search } from "@cocalc/frontend/project/search/run";
112112
import { type CopyOptions } from "@cocalc/conat/files/fs";
113113
import { getFileTemplate } from "./project/templates";
114+
import { SNAPSHOTS } from "@cocalc/util/consts/snapshots";
114115

115116
const { defaults, required } = misc;
116117

@@ -2510,8 +2511,29 @@ export class ProjectActions extends Actions<ProjectStoreState> {
25102511
this.set_activity({ id, status: `Deleting ${mesg}...` });
25112512

25122513
try {
2513-
const fs = this.fs(compute_server_id);
2514-
await fs.rm(paths, { force: true, recursive: true });
2514+
// delete any snapshots:
2515+
const snapshots: string[] = [];
2516+
const nonSnapshotPaths: string[] = [];
2517+
for (const path of paths) {
2518+
if (dirname(path) == SNAPSHOTS) {
2519+
snapshots.push(basename(path));
2520+
} else {
2521+
nonSnapshotPaths.push(path);
2522+
}
2523+
}
2524+
if (snapshots.length > 0) {
2525+
for (const name of snapshots) {
2526+
await webapp_client.conat_client.hub.projects.deleteSnapshot({
2527+
project_id: this.project_id,
2528+
name,
2529+
});
2530+
}
2531+
}
2532+
if (nonSnapshotPaths.length > 0) {
2533+
const fs = this.fs(compute_server_id);
2534+
await fs.rm(nonSnapshotPaths, { force: true, recursive: true });
2535+
}
2536+
25152537
this.log({
25162538
event: "file_action",
25172539
action: "deleted",

0 commit comments

Comments
 (0)