From 9779cc9d5ee767c65232b19ddd1fddc5e86252a1 Mon Sep 17 00:00:00 2001 From: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com> Date: Wed, 8 Jan 2025 06:18:01 -0600 Subject: [PATCH] UX: Conditionally render permalinks filter (#30633) --- .../addon/components/admin-permalink-form.gjs | 10 ++++--- .../controllers/admin-permalinks-index.js | 2 +- .../admin/addon/models/permalink.js | 14 +++++++--- .../addon/templates/permalinks-index.hbs | 26 ++++++++++--------- .../tests/acceptance/admin-permalink-test.js | 6 ++--- spec/system/admin_permalinks_page_spec.rb | 9 +++++++ .../page_objects/pages/admin_permalinks.rb | 16 ++++++++++++ 7 files changed, 59 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/admin-permalink-form.gjs b/app/assets/javascripts/admin/addon/components/admin-permalink-form.gjs index f0e4f0a925d..eea8eed3f99 100644 --- a/app/assets/javascripts/admin/addon/components/admin-permalink-form.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-permalink-form.gjs @@ -87,7 +87,9 @@ export default class AdminFlagsForm extends Component { permalink_type: data.permalinkType, permalink_type_value: this.valueForPermalinkType(data), }); - this.adminPermalinks.model.unshift(Permalink.create(result.payload)); + this.adminPermalinks.model.allLinks.unshift( + Permalink.create(result.payload) + ); this.router.transitionTo("adminPermalinks"); } catch (error) { popupAjaxError(error); @@ -106,10 +108,12 @@ export default class AdminFlagsForm extends Component { permalink_type_value: this.valueForPermalinkType(data), } ); - const index = this.adminPermalinks.model.findIndex( + const index = this.adminPermalinks.model.allLinks.findIndex( (permalink) => permalink.id === this.args.permalink.id ); - this.adminPermalinks.model[index] = Permalink.create(result.payload); + this.adminPermalinks.model.allLinks[index] = Permalink.create( + result.payload + ); this.router.transitionTo("adminPermalinks"); } catch (error) { popupAjaxError(error); diff --git a/app/assets/javascripts/admin/addon/controllers/admin-permalinks-index.js b/app/assets/javascripts/admin/addon/controllers/admin-permalinks-index.js index 6496aa840c1..35697f515c0 100644 --- a/app/assets/javascripts/admin/addon/controllers/admin-permalinks-index.js +++ b/app/assets/javascripts/admin/addon/controllers/admin-permalinks-index.js @@ -49,7 +49,7 @@ export default class AdminPermalinksIndexController extends Controller { didConfirm: async () => { try { await this.store.destroyRecord("permalink", permalink); - this.model.removeObject(permalink); + this.model.allLinks.removeObject(permalink); } catch { this.dialog.alert(i18n("generic_error")); } diff --git a/app/assets/javascripts/admin/addon/models/permalink.js b/app/assets/javascripts/admin/addon/models/permalink.js index af4ef5bdefd..72f2fe42a33 100644 --- a/app/assets/javascripts/admin/addon/models/permalink.js +++ b/app/assets/javascripts/admin/addon/models/permalink.js @@ -6,10 +6,16 @@ import discourseComputed from "discourse-common/utils/decorators"; export default class Permalink extends RestModel { static findAll(filter) { - return ajax("/admin/permalinks.json", { data: { filter } }).then(function ( - permalinks - ) { - return permalinks.map((p) => Permalink.create(p)); + return ajax("/admin/permalinks.json").then(function (permalinks) { + let allLinks = permalinks.map((p) => Permalink.create(p)); + + let filteredLinks = filter + ? allLinks.filter( + (p) => p.url.includes(filter) || p.external_url?.includes(filter) + ) + : allLinks; + + return { allLinks, filteredLinks }; }); } diff --git a/app/assets/javascripts/admin/addon/templates/permalinks-index.hbs b/app/assets/javascripts/admin/addon/templates/permalinks-index.hbs index e9987727728..16c27845167 100644 --- a/app/assets/javascripts/admin/addon/templates/permalinks-index.hbs +++ b/app/assets/javascripts/admin/addon/templates/permalinks-index.hbs @@ -1,25 +1,27 @@ -
- + {{/if}}