Skip to content

Commit

Permalink
chore(ChytCliqueActions): use side-panel for SQL [YTFRONT-3683]
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Dec 15, 2023
1 parent fc77a27 commit 9d6d00f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react';
import {useDispatch, useSelector} from 'react-redux';
import {useHistory} from 'react-router';
import cn from 'bem-cn-lite';

import {Button, DropdownMenu, DropdownMenuItem} from '@gravity-ui/uikit';

import {Page} from '../../../../shared/constants/settings';

import Icon from '../../../components/Icon/Icon';
import {getCluster, isQueryTrackerAllowed} from '../../../store/selectors/global';
import {updateQueryDraft} from '../../../pages/query-tracker/module/query/actions';
Expand All @@ -19,23 +16,47 @@ import './ChytCliqueActions.scss';

const block = cn('chyt-clique-actions');

export function useCliqueOnSqlAction(openWidget: () => void) {
const cluster = useSelector(getCluster);
const allowQueryTracker = useSelector(isQueryTrackerAllowed);
const dispatch = useDispatch();

return React.useCallback(
(alias: string) => {
if (allowQueryTracker) {
setTimeout(() => {
dispatch(
updateQueryDraft({
engine: QueryEngine.CHYT,
query: `SELECT 1;`,
settings: {cluster, clique: alias},
}),
);
}, 500);
openWidget();
} else {
UIFactory.onChytAliasSqlClick({alias, cluster});
}
},
[cluster, openWidget, allowQueryTracker, dispatch],
);
}

export function ChytCliqueActions({
alias,
pool,
showAllButtons,
allButtonsClassName,
onAction,
onSqlClick,
}: {
showAllButtons?: boolean;
allButtonsClassName?: string;
alias: string;
pool?: string;
onSqlClick: (alias: string) => void;
onAction?: (action: 'remove' | 'start' | 'stop') => void;
}) {
const dispatch = useDispatch();
const history = useHistory();
const allowQueryTracker = useSelector(isQueryTrackerAllowed);

const [visibleConfirmation, setVisibleConirmation] = React.useState<
undefined | 'remove' | 'start' | 'stop'
>();
Expand Down Expand Up @@ -64,28 +85,8 @@ export function ChytCliqueActions({

const menuItems: Array<Array<DropdownMenuItem>> = [[start, stop], [remove]];

const cluster = useSelector(getCluster);

const sqlButton = (
<Button
view="flat"
onClick={() => {
if (allowQueryTracker) {
history.push(`/${cluster}/${Page.QUERIES}`);
setTimeout(() => {
dispatch(
updateQueryDraft({
engine: QueryEngine.CHYT,
query: `SELECT 1;`,
settings: {cluster, clique: alias},
}),
);
}, 500);
} else {
UIFactory.onChytAliasSqlClick({alias, cluster});
}
}}
>
<Button view="flat" onClick={() => onSqlClick(alias)}>
<Icon awesome="sql" />
</Button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {OperationId} from '../../../components/OperationId/OperationId';
import StatusLabel from '../../../components/StatusLabel/StatusLabel';
import {UserCard} from '../../../components/UserLink/UserLink';

import {useQueryWidgetSidePanel} from '../../../pages/query-tracker/QueryWidget/side-panel';

import {chytCliqueLoad, chytResetCurrentClique} from '../../../store/actions/chyt/clique';
import {
getChytCliqueData,
Expand All @@ -28,7 +30,7 @@ import {getCluster} from '../../../store/selectors/global';
import {Page} from '../../../../shared/constants/settings';

import {CliqueState} from '../components/CliqueState';
import {ChytCliqueActions} from '../ChytCliqueActions/ChytCliqueActions';
import {ChytCliqueActions, useCliqueOnSqlAction} from '../ChytCliqueActions/ChytCliqueActions';
import {ChytPageCliqueTabs} from './ChytPageCliqueTabs';
import {ChytSpecletEditButton} from './ChytPageCliqueSpeclet';
import cn from 'bem-cn-lite';
Expand Down Expand Up @@ -58,6 +60,9 @@ export function ChytPageClique(props: RouteComponentProps<{alias: string}>) {

useUpdater(update);

const {openWidget, widgetContent} = useQueryWidgetSidePanel();
const onSqlClick = useCliqueOnSqlAction(openWidget);

return (
<div className={block()}>
<div className={block('header')}>
Expand All @@ -80,6 +85,7 @@ export function ChytPageClique(props: RouteComponentProps<{alias: string}>) {
update();
}
}}
onSqlClick={onSqlClick}
/>
<span className={block('edit')}>
<ChytSpecletEditButton compact />
Expand All @@ -88,6 +94,7 @@ export function ChytPageClique(props: RouteComponentProps<{alias: string}>) {
<ChytCliqueErrors />
<ChytCliqueMetaTable />
<ChytPageCliqueTabs className={block('tabs')} />
{widgetContent}
</div>
);
}
Expand Down
35 changes: 23 additions & 12 deletions packages/ui/src/ui/pages/chyt/ChytPageList/ChytPageListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import {ChytInfo} from '../../../store/reducers/chyt/list';
import {Page} from '../../../../shared/constants/settings';
import {CHYT_TABLE_TITLES} from '../../../constants/chyt-page';
import {OperationPool} from '../../../components/OperationPool/OperationPool';
import {useQueryWidgetSidePanel} from '../../../pages/query-tracker/QueryWidget/side-panel';

import {CliqueState} from '../components/CliqueState';

import {ChytCliqueActions} from '../ChytCliqueActions/ChytCliqueActions';
import {ChytCliqueActions, useCliqueOnSqlAction} from '../ChytCliqueActions/ChytCliqueActions';
import './ChytPageListTable.scss';

const block = cn('chyt-page-list-table');

function useChytListColumns(cluster: string) {
function useChytListColumns(cluster: string, onSqlClick: (alias: string) => void) {
const checkedColumns = useSelector(getChytListVisibleColumns);

const columns: Array<Column<ChytInfo>> = React.useMemo(() => {
Expand Down Expand Up @@ -237,15 +238,19 @@ function useChytListColumns(cluster: string) {
render({row}) {
return (
<span className={block('one-row-cell')}>
<ChytCliqueActions alias={row.alias} pool={row.pool} />
<ChytCliqueActions
alias={row.alias}
pool={row.pool}
onSqlClick={onSqlClick}
/>
</span>
);
},
align: 'center',
width: 60,
} as Column<ChytInfo>,
];
}, [cluster, checkedColumns]);
}, [cluster, checkedColumns, onSqlClick]);

return columns;
}
Expand Down Expand Up @@ -299,16 +304,22 @@ function ChytPageListTable() {
const items = useSelector(getChytListTableItems);
const cluster = useSelector(getCluster);

const columns = useChytListColumns(cluster);
const {openWidget, widgetContent} = useQueryWidgetSidePanel();
const onSqlClick = useCliqueOnSqlAction(openWidget);

const columns = useChytListColumns(cluster, onSqlClick);

return (
<DataTableYT
className={block()}
settings={DATA_TABLE_YT_SETTINGS_UNDER_TOOLBAR}
useThemeYT
columns={columns}
data={items}
/>
<React.Fragment>
<DataTableYT
className={block()}
settings={DATA_TABLE_YT_SETTINGS_UNDER_TOOLBAR}
useThemeYT
columns={columns}
data={items}
/>
{widgetContent}
</React.Fragment>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Loader from '../../../components/Loader/Loader';
export const QueryWidgetLazy = React.lazy(() => import('./index'));

export const QueryWidgetPortal = withSplit(
withLazyLoading<QueryWidgetProps>(QueryWidgetLazy, <Loader />),
withLazyLoading<QueryWidgetProps>(QueryWidgetLazy, <Loader visible centered size="l" />),
);

export function useQueryWidgetSidePanel() {
Expand Down

0 comments on commit 9d6d00f

Please sign in to comment.