-
Notifications
You must be signed in to change notification settings - Fork 14k
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
[dashboard] After update filter, trigger new queries when charts are visible #7233
Merged
graceguo-supercat
merged 2 commits into
apache:master
from
graceguo-supercat:gg-DashApplyFilter
May 8, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { TABBED_DASHBOARD } from './dashboard.helper'; | ||
|
||
export default () => describe('tabs', () => { | ||
let filterId; | ||
let treemapId; | ||
let linechartId; | ||
let boxplotId; | ||
|
||
// cypress can not handle window.scrollTo | ||
// https://github.com/cypress-io/cypress/issues/2761 | ||
// add this exception handler to pass test | ||
const handleException = () => { | ||
// return false to prevent the error from | ||
// failing this test | ||
cy.on('uncaught:exception', () => false); | ||
}; | ||
|
||
beforeEach(() => { | ||
cy.server(); | ||
cy.login(); | ||
|
||
cy.visit(TABBED_DASHBOARD); | ||
|
||
cy.get('#app').then((data) => { | ||
const bootstrapData = JSON.parse(data[0].dataset.bootstrap); | ||
const dashboard = bootstrapData.dashboard_data; | ||
filterId = dashboard.slices.find(slice => (slice.form_data.viz_type === 'filter_box')).slice_id; | ||
boxplotId = dashboard.slices.find(slice => (slice.form_data.viz_type === 'box_plot')).slice_id; | ||
treemapId = dashboard.slices.find(slice => (slice.form_data.viz_type === 'treemap')).slice_id; | ||
linechartId = dashboard.slices.find(slice => (slice.form_data.viz_type === 'line')).slice_id; | ||
|
||
const filterFormdata = { | ||
slice_id: filterId, | ||
}; | ||
const filterRequest = `/superset/explore_json/?form_data=${JSON.stringify(filterFormdata)}`; | ||
cy.route('POST', filterRequest).as('filterRequest'); | ||
|
||
const treemapFormdata = { | ||
slice_id: treemapId, | ||
}; | ||
const treemapRequest = `/superset/explore_json/?form_data=${JSON.stringify(treemapFormdata)}`; | ||
cy.route('POST', treemapRequest).as('treemapRequest'); | ||
|
||
const linechartFormdata = { | ||
slice_id: linechartId, | ||
}; | ||
const linechartRequest = `/superset/explore_json/?form_data=${JSON.stringify(linechartFormdata)}`; | ||
cy.route('POST', linechartRequest).as('linechartRequest'); | ||
|
||
const boxplotFormdata = { | ||
slice_id: boxplotId, | ||
}; | ||
const boxplotRequest = `/superset/explore_json/?form_data=${JSON.stringify(boxplotFormdata)}`; | ||
cy.route('POST', boxplotRequest).as('boxplotRequest'); | ||
}); | ||
}); | ||
|
||
it('should load charts when tab is visible', () => { | ||
// landing in first tab, should see 2 charts | ||
cy.wait('@filterRequest'); | ||
cy.get('.grid-container .filter_box').should('be.exist'); | ||
cy.wait('@treemapRequest'); | ||
cy.get('.grid-container .treemap').should('be.exist'); | ||
cy.get('.grid-container .box_plot').should('not.be.exist'); | ||
cy.get('.grid-container .line').should('not.be.exist'); | ||
|
||
// click row level tab, see 1 more chart | ||
cy.get('.tab-content ul.nav.nav-tabs li') | ||
.last() | ||
.find('.editable-title input') | ||
.click(); | ||
cy.wait('@linechartRequest'); | ||
cy.get('.grid-container .line').should('be.exist'); | ||
|
||
// click top level tab, see 1 more chart | ||
handleException(); | ||
cy.get('.dashboard-component-tabs') | ||
.first() | ||
.find('ul.nav.nav-tabs li') | ||
.last() | ||
.find('.editable-title input') | ||
.click(); | ||
cy.wait('@boxplotRequest'); | ||
cy.get('.grid-container .box_plot').should('be.exist'); | ||
}); | ||
|
||
it('should send new queries when tab becomes visible', () => { | ||
// landing in first tab | ||
cy.wait('@filterRequest'); | ||
cy.wait('@treemapRequest'); | ||
|
||
// creating route and stubbing filtered route | ||
cy.route('POST', '/superset/explore_json/*').as('updatedChartRequest'); | ||
|
||
// apply filter | ||
cy.get('.Select-control') | ||
.first() | ||
.find('input') | ||
.first() | ||
.type('South Asia{enter}', { force: true }); | ||
|
||
// send new query from same tab | ||
cy.wait('@updatedChartRequest') | ||
.then((xhr) => { | ||
const requestFormData = xhr.request.body; | ||
const requestParams = JSON.parse(requestFormData.get('form_data')); | ||
expect(requestParams.extra_filters[0]) | ||
.deep.eq({ col: 'region', op: 'in', val: ['South Asia'] }); | ||
}); | ||
|
||
// click row level tab, send 1 more query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
cy.get('.tab-content ul.nav.nav-tabs li') | ||
.last() | ||
.click(); | ||
cy.wait('@updatedChartRequest') | ||
.then((xhr) => { | ||
const requestFormData = xhr.request.body; | ||
const requestParams = JSON.parse(requestFormData.get('form_data')); | ||
expect(requestParams.extra_filters[0]) | ||
.deep.eq({ col: 'region', op: 'in', val: ['South Asia'] }); | ||
}); | ||
|
||
// click top level tab, send 1 more query | ||
handleException(); | ||
cy.get('.dashboard-component-tabs') | ||
.first() | ||
.find('ul.nav.nav-tabs li') | ||
.last() | ||
.find('.editable-title input') | ||
.click(); | ||
cy.wait('@updatedChartRequest') | ||
.then((xhr) => { | ||
const requestFormData = xhr.request.body; | ||
const requestParams = JSON.parse(requestFormData.get('form_data')); | ||
expect(requestParams.extra_filters[0]) | ||
.deep.eq({ col: 'region', op: 'in', val: ['South Asia'] }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
"row"
=>"top"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in integration test for dashboard, i created layout a like this (so that i can test current solution works for both row-level tab and root-level tab):
root level tab A: has only 1 row
root level tab B: has 2 rows
when i update filter, chart-2 is always visible, so it get updated right away.
when i click row-level tab 2, i can see chart-3 become visible, and it sends new query.
when i click root-level tab A, i can see chart-1 becomes visible, and it sends new query.