1
1
import { FetchResult } from "@apollo/client" ;
2
2
import { entries , map } from "lodash" ;
3
3
import { FC , useCallback , useEffect , useMemo , useState } from "react" ;
4
- import { Navigate , useLocation } from "react-router-dom" ;
4
+ import { Navigate , useLocation , useNavigate } from "react-router-dom" ;
5
5
import { AnimatedButton } from "../../components/button" ;
6
6
import { Icons } from "../../components/icons" ;
7
7
import { InputWithlabel } from "../../components/input" ;
@@ -23,15 +23,20 @@ export const ExploreStorageUnit: FC = () => {
23
23
const unit : StorageUnit = useLocation ( ) . state ?. unit ;
24
24
const schema = useAppSelector ( state => state . database . schema ) ;
25
25
const current = useAppSelector ( state => state . auth . current ) ;
26
+ const navigate = useNavigate ( ) ;
26
27
27
28
const [ getStorageUnitRows , { data : rows , loading } ] = useGetStorageUnitRowsLazyQuery ( ) ;
28
29
30
+ const unitName = useMemo ( ( ) => {
31
+ return unit ?. Name ;
32
+ } , [ unit ] ) ;
33
+
29
34
const handleSubmitRequest = useCallback ( ( ) => {
30
35
getStorageUnitRows ( {
31
36
variables : {
32
37
type : current ?. Type as DatabaseType ,
33
38
schema,
34
- storageUnit : unit . Name ,
39
+ storageUnit : unitName ,
35
40
where : whereCondition ,
36
41
pageSize : Number . parseInt ( bufferPageSize ) ,
37
42
pageOffset : currentPage ,
@@ -41,21 +46,21 @@ export const ExploreStorageUnit: FC = () => {
41
46
} ,
42
47
fetchPolicy : "no-cache" ,
43
48
} ) ;
44
- } , [ getStorageUnitRows , current ?. Type , schema , unit . Name , whereCondition , bufferPageSize , currentPage ] ) ;
49
+ } , [ getStorageUnitRows , current ?. Type , schema , unitName , whereCondition , bufferPageSize , currentPage ] ) ;
45
50
46
51
const handlePageChange = useCallback ( ( page : number ) => {
47
52
setCurrentPage ( page - 1 ) ;
48
53
getStorageUnitRows ( {
49
54
variables : {
50
55
type : current ?. Type as DatabaseType ,
51
56
schema,
52
- storageUnit : unit . Name ,
57
+ storageUnit : unitName ,
53
58
where : whereCondition ,
54
59
pageSize : Number . parseInt ( bufferPageSize ) ,
55
60
pageOffset : currentPage ,
56
61
}
57
62
} ) ;
58
- } , [ current ?. Type , currentPage , getStorageUnitRows , bufferPageSize , schema , unit . Name , whereCondition ] ) ;
63
+ } , [ getStorageUnitRows , current ?. Type , schema , unitName , whereCondition , bufferPageSize , currentPage ] ) ;
59
64
60
65
const handleQuery = useCallback ( ( ) => {
61
66
handleSubmitRequest ( ) ;
@@ -78,7 +83,7 @@ export const ExploreStorageUnit: FC = () => {
78
83
mutation : UpdateStorageUnitDocument ,
79
84
variables : {
80
85
schema,
81
- storageUnit : unit . Name ,
86
+ storageUnit : unitName ,
82
87
type : current . Type as DatabaseType ,
83
88
values,
84
89
} ,
@@ -93,7 +98,7 @@ export const ExploreStorageUnit: FC = () => {
93
98
}
94
99
return rej ( ) ;
95
100
} ) ;
96
- } , [ current , schema , unit . Name ] ) ;
101
+ } , [ current , schema , unitName ] ) ;
97
102
98
103
const totalCount = useMemo ( ( ) => {
99
104
return unit ?. Attributes . find ( attribute => attribute . Key === "Count" ) ?. Value ?? "unknown" ;
@@ -122,6 +127,12 @@ export const ExploreStorageUnit: FC = () => {
122
127
] ;
123
128
} , [ current ] ) ;
124
129
130
+ useEffect ( ( ) => {
131
+ if ( unitName == null ) {
132
+ navigate ( InternalRoutes . Dashboard . StorageUnit . path ) ;
133
+ }
134
+ } , [ navigate , unitName ] ) ;
135
+
125
136
if ( unit == null ) {
126
137
return < Navigate to = { InternalRoutes . Dashboard . StorageUnit . path } />
127
138
}
@@ -136,7 +147,7 @@ export const ExploreStorageUnit: FC = () => {
136
147
< div className = "flex flex-col grow gap-4 h-[calc(100%-100px)]" >
137
148
< div className = "flex items-center justify-between" >
138
149
< div className = "flex gap-2 items-center" >
139
- < div className = "text-xl font-bold mr-4 dark:text-neutral-300" > { unit . Name } </ div >
150
+ < div className = "text-xl font-bold mr-4 dark:text-neutral-300" > { unitName } </ div >
140
151
</ div >
141
152
< div className = "text-sm mr-4 dark:text-neutral-300" > < span className = "font-semibold" > Total Count:</ span > { totalCount } </ div >
142
153
</ div >
0 commit comments