無効化された未分類がカテゴリードロップダウンに表示される

ローカルデバッグを少し行ったところ、デフォルトの Discourse インストールで 100% 再現可能であることを確認しました。

以下にまとめます。

「未分類」に関する設定は 2 つあります。

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