feat: add snapshot memory and blocked create button

This commit is contained in:
2026-04-09 18:50:40 +03:00
parent 4b02c6e9d3
commit 8d1de769c5
5 changed files with 210 additions and 40 deletions

View File

@@ -23,6 +23,7 @@ type Snapshot = {
Name: string;
ParentID: string;
CreationTime: string;
occupied_memory: number;
};
type SnapshotStatus = {
@@ -32,11 +33,17 @@ type SnapshotStatus = {
Error: string;
};
type StorageInfo = {
available_memory: number;
all_memory: number;
};
class SnapshotStore {
snapshots: Snapshot[] = [];
snapshot: Snapshot | null = null;
lastRequestId: string | null = null;
snapshotStatus: SnapshotStatus | null = null;
storageInfo: StorageInfo | null = null;
constructor() {
makeAutoObservable(this);
@@ -259,10 +266,17 @@ class SnapshotStore {
};
deleteSnapshot = async (id: string) => {
const snapshot = this.snapshots.find((s) => s.ID === id);
await authInstance.delete(`/snapshots/${id}`);
runInAction(() => {
this.snapshots = this.snapshots.filter((snapshot) => snapshot.ID !== id);
this.snapshots = this.snapshots.filter((s) => s.ID !== id);
if (this.storageInfo && snapshot?.occupied_memory) {
this.storageInfo = {
...this.storageInfo,
available_memory: this.storageInfo.available_memory + snapshot.occupied_memory,
};
}
});
};
@@ -299,6 +313,14 @@ class SnapshotStore {
this.snapshotStatus = response.data;
});
};
getStorageInfo = async () => {
const response = await authInstance.get(`/snapshots/storage`);
runInAction(() => {
this.storageInfo = response.data;
});
};
}
export const snapshotStore = new SnapshotStore();