Skip to content

Commit 7239727

Browse files
feat(PDisk): add restart button (#766)
1 parent 6902afa commit 7239727

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

src/containers/PDisk/PDisk.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
&__meta,
1717
&__title,
1818
&__info,
19+
&__controls,
1920
&__groups-title {
2021
position: sticky;
2122
left: 0;

src/containers/PDisk/PDisk.tsx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {useCallback, useEffect} from 'react';
22
import {StringParam, useQueryParams} from 'use-query-params';
33
import {Helmet} from 'react-helmet-async';
44

5+
import {Icon} from '@gravity-ui/uikit';
6+
import ArrowRotateLeftIcon from '@gravity-ui/icons/svgs/arrow-rotate-left.svg';
7+
58
import {
69
getPDiskData,
710
getPDiskStorage,
@@ -17,6 +20,7 @@ import {PageMeta} from '../../components/PageMeta/PageMeta';
1720
import {StatusIcon} from '../../components/StatusIcon/StatusIcon';
1821
import {PDiskInfo} from '../../components/PDiskInfo/PDiskInfo';
1922
import {InfoViewerSkeleton} from '../../components/InfoViewerSkeleton/InfoViewerSkeleton';
23+
import {ButtonWithConfirmDialog} from '../../components/ButtonWithConfirmDialog/ButtonWithConfirmDialog';
2024

2125
import {PDiskGroups} from './PDiskGroups';
2226
import {pdiskPageCn} from './shared';
@@ -46,20 +50,37 @@ export function PDisk() {
4650
}, [dispatch]);
4751

4852
const fetchData = useCallback(
49-
(isBackground: boolean) => {
53+
async (isBackground?: boolean) => {
5054
if (!isBackground) {
5155
dispatch(setPDiskDataWasNotLoaded());
5256
}
57+
5358
if (nodeId && pDiskId) {
54-
dispatch(getPDiskData({nodeId, pDiskId}));
55-
dispatch(getPDiskStorage({nodeId, pDiskId}));
59+
return Promise.all([
60+
dispatch(getPDiskData({nodeId, pDiskId})),
61+
dispatch(getPDiskStorage({nodeId, pDiskId})),
62+
]);
5663
}
64+
65+
return undefined;
5766
},
5867
[dispatch, nodeId, pDiskId],
5968
);
6069

6170
useAutofetcher(fetchData, [fetchData], true);
6271

72+
const handleRestart = async () => {
73+
if (nodeId && pDiskId) {
74+
return window.api.restartPDisk(nodeId, pDiskId);
75+
}
76+
77+
return undefined;
78+
};
79+
80+
const handleAfterRestart = async () => {
81+
return fetchData(true);
82+
};
83+
6384
const renderHelmet = () => {
6485
const pDiskPagePart = pDiskId
6586
? `${pDiskPageKeyset('pdisk')} ${pDiskId}`
@@ -97,6 +118,23 @@ export function PDisk() {
97118
);
98119
};
99120

121+
const renderControls = () => {
122+
return (
123+
<div className={pdiskPageCn('controls')}>
124+
<ButtonWithConfirmDialog
125+
onConfirmAction={handleRestart}
126+
onConfirmActionSuccess={handleAfterRestart}
127+
buttonDisabled={!nodeId || !pDiskId}
128+
buttonView="normal"
129+
dialogContent={pDiskPageKeyset('restart-pdisk-dialog')}
130+
>
131+
<Icon data={ArrowRotateLeftIcon} />
132+
{pDiskPageKeyset('restart-pdisk-button')}
133+
</ButtonWithConfirmDialog>
134+
</div>
135+
);
136+
};
137+
100138
const renderInfo = () => {
101139
if (pDiskLoading && !pDiskWasLoaded) {
102140
return <InfoViewerSkeleton className={pdiskPageCn('info')} rows={10} />;
@@ -126,6 +164,7 @@ export function PDisk() {
126164
{renderHelmet()}
127165
{renderPageMeta()}
128166
{renderPageTitle()}
167+
{renderControls()}
129168
{renderInfo()}
130169
{renderGroupsTable()}
131170
</div>

src/containers/PDisk/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"fqdn": "FQDN",
33
"pdisk": "PDisk",
44
"groups": "Groups",
5-
"node": "Node"
5+
"node": "Node",
6+
7+
"restart-pdisk-button": "Restart PDisk",
8+
"restart-pdisk-dialog": "PDisk will be restarted. Do you want to proceed?"
69
}

src/services/api.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {JsonHotKeysResponse} from '../types/api/hotkeys';
3838

3939
import {backend as BACKEND, metaBackend as META_BACKEND} from '../store';
4040
import {prepareSortValue} from '../utils/filters';
41+
import {createPDiskDeveloperUILink} from '../utils/developerUI/developerUI';
4142
import {BINARY_DATA_IN_PLAIN_TEXT_DISPLAY} from '../utils/constants';
4243
import {parseMetaCluster} from './parsers/parseMetaCluster';
4344
import {parseMetaTenants} from './parsers/parseMetaTenants';
@@ -378,6 +379,24 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
378379
{concurrentId},
379380
);
380381
}
382+
restartPDisk(nodeId: number | string, pDiskId: number | string) {
383+
const pDiskPath = createPDiskDeveloperUILink({
384+
nodeId,
385+
pDiskId,
386+
host: this.getPath(''),
387+
});
388+
389+
return this.post(
390+
pDiskPath,
391+
'restartPDisk=',
392+
{},
393+
{
394+
headers: {
395+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
396+
},
397+
},
398+
);
399+
}
381400
killTablet(id?: string) {
382401
return this.get<string>(this.getPath(`/tablets?KillTabletID=${id}`), {});
383402
}

0 commit comments

Comments
 (0)