From bc9c0cc9476eea7bd310c9ccaa3152e7c28bcbc7 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 2 Oct 2024 11:32:38 +0100 Subject: [PATCH 1/4] feat: option to display tags in DiscussionsSearchSource --- extensions/tags/extend.php | 2 ++ .../tags/js/src/admin/components/TagsPage.js | 8 ++++++++ .../js/src/forum/addTagsToDiscussionSearch.tsx | 16 ++++++++++++++++ extensions/tags/js/src/forum/index.ts | 2 ++ extensions/tags/locale/en.yml | 3 +++ 5 files changed, 31 insertions(+) create mode 100644 extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx diff --git a/extensions/tags/extend.php b/extensions/tags/extend.php index 4ca124e5b4..4f42784a37 100644 --- a/extensions/tags/extend.php +++ b/extensions/tags/extend.php @@ -100,6 +100,8 @@ ->prepareDataForSerialization(LoadForumTagsRelationship::class), (new Extend\Settings()) + ->default('flarum-tags.show_tags_in_discussion_search_results', false) + ->serializeToForum('showTagsInDiscussionSearchResults', 'flarum-tags.show_tags_in_discussion_search_results', 'boolVal') ->serializeToForum('minPrimaryTags', 'flarum-tags.min_primary_tags') ->serializeToForum('maxPrimaryTags', 'flarum-tags.max_primary_tags') ->serializeToForum('minSecondaryTags', 'flarum-tags.min_secondary_tags') diff --git a/extensions/tags/js/src/admin/components/TagsPage.js b/extensions/tags/js/src/admin/components/TagsPage.js index 4564869bb9..24f4725a59 100644 --- a/extensions/tags/js/src/admin/components/TagsPage.js +++ b/extensions/tags/js/src/admin/components/TagsPage.js @@ -118,6 +118,14 @@ export default class TagsPage extends ExtensionPage { +
+ {this.buildSettingComponent({ + setting: 'flarum-tags.show_tags_in_discussion_search_results', + type: 'boolean', + label: app.translator.trans('flarum-tags.admin.tag_settings.show_tags_in_discussion_search_results.label'), + help: app.translator.trans('flarum-tags.admin.tag_settings.show_tags_in_discussion_search_results.help'), + })} +
{this.submitButton()}
diff --git a/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx b/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx new file mode 100644 index 0000000000..86de0f17a1 --- /dev/null +++ b/extensions/tags/js/src/forum/addTagsToDiscussionSearch.tsx @@ -0,0 +1,16 @@ +import app from 'flarum/forum/app'; +import { extend } from 'flarum/common/extend'; +import DiscussionsSearchItem from 'flarum/forum/components/DiscussionsSearchItem'; +import DiscussionsSearchSource from 'flarum/forum/components/DiscussionsSearchSource'; +import tagsLabel from '../common/helpers/tagsLabel'; + +export default function addTagsToDiscussionSearch() { + extend(DiscussionsSearchSource.prototype, 'includes', function (includes) { + app.forum.attribute('showTagsInDiscussionSearchResults') && includes.push('tags'); + }); + + extend(DiscussionsSearchItem.prototype, 'viewItems', function (items) { + app.forum.attribute('showTagsInDiscussionSearchResults') && + items.add('tags',
{tagsLabel(this.discussion.tags())}
, 100); + }); +} diff --git a/extensions/tags/js/src/forum/index.ts b/extensions/tags/js/src/forum/index.ts index 838f669481..f9ba52d5a3 100644 --- a/extensions/tags/js/src/forum/index.ts +++ b/extensions/tags/js/src/forum/index.ts @@ -18,10 +18,12 @@ app.initializers.add('flarum-tags', function () { addTagLabels(); addTagControl(); addTagComposer(); + addTagsToDiscussionSearch(); }); // Expose compat API import tagsCompat from './compat'; import { compat } from '@flarum/core/forum'; +import addTagsToDiscussionSearch from './addTagsToDiscussionSearch'; Object.assign(compat, tagsCompat); diff --git a/extensions/tags/locale/en.yml b/extensions/tags/locale/en.yml index 3890539d2d..47f5830a31 100644 --- a/extensions/tags/locale/en.yml +++ b/extensions/tags/locale/en.yml @@ -49,6 +49,9 @@ flarum-tags: required_primary_text: Enter the minimum and maximum number of primary tags that may be applied to a discussion. required_secondary_heading: Required Number of Secondary Tags required_secondary_text: Enter the minimum and maximum number of secondary tags that may be applied to a discussion. + show_tags_in_discussion_search_results: + label: Show Tags in Discussion Search Results + help: "When enabled, tags will be displayed in the search results for discussions." title: Tag Settings # These translations are used in the Tags page. From 916cefd03a96256c94c910fccbbb7e6fbb0c277d Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 2 Oct 2024 11:48:02 +0100 Subject: [PATCH 2/4] chore: move import statement --- extensions/tags/js/src/forum/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/tags/js/src/forum/index.ts b/extensions/tags/js/src/forum/index.ts index f9ba52d5a3..f74ba9d1f9 100644 --- a/extensions/tags/js/src/forum/index.ts +++ b/extensions/tags/js/src/forum/index.ts @@ -7,6 +7,7 @@ import addTagFilter from './addTagFilter'; import addTagLabels from './addTagLabels'; import addTagControl from './addTagControl'; import addTagComposer from './addTagComposer'; +import addTagsToDiscussionSearch from './addTagsToDiscussionSearch'; export { default as extend } from './extend'; @@ -24,6 +25,5 @@ app.initializers.add('flarum-tags', function () { // Expose compat API import tagsCompat from './compat'; import { compat } from '@flarum/core/forum'; -import addTagsToDiscussionSearch from './addTagsToDiscussionSearch'; Object.assign(compat, tagsCompat); From 9155852028b63a834953d80c5e6e412dd4992c71 Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 2 Oct 2024 13:21:34 +0100 Subject: [PATCH 3/4] fix?: typings --- framework/core/js/dist-typings/forum/components/Search.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/core/js/dist-typings/forum/components/Search.d.ts b/framework/core/js/dist-typings/forum/components/Search.d.ts index 2d2a34efb4..38b4313f60 100644 --- a/framework/core/js/dist-typings/forum/components/Search.d.ts +++ b/framework/core/js/dist-typings/forum/components/Search.d.ts @@ -55,6 +55,12 @@ export default class Search extends Compone * * @deprecated Replace with`this.searchState` instead. */ + /** + * The instance of `SearchState` for this component. + * + * @deprecated Replace with`this.searchState` instead. + */ + // @ts-expect-error This is a get accessor, while superclass defines this as a property. This is needed to prevent breaking changes, however. get state(): SearchState; set state(state: SearchState); /** From dfe119c8237c0cbcf160e7fd8df4c837ad995a6b Mon Sep 17 00:00:00 2001 From: IanM Date: Wed, 2 Oct 2024 13:31:37 +0100 Subject: [PATCH 4/4] fix? --- .../tags/js/dist-typings/forum/addTagsToDiscussionSearch.d.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 extensions/tags/js/dist-typings/forum/addTagsToDiscussionSearch.d.ts diff --git a/extensions/tags/js/dist-typings/forum/addTagsToDiscussionSearch.d.ts b/extensions/tags/js/dist-typings/forum/addTagsToDiscussionSearch.d.ts new file mode 100644 index 0000000000..524c049286 --- /dev/null +++ b/extensions/tags/js/dist-typings/forum/addTagsToDiscussionSearch.d.ts @@ -0,0 +1 @@ +export default function addTagsToDiscussionSearch(): void;