Skip to content

fix(client-vue3): prevent heuristic call when initial query is empty in computed property validateQuery #9656

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
2 changes: 1 addition & 1 deletion packages/cubejs-client-vue3/src/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default {
}

// query heuristics should only apply on query change (not applied to the initial query)
if (this.prevValidatedQuery !== null) {
if (this.prevValidatedQuery !== null && isQueryPresent(validatedQuery)) {
this.skipHeuristics = false;
}

Expand Down
50 changes: 50 additions & 0 deletions packages/cubejs-client-vue3/tests/unit/QueryBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,56 @@ describe('QueryBuilder.vue', () => {
expect(wrapper.vm.prevValidatedQuery.measures).not.toEqual(initialValidatedQuery.measures);
expect(wrapper.vm.prevValidatedQuery.dimensions).toEqual(initialValidatedQuery.dimensions);
});

it('should not set skipHeuristics to false if query is empty', async () => {
const cube = createCubeApi();
jest
.spyOn(cube, 'request')
.mockImplementation(fetchMock(load))
.mockImplementationOnce(fetchMock(meta));

const wrapper = shallowMount(QueryBuilder, {
propsData: {
cubeApi: cube,
query: {},
},
});

await flushPromises();

expect(wrapper.vm.skipHeuristics).toBeTruthy();
});
it('should set skipHeuristics to false if query is not empty and prevValidateQuery is not null', async () => {
const cube = createCubeApi();
jest
.spyOn(cube, 'request')
.mockImplementation(fetchMock(load))
.mockImplementationOnce(fetchMock(meta));

const wrapper = shallowMount(QueryBuilder, {
propsData: {
cubeApi: cube,
query: {
measures: ['Orders.count'],
timeDimensions: [
{
dimension: 'Orders.createdAt',
},
],
},
},
});

const initialValidatedQuery = {
measures: ['measure1'],
dimensions: ['dimension1'],
};
wrapper.setData({ prevValidatedQuery: initialValidatedQuery });

await flushPromises();

expect(wrapper.vm.skipHeuristics).toBeFalsy();
});
});
describe('orderMembers', () => {
it('does not contain time dimension if granularity is set to none', async () => {
Expand Down
Loading