Skip to content

Fix transitionTo() and replaceWith() deprecations on routes #4239

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

Merged
merged 1 commit into from
Dec 9, 2021
Merged
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/routes/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';

export default class CategoryRoute extends Route {
@service notifications;
@service router;
@service store;

async model(params) {
Expand All @@ -12,7 +13,7 @@ export default class CategoryRoute extends Route {
} catch (error) {
if (error instanceof NotFoundError) {
this.notifications.error(`Category '${params.category_id}' does not exist`);
return this.replaceWith('index');
return this.router.replaceWith('index');
}

throw error;
Expand Down
3 changes: 2 additions & 1 deletion app/routes/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ajax from '../utils/ajax';

export default class ConfirmRoute extends Route {
@service notifications;
@service router;
@service session;
@service store;

Expand All @@ -29,6 +30,6 @@ export default class ConfirmRoute extends Route {
}
}

this.replaceWith('index');
this.router.replaceWith('index');
}
}
5 changes: 4 additions & 1 deletion app/routes/crate/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class VersionRoute extends Route {
@service router;

async model() {
let crate = this.modelFor('crate');
let versions = await crate.get('versions');

let { defaultVersion } = crate;
let version = versions.find(version => version.num === defaultVersion) ?? versions.lastObject;

this.replaceWith('crate.version-dependencies', crate, version.num);
this.router.replaceWith('crate.version-dependencies', crate, version.num);
}
}
3 changes: 2 additions & 1 deletion app/routes/crate/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';
export default class CrateDocsRoute extends Route {
@service notifications;
@service redirector;
@service router;

redirect() {
let crate = this.modelFor('crate');
Expand All @@ -16,7 +17,7 @@ export default class CrateDocsRoute extends Route {
// no documentation is found
let message = 'Crate does not supply a documentation URL';
this.notifications.error(message);
this.replaceWith('crate', crate);
this.router.replaceWith('crate', crate);
}
}
}
5 changes: 4 additions & 1 deletion app/routes/crate/owners.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class OwnersRoute extends Route {
@service router;

redirect() {
let crate = this.modelFor('crate');

this.transitionTo('crate.settings', crate);
this.router.transitionTo('crate.settings', crate);
}
}
2 changes: 1 addition & 1 deletion app/routes/crate/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class VersionRoute extends Route {
let versionNum = maxSatisfying(unyankedVersionNums, npmRange) ?? maxSatisfying(allVersionNums, npmRange);
if (!versionNum) {
this.notifications.error(`No matching version of crate '${crate.name}' found for: ${range}`);
this.replaceWith('crate.index');
this.router.replaceWith('crate.index');
}

this.router.replaceWith('crate.version', versionNum);
Expand Down
3 changes: 2 additions & 1 deletion app/routes/crate/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';
export default class RepoRoute extends Route {
@service notifications;
@service redirector;
@service router;

redirect() {
let crate = this.modelFor('crate');
Expand All @@ -16,7 +17,7 @@ export default class RepoRoute extends Route {
// no repository is found
let message = 'Crate does not supply a repository URL';
this.notifications.error(message);
this.replaceWith('crate', crate);
this.router.replaceWith('crate', crate);
}
}
}
3 changes: 2 additions & 1 deletion app/routes/crate/reverse-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';

export default class ReverseDependenciesRoute extends Route {
@service notifications;
@service router;
@service store;

queryParams = {
Expand All @@ -25,7 +26,7 @@ export default class ReverseDependenciesRoute extends Route {
}

this.notifications.error(message);
this.replaceWith('index');
this.router.replaceWith('index');
}
}

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

export default class VersionRoute extends Route {
@service notifications;
@service router;

async model(params) {
let crate = this.modelFor('crate');
Expand All @@ -12,7 +13,7 @@ export default class VersionRoute extends Route {
let version = versions.find(version => version.num === requestedVersion);
if (!version) {
this.notifications.error(`Version '${requestedVersion}' of crate '${crate.name}' does not exist`);
this.replaceWith('crate.index');
this.router.replaceWith('crate.index');
}

try {
Expand All @@ -21,7 +22,7 @@ export default class VersionRoute extends Route {
this.notifications.error(
`Failed to load the list of dependencies for the '${crate.name}' crate. Please try again later!`,
);
this.replaceWith('crate.index');
this.router.replaceWith('crate.index');
}

return version;
Expand Down
3 changes: 2 additions & 1 deletion app/routes/keyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';

export default class KeywordRoute extends Route {
@service notifications;
@service router;
@service store;

async model({ keyword_id }) {
Expand All @@ -12,7 +13,7 @@ export default class KeywordRoute extends Route {
} catch (error) {
if (error instanceof NotFoundError) {
this.notifications.error(`Keyword '${keyword_id}' does not exist`);
return this.replaceWith('index');
return this.router.replaceWith('index');
}

throw error;
Expand Down
3 changes: 2 additions & 1 deletion app/routes/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';

export default class TeamRoute extends Route {
@service notifications;
@service router;
@service store;

queryParams = {
Expand All @@ -24,7 +25,7 @@ export default class TeamRoute extends Route {
} catch (error) {
if (error.errors?.some(e => e.detail === 'Not Found')) {
this.notifications.error(`Team '${params.team_id}' does not exist`);
return this.replaceWith('index');
return this.router.replaceWith('index');
}

throw error;
Expand Down
3 changes: 2 additions & 1 deletion app/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';

export default class UserRoute extends Route {
@service notifications;
@service router;
@service store;

queryParams = {
Expand All @@ -23,7 +24,7 @@ export default class UserRoute extends Route {
} catch (error) {
if (error.errors?.some(e => e.detail === 'Not Found')) {
this.notifications.error(`User '${params.user_id}' does not exist`);
return this.replaceWith('index');
return this.router.replaceWith('index');
}

throw error;
Expand Down