-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add to embedded ui link to plan2svg converter #1619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c0b4f7
feat: UI link to Plan2Svg
astandrik b67bda0
fix: some fixes
7f4ea09
fix: better code
23e096d
fix: better code
cfeb98f
fix: add setting
3438f11
fix: move to experiments
astandrik b3f15bb
Merge branch 'main' into astandrik.link-to-plan2svg
astandrik dcd682c
fix: rm comment
astandrik 98f4ff2
fix: plan is required field
astandrik 3411cad
fix: review fixes
astandrik 8950b3e
fix: review fix
astandrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
src/containers/Tenant/Query/ExecuteResult/PlanToSvgButton.tsx
This file contains hidden or 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,53 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {ArrowUpRightFromSquare} from '@gravity-ui/icons'; | ||
| import {Button, Tooltip} from '@gravity-ui/uikit'; | ||
|
|
||
| import type {QueryPlan, ScriptPlan} from '../../../../types/api/query'; | ||
|
|
||
| import {usePlanToSvg} from './hooks'; | ||
| import i18n from './i18n'; | ||
|
|
||
| function getButtonView(error: string | null, isLoading: boolean) { | ||
| if (error) { | ||
| return 'flat-danger'; | ||
| } | ||
| return isLoading ? 'flat-secondary' : 'flat-info'; | ||
| } | ||
|
|
||
| interface PlanToSvgButtonProps { | ||
| plan: QueryPlan | ScriptPlan; | ||
| database: string; | ||
| } | ||
|
|
||
| export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) { | ||
| const {error, blobUrl, isLoading, isUninitialized} = usePlanToSvg(database, plan); | ||
|
|
||
| const handleClick = React.useCallback(() => { | ||
| if (blobUrl) { | ||
| window.open(blobUrl, '_blank'); | ||
| } | ||
| }, [blobUrl]); | ||
|
|
||
| if (isUninitialized) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Tooltip | ||
| content={error ? i18n('text_error-plan-svg', {error}) : i18n('text_open-plan-svg')} | ||
| > | ||
| <Button | ||
| view={getButtonView(error, isLoading)} | ||
| loading={isLoading} | ||
| onClick={handleClick} | ||
| disabled={isLoading || !blobUrl} | ||
| > | ||
| {i18n('text_plan-svg')} | ||
| <Button.Icon> | ||
| <ArrowUpRightFromSquare /> | ||
| </Button.Icon> | ||
| </Button> | ||
| </Tooltip> | ||
| ); | ||
| } |
This file contains hidden or 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,47 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {planToSvgQueryApi} from '../../../../store/reducers/planToSvgQuery'; | ||
| import type {QueryPlan, ScriptPlan} from '../../../../types/api/query'; | ||
|
|
||
| interface UsePlanToSvgResult { | ||
| error: string | null; | ||
| blobUrl: string | null; | ||
| isLoading: boolean; | ||
| isUninitialized: boolean; | ||
| } | ||
|
|
||
| export function usePlanToSvg(database: string, plan: QueryPlan | ScriptPlan): UsePlanToSvgResult { | ||
| const [error, setError] = React.useState<string | null>(null); | ||
| const [blobUrl, setBlobUrl] = React.useState<string | null>(null); | ||
| const [getPlanToSvg, {isLoading, isUninitialized}] = | ||
| planToSvgQueryApi.usePlanToSvgQueryMutation(); | ||
|
|
||
| React.useEffect(() => { | ||
| let currentUrl: string | null = null; | ||
|
|
||
| getPlanToSvg({plan, database}) | ||
| .unwrap() | ||
| .then((result) => { | ||
| const blob = new Blob([result], {type: 'image/svg+xml'}); | ||
| currentUrl = URL.createObjectURL(blob); | ||
| setBlobUrl(currentUrl); | ||
| setError(null); | ||
| }) | ||
| .catch((err) => { | ||
| setError(JSON.stringify(err)); | ||
| }); | ||
|
|
||
| return () => { | ||
| if (currentUrl) { | ||
| URL.revokeObjectURL(currentUrl); | ||
| } | ||
| }; | ||
| }, [getPlanToSvg, database, plan]); | ||
|
|
||
| return { | ||
| error, | ||
| blobUrl, | ||
| isLoading, | ||
| isUninitialized, | ||
| }; | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -33,6 +33,9 @@ | |
| "settings.usePaginatedTables.title": "Use paginated tables", | ||
| "settings.usePaginatedTables.description": " Use table with data load on scroll for Nodes and Storage tabs. It will increase performance, but could work unstable", | ||
|
|
||
| "settings.useShowPlanToSvg.title": "Use show plan to svg", | ||
|
||
| "settings.useShowPlanToSvg.description": " Show \"Plan to svg\" button in query result widow (if query was executed with full stats option).", | ||
|
|
||
| "settings.showDomainDatabase.title": "Show domain database", | ||
|
|
||
| "settings.useClusterBalancerAsBackend.title": "Use cluster balancer as backend", | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,31 @@ | ||
| import type {QueryPlan, ScriptPlan} from '../../types/api/query'; | ||
|
|
||
| import {api} from './api'; | ||
|
|
||
| export interface PlanToSvgQueryParams { | ||
| plan: ScriptPlan | QueryPlan; | ||
| database: string; | ||
| } | ||
|
|
||
| export const planToSvgQueryApi = api.injectEndpoints({ | ||
| endpoints: (build) => ({ | ||
| planToSvgQuery: build.mutation<string, PlanToSvgQueryParams>({ | ||
| queryFn: async ({plan, database}, {signal}) => { | ||
| try { | ||
| const response = await window.api.planToSvg( | ||
| { | ||
| database, | ||
| plan, | ||
| }, | ||
| {signal}, | ||
| ); | ||
|
|
||
| return {data: response}; | ||
| } catch (error) { | ||
| return {error}; | ||
| } | ||
| }, | ||
| }), | ||
| }), | ||
| overrideExisting: 'throw', | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get rid of
useEffect? What if we initialize mutation whenPlanToSvgButtonis clicked?