-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.tsx
162 lines (155 loc) · 5.27 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Box, Flex, Button, useTheme } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { useDBStore } from '@/store/db';
import { useToast } from '@/hooks/useToast';
import { useLoading } from '@/hooks/useLoading';
import { useGlobalStore } from '@/store/global';
import { serviceSideProps } from '@/utils/i18n';
import { useRouter } from 'next/router';
import Header from './components/Header';
import AppBaseInfo from './components/AppBaseInfo';
import Pods from './components/Pods';
import BackupTable, { type ComponentRef } from './components/BackupTable';
import { useTranslation } from 'next-i18next';
import { DBTypeEnum } from '@/constants/db';
enum TabEnum {
pod = 'pod',
backup = 'backup'
}
const AppDetail = ({ dbName, listType }: { dbName: string; listType: `${TabEnum}` }) => {
const BackupTableRef = useRef<ComponentRef>(null);
const router = useRouter();
const { t } = useTranslation();
const listNav = useRef([
{ label: 'Replicas List', value: TabEnum.pod },
{ label: 'Backup List', value: TabEnum.backup }
]);
const theme = useTheme();
const { toast } = useToast();
const { Loading } = useLoading();
const { screenWidth } = useGlobalStore();
const isLargeScreen = useMemo(() => screenWidth > 1280, [screenWidth]);
const { dbDetail, loadDBDetail, dbPods } = useDBStore();
const [showSlider, setShowSlider] = useState(false);
useQuery([dbName, 'loadDBDetail', 'intervalLoadPods'], () => loadDBDetail(dbName), {
refetchInterval: 3000,
onError(err) {
router.replace('/dbs');
toast({
title: String(err),
status: 'error'
});
}
});
return (
<Flex flexDirection={'column'} height={'100vh'} bg={'#F3F4F5'} px={9} pb={4}>
<Box>
<Header db={dbDetail} setShowSlider={setShowSlider} isLargeScreen={isLargeScreen} />
</Box>
<Flex position={'relative'} flex={'1 0 0'} h={0}>
<Box
h={'100%'}
flex={'0 0 400px'}
mr={4}
overflowY={'auto'}
zIndex={1}
transition={'0.4s'}
bg={'white'}
border={theme.borders.sm}
borderRadius={'md'}
{...(isLargeScreen
? {}
: {
w: '400px',
position: 'absolute',
left: 0,
boxShadow: '7px 4px 12px rgba(165, 172, 185, 0.25)',
transform: `translateX(${showSlider ? '0' : '-800px'})`
})}
>
{dbDetail ? <AppBaseInfo db={dbDetail} /> : <Loading loading={true} fixed={false} />}
</Box>
<Flex
flexDirection={'column'}
flex={'1 0 0'}
w={0}
h={'100%'}
bg={'white'}
border={theme.borders.sm}
borderRadius={'md'}
>
<Flex p={'26px'} alignItems={'flex-start'}>
{listNav.current.map((item) => (
<Box
key={item.value}
mr={5}
pb={2}
borderBottom={'2px solid'}
cursor={'pointer'}
fontSize={'lg'}
{...(item.value === listType
? {
color: 'black',
borderBottomColor: 'black'
}
: {
color: 'myGray.500',
borderBottomColor: 'transparent',
onClick: () =>
router.replace(`/db/detail?name=${dbName}&listType=${item.value}`)
})}
>
{t(item.label)}
</Box>
))}
<Box flex={1}></Box>
{listType === 'pod' && <Box color={'myGray.500'}>{dbPods.length} Items</Box>}
{listType === 'backup' && !BackupTableRef.current?.backupProcessing && (
<Flex alignItems={'center'}>
<Button
ml={3}
variant={'primary'}
onClick={() => {
if (dbDetail.dbType === DBTypeEnum.redis) {
return toast({
status: 'warning',
title: t('Redis does not support backup at this time')
});
}
BackupTableRef.current?.openBackup();
}}
>
{t('Backup')}
</Button>
</Flex>
)}
</Flex>
<Box flex={'1 0 0'} h={0}>
{listType === 'pod' && <Pods dbName={dbName} dbType={dbDetail.dbType} />}
{listType === 'backup' && <BackupTable ref={BackupTableRef} db={dbDetail} />}
</Box>
</Flex>
</Flex>
{/* mask */}
{!isLargeScreen && showSlider && (
<Box
position={'fixed'}
top={0}
left={0}
right={0}
bottom={0}
onClick={() => setShowSlider(false)}
/>
)}
</Flex>
);
};
export default AppDetail;
export async function getServerSideProps(context: any) {
const dbName = context.query?.name || '';
const listType = context.query?.listType || TabEnum.pod;
return {
props: { ...(await serviceSideProps(context)), dbName, listType }
};
}