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

fixes #756: don't make the odata request when route is being changed #1042

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/composables/query-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export default ({ fromQuery, toQuery }) => {
the same -- something we want to avoid.
*/
let ignoreNextRouteChange = false;
watch(router.currentRoute, ({ query: newQuery }, { query: oldQuery }) => {
watch(router.currentRoute, ({ query: newQuery, name: oldRouteName }, { query: oldQuery, name: newRouteName }) => {
// If route is different then we don't need to set value from the query, it
// will be set during setup phase
if (oldRouteName !== newRouteName) return;

if (ignoreNextRouteChange) {
ignoreNextRouteChange = false;
return;
Expand Down
19 changes: 19 additions & 0 deletions test/components/submission/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,23 @@ describe('SubmissionFilters', () => {
});
});
});

it('should not send Submission OData request on navigating to another route after filter', () => {
testData.extendedForms.createPast(1);

return loadComponent('reviewState=%27approved%27')
.beforeEachResponse((_, { url }) => {
if (url.includes('.svc')) {
const filter = relativeUrl(url).searchParams.get('$filter');
filter.should.equal("(__system/reviewState eq 'approved')");
}
})
.afterResponses(component => {
const filters = component.getComponent(SubmissionFilters).props();
filters.reviewState.should.eql(["'approved'"]);
})
.complete()
.route('/projects/1/forms/f/draft/testing')
.testNoRequest();
});
});
15 changes: 15 additions & 0 deletions test/composables/query-ref.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ describe('useQueryRef()', () => {
result.value.should.equal('c,d');
});

it('should not changes value of ref after a change of route name', async () => {
let result;
return load('/?x=a&y=b')
.afterResponses(app => {
result = withSetup(() => useQueryRef(options.comma), {
container: app.vm.$container
});
result.value.should.equal('a,b');
})
.load('/users?x=c&y=d')
.afterResponses(() => {
result.value.should.equal('a,b');
});
});

describe('change to an irrelevant query parameter', () => {
it('does not change the value of the ref', async () => {
// `z` is the irrelevant query parameter that the ref doesn't use.
Expand Down