Skip to content

Commit 7462b07

Browse files
authored
feat(api, utils, cluster): add data replication management (#105)
1 parent 51e9d2b commit 7462b07

File tree

52 files changed

+2263
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2263
-2
lines changed

apps/main/[3]cluster/[1]instances/[-2]_clusterId/Layout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const Layout: FC = ({ children }) => {
2727
{ key: resolveRoute('alert', clusterId), tab: t('pages.alert') },
2828
{ key: resolveRoute('params', clusterId), tab: t('pages.params') },
2929
{ key: resolveRoute('backup', clusterId), tab: t('pages.backup') },
30+
{
31+
key: resolveRoute('replication', clusterId),
32+
tab: t('pages.replication'),
33+
},
3034
],
3135
[clusterId, i18n.language]
3236
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { FC, useCallback } from 'react'
2+
import { useQueryClient } from 'react-query'
3+
import { loadI18n, useI18n } from '@i18n-macro'
4+
import { ClusterDataReplicationDownstreamType } from '@/api/model'
5+
import {
6+
invalidateClusterDataReplicationList,
7+
useCreateClusterDataReplication,
8+
} from '@/api/hooks/cluster'
9+
import { EditSumbitValues } from '../../../components/ReplicationEdit/helper'
10+
import EditBlock from '../../../components/ReplicationEdit/EditBlock'
11+
12+
loadI18n()
13+
14+
interface CreationPanelProps {
15+
clusterId: string
16+
back: () => void
17+
}
18+
19+
const CreationPanel: FC<CreationPanelProps> = ({ clusterId, back }) => {
20+
const { t, i18n } = useI18n()
21+
22+
const queryClient = useQueryClient()
23+
24+
const createDataReplication = useCreateClusterDataReplication()
25+
26+
const onFinish = useCallback(
27+
async (fields: EditSumbitValues) => {
28+
try {
29+
await createDataReplication.mutateAsync({
30+
payload: {
31+
clusterId,
32+
name: fields.name,
33+
startTS: fields.tso,
34+
rules: fields.filterRuleList?.filter((el) => el),
35+
downstreamType: fields.downstreamType as any,
36+
downstream: fields.downstream,
37+
},
38+
options: {
39+
actionName: t('message.name'),
40+
},
41+
})
42+
43+
back()
44+
} finally {
45+
invalidateClusterDataReplicationList(queryClient)
46+
}
47+
},
48+
[i18n.language, queryClient, createDataReplication, clusterId]
49+
)
50+
51+
return (
52+
<EditBlock
53+
mode="new"
54+
initialValues={{
55+
tso: '0',
56+
downstreamType: ClusterDataReplicationDownstreamType.tidb,
57+
downstream: {
58+
mysql: {
59+
concurrentThreads: 16,
60+
},
61+
tidb: {
62+
concurrentThreads: 16,
63+
},
64+
},
65+
}}
66+
onEditSubmit={onFinish}
67+
/>
68+
)
69+
}
70+
71+
export default CreationPanel
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
message:
2+
name: Create
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
message:
2+
name: 创建
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useI18n } from '@i18n-macro'
2+
import Header from '@/components/Header'
3+
4+
interface HeaderBarProps {
5+
back: () => void
6+
}
7+
8+
export default function HeaderBar({ back }: HeaderBarProps) {
9+
const { t } = useI18n()
10+
11+
return <Header onBack={back} title={t('header.title')} />
12+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useCallback } from 'react'
2+
import { useHistory } from 'react-router-dom'
3+
import { resolveRoute } from '@pages-macro'
4+
import HeaderBar from './components/HeaderBar'
5+
import { useClusterContext } from '../../context'
6+
import CreationPanel from './components/CreationPanel'
7+
8+
export default function () {
9+
const history = useHistory()
10+
11+
const { info } = useClusterContext()
12+
13+
const back = useCallback(
14+
() => history.push(resolveRoute('../', info!.clusterId!)),
15+
[history]
16+
)
17+
18+
return (
19+
<>
20+
<HeaderBar back={back} />
21+
<CreationPanel clusterId={info!.clusterId!} back={back} />
22+
</>
23+
)
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { definePage } from '@/model/page'
2+
3+
export default definePage({})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: New Replication Task
2+
header:
3+
title: New Replication Task
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: 创建数据同步任务
2+
header:
3+
title: 创建数据同步任务
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { FC, useCallback } from 'react'
2+
import { useQueryClient } from 'react-query'
3+
import { loadI18n, useI18n } from '@i18n-macro'
4+
import { Spin } from 'antd'
5+
import {
6+
invalidateClusterDataReplicationList,
7+
useQueryClusterDataReplicationDetail,
8+
useUpdateClusterDataReplication,
9+
} from '@/api/hooks/cluster'
10+
import EditBlock from '../../../../components/ReplicationEdit/EditBlock'
11+
import { EditSumbitValues } from '../../../../components/ReplicationEdit/helper'
12+
13+
loadI18n()
14+
15+
const useFetchReplicationDetail = ({ taskId }: { taskId: string }) => {
16+
const { data, isLoading } = useQueryClusterDataReplicationDetail(
17+
{
18+
id: taskId,
19+
},
20+
{
21+
refetchOnWindowFocus: false,
22+
enabled: !!taskId,
23+
}
24+
)
25+
const result = data?.data.data
26+
27+
return {
28+
data: result,
29+
isLoading,
30+
}
31+
}
32+
33+
interface EditingPanelProps {
34+
taskId: string
35+
back: () => void
36+
}
37+
38+
const EditingPanel: FC<EditingPanelProps> = ({ taskId, back }) => {
39+
const { t, i18n } = useI18n()
40+
41+
const { data: dataSource, isLoading } = useFetchReplicationDetail({ taskId })
42+
43+
const queryClient = useQueryClient()
44+
45+
const updateDataReplication = useUpdateClusterDataReplication()
46+
47+
const onFinish = useCallback(
48+
async (fields: EditSumbitValues) => {
49+
try {
50+
await updateDataReplication.mutateAsync({
51+
payload: {
52+
id: taskId,
53+
name: fields.name,
54+
rules: fields.filterRuleList?.filter((el) => el),
55+
downstreamType: fields.downstreamType as any,
56+
downstream: fields.downstream,
57+
},
58+
options: {
59+
actionName: t('message.name'),
60+
},
61+
})
62+
63+
back()
64+
} finally {
65+
invalidateClusterDataReplicationList(queryClient)
66+
}
67+
},
68+
[i18n.language, queryClient, updateDataReplication, taskId]
69+
)
70+
71+
if (isLoading || !dataSource) {
72+
return <Spin />
73+
}
74+
75+
return (
76+
<EditBlock
77+
mode="edit"
78+
staticData={{ taskId: taskId }}
79+
initialValues={{
80+
name: dataSource.name,
81+
tso: dataSource.startTS,
82+
filterRuleList: dataSource.rules,
83+
downstreamType: dataSource.downstreamType as any,
84+
downstream: {
85+
[dataSource.downstreamType!]: {
86+
...dataSource.downstream,
87+
ip: (dataSource.downstream as any)?.ip?.replace(/^https?:\/\//, ''),
88+
},
89+
},
90+
}}
91+
onEditSubmit={onFinish}
92+
/>
93+
)
94+
}
95+
96+
export default EditingPanel

0 commit comments

Comments
 (0)