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

add refreshModel to namespace query param #11326

Closed
wants to merge 5 commits into from

Conversation

ChaiWithJai
Copy link
Contributor

There is a bug in the Ember Router service that does not preserve query parameters
during a partial transition which is what happens when we forward a query parameter
using transitionTo or LinkTo. That initializes a new set of queryParameters and since
we're inheriting from a sibling route, the new navigated to controller and route have
no knowledge of that previous query parameter. To work around this, we rely on adding
refreshModel to the queryParameter because refreshModel calls Router.refresh which
maps all query params from the previous state into the refresh. Since we're relying on
this bug in the API (Hyrum's Law), we'll follow the Beyonce rule and test the dependency
on the API in an acceptance test (if you like it, then you shoulda put a test on it). If
we update Ember and this test fails, its because Ember fixed this Router bug.

@github-actions
Copy link

github-actions bot commented Oct 15, 2021

Ember Asset Size action

As of 4cc749e

Files that got Bigger 🚨:

File raw gzip
nomad-ui.js +3.32 kB +458 B

Files that stayed the same size 🤷‍:

File raw gzip
vendor.js 0 B 0 B
nomad-ui.css 0 B 0 B
vendor.css 0 B 0 B

@github-actions
Copy link

github-actions bot commented Oct 15, 2021

Ember Test Audit comparison

main 4cc749e change
passes 1195 1189 -6
failures 1 11 +10
flaky 4 0 -4
duration 000ms 000ms -000ms

@github-actions
Copy link

Ember Test Audit flaky tests

Ember Test Audit detected these flaky tests on d9f1e18:

  • Acceptance | task group detail: /jobs/:id/:task-group second breadcrumb should link to the job for the task group
  • Integration | Component | TopoViz: clicking on an allocation in a deeply nested TopoViz::Node will associate sibling allocations with curves
  • Integration | Component | TopoViz: when the count of sibling allocations is high enough relative to the node count, curves are not rendered
  • Integration | Utility | exec-socket-xterm-adapter: resizing the window passes a resize message through the socket

queryParams = {
jobNamespace: {
as: 'namespace',
refreshModel: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgfa29 The reason this wasn't working earlier is that the refreshModel hook must be on the route and not the controller. There is no explanation why, but reading the test coverage - it appears that having refreshModel set on the route opts us into a full transition causing queryParams from the previous state to map to the new state.

https://github.com/emberjs/ember.js/blob/67d465f7603685b20a4dc27833164ceab7003559/packages/ember/tests/routing/query_params_test.js#L584

Comment on lines 85 to 140
test('sorting the allocations tables does not clear namespace query parameter', async function(assert) {
/*
We rely on the router bug reported in https://github.com/emberjs/ember.js/issues/18683
Nomad passes job namespaces to sibling routes using LinkTo and transitions
These only trigger partial transitions which do not map the query parameters of the previous
state, the workaround to trigger a full transition is calling refreshModel. We depend on this
API to preserve namespaces. If this test breaks, its likely associated to an Ember update and
a change to that API.
*/
server.createList('allocation', Allocations.pageSize - 1);
server.create('namespace', { id: 'afc-richmond' });
job.update({
namespaceId: 'afc-richmond',
});
allocations = server.schema.allocations.where({
jobId: job.id,
}).models;

await Allocations.visit({ id: job.id, namespace: 'afc-richmond' });
await Allocations.sortBy('taskGroupName');

assert.equal(
currentURL(),
`/jobs/${job.id}/allocations?namespace=afc-richmond&sort=taskGroupName`,
'the URL persists the namespace parameter'
);
});

test('searching the allocations tables does not clear namespace query parameter', async function(assert) {
/*
We rely on the router bug reported in https://github.com/emberjs/ember.js/issues/18683
Nomad passes job namespaces to sibling routes using LinkTo and transitions
These only trigger partial transitions which do not map the query parameters of the previous
state, the workaround to trigger a full transition is calling refreshModel. We depend on this
API to preserve namespaces. If this test breaks, its likely associated to an Ember update and
a change to that API.
*/
server.create('namespace', { id: 'afc-richmond' });
job.update({
namespace: 'afc-richmond',
namespaceId: 'afc-richmond',
});

makeSearchAllocations(server);

allocations = server.schema.allocations.where({ jobId: job.id }).models;

await Allocations.visit({ id: job.id, namespace: 'afc-richmond' });
await Allocations.search('ffffff');

assert.equal(
currentURL(),
`/jobs/${job.id}/allocations?namespace=afc-richmond&search=ffffff`,
'the URL persists the namespace parameter'
);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove these tests since they didn't catch the error. I'll just make a comment and that's how we'll live for now.

@github-actions
Copy link

Ember Test Audit flaky tests

Ember Test Audit detected these flaky tests on main:

  • Acceptance | task group detail: /jobs/:id/:task-group second breadcrumb should link to the job for the task group

Ember Test Audit detected these flaky tests on 21fdeef:

  • Acceptance | task group detail: /jobs/:id/:task-group second breadcrumb should link to the job for the task group
  • Integration | Component | TopoViz: clicking on an allocation in a deeply nested TopoViz::Node will associate sibling allocations with curves
  • Integration | Component | TopoViz: when the count of sibling allocations is high enough relative to the node count, curves are not rendered
  • Integration | Utility | exec-socket-xterm-adapter: resizing the window passes a resize message through the socket

There is a bug in the Ember Router service that does not preserve query parameters
during a partial transition which is what happens when we forward a query parameter
using transitionTo or LinkTo. That initializes a new set of queryParameters and since
we're inheriting from a sibling route, the new navigated to controller and route have
no knowledge of that previous query parameter. To work around this, we rely on adding
refreshModel to the queryParameter because refreshModel calls Router.refresh which
maps all query params from the previous state into the refresh. Since we're relying on
this bug in the API (Hyrum's Law), we'll follow the Beyonce rule and test the dependency
on the API in an acceptance test (if you like it, then you shoulda put a test on it). If
we update Ember and this test fails, its because Ember fixed this Router bug.
Ember documentation shows refreshModel hook on the route
instead of the controller. Making this change does trigger
a full transition. Unsure why at the moment, however.
The tests don't actually catch the error. The Ember test server
does not fully replicate the behavior of triggering partial
and full transitions for routes. The page transition is being
triggered by the Search Mixin when resetPagination is called on
change. We can't test the route in isolation because we're using
the Search mixin and that's where the behavior causing namespaces
to disappear is coming from.
The bug is caused by clicking the sort or search button. This commit resolves the
disappearing namespace when the sort button is clicked by ensuring that when we
click the sort button and thus are clicking the LinkTo property that we're adding
namespace to the query hash.
@github-actions
Copy link

github-actions bot commented Nov 7, 2021

Ember Test Audit flaky tests

Ember Test Audit detected these flaky tests on main:

  • Acceptance | task group detail: /jobs/:id/:task-group second breadcrumb should link to the job for the task group
  • Integration | Component | TopoViz: clicking on an allocation in a deeply nested TopoViz::Node will associate sibling allocations with curves
  • Integration | Component | TopoViz: when the count of sibling allocations is high enough relative to the node count, curves are not rendered
  • Integration | Utility | exec-socket-xterm-adapter: resizing the window passes a resize message through the socket

@ChaiWithJai ChaiWithJai marked this pull request as draft December 17, 2021 16:52
@lgfa29
Copy link
Contributor

lgfa29 commented Jan 5, 2022

Closing this one since it requires a different approach.

@lgfa29 lgfa29 closed this Jan 5, 2022
@lgfa29 lgfa29 deleted the b-ui/namespace-qp-fwd branch January 5, 2022 22:46
@github-actions
Copy link

github-actions bot commented Nov 5, 2022

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ui] namespace query parameter vanishes when searching and sorting allocation and client tab
2 participants