Skip to content

Commit

Permalink
In QL charts, two queries are executed on Run button click (datalens-…
Browse files Browse the repository at this point in the history
…tech#852)

* In QL charts, two queries are executed on Run button click

* temporarily fix yagr onRender issue
  • Loading branch information
kuzmadom authored Apr 8, 2024
1 parent 873918b commit a39692d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ui/units/ql/containers/PanePreview/PanePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {connect} from 'react-redux';
import {compose} from 'recompose';
import {DatalensGlobalState, Utils} from 'ui';
import {PlaceholderIllustration} from 'ui/components/PlaceholderIllustration/PlaceholderIllustration';
import {getRandomCKId} from 'ui/libs/DatalensChartkit/helpers/helpers';

import {ChartWrapper} from '../../../../components/Widgets/Chart/ChartWidgetWithProvider';
import {ChartKitWrapperOnLoadProps} from '../../../../libs/DatalensChartkit/components/ChartKitBase/types';
Expand Down Expand Up @@ -107,11 +106,9 @@ class Preview extends React.PureComponent<PreviewProps, PreviewState> {
<ChartWrapper
usageType="chart"
id={entry?.entryId}
key={getRandomCKId()}
config={previewConfig}
params={params}
onChartLoad={this.onChartLoad}
onChartRender={this.onChartRender}
ref={this.chartKitRef}
disableChartLoader={true}
noVeil={true}
Expand Down Expand Up @@ -156,6 +153,10 @@ class Preview extends React.PureComponent<PreviewProps, PreviewState> {
// Case when chart execution errored or has empty result
this.props.setTablePreviewData({tablePreviewData: {}});
}

// There is a problem with yagr widget - it does not call onRender callback every time it is rendered, only once
// Therefore, for now we are artificially calling callback to remove the loader
setTimeout(this.onChartRender);
};

onChartRender = () => {
Expand Down
34 changes: 34 additions & 0 deletions tests/opensource-suites/ql/common/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {expect} from '@playwright/test';

import QLPage from '../../../page-objects/ql/QLPage';
import datalensTest from '../../../utils/playwright/globalTestDefinition';
import {openTestPage} from '../../../utils';

datalensTest.describe('QL', () => {
datalensTest(
'First and next click on Run button should trigger only one api/run request',
async ({page, config}) => {
await openTestPage(page, config.ql.urls.NewQLChartWithConnection);
const qlPage = new QLPage({page});
await qlPage.setScript(`select 1`);

let numberOfRequests = 0;
await page.on('request', (request) => {
if (request.url().includes('api/run')) {
numberOfRequests += 1;
}
});

// Check first run
await qlPage.runScript();
await qlPage.chartkit.waitUntilLoaderExists();
expect(numberOfRequests).toEqual(1);

// Check second and other runs
numberOfRequests = 0;
await qlPage.runScript();
await qlPage.chartkit.waitUntilLoaderExists();
expect(numberOfRequests).toEqual(1);
},
);
});

0 comments on commit a39692d

Please sign in to comment.