-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathResourceGroupInfoModal.tsx
More file actions
185 lines (180 loc) · 6 KB
/
ResourceGroupInfoModal.tsx
File metadata and controls
185 lines (180 loc) · 6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
@license
Copyright (c) 2015-2026 Lablup Inc. All rights reserved.
*/
import { ResourceGroupInfoModalFragment$key } from '../__generated__/ResourceGroupInfoModalFragment.graphql';
import { ScalingGroupOpts } from './ResourceGroupList';
import { CheckOutlined, CloseOutlined } from '@ant-design/icons';
import { Descriptions, Tag, Typography, theme } from 'antd';
import { BAIModal, BAIModalProps, BAIFlex } from 'backend.ai-ui';
import * as _ from 'lodash-es';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { graphql, useFragment } from 'react-relay';
interface ResourceGroupInfoModalProps extends BAIModalProps {
resourceGroupFrgmt?: ResourceGroupInfoModalFragment$key | null;
onRequestClose?: () => void;
}
const ResourceGroupInfoModal: React.FC<ResourceGroupInfoModalProps> = ({
resourceGroupFrgmt = null,
onRequestClose,
...modalProps
}) => {
const { t } = useTranslation();
const { token } = theme.useToken();
const resourceGroup = useFragment(
graphql`
fragment ResourceGroupInfoModalFragment on ScalingGroup {
name @required(action: NONE)
description
is_active
is_public
driver
driver_opts
scheduler
scheduler_opts
wsproxy_addr
}
`,
resourceGroupFrgmt,
);
const driverOpts = useMemo(
() => JSON.parse(resourceGroup?.driver_opts || '{}'),
[resourceGroup?.driver_opts],
);
const schedulerOpts: Partial<ScalingGroupOpts> = useMemo(
() => JSON.parse(resourceGroup?.scheduler_opts || '{}'),
[resourceGroup?.scheduler_opts],
);
return (
<BAIModal
title={t('resourceGroup.ResourceGroupDetail')}
onCancel={onRequestClose}
footer={null}
centered
{...modalProps}
>
<Descriptions
column={1}
size="small"
title={t('resourceGroup.Information')}
labelStyle={{ width: '50%' }}
>
<Descriptions.Item label={t('resourceGroup.Name')}>
{resourceGroup?.name}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.Description')}>
{resourceGroup?.description || '-'}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.Active')}>
{resourceGroup?.is_active ? (
<CheckOutlined style={{ color: token.colorSuccess }} />
) : (
<CloseOutlined style={{ color: token.colorTextSecondary }} />
)}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.Public')}>
{resourceGroup?.is_public ? (
<CheckOutlined style={{ color: token.colorSuccess }} />
) : (
<CloseOutlined style={{ color: token.colorTextSecondary }} />
)}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.Driver')}>
{resourceGroup?.driver}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.Scheduler')}>
{_.toUpper(resourceGroup?.scheduler ?? '')}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.AppProxyAddress')}>
{resourceGroup?.wsproxy_addr || '-'}
</Descriptions.Item>
</Descriptions>
<br />
<Descriptions
column={1}
size="small"
title={t('resourceGroup.SchedulerOptions')}
labelStyle={{ width: '50%' }}
>
<Descriptions.Item label={t('resourceGroup.AllowedSessionTypes')}>
<BAIFlex
wrap="wrap"
direction="row"
gap={'xs'}
style={{
width: '100%',
}}
>
{_.map(schedulerOpts?.allowed_session_types, (value) => {
return (
<Tag
key={value}
style={{
margin: 0,
}}
>
{_.startCase(value)}
</Tag>
);
})}
</BAIFlex>
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.PendingTimeout')}>
{!_.isNil(schedulerOpts?.pending_timeout) ? (
<BAIFlex gap={'xxs'} align="end">
<Typography.Text>
{`${schedulerOpts.pending_timeout}
${t('resourceGroup.TimeoutSeconds')}`}
</Typography.Text>
{!schedulerOpts?.pending_timeout ? (
<Typography.Text
style={{
color: token.colorTextSecondary,
fontSize: token.fontSizeSM,
}}
>
{`(${t('general.Disabled')})`}
</Typography.Text>
) : null}
</BAIFlex>
) : (
'-'
)}
</Descriptions.Item>
<Descriptions.Item label={t('resourceGroup.RetriesToSkipDesc')}>
{schedulerOpts?.config?.num_retries_to_skip
? `${schedulerOpts.config.num_retries_to_skip} ${t('resourceGroup.RetriesToSkip')}`
: '-'}
</Descriptions.Item>
</Descriptions>
{/* FIXME: Currently, the driver options feature is unimplemented. After the feature is implemented,
it should be changed to show each type instead of the map type. */}
{!_.isEmpty(driverOpts) ? (
<Descriptions
column={1}
size="small"
title={t('resourceGroup.DriverOptions')}
labelStyle={{ width: '50%' }}
>
{_.map(driverOpts, (value, key) => {
return (
<Descriptions.Item key={key} label={_.startCase(key)}>
{_.isArray(value) ? (
<BAIFlex direction="column">
{_.map(value, (item) => {
return <Tag key={item}>{item}</Tag>;
})}
</BAIFlex>
) : (
value
)}
</Descriptions.Item>
);
})}
</Descriptions>
) : null}
</BAIModal>
);
};
export default ResourceGroupInfoModal;