Skip to content

Commit

Permalink
feat: added ability to render custom query tab at query-tracker page
Browse files Browse the repository at this point in the history
  • Loading branch information
vrozaev committed May 7, 2024
1 parent 675adb6 commit 193d24b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/ui/src/ui/UIFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {PreparedAclSubject} from './utils/acl/acl-types';
import {PreparedRole} from './utils/acl';
import {UISettingsMonitoring} from '../shared/ui-settings';
import {DefaultSubjectCard, type SubjectCardProps} from './components/SubjectLink/SubjectLink';
import type {QueryItem} from './pages/query-tracker/module/api';

type HeaderItemOrPage =
| {
Expand Down Expand Up @@ -355,6 +356,13 @@ export interface UIFactory {

renderRolesLink(params: {cluster: string; login: string; className?: string}): React.ReactNode;

getCustomQueryResultTab():
| undefined
| {
title: string;
renderContent: (params: {query: QueryItem}) => React.ReactNode;
};

getExternalSettings(params: {
cluster: string;
login: string;
Expand Down Expand Up @@ -617,6 +625,10 @@ const uiFactory: UIFactory = {
return undefined;
},

getCustomQueryResultTab() {
return undefined;
},

getExternalSettings() {
return [];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {useDispatch, useSelector} from 'react-redux';
import {loadQueryResultsErrors} from '../../module/query_result/actions';
import {getQueryResults} from '../../module/query_result/selectors';
import {RootState} from '../../../../store/reducers';
import UIFactory from '../../../../UIFactory';

export enum QueryResultTab {
ERROR = 'error',
META = 'meta',
RESULT = 'result',
STATISTIC = 'statistic',
PROGRESS = 'progress',
CUSTOM_TAB = 'custom-tab',
}

const isResultTab = (tabId: string) => tabId.startsWith('result/');
Expand Down Expand Up @@ -87,6 +89,15 @@ export const useQueryResultTabs = (
if (query.state === QueryStatus.FAILED) {
items.unshift({id: QueryResultTab.ERROR, title: 'Error'});
} else if (query.state === QueryStatus.COMPLETED) {
const customQueryResultTab = UIFactory.getCustomQueryResultTab();

if (customQueryResultTab) {
items.unshift({
id: QueryResultTab.CUSTOM_TAB,
title: customQueryResultTab.title,
});
}

if (query.progress?.yql_statistics) {
items.unshift({
id: QueryResultTab.STATISTIC,
Expand Down
22 changes: 22 additions & 0 deletions packages/ui/src/ui/pages/query-tracker/QueryResults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PlanActions from '../Plan/PlanActions';
import './index.scss';
import {ErrorTree} from './ErrorTree';
import {QueryProgress} from './QueryResultActions/QueryProgress';
import UIFactory from '../../../UIFactory';

const b = block('query-results');

Expand All @@ -38,6 +39,16 @@ function QueryResultContainer({
return <QueryResultsView query={query} index={activeResultParams?.resultIndex || 0} />;
}

function CustomQueryTabContainer({query}: {query: QueryItem}) {
const customQueryResultTab = UIFactory.getCustomQueryResultTab();

if (!customQueryResultTab) {
return null;
}

return customQueryResultTab.renderContent({query});
}

function extractOperationIdToCluster(obj: YQLSstatistics | undefined): Map<string, string> {
const clusterNames: Map<string, string> = new Map();

Expand Down Expand Up @@ -118,6 +129,17 @@ export const QueryResults = React.memo(function QueryResults({
activeResultParams={activeResultParams}
/>
</NotRenderUntilFirstVisible>
<NotRenderUntilFirstVisible
hide={
category !== QueryResultTab.CUSTOM_TAB &&
!Number.isInteger(resultIndex)
}
className={b('result-wrap')}
>
{category === QueryResultTab.CUSTOM_TAB && (
<CustomQueryTabContainer query={query} />
)}
</NotRenderUntilFirstVisible>
{category === QueryResultTab.ERROR && <ErrorTree rootError={query.error} />}
{category === QueryResultTab.META && <QueryMetaTable query={query} />}

Expand Down

0 comments on commit 193d24b

Please # to comment.