-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathgetColumns.tsx
More file actions
152 lines (150 loc) · 4.11 KB
/
Copy pathgetColumns.tsx
File metadata and controls
152 lines (150 loc) · 4.11 KB
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
import * as React from 'react'
import { Column } from '@src/polaris/common/ducks/GridPage'
import { Instance, HEALTH_STATUS_MAP, ISOLATE_STATUS_MAP } from './types'
import { DuckCmpProps } from 'saga-duck'
import ServiceInstanceDuck from './PageDuck'
import { Text, Icon } from 'tea-component'
import Action from '@src/polaris/common/duckComponents/grid/Action'
import { checkGlobalRegistry, isReadOnly } from '../../utils'
import { disableDeleteTip } from '../../getColumns'
export const SourcePolarisIpKey = 'internal-sync-local-registry-host'
export const getSourcePolairisIp = x => {
// metadata 可能缺失(开源版 server),必须判空
const hasSyncGlobal = Object.entries(x.metadata ?? {}).find(([key]) => key === SourcePolarisIpKey)
return hasSyncGlobal?.[1]
}
export default ({ duck: { creators, selector }, store }: DuckCmpProps<ServiceInstanceDuck>): Column<Instance>[] => [
// {
// key: "id",
// header: "id",
// render: (x) => (
// <>
// <Text overflow tooltip={x.id} style={{ width: "100px" }}>
// {x.id}
// </Text>
// <Copy text={x.id}>
// <Button type={"icon"} icon={"copy"}></Button>
// </Copy>
// </>
// ),
// },
{
key: 'host',
header: '实例IP',
render: x => <Text overflow>{x.host}</Text>,
},
{
key: 'sourceIp',
header: '来源北极星IP',
render: x => <Text overflow>{getSourcePolairisIp(x) || '-'}</Text>,
},
{
key: 'port',
header: '端口',
render: x => (
<Text tooltip={x.port} overflow>
{x.port || '-'}
</Text>
),
},
{
key: 'protocol',
header: '协议',
render: x => (
<Text tooltip={x.protocol} overflow>
{x.protocol || '-'}
</Text>
),
},
{
key: 'version',
header: '版本',
render: x => (
<Text tooltip={x.version} overflow>
{x.version || '-'}
</Text>
),
},
{
key: 'weight',
header: '权重',
render: x => (
<Text tooltip={x.weight} overflow>
{x.weight}
</Text>
),
},
{
key: 'healthy',
header: '健康状态',
render: x => <Text theme={HEALTH_STATUS_MAP[x.healthy].theme}>{HEALTH_STATUS_MAP[x.healthy].text}</Text>,
},
{
key: 'isolate',
header: '隔离状态',
render: x => <Text theme={ISOLATE_STATUS_MAP[x.isolate].theme}>{ISOLATE_STATUS_MAP[x.isolate].text}</Text>,
},
{
key: 'cmdb',
header: '地区/地域/可用区',
render: x => (
<Text tooltip={`${x.location?.region ?? '-'}/${x.location?.zone ?? '-'}/${x.location?.campus ?? '-'}`}>
{`${x.location?.region ?? '-'}/${x.location?.zone ?? '-'}/${x.location?.campus ?? '-'}`}
</Text>
),
},
{
key: 'ctime',
header: '创建时间',
render: x => (
<Text tooltip={x.ctime} overflow>
{x.ctime || '-'}
</Text>
),
},
{
key: 'mtime',
header: '修改时间',
render: x => (
<Text tooltip={x.mtime} overflow>
{x.mtime || '-'}
</Text>
),
},
{
key: 'action',
header: '操作',
render: x => {
const {
data: { namespace, editable, deleteable },
} = selector(store)
const hasGlobalRegistry = checkGlobalRegistry(x)
return (
<React.Fragment>
<Action
fn={dispatch => dispatch(creators.edit(x))}
disabled={isReadOnly(namespace) || !editable || hasGlobalRegistry}
tip={
isReadOnly(namespace)
? '该命名空间为只读的'
: !editable
? '无写权限'
: hasGlobalRegistry
? disableDeleteTip
: '编辑'
}
>
<Icon type={'pencil'}></Icon>
</Action>
<Action
fn={dispatch => dispatch(creators.remove([x.id]))}
disabled={isReadOnly(namespace) || deleteable === false}
tip={isReadOnly(namespace) ? '该命名空间为只读的' : deleteable === false ? '无写权限' : '删除'}
>
<Icon type={'delete'}></Icon>
</Action>
</React.Fragment>
)
},
},
]