-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Navigation/Table): add remount option [YTFRONT-3593]
- Loading branch information
1 parent
8097144
commit c8c1270
Showing
7 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/ui/src/ui/pages/navigation/content/Table/RemountAlert/RemountAlert.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.remount-alert { | ||
&__button { | ||
width: fit-content; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/ui/src/ui/pages/navigation/content/Table/RemountAlert/RemountAlert.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, {useState} from 'react'; | ||
import b from 'bem-cn-lite'; | ||
import {useDispatch, useSelector} from 'react-redux'; | ||
import {Alert, Button} from '@gravity-ui/uikit'; | ||
import ypath from '../../../../../common/thor/ypath'; | ||
|
||
import {remountTable} from '../../../../../store/actions/navigation/content/table/remount-table'; | ||
import {getAttributesWithTypes} from '../../../../../store/selectors/navigation'; | ||
|
||
import './RemountAlert.scss'; | ||
|
||
const block = b('remount-alert'); | ||
|
||
export function RemountAlert() { | ||
const dispatch = useDispatch(); | ||
const attributesWithTypes = useSelector(getAttributesWithTypes); | ||
const [pending, setPending] = useState(false); | ||
|
||
const handleOnRemount = async () => { | ||
setPending(true); | ||
await dispatch(remountTable()); | ||
setPending(false); | ||
}; | ||
|
||
const remountNeededTabletCount = ypath.getValue( | ||
attributesWithTypes, | ||
'/remount_needed_tablet_count', | ||
); | ||
const tabletCount = ypath.getValue(attributesWithTypes, '/tablet_count'); | ||
|
||
const showDiffInfo = remountNeededTabletCount !== tabletCount; | ||
const diffInfo = `(${remountNeededTabletCount} of ${tabletCount} tablets pending)`; | ||
|
||
const message = `Some settings are not applied to tablets ${showDiffInfo && diffInfo}. | ||
See Mount config tab for details. Note: this action will not cause any downtime`; | ||
|
||
return ( | ||
<Alert | ||
theme="warning" | ||
title="Remount needed" | ||
message={message} | ||
className={block('')} | ||
actions={ | ||
<Button | ||
onClick={handleOnRemount} | ||
disabled={pending} | ||
className={block('button')} | ||
view="normal-contrast" | ||
size="s" | ||
> | ||
Remount | ||
</Button> | ||
} | ||
></Alert> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/ui/src/ui/store/actions/navigation/content/table/remount-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {ThunkAction} from 'redux-thunk'; | ||
import {UnknownAction} from '@reduxjs/toolkit'; | ||
|
||
import {RootState} from '../../../../reducers'; | ||
import {updateView} from '../..'; | ||
|
||
import {wrapApiPromiseByToaster} from '../../../../../utils/utils'; | ||
import {ytApiV4} from '../../../../../rum/rum-wrap-api'; | ||
|
||
type AsyncAction<R = void> = ThunkAction<R, RootState, unknown, UnknownAction>; | ||
|
||
export function remountTable(): AsyncAction<Promise<void>> { | ||
return async (dispatch, getState) => { | ||
await new Promise((res) => setTimeout(res, 3000)); | ||
const state = getState(); | ||
const path = state.navigation.navigation.path; | ||
|
||
return wrapApiPromiseByToaster(ytApiV4.remountTable({path}), { | ||
toasterName: 'remount_tabe', | ||
skipSuccessToast: false, | ||
}).finally(() => { | ||
dispatch(updateView()); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters