已禁用的未分类显示在类别下拉列表中

好的,我明白了,我进行了一些本地调试,我确认在默认的 Discourse 安装中,这个问题 100% 可以复现。

我在此总结一下:

关于“未分类”有两个设置:

allow_uncategorized_topics 默认 关闭
suppress_uncategorized_badge 默认 开启

allow_uncategorized_topics 被禁用时(默认设置),我们会将其存在泄露到某些地方。

如果你尝试通过启用“未分类”来删除它,你会看到:

在 Discourse 中,这个分类非常奇怪,因为它:

  1. 必须 存在
  2. 不能 被删除
  3. 我们将其注入到 很多 逻辑的 很多 地方:

我们可以通过添加越来越多的条件语句来修复这种泄露,现在客户端和服务器端大概有 10 个左右。

或者我们可以 从根本上解决这个问题,只允许管理员 删除该分类,然后它就会消失,我们再也不需要检查它了。

我的建议是:

  1. 删除这两个设置,并删除隐藏设置 uncategorized_category_id
  2. 拥有一个默认分类的概念(我们已经有了)- 我们已经有了 default_composer_category
  3. “未分类”就不再是一个特殊概念,需要考虑的东西更少。
  4. 为那些必须有一个“没有徽章的分类”的人提供一个主题组件。

当前的搜索错误可以通过类似以下方式修复:

diff --git a/app/assets/javascripts/select-kit/addon/components/search-advanced-category-chooser.js b/app/assets/javascripts/select-kit/addon/components/search-advanced-category-chooser.js
index a678919d16..83a9ed27db 100644
--- a/app/assets/javascripts/select-kit/addon/components/search-advanced-category-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/search-advanced-category-chooser.js
@@ -1,4 +1,5 @@
 import { classNames } from "@ember-decorators/component";
+import { setting } from "discourse/lib/computed";
 import CategoryChooserComponent from "select-kit/components/category-chooser";
 import {
   pluginApiIdentifiers,
@@ -7,11 +8,13 @@ import {
 
 @classNames("search-advanced-category-chooser")
 @selectKitOptions({
-  allowUncategorized: true,
+  allowUncategorized: "allowUncategorized",
   clearable: true,
   none: "category.all",
   displayCategoryDescription: false,
   permissionType: null,
 })
 @pluginApiIdentifiers("search-advanced-category-chooser")
-export default class SearchAdvancedCategoryChooser extends CategoryChooserComponent {}
+export default class SearchAdvancedCategoryChooser extends CategoryChooserComponent {
+  @setting("allow_uncategorized_topics") allowUncategorized;
+}
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import SearchAdvancedCategoryChooser from "select-kit/components/search-advanced-category-chooser";

module(
  "Integration | Component | select-kit/search-advanced-category-chooser",
  function (hooks) {
    setupRenderingTest(hooks);

    hooks.beforeEach(function () {
      this.set("subject", selectKit());
    });

    test("respects allow_uncategorized_topics setting when false", async function (assert) {
      this.siteSettings.allow_uncategorized_topics = false;

      await render(
        <template><SearchAdvancedCategoryChooser /></template>
      );

      await this.subject.expand();

      // Uncategorized category (ID 17 in test data) should not be present when setting is false
      assert.false(
        this.subject.rowByValue(17).exists(),
        "uncategorized category is not available when allow_uncategorized_topics is false"
      );
    });

    test("shows uncategorized category when allow_uncategorized_topics is true", async function (assert) {
      this.siteSettings.allow_uncategorized_topics = true;

      await render(
        <template><SearchAdvancedCategoryChooser /></template>
      );

      await this.subject.expand();

      // Uncategorized category (ID 17 in test data) should be present when setting is true
      assert.true(
        this.subject.rowByValue(17).exists(),
        "uncategorized category is available when allow_uncategorized_topics is true"
      );
    });

    test("has correct default options", async function (assert) {
      await render(
        <template><SearchAdvancedCategoryChooser /></template>
      );

      assert.strictEqual(
        this.subject.header().label(),
        "All categories",
        "has correct default none label"
      );
    });
  }
);

但这只是高级搜索的错误,我们一直在玩打地鼠游戏……

3 个赞