feat: add snapshot memory and blocked create button
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user