DEV: Fix ember/no-private-routing-service (#24009)

This commit is contained in:
Jarek Radosz 2023-11-29 12:26:52 +01:00 committed by GitHub
parent cbe772f6fa
commit d38360b23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 40 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable ember/no-private-routing-service */
import { getOwner } from "@ember/application";
import { A } from "@ember/array";
import Helper from "@ember/component/helper";

View File

@ -55,16 +55,16 @@ export default {
const siteSettings = owner.lookup("service:site-settings");
const loginError = (errorMsg, className, properties, callback) => {
const applicationRouter = owner.lookup("route:application");
const applicationRoute = owner.lookup("route:application");
const applicationController = owner.lookup(
"controller:application"
);
modal.show(LoginModal, {
model: {
showNotActivated: (props) =>
applicationRouter.send("showNotActivated", props),
applicationRoute.send("showNotActivated", props),
showCreateAccount: (props) =>
applicationRouter.send("showCreateAccount", props),
applicationRoute.send("showCreateAccount", props),
canSignUp: applicationController.canSignUp,
flash: errorMsg,
flashType: className || "success",

View File

@ -37,7 +37,7 @@ export default {
after: "inject-objects",
initialize(owner) {
const router = owner.lookup("router:main");
const router = owner.lookup("service:router");
router.on("routeDidChange", (transition) => {
if (transition.isAborted) {

View File

@ -10,6 +10,7 @@ export default {
initialize(owner) {
// Tell our AJAX system to track a page transition
// eslint-disable-next-line ember/no-private-routing-service
const router = owner.lookup("router:main");
router.on("routeWillChange", this.handleRouteWillChange);

View File

@ -30,7 +30,7 @@ export default {
this.appEvents = owner.lookup("service:app-events");
this.siteSettings = owner.lookup("service:site-settings");
this.site = owner.lookup("service:site");
this.router = owner.lookup("router:main");
this.router = owner.lookup("service:router");
this.reviewableCountsChannel = `/reviewable_counts/${this.currentUser.id}`;

View File

@ -93,8 +93,7 @@ export function register(user, router, appEvents) {
navigator.serviceWorker.addEventListener("message", (event) => {
if ("url" in event.data) {
const url = event.data.url;
router.handleURL(url);
router.transitionTo(event.data.url);
}
});
}

View File

@ -1,3 +1,4 @@
/* eslint-disable ember/no-private-routing-service */
import { setOwner } from "@ember/application";
import EmberObject from "@ember/object";
import { next, schedule } from "@ember/runloop";

View File

@ -34,7 +34,9 @@ const Scrolling = Mixin.create({
if (!opts.throttle) {
opts.throttle = 100;
}
// So we can not call the scrolled event while transitioning. There is no public API for this :'(
// eslint-disable-next-line ember/no-private-routing-service
const microLib = this.router._router._routerMicrolib;
let scheduleScrolled = () => {

View File

@ -10,17 +10,13 @@ export default createWidget("link", {
tagName: "a",
href(attrs) {
const route = attrs.route;
if (route) {
const router = this.register.lookup("router:main");
if (router && router._routerMicrolib) {
const params = [route];
if (attrs.model) {
params.push(attrs.model);
}
return getURL(
router._routerMicrolib.generate.apply(router._routerMicrolib, params)
);
if (attrs.route) {
const router = this.register.lookup("service:router");
if (attrs.model) {
return router.urlFor(attrs.route, attrs.model);
} else {
return router.urlFor(attrs.route);
}
} else {
return getURL(attrs.href);

View File

@ -51,7 +51,7 @@ acceptance("Auth Complete", function (needs) {
withPluginApi("1.11.0", (api) => {
api.addBeforeAuthCompleteCallback(() => {
api.container
.lookup("router:main")
.lookup("service:router")
.transitionTo("discovery.categories");
return false;
});

View File

@ -44,27 +44,6 @@ acceptance(
);
});
test("viewing group messages on subfolder setup", async function (assert) {
const router = this.container.lookup("router:main");
const originalRootURL = router.rootURL;
try {
router.set("rootURL", "/forum/");
await visit("/forum/u/eviltrout/messages");
const messagesDropdown = selectKit(".user-nav-messages-dropdown");
assert.strictEqual(
messagesDropdown.header().name(),
I18n.t("user.messages.inbox"),
"User personal inbox is selected in dropdown"
);
} finally {
router.set("rootURL", originalRootURL);
}
});
test("viewing messages of another user", async function (assert) {
updateCurrentUser({ id: 5, username: "charlie" });

View File

@ -27,4 +27,13 @@ describe "Viewing user private messages", type: :system do
expect(user_private_messages_page).to have_right_inbox_dropdown_value("miXeD_caSE_name")
end
end
describe "on subfolder setup" do
it "allows the user to view the default messages inbox" do
set_subfolder "/forum"
page.visit "/forum/u/#{user.username}/messages"
expect(user_private_messages_page).to have_right_inbox_dropdown_value("Inbox")
end
end
end