File tree Expand file tree Collapse file tree 4 files changed +68
-0
lines changed Expand file tree Collapse file tree 4 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { useState } from "react" ;
2
+ import { useQueryClient } from "react-query" ;
3
+
4
+ import type { InstanceSummary } from "@squonk/data-manager-client" ;
5
+ import {
6
+ getGetInstanceQueryKey ,
7
+ getGetInstancesQueryKey ,
8
+ usePatchInstance ,
9
+ } from "@squonk/data-manager-client/instance" ;
10
+
11
+ import { Button , Tooltip } from "@mui/material" ;
12
+
13
+ export interface ArchiveInstanceProps {
14
+ instanceId : InstanceSummary [ "id" ] ;
15
+ archived : boolean ;
16
+ }
17
+
18
+ export const ArchiveInstance = ( { instanceId, archived } : ArchiveInstanceProps ) => {
19
+ const { mutateAsync : patchInstance } = usePatchInstance ( ) ;
20
+ const queryClient = useQueryClient ( ) ;
21
+ const [ archiving , setArchiving ] = useState ( false ) ;
22
+
23
+ const archiveInstance = async ( ) => {
24
+ setArchiving ( true ) ;
25
+ await patchInstance ( { instanceId, params : { archive : ! archived } } ) ;
26
+ await Promise . allSettled ( [
27
+ queryClient . invalidateQueries ( getGetInstanceQueryKey ( instanceId ) ) ,
28
+ queryClient . invalidateQueries ( getGetInstancesQueryKey ( ) ) ,
29
+ ] ) ;
30
+ setArchiving ( false ) ;
31
+ } ;
32
+
33
+ return (
34
+ < Tooltip title = "Toggle whether an instance will be deleted automatically" >
35
+ < span >
36
+ < Button disabled = { archiving } onClick = { archiveInstance } >
37
+ { archived ? "Unarchive" : "Archive" }
38
+ </ Button >
39
+ </ span >
40
+ </ Tooltip >
41
+ ) ;
42
+ } ;
Original file line number Diff line number Diff line change
1
+ import InventoryIcon from "@mui/icons-material/Inventory" ;
2
+ import { ListItem , ListItemIcon , Tooltip } from "@mui/material" ;
3
+
4
+ export interface ArchivedStatusProps {
5
+ archived : boolean ;
6
+ }
7
+
8
+ export const ArchivedStatus = ( { archived } : ArchivedStatusProps ) => {
9
+ return archived ? (
10
+ < Tooltip title = "This instance won't be deleted automatically" >
11
+ < ListItem >
12
+ < ListItemIcon sx = { { minWidth : "40px" } } >
13
+ < InventoryIcon />
14
+ </ ListItemIcon >
15
+ </ ListItem >
16
+ </ Tooltip >
17
+ ) : null ;
18
+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import { useProjectFromId } from "../../hooks/projectHooks";
9
9
import { ProjectListItem } from "../projects/ProjectListItem" ;
10
10
import { ResultCard } from "../results/ResultCard" ;
11
11
import { ApplicationDetails } from "./ApplicationDetails" ;
12
+ import { ArchivedStatus } from "./ArchivedStatus" ;
13
+ import { ArchiveInstance } from "./ArchiveInstance" ;
12
14
import { TerminateInstance } from "./TerminateInstance" ;
13
15
import { useInstanceRouterQuery } from "./useInstanceRouterQuery" ;
14
16
@@ -62,6 +64,7 @@ export const ResultApplicationCard = ({
62
64
Open
63
65
</ HrefButton >
64
66
) }
67
+ < ArchiveInstance archived = { instance . archived } instanceId = { instanceId } />
65
68
</ >
66
69
) }
67
70
collapsed = {
@@ -82,6 +85,7 @@ export const ResultApplicationCard = ({
82
85
< ListItemText primary = { instance . name } />
83
86
</ ListItem >
84
87
< ProjectListItem projectName = { associatedProject ?. name || "loading..." } />
88
+ < ArchivedStatus archived = { instance . archived } />
85
89
</ ResultCard >
86
90
) ;
87
91
} ;
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import { RerunJobButton } from "../../components/results/RerunJobButton";
7
7
import { ResultCard } from "../../components/results/ResultCard" ;
8
8
import { useProjectFromId } from "../../hooks/projectHooks" ;
9
9
import { ProjectListItem } from "../projects/ProjectListItem" ;
10
+ import { ArchivedStatus } from "./ArchivedStatus" ;
11
+ import { ArchiveInstance } from "./ArchiveInstance" ;
10
12
import { JobDetails } from "./JobDetails" ;
11
13
import { TerminateInstance } from "./TerminateInstance" ;
12
14
import { useInstanceRouterQuery } from "./useInstanceRouterQuery" ;
@@ -54,6 +56,7 @@ export const ResultJobCard = ({
54
56
/>
55
57
< RerunJobButton instance = { instance } />
56
58
< LogsButton instance = { instance } instanceId = { instanceId } />
59
+ < ArchiveInstance archived = { instance . archived } instanceId = { instanceId } />
57
60
</ >
58
61
) }
59
62
collapsed = {
@@ -74,6 +77,7 @@ export const ResultJobCard = ({
74
77
< ListItemText primary = { instance . name } secondary = { instance . job_name } />
75
78
</ ListItem >
76
79
< ProjectListItem projectName = { associatedProject ?. name || "loading..." } />
80
+ < ArchivedStatus archived = { instance . archived } />
77
81
</ ResultCard >
78
82
) ;
79
83
} ;
You can’t perform that action at this time.
0 commit comments