Skip to content

Commit e7043bb

Browse files
authored
fix(@cubejs-client/vue): Pivot config can use null from heuristics (#7167)
* fix(@cubejs-client/vue): Pivot config can use null from heuristics * test(@cubejs-client/vue): Unit test for builder computed validatedQuery - Correctly updates pivot config after chart type change * fix(@cubejs-client/vue3): Pivot config can use null from heuristics * test(@cubejs-client/vue3): Unit test for builder computed validatedQuery - Correctly updates pivot config after chart type change
1 parent 4bb84a7 commit e7043bb

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

packages/cubejs-client-vue/src/QueryBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export default {
393393
this.chartType = chartType || this.chartType;
394394
this.pivotConfig = ResultSet.getNormalizedPivotConfig(
395395
validatedQuery,
396-
pivotConfig || this.pivotConfig
396+
pivotConfig !== undefined ? pivotConfig : this.pivotConfig
397397
);
398398
this.copyQueryFromProps(validatedQuery);
399399
}

packages/cubejs-client-vue/tests/unit/QueryBuilder.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,4 +919,60 @@ describe('QueryBuilder.vue', () => {
919919
expect(wrapper.vm.pivotConfig).toMatchObject(pivotConfig);
920920
});
921921
});
922+
923+
describe('builder computed', () => {
924+
describe('validatedQuery', () => {
925+
it('correctly updates pivot config after chart type change', async () => {
926+
const expectedPivotForTable = {
927+
x: ['Orders.status'],
928+
y: ['measures'],
929+
fillMissingDates: true,
930+
joinDateRange: false,
931+
};
932+
933+
const expectedPivotForLine = {
934+
x: ['Orders.createdAt.day'],
935+
y: ['Orders.status', 'measures'],
936+
fillMissingDates: true,
937+
joinDateRange: false,
938+
};
939+
940+
const cube = createCubejsApi();
941+
jest
942+
.spyOn(cube, 'request')
943+
.mockImplementation(fetchMock(load))
944+
.mockImplementationOnce(fetchMock(meta));
945+
946+
const wrapper = mount(QueryBuilder, {
947+
propsData: {
948+
cubejsApi: cube,
949+
query: {
950+
measures: ['Orders.count'],
951+
timeDimensions: [{
952+
dimension: 'Orders.createdAt',
953+
}],
954+
},
955+
},
956+
scopedSlots: {
957+
builder: function ({ updateChartType }) {
958+
return this.$createElement('input', {
959+
on: { change: () => updateChartType('line')}
960+
});
961+
},
962+
},
963+
});
964+
965+
await flushPromises();
966+
967+
wrapper.vm.addMember('dimensions', 'Orders.status'); // to trigger first heuristics
968+
await wrapper.vm.$nextTick();
969+
expect(wrapper.vm.pivotConfig).toEqual(expectedPivotForTable);
970+
expect(wrapper.vm.chartType).toBe('table');
971+
wrapper.find('input').trigger('change');
972+
await wrapper.vm.$nextTick();
973+
expect(wrapper.vm.pivotConfig).toEqual(expectedPivotForLine);
974+
expect(wrapper.vm.chartType).toBe('line');
975+
});
976+
});
977+
});
922978
});

packages/cubejs-client-vue3/src/QueryBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ export default {
378378
this.chartType = chartType || this.chartType;
379379
this.pivotConfig = ResultSet.getNormalizedPivotConfig(
380380
validatedQuery,
381-
pivotConfig || this.pivotConfig
381+
pivotConfig !== undefined ? pivotConfig : this.pivotConfig
382382
);
383383
this.copyQueryFromProps(validatedQuery);
384384
}

packages/cubejs-client-vue3/tests/unit/QueryBuilder.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,4 +881,53 @@ describe('QueryBuilder.vue', () => {
881881
// expect(wrapper.vm.filters[0].values).toContain('1');
882882
// });
883883
});
884+
885+
describe('builder computed', () => {
886+
describe('validatedQuery', () => {
887+
it('correctly updates pivot config after chart type change', async () => {
888+
const expectedPivotForTable = {
889+
x: ['Orders.status'],
890+
y: ['measures'],
891+
fillMissingDates: true,
892+
joinDateRange: false,
893+
};
894+
895+
const expectedPivotForLine = {
896+
x: ['Orders.createdAt.day'],
897+
y: ['Orders.status', 'measures'],
898+
fillMissingDates: true,
899+
joinDateRange: false,
900+
};
901+
902+
const cube = createCubejsApi();
903+
jest
904+
.spyOn(cube, 'request')
905+
.mockImplementation(fetchMock(load))
906+
.mockImplementationOnce(fetchMock(meta));
907+
908+
const wrapper = shallowMount(QueryBuilder, {
909+
propsData: {
910+
cubejsApi: cube,
911+
query: {
912+
measures: ['Orders.count'],
913+
timeDimensions: [{
914+
dimension: 'Orders.createdAt',
915+
}],
916+
},
917+
},
918+
});
919+
920+
await flushPromises();
921+
922+
wrapper.vm.addMember('dimensions', 'Orders.status'); // to trigger first heuristics
923+
await wrapper.vm.$nextTick();
924+
expect(wrapper.vm.pivotConfig).toEqual(expectedPivotForTable);
925+
expect(wrapper.vm.chartType).toBe('table');
926+
wrapper.vm.updateChart('line');
927+
await wrapper.vm.$nextTick();
928+
expect(wrapper.vm.pivotConfig).toEqual(expectedPivotForLine);
929+
expect(wrapper.vm.chartType).toBe('line');
930+
});
931+
});
932+
});
884933
});

0 commit comments

Comments
 (0)