-
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 10 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
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {ArrowUpRightFromSquare} from '@gravity-ui/icons'; | ||
| import {Button, Tooltip} from '@gravity-ui/uikit'; | ||
|
|
||
| import {planToSvgApi} from '../../../../store/reducers/planToSvg'; | ||
| import type {QueryPlan, ScriptPlan} from '../../../../types/api/query'; | ||
|
|
||
| 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, setError] = React.useState<string | null>(null); | ||
| const [blobUrl, setBlobUrl] = React.useState<string | null>(null); | ||
| const [getPlanToSvg, {isLoading}] = planToSvgApi.usePlanToSvgQueryMutation(); | ||
|
|
||
| const handleClick = React.useCallback(() => { | ||
| getPlanToSvg({plan, database}) | ||
| .unwrap() | ||
| .then((result) => { | ||
| if (blobUrl) { | ||
| URL.revokeObjectURL(blobUrl); | ||
| } | ||
|
|
||
| const blob = new Blob([result], {type: 'image/svg+xml'}); | ||
| const url = URL.createObjectURL(blob); | ||
| setBlobUrl(url); | ||
| setError(null); | ||
| window.open(url, '_blank'); | ||
| }) | ||
| .catch((err) => { | ||
| setError(JSON.stringify(err)); | ||
| }); | ||
| }, [blobUrl, database, getPlanToSvg, plan]); | ||
|
|
||
| React.useEffect(() => { | ||
| return () => { | ||
| if (blobUrl) { | ||
| URL.revokeObjectURL(blobUrl); | ||
| } | ||
| }; | ||
| }, [blobUrl]); | ||
|
|
||
| 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} | ||
| > | ||
| {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
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
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 planToSvgApi = 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.
Lets remove this check.
blobUrlwill be revoked in cleanup function ofuseEffect.