fix: dashboard filter scope bug (#10114)

* fix: dashboard filter scope bug

* add extra comments per review
This commit is contained in:
Grace Guo
2020-06-22 10:18:04 -07:00
committed by GitHub
parent 221f38099b
commit a80453d945
2 changed files with 165 additions and 4 deletions

View File

@@ -71,6 +71,19 @@ describe('getFilterScopeFromNodesTree', () => {
});
describe('should return scope for tabbed dashboard', () => {
// this is a commonly used layout for dashboard:
// - Tab 1
// - filter_107
// - chart_106
// - Tab 2
// - filter_108
// - chart_104
// - Row Tab
// - chart_105
// - chart_103
// - New Tab
// - chart_101
// - chart_102
const nodes = [
{
label: 'All dashboard',
@@ -157,6 +170,120 @@ describe('getFilterScopeFromNodesTree', () => {
},
];
// this is another commonly used layout for dashboard:
// - filter_109
// - Tab 1
// - Row Tab 1
// - filter_107
// - chart_106
// - Tab 2
// - filter_108
// - chart_104
// - Row Tab
// - chart_105
// - chart_103
// - New Tab
// - chart_101
// - chart_102
const nodes2 = [
{
label: 'All dashboard',
type: 'ROOT',
value: 'ROOT_ID',
children: [
{
label: 'Time Filter',
showCheckbox: true,
type: 'CHART',
value: 109,
},
{
label: 'Tab 1',
type: 'TAB',
value: 'TAB-Rb5aaqKWgG',
children: [
{
label: 'Row Tab 1',
type: 'TAB',
value: 'TAB-row-tab1',
children: [
{
label: 'Geo Filters',
showCheckbox: false,
type: 'CHART',
value: 107,
},
{
label: "World's Pop Growth",
showCheckbox: true,
type: 'CHART',
value: 106,
},
],
},
],
},
{
label: 'Tab 2',
type: 'TAB',
value: 'TAB-w5Fp904Rs',
children: [
{
label: 'Time Filter',
showCheckbox: true,
type: 'CHART',
value: 108,
},
{
label: 'Life Expectancy VS Rural %',
showCheckbox: true,
type: 'CHART',
value: 104,
},
{
label: 'Row Tab 1',
type: 'TAB',
value: 'TAB-E4mJaZ-uQM',
children: [
{
value: 105,
label: 'Rural Breakdown',
type: 'CHART',
showCheckbox: true,
},
{
value: 103,
label: '% Rural',
type: 'CHART',
showCheckbox: true,
},
],
},
{
value: 'TAB-rLYu-Cryu',
label: 'New Tab',
type: 'TAB',
children: [
{
value: 102,
label: 'Most Populated Countries',
type: 'CHART',
showCheckbox: true,
},
{
value: 101,
label: "World's Population",
type: 'CHART',
showCheckbox: true,
},
],
},
],
},
],
},
];
it('root level tab scope', () => {
const checkedChartIds = [106];
expect(
@@ -226,5 +353,33 @@ describe('getFilterScopeFromNodesTree', () => {
immune: [101],
});
});
it('exclude sub-tab', () => {
const checkedChartIds = [103, 104, 105];
expect(
getFilterScopeFromNodesTree({
filterKey: '108___time_range',
nodes,
checkedChartIds,
}),
).toEqual({
scope: ['TAB-w5Fp904Rs'],
immune: [102, 101],
});
});
it('exclude top-tab', () => {
const checkedChartIds = [106, 109];
expect(
getFilterScopeFromNodesTree({
filterKey: '107_region',
nodes: nodes2,
checkedChartIds,
}),
).toEqual({
scope: ['ROOT_ID'],
immune: [105, 103, 102, 101, 108, 104],
});
});
});
});