Skip to content
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

SceneQueryRunner: Only use containerWidth when maxDataPointsFromWidth is true #223

Merged
merged 1 commit into from
Jun 1, 2023
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
22 changes: 19 additions & 3 deletions packages/scenes/src/querying/SceneQueryRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ describe('SceneQueryRunner', () => {
expect(sentRequest?.maxDataPoints).toBe(500);
});

it('should not use containerWidth by default', async () => {
const queryRunner = new SceneQueryRunner({
queries: [{ refId: 'A' }],
$timeRange: new SceneTimeRange(),
});

queryRunner.setContainerWidth(100);
queryRunner.activate();

await new Promise((r) => setTimeout(r, 1));

// Should not use container width
expect(sentRequest?.maxDataPoints).toBe(500);
});

it('should pass scene object via scoped vars when resolving datasource and running request', async () => {
const queryRunner = new SceneQueryRunner({
queries: [{ refId: 'A' }],
Expand All @@ -95,22 +110,22 @@ describe('SceneQueryRunner', () => {
it('and container width is 0 but previously was rendered', async () => {
const timeRange = new SceneTimeRange();
const queryRunner = new SceneQueryRunner({
maxDataPointsFromWidth: true,
queries: [{ refId: 'A' }],
$timeRange: timeRange,
});

expect(queryRunner.state.data).toBeUndefined();

const deactivateQueryRunner = queryRunner.activate();
queryRunner.setContainerWidth(1000);

// When consumer viz is rendered with width 1000
await new Promise((r) => setTimeout(r, 1));

const runRequestCall1 = runRequestMock.mock.calls[0];
// should be run with default maxDataPoints
expect(runRequestCall1[1].maxDataPoints).toEqual(500);

queryRunner.setContainerWidth(1000);
expect(runRequestCall1[1].maxDataPoints).toEqual(1000);
deactivateQueryRunner();

// When width is externally set to 0 before the consumer container has not yet rendered with expected width
Expand All @@ -125,6 +140,7 @@ describe('SceneQueryRunner', () => {
expect(queryRunner.state.data?.state).toBe(LoadingState.Done);
});
});

describe('when activated and maxDataPointsFromWidth set to true', () => {
it('should run queries', async () => {
const queryRunner = new SceneQueryRunner({
Expand Down
6 changes: 5 additions & 1 deletion packages/scenes/src/querying/SceneQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen
}

private getMaxDataPoints() {
return this.state.maxDataPoints ?? this._containerWidth ?? 500;
if (this.state.maxDataPoints) {
return this.state.maxDataPoints;
}

return this.state.maxDataPointsFromWidth ? this._containerWidth ?? 500 : 500;
}

private async runWithTimeRange(timeRange: SceneTimeRangeLike) {
Expand Down