-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ObjectSummary): add button to refresh tree (#1559)
- Loading branch information
Showing
9 changed files
with
134 additions
and
64 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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
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
21 changes: 21 additions & 0 deletions
21
src/containers/Tenant/ObjectSummary/SchemaTree/RefreshTreeButton.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,21 @@ | ||
import {ArrowRotateRight} from '@gravity-ui/icons'; | ||
import {ActionTooltip, Button, Icon} from '@gravity-ui/uikit'; | ||
import {nanoid} from '@reduxjs/toolkit'; | ||
|
||
import {useDispatchTreeKey} from '../UpdateTreeContext'; | ||
|
||
export function RefreshTreeButton() { | ||
const updateTreeKey = useDispatchTreeKey(); | ||
return ( | ||
<ActionTooltip title="Refresh"> | ||
<Button | ||
view="flat-secondary" | ||
onClick={() => { | ||
updateTreeKey(nanoid()); | ||
}} | ||
> | ||
<Icon data={ArrowRotateRight} /> | ||
</Button> | ||
</ActionTooltip> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
const TreeKeyContext = React.createContext<string | undefined>(undefined); | ||
const TreeKeyDispatchContext = React.createContext<React.Dispatch<string> | undefined>(undefined); | ||
|
||
interface TreeKeyProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export function TreeKeyProvider({children}: TreeKeyProviderProps) { | ||
const [key, setKey] = React.useState<string>(''); | ||
|
||
return ( | ||
<TreeKeyContext.Provider value={key}> | ||
<TreeKeyDispatchContext.Provider value={setKey}> | ||
{children} | ||
</TreeKeyDispatchContext.Provider> | ||
</TreeKeyContext.Provider> | ||
); | ||
} | ||
|
||
export function useTreeKey() { | ||
const key = React.useContext(TreeKeyContext); | ||
if (key === undefined) { | ||
throw new Error('useTreeKey must be used within a TreeKeyProvider'); | ||
} | ||
return key; | ||
} | ||
export function useDispatchTreeKey() { | ||
const updateKey = React.useContext(TreeKeyDispatchContext); | ||
if (updateKey === undefined) { | ||
throw new Error('useDispatchTreeKey must be used within a TreeKeyProvider'); | ||
} | ||
return updateKey; | ||
} |
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