Skip to content

Commit

Permalink
feat(Navigation/Document): allow YQL query button if _yql_type == "…
Browse files Browse the repository at this point in the history
…view" [YTFRONT-4463]
  • Loading branch information
ma-efremoff committed Nov 7, 2024
1 parent 68e0079 commit 4bd17a2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, {FC, Fragment} from 'react';
import {Flex} from '@gravity-ui/uikit';

// @ts-ignore
import ypath from '@ytsaurus/interface-helpers/lib/ypath';
import MetaTable from '../../../../components/MetaTable/MetaTable';
Expand All @@ -7,6 +9,11 @@ import Yson from '../../../../components/Yson/Yson';
import {Alert, Button} from '@gravity-ui/uikit';
import {UnipikaSettings} from '../../../../components/Yson/StructuredYson/StructuredYsonTypes';
import Icon from '../../../../components/Icon/Icon';
import {OpenQueryButton} from '../../../../containers/OpenQueryButton/OpenQueryButton';
import {YQLKitButton} from '../../../../containers/YQLKitButton/YQLKitButton';
import {useSelector} from 'react-redux';
import {getPath} from '../../../../store/selectors/navigation';
import {getCluster} from '../../../../store/selectors/global';

type Props = {
attributes: Record<any, any>;
Expand All @@ -24,6 +31,24 @@ const EditButton: FC<Pick<Props, 'onEditClick'>> = ({onEditClick}) => {
);
};

function OpenYqlViewButton() {
const path: string = useSelector(getPath);
const cluster = useSelector(getCluster);

return <OpenQueryButton path={path} cluster={cluster} />;
}

function DocumentExtraTools({onEditClick, attributes}: Pick<Props, 'attributes' | 'onEditClick'>) {
const isYqlView = 'view' === ypath.getValue(attributes, '/_yql_type');
return (
<Flex gap={4}>
{isYqlView && <OpenYqlViewButton />}
{isYqlView && <YQLKitButton />}
<EditButton onEditClick={onEditClick} />
</Flex>
);
}

const DocumentBody: FC<Props> = ({attributes, settings, onEditClick, document = null}) => {
const [type] = ypath.getValues(attributes, ['/type']);

Expand All @@ -42,7 +67,9 @@ const DocumentBody: FC<Props> = ({attributes, settings, onEditClick, document =
value={document}
settings={settings}
folding
extraTools={<EditButton onEditClick={onEditClick} />}
extraTools={
<DocumentExtraTools onEditClick={onEditClick} attributes={attributes} />
}
/>
)}
</Fragment>
Expand Down
25 changes: 18 additions & 7 deletions packages/ui/src/ui/pages/query-tracker/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,31 +223,42 @@ export async function generateQueryFromTable(
const node = await ytApiV3.get({
parameters: {
path: `${path}/@`,
attributes: ['type', 'schema', 'dynamic'],
attributes: ['type', 'schema', 'dynamic', '_yql_type'],
output_format: 'json',
},
setup: {
proxy: getClusterProxy(selectedCluster),
...JSONParser,
},
});

const commonData = {
engine,
files: [],
annotations: {},
access_control_object: defaultQueryACO,
access_control_objects: [defaultQueryACO],
settings: generateQuerySettings(engine, cluster),
};

if (node.type === 'table') {
const schema = ypath.getValue(node.schema) as {name: string}[];
return {
engine,
query: generateQueryText(cluster, engine, {
path,
columns: schema.map(({name}) => name),
pageSize: 50,
schemaExists: Boolean(schema.length),
dynamic: node.dynamic,
}),
files: [],
annotations: {},
access_control_object: defaultQueryACO,
access_control_objects: [defaultQueryACO],
settings: generateQuerySettings(engine, cluster),
...commonData,
};
} else if (node.type === 'document' && 'view' === ypath.getValue(node._yql_type)) {
const query = await ytApiV3.get({
parameters: {path},
setup: {proxy: getClusterProxy(selectedCluster), ...JSONParser},
});
return {query, ...commonData};
}
return undefined;
}
Expand Down

0 comments on commit 4bd17a2

Please sign in to comment.