Skip to content

fix: do not reset query results when switch query tabs #1198

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"path-to-regexp": "^3.0.0",
"qs": "^6.12.0",
"react-error-boundary": "^4.0.13",
"react-freeze": "^1.0.4",
"react-helmet-async": "^2.0.5",
"react-hook-form": "^7.52.1",
"react-json-inspector": "^7.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ydb-not-render-until-first-visible {
display: contents;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

import {Freeze} from 'react-freeze';

import {cn} from '../../utils/cn';

import './NotRenderUntilFirstVisible.scss';

const block = cn('ydb-not-render-until-first-visible');

interface Props {
show?: boolean;
className?: string;
children: React.ReactNode;
}

export default function NotRenderUntilFirstVisible({show, className, children}: Props) {
return (
<div style={show ? undefined : {display: 'none'}} className={block(null, className)}>
<Freeze freeze={!show}>{children}</Freeze>
</div>
);
}
22 changes: 13 additions & 9 deletions src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';

import {useThemeValue} from '@gravity-ui/uikit';

import NotRenderUntilFirstVisible from '../../../components/NotRenderUntilFirstVisible/NotRenderUntilFirstVisible';
import {TENANT_PAGES_IDS} from '../../../store/reducers/tenant/constants';
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../../types/additionalProps';
import type {EPathType} from '../../../types/api/schema';
Expand Down Expand Up @@ -28,22 +31,23 @@ function ObjectGeneral(props: ObjectGeneralProps) {

const renderPageContent = () => {
const {type, additionalTenantProps, additionalNodesProps, tenantName, path} = props;
switch (tenantPage) {
case TENANT_PAGES_IDS.query: {
return <Query tenantName={tenantName} path={path} theme={theme} type={type} />;
}
default: {
return (

return (
<React.Fragment>
<NotRenderUntilFirstVisible show={tenantPage === TENANT_PAGES_IDS.query}>
<Query tenantName={tenantName} path={path} theme={theme} type={type} />
</NotRenderUntilFirstVisible>
<NotRenderUntilFirstVisible show={tenantPage === TENANT_PAGES_IDS.diagnostics}>
<Diagnostics
type={type}
tenantName={tenantName}
path={path}
additionalTenantProps={additionalTenantProps}
additionalNodesProps={additionalNodesProps}
/>
);
}
}
</NotRenderUntilFirstVisible>
</React.Fragment>
);
};

return (
Expand Down
28 changes: 14 additions & 14 deletions src/containers/Tenant/Query/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import {Helmet} from 'react-helmet-async';

import NotRenderUntilFirstVisible from '../../../components/NotRenderUntilFirstVisible/NotRenderUntilFirstVisible';
import {changeUserInput} from '../../../store/reducers/executeQuery';
import {TENANT_QUERY_TABS_ID} from '../../../store/reducers/tenant/constants';
import type {EPathType} from '../../../types/api/schema';
Expand Down Expand Up @@ -39,20 +40,19 @@ export const Query = (props: QueryProps) => {
);

const renderContent = () => {
switch (queryTab) {
case TENANT_QUERY_TABS_ID.newQuery: {
return <QueryEditor changeUserInput={handleUserInputChange} {...props} />;
}
case TENANT_QUERY_TABS_ID.history: {
return <QueriesHistory changeUserInput={handleUserInputChange} />;
}
case TENANT_QUERY_TABS_ID.saved: {
return <SavedQueries changeUserInput={handleUserInputChange} />;
}
default: {
return null;
}
}
return (
<React.Fragment>
<NotRenderUntilFirstVisible show={queryTab === TENANT_QUERY_TABS_ID.newQuery}>
<QueryEditor changeUserInput={handleUserInputChange} {...props} />
</NotRenderUntilFirstVisible>
<NotRenderUntilFirstVisible show={queryTab === TENANT_QUERY_TABS_ID.history}>
<QueriesHistory changeUserInput={handleUserInputChange} />
</NotRenderUntilFirstVisible>
<NotRenderUntilFirstVisible show={queryTab === TENANT_QUERY_TABS_ID.saved}>
<SavedQueries changeUserInput={handleUserInputChange} />
</NotRenderUntilFirstVisible>
</React.Fragment>
);
};

return (
Expand Down
21 changes: 20 additions & 1 deletion tests/suites/tenant/TenantPage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import type {Page} from '@playwright/test';
import type {Locator, Page} from '@playwright/test';

import {PageModel} from '../../models/PageModel';
import {tenantPage} from '../../utils/constants';

export const VISIBILITY_TIMEOUT = 5000;

export enum NavigationTabs {
Query = 'Query',
Diagnostics = 'Diagnostics',
}

export class TenantPage extends PageModel {
private navigation: Locator;
private radioGroup: Locator;

constructor(page: Page) {
super(page, tenantPage);

this.navigation = page.locator('.ydb-tenant-navigation');
this.radioGroup = this.navigation.locator('.g-radio-button');
}

async selectNavigationTab(tabName: NavigationTabs) {
const tabInput = this.radioGroup.locator(`input[value="${tabName.toLowerCase()}"]`);
await tabInput.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
await tabInput.click();
}
}
80 changes: 62 additions & 18 deletions tests/suites/tenant/queryEditor/QueryEditor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Locator, Page} from '@playwright/test';

export const VISIBILITY_TIMEOUT = 5000;
import {VISIBILITY_TIMEOUT} from '../TenantPage';

export enum QueryMode {
YQLScript = 'YQL Script',
Expand All @@ -22,6 +22,46 @@ export enum ButtonNames {
Stop = 'Stop',
}

export enum ResultTabNames {
Result = 'Result',
Stats = 'Stats',
Schema = 'Schema',
ExplainPlan = 'Explain Plan',
}

export enum QueryTabs {
Editor = 'Editor',
History = 'History',
Saved = 'Saved',
}

export class QueryTabsNavigation {
private tabsContainer: Locator;

constructor(page: Page) {
this.tabsContainer = page.locator('.ydb-query__tabs');
}

async selectTab(tabName: QueryTabs) {
const tab = this.tabsContainer.locator(`role=tab[name="${tabName}"]`);
await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
await tab.click();
}

async isTabSelected(tabName: QueryTabs): Promise<boolean> {
const tab = this.tabsContainer.locator(`role=tab[name="${tabName}"]`);
await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
const isSelected = await tab.getAttribute('aria-selected');
return isSelected === 'true';
}

async getTabHref(tabName: QueryTabs): Promise<string | null> {
const link = this.tabsContainer.locator(`a:has(div[role="tab"][title="${tabName}"])`);
await link.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
return link.getAttribute('href');
}
}

export class SettingsDialog {
private dialog: Locator;
private page: Page;
Expand Down Expand Up @@ -81,6 +121,22 @@ export class SettingsDialog {
}
}

class PaneWrapper {
paneWrapper: Locator;
private radioButton: Locator;

constructor(page: Page) {
this.paneWrapper = page.locator('.query-editor__pane-wrapper');
this.radioButton = this.paneWrapper.locator('.g-radio-button');
}

async selectTab(tabName: ResultTabNames) {
const tab = this.radioButton.getByLabel(tabName);
await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
await tab.click();
}
}

export class ResultTable {
private table: Locator;
private preview: Locator;
Expand Down Expand Up @@ -123,8 +179,10 @@ export class ResultTable {

export class QueryEditor {
settingsDialog: SettingsDialog;
paneWrapper: PaneWrapper;
queryTabs: QueryTabsNavigation;
resultTable: ResultTable;

private resultTable: ResultTable;
private page: Page;
private selector: Locator;
private editorTextArea: Locator;
Expand Down Expand Up @@ -158,6 +216,8 @@ export class QueryEditor {

this.settingsDialog = new SettingsDialog(page);
this.resultTable = new ResultTable(this.selector);
this.paneWrapper = new PaneWrapper(page);
this.queryTabs = new QueryTabsNavigation(page);
}

async run(query: string, mode: QueryMode) {
Expand Down Expand Up @@ -265,22 +325,6 @@ export class QueryEditor {
return true;
}

async isResultTableVisible() {
return await this.resultTable.isVisible();
}

async isResultTableHidden() {
return await this.resultTable.isHidden();
}

async isPreviewVisible() {
return await this.resultTable.isPreviewVisible();
}

async isPreviewHidden() {
return await this.resultTable.isPreviewHidden();
}

async isStopButtonVisible() {
await this.stopButton.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
return true;
Expand Down
52 changes: 48 additions & 4 deletions tests/suites/tenant/queryEditor/queryEditor.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {expect, test} from '@playwright/test';

import {tenantName} from '../../../utils/constants';
import {TenantPage} from '../TenantPage';
import {NavigationTabs, TenantPage, VISIBILITY_TIMEOUT} from '../TenantPage';

import {
ButtonNames,
ExplainResultType,
QueryEditor,
QueryMode,
VISIBILITY_TIMEOUT,
QueryTabs,
ResultTabNames,
} from './QueryEditor';
import {longRunningQuery} from './constants';

Expand Down Expand Up @@ -53,14 +54,14 @@ test.describe('Test Query Editor', async () => {
const queryEditor = new QueryEditor(page);
await queryEditor.run(testQuery, QueryMode.YQLScript);

await expect(queryEditor.isResultTableVisible()).resolves.toBe(true);
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
});

test('Run button executes Scan', async ({page}) => {
const queryEditor = new QueryEditor(page);
await queryEditor.run(testQuery, QueryMode.Scan);

await expect(queryEditor.isResultTableVisible()).resolves.toBe(true);
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
});

test('Explain button executes YQL script explanation', async ({page}) => {
Expand Down Expand Up @@ -333,4 +334,47 @@ test.describe('Test Query Editor', async () => {
const statusElement = await queryEditor.getExecutionStatus();
await expect(statusElement).toBe('Failed');
});

test('Changing tab inside results pane doesnt change results view', async ({page}) => {
const queryEditor = new QueryEditor(page);
await queryEditor.setQuery(testQuery);
await queryEditor.clickGearButton();
await queryEditor.settingsDialog.changeStatsLevel('Profile');
await queryEditor.settingsDialog.clickButton(ButtonNames.Save);
await queryEditor.clickRunButton();
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
await queryEditor.paneWrapper.selectTab(ResultTabNames.Schema);
await expect(queryEditor.resultTable.isHidden()).resolves.toBe(true);
await queryEditor.paneWrapper.selectTab(ResultTabNames.Result);
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
});

test('Changing tab inside editor doesnt change results view', async ({page}) => {
const queryEditor = new QueryEditor(page);
await queryEditor.setQuery(testQuery);
await queryEditor.clickGearButton();
await queryEditor.settingsDialog.changeStatsLevel('Profile');
await queryEditor.settingsDialog.clickButton(ButtonNames.Save);
await queryEditor.clickRunButton();
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
await queryEditor.queryTabs.selectTab(QueryTabs.History);
await expect(queryEditor.resultTable.isHidden()).resolves.toBe(true);
await queryEditor.queryTabs.selectTab(QueryTabs.Editor);
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
});

test('Changing tab to diagnostics doesnt change results view', async ({page}) => {
const queryEditor = new QueryEditor(page);
const tenantPage = new TenantPage(page);
await queryEditor.setQuery(testQuery);
await queryEditor.clickGearButton();
await queryEditor.settingsDialog.changeStatsLevel('Profile');
await queryEditor.settingsDialog.clickButton(ButtonNames.Save);
await queryEditor.clickRunButton();
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
await tenantPage.selectNavigationTab(NavigationTabs.Diagnostics);
await expect(queryEditor.resultTable.isHidden()).resolves.toBe(true);
await tenantPage.selectNavigationTab(NavigationTabs.Query);
await expect(queryEditor.resultTable.isVisible()).resolves.toBe(true);
});
});
2 changes: 1 addition & 1 deletion tests/suites/tenant/summary/ObjectSummary.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Locator, Page} from '@playwright/test';

export const VISIBILITY_TIMEOUT = 5000;
import {VISIBILITY_TIMEOUT} from '../TenantPage';

export class ObjectSummary {
private tree: Locator;
Expand Down
Loading
Loading