From 3fe8cc811cd8606c4bf895743c192c9b5986192d Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 7 Nov 2023 13:20:57 +1000 Subject: [PATCH] DEV: Make admin experimental sidebar config more forgiving (#24236) Followup to b53449eac98dbb579f2d2ebc275badc2cafaed64, it was too easy to add broken routes which would break configuration for the whole site, so now we validate ember routes on save. --- .../admin-config-area-sidebar-experiment.hbs | 12 +++- .../admin-config-area-sidebar-experiment.js | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/addon/components/admin-config-area-sidebar-experiment.hbs b/app/assets/javascripts/admin/addon/components/admin-config-area-sidebar-experiment.hbs index 0f2831af96a..6aaddf69381 100644 --- a/app/assets/javascripts/admin/addon/components/admin-config-area-sidebar-experiment.hbs +++ b/app/assets/javascripts/admin/addon/components/admin-config-area-sidebar-experiment.hbs @@ -14,7 +14,17 @@ or a href, if you want to link to a specific page but don't know the Ember route. You can also use the Ember Inspector extension to find route - names, for example for plugin routes which are not auto-generated here.

+ names, for example for plugin routes which are not auto-generated here. +

+ routeModels + is an array of values that correspond to parts of the route; for example the + topic route may be + /t/:id, so to get a link to topic with ID 123 you would do + routeModels: [123].

+ +

All configuration options for a section and its links looks like this:

+ +
{{this.exampleJson}}
{ + section.links.forEach((link) => { + if (!link.route) { + return; + } + + if (this.validRouteNames.has(link.route)) { + return; + } + + try { + this.router._router._routerMicrolib.recognizer.handlersFor( + link.route + ); + this.validRouteNames.add(link.route); + } catch { + invalidRoutes.push(link.route); + } + }); + }); + + if (invalidRoutes.length) { + this.toasts.error({ + duration: 3000, + data: { + message: `There was an error with one or more of the routes provided: ${invalidRoutes.join( + ", " + )}`, + }, + }); + return; + } + this.#saveConfig(config); }