A platform for community discussion. Free, open, simple.
DEV: Show active categories in form templates customize table (#20498)
Keegan Georgebb0ef4c7b45f
diff --git a/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs b/app/assets/javascripts/admin/addon/components/form-template/row-item.hbsindex 09a8738f2fe..a4cd830244c 100644--- a/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs+++ b/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs@@ -1,5 +1,10 @@<tr class="admin-list-item"><td class="col first">{{@template.name}}</td>+ <td class="col categories">+ {{#each this.activeCategories as |category|}}+ {{category-link category}}+ {{/each}}+ </td><td class="col action"><DButton@title="admin.form_templates.list_table.actions.view"diff --git a/app/assets/javascripts/admin/addon/components/form-template/row-item.js b/app/assets/javascripts/admin/addon/components/form-template/row-item.jsindex 823c17847cb..c4de1a616c2 100644--- a/app/assets/javascripts/admin/addon/components/form-template/row-item.js+++ b/app/assets/javascripts/admin/addon/components/form-template/row-item.js@@ -9,6 +9,13 @@ import I18n from "I18n";export default class FormTemplateRowItem extends Component {@service router;@service dialog;+ @service site;++ get activeCategories() {+ return this.site?.categories?.filter((c) =>+ c["form_template_ids"].includes(this.args.template.id)+ );+ }@actionviewTemplate() {diff --git a/app/assets/javascripts/admin/addon/templates/customize-form-templates-index.hbs b/app/assets/javascripts/admin/addon/templates/customize-form-templates-index.hbsindex b9a61cc44b4..2a41eedce4f 100644--- a/app/assets/javascripts/admin/addon/templates/customize-form-templates-index.hbs+++ b/app/assets/javascripts/admin/addon/templates/customize-form-templates-index.hbs@@ -7,6 +7,9 @@<th class="col heading">{{i18n "admin.form_templates.list_table.headings.name"}}</th>+ <th class="col heading">+ {{i18n "admin.form_templates.list_table.headings.active_categories"}}+ </th><th class="col heading sr-only">{{i18n "admin.form_templates.list_table.headings.actions"}}</th>diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 7ee5d8212ef..1ddf02dd2d2 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5538,6 +5538,7 @@ en:list_table:headings:name: "Name"+ active_categories: "Active Categories"actions: "Actions"actions:view: "View Template"diff --git a/spec/system/admin_customize_form_templates_spec.rb b/spec/system/admin_customize_form_templates_spec.rbindex 9ecd2035ee0..c5751453ef4 100644--- a/spec/system/admin_customize_form_templates_spec.rb+++ b/spec/system/admin_customize_form_templates_spec.rb@@ -5,6 +5,9 @@ describe "Admin Customize Form Templates", type: :system, js: true dolet(:ace_editor) { PageObjects::Components::AceEditor.new }fab!(:admin) { Fabricate(:admin) }fab!(:form_template) { Fabricate(:form_template) }+ fab!(:category) do+ Fabricate(:category, name: "Cool Category", slug: "cool-cat", topic_count: 3234)+ endbefore doSiteSetting.experimental_form_templates = true@@ -12,12 +15,20 @@ describe "Admin Customize Form Templates", type: :system, js: true doenddescribe "when visiting the page to customize form templates" do+ before { category.update(form_template_ids: [form_template.id]) }+it "should show the existing form templates in a table" dovisit("/admin/customize/form-templates")expect(form_template_page).to have_form_template_tableexpect(form_template_page).to have_form_template(form_template.name)end+ it "should show the categories the form template is used in" do+ visit("/admin/customize/form-templates")+ expect(form_template_page).to have_form_template_table+ expect(form_template_page).to have_category_in_template_row(category.name)+ end+it "should show the form template structure in a modal" dovisit("/admin/customize/form-templates")form_template_page.click_view_form_templatediff --git a/spec/system/page_objects/pages/form_template.rb b/spec/system/page_objects/pages/form_template.rbindex 508a396f6b2..2be3e60d7c9 100644--- a/spec/system/page_objects/pages/form_template.rb+++ b/spec/system/page_objects/pages/form_template.rb@@ -21,6 +21,10 @@ module PageObjectsfind(".form-templates__table tbody tr td", text: name).present?end+ def has_category_in_template_row?(category_name)+ find(".form-templates__table .categories .category-name", text: category_name).present?+ end+def has_template_structure?(structure)find("code", text: structure).present?end