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

refactor: remove routing.transition methods deprecation #1271

Closed
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
3 changes: 2 additions & 1 deletion app/controllers/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class SubmissionsDetail extends Controller {
@service submissionHandler;
@service searchHelper;
@service flashMessages;
@service router;

constructor() {
super(...arguments);
Expand Down Expand Up @@ -479,7 +480,7 @@ export default class SubmissionsDetail extends Controller {

ignoreList.clearIgnore();
ignoreList.ignore(submission.get('id'));
this.transitionToRoute('submissions');
this.router.transitionTo('submissions');
} catch (e) {
this.flashMessages.danger(
'We encountered an error deleting this draft submission. Please try again later or contact your administrator'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class SubmissionsNew extends Controller {
set(this, 'uploading', false);
set(this, 'comment', '');
set(this, 'workflow.filesTemp', A());
this.transitionToRoute('thanks', { queryParams: { submission: get(sub, 'id') } });
this.router.transitionTo('thanks', { queryParams: { submission: get(sub, 'id') } });
})
.catch((error) => {
this.set('uploading', false);
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submissions/new/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { task } from 'ember-concurrency-decorators';
export default class SubmissionsNewBasics extends Controller {
@service workflow;
@service flashMessages;
@service router;

@alias('model.newSubmission') submission;
@alias('model.publication') publication;
Expand Down Expand Up @@ -64,7 +65,7 @@ export default class SubmissionsNewBasics extends Controller {
this.doiInfo.title = this.publication.title;

await this.submission.save();
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submissions/new/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { inject as service } from '@ember/service';
export default class SubmissionsNewFiles extends Controller {
@service workflow;
@service flashMessages;
@service router;

@alias('model.newSubmission') submission;
@alias('model.files') files;
Expand Down Expand Up @@ -50,7 +51,7 @@ export default class SubmissionsNewFiles extends Controller {
this.updateRelatedData();
await this.submission.save();
set(this, 'loadingNext', false); // reset for next time
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/submissions/new/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import Controller, { inject as controller } from '@ember/controller';
import { action } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';

export default class SubmissionsNewGrants extends Controller {
@service router;

@alias('model.newSubmission') submission;
@alias('model.publication') publication;
@alias('model.submissionEvents') submissionEvents;
Expand All @@ -24,7 +27,7 @@ export default class SubmissionsNewGrants extends Controller {
async loadTab(gotoRoute) {
// add validation, processing
await this.submission.save();
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/submissions/new/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import Controller, { inject as controller } from '@ember/controller';
import { action } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';

export default class SubmissionsNewMetadata extends Controller {
@service router;

@alias('model.newSubmission') submission;
@alias('model.repositories') repositories;
@alias('model.publication') publication;
Expand All @@ -25,7 +28,7 @@ export default class SubmissionsNewMetadata extends Controller {
async loadTab(gotoRoute) {
// add validation, processing
await this.submission.save();
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/submissions/new/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import Controller, { inject as controller } from '@ember/controller';
import { action } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';

export default class SubmissionsNewPolicies extends Controller {
@service router;

@alias('model.newSubmission') submission;
@alias('model.policies') policies;
@alias('model.publication') publication;
Expand All @@ -25,7 +28,7 @@ export default class SubmissionsNewPolicies extends Controller {
async loadTab(gotoRoute) {
// add validation, processing
await this.submission.save();
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/submissions/new/repositories.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { inject as service } from '@ember/service';

export default class SubmissionsNewRepositories extends Controller {
@service workflow;
@service router;

@alias('model.newSubmission') submission;
@alias('model.repositories') repositories;
Expand Down Expand Up @@ -82,7 +83,7 @@ export default class SubmissionsNewRepositories extends Controller {
@action
async loadTab(gotoRoute) {
await this.submission.save();
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
set(this, 'loadingNext', false); // reset for next time
}

Expand All @@ -102,7 +103,7 @@ export default class SubmissionsNewRepositories extends Controller {
});

if (value.dismiss) {
this.transitionToRoute('dashboard');
this.router.transitionTo('dashboard');
}
// do nothing
} else {
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/submissions/new/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import Controller, { inject as controller } from '@ember/controller';
import { action, computed, get } from '@ember/object';
import { alias } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';

export default class SubmissionsNewReview extends Controller {
@service router;

@alias('model.newSubmission') submission;
@alias('model.files') files;
@alias('model.publication') publication;
Expand All @@ -31,9 +34,7 @@ export default class SubmissionsNewReview extends Controller {

@action
loadTab(gotoRoute) {
// add validation, processing
// this.submission.save().then(() => this.transitionToRoute(gotoRoute));
this.transitionToRoute(gotoRoute);
this.router.transitionTo(gotoRoute);
}

@action
Expand Down
1 change: 0 additions & 1 deletion app/deprecation-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow';

setupDeprecationWorkflow({
workflow: [
{ handler: 'silence', matchId: 'routing.transition-methods' },
{ handler: 'silence', matchId: 'ember-data:deprecate-promise-many-array-behaviors' },
{ handler: 'silence', matchId: 'ember-data:deprecate-array-like' },
{ handler: 'silence', matchId: 'ember-data:no-a-with-array-like' },
Expand Down
3 changes: 2 additions & 1 deletion app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { action } from '@ember/object';

export default class ApplicationRoute extends CheckSessionRoute {
@service('app-static-config') staticConfig;
@service router;

queryParams = ['userToken'];

Expand All @@ -16,7 +17,7 @@ export default class ApplicationRoute extends CheckSessionRoute {

@action
transitionTo(route, model) {
this.transitionTo(route, model);
this.router.transitionTo(route, model);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/routes/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export default class NewRoute extends CheckSessionRoute {
@service('workflow')
workflow;
@service store;
@service router;

@service('current-user')
currentUser;

beforeModel() {
if (this.workflow.getCurrentStep() === 0) {
this.transitionTo('submissions.new');
this.router.transitionTo('submissions.new');
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/routes/submissions/new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { inject as service } from '@ember/service';
import CheckSessionRoute from './../../check-session-route';

export default class IndexRoute extends CheckSessionRoute {
@service('workflow')
workflow;
@service workflow;
@service router;

beforeModel() {
this.workflow.resetWorkflow();
this.replaceWith('submissions.new.basics');
this.router.replaceWith('submissions.new.basics');
}
}
6 changes: 3 additions & 3 deletions tests/unit/controllers/submissions/detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module('Unit | Controller | submissions/detail', (hooks) => {
});

test('delete action should call the submission handler', function (assert) {
assert.expect(3);
assert.expect(2);

// Mock the global SweetAlert object to always return immediately
swal = () =>
Expand All @@ -35,7 +35,6 @@ module('Unit | Controller | submissions/detail', (hooks) => {
},
})
);
controller.set('transitionToRoute', () => assert.ok(true));

controller.send('deleteSubmission', submission);
});
Expand All @@ -47,7 +46,8 @@ module('Unit | Controller | submissions/detail', (hooks) => {
swal = Sinon.fake.resolves({ value: true });

const controller = this.owner.lookup('controller:submissions/detail');
const transitionFake = Sinon.replace(controller, 'transitionToRoute', Sinon.fake());
const routerService = this.owner.lookup('service:router');
const transitionFake = Sinon.replace(routerService, 'transitionTo', Sinon.fake());

controller.submissionHandler = this.owner.lookup('service:submission-handler');
const deleteFake = Sinon.replace(controller.submissionHandler, 'deleteSubmission', Sinon.fake.rejects());
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/controllers/submissions/new-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ module('Unit | Controller | submissions/new', (hooks) => {

// After the route transition to thanks, all promises should be resolved handler
// and tests can be run.
controller.set('transitionToRoute', (name) => {

const routerService = this.owner.lookup('service:router');
routerService.transitionTo = (name) => {
assert.strictEqual(name, 'thanks');

assert.true(publicationSaved);
Expand All @@ -120,7 +122,7 @@ module('Unit | Controller | submissions/new', (hooks) => {
assert.deepEqual(md.agreements[0], {
moo: 'Milk cows',
});
});
};

controller.set('model', model);
controller.set('comment', comment);
Expand Down Expand Up @@ -193,7 +195,8 @@ module('Unit | Controller | submissions/new', (hooks) => {

// After the route transition to thanks, all promises should be resolved handler
// and tests can be run.
controller.set('transitionToRoute', (name) => {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = (name) => {
assert.strictEqual(name, 'thanks');

assert.true(publicationSaved);
Expand All @@ -207,7 +210,7 @@ module('Unit | Controller | submissions/new', (hooks) => {
assert.strictEqual(submissionEvent.performerRole, 'preparer');
assert.strictEqual(submissionEvent.eventType, 'approval-requested');
assert.strictEqual(submissionEvent.comment, comment);
});
};

controller.set('model', model);
controller.set('comment', comment);
Expand Down Expand Up @@ -279,7 +282,8 @@ module('Unit | Controller | submissions/new', (hooks) => {

// After the route transition to thanks, all promises should be resolved handler
// and tests can be run.
controller.set('transitionToRoute', (name) => {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = (name) => {
assert.strictEqual(name, 'thanks');

assert.true(publicationSaved);
Expand All @@ -295,7 +299,7 @@ module('Unit | Controller | submissions/new', (hooks) => {
assert.strictEqual(submissionEvent.performerRole, 'preparer');
assert.strictEqual(submissionEvent.eventType, 'approval-requested-newuser');
assert.strictEqual(submissionEvent.comment, comment);
});
};

controller.set('model', model);
controller.set('comment', comment);
Expand All @@ -310,7 +314,7 @@ module('Unit | Controller | submissions/new', (hooks) => {
* to the expected route.
*
* This action should first create a SweetAlert (swal), then call 'deleteSubmission' in the
* submission handler, finally call 'transitionToRoute' to transition to the 'submissions'
* submission handler, finally call 'transitionTo' to transition to the 'submissions'
* route.
*/
test('abort should delete submission and transition', async function (assert) {
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/controllers/submissions/new/basics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ module('Unit | Controller | submissions/new/basics', (hooks) => {
publication,
};
controller.set('model', model);
controller.transitionToRoute = function () {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = () => {
assert.ok(true);
loadTabAccessed = true;
};
Expand Down Expand Up @@ -192,7 +193,8 @@ module('Unit | Controller | submissions/new/basics', (hooks) => {
};

controller.set('model', model);
controller.set('transitionToRoute', (route) => {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = () => {
// no errors and loadTab accessed
assert.false(controller.get('submitterIsInvalid'));
assert.false(controller.get('titleError'));
Expand All @@ -203,7 +205,7 @@ module('Unit | Controller | submissions/new/basics', (hooks) => {
assert.strictEqual(controller.get('flaggedFields').indexOf('submitterEmail'), -1);

assert.ok(subSaved, 'submission was not saved');
});
};

assert.true(controller.get('model.newSubmission.isProxySubmission'));
controller.send('validateAndLoadTab', 'submissions.new.basics');
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/controllers/submissions/new/files-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ module('Unit | Controller | submissions/new/files', (hooks) => {
}),
};
controller.set('model', model);
controller.transitionToRoute = function () {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = () => {
assert.ok(subSaved, 'Submission was not saved');
assert.strictEqual(controller.get('workflow').getFilesTemp().length, 0);
assert.strictEqual(controller.get('model.files').length, 1);
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/controllers/submissions/new/grants-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module('Unit | Controller | submissions/new/grants', (hooks) => {

controller.set('model', model);

controller.transitionToRoute = function (route) {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = function (route) {
assert.strictEqual(route, 'submissions.new.basics');
};
controller.send('loadPrevious');
Expand All @@ -41,7 +42,8 @@ module('Unit | Controller | submissions/new/grants', (hooks) => {

controller.set('model', model);

controller.transitionToRoute = function (route) {
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = function (route) {
assert.strictEqual(route, 'submissions.new.policies');
};
controller.send('loadNext');
Expand All @@ -62,7 +64,8 @@ module('Unit | Controller | submissions/new/grants', (hooks) => {
});

controller.set('model', model);
controller.set('transitionToRoute', () => {});
const routerService = this.owner.lookup('service:router');
routerService.transitionTo = () => {};

controller.send('loadNext');
controller.send('loadPrevious');
Expand Down
Loading
Loading