Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: toggle removing best answers from all discussion search #104

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: true
enable_typescript: false

frontend_directory: ./js
backend_directory: .
Expand Down
1 change: 1 addition & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
->default('fof-best-answer.store_log_output', false)
->default('fof-best-answer.enabled-tags', '[]')
->default('fof-best-answer.search.solution_search', true)
->default('fof-best-answer.search.remove_solutions_from_main_search', false)
->default('fof-best-answer.search.display_tags', true)
->default('fof-best-answer.discussion_sidebar_jump_button', false)
->serializeToForum('fof-best-answer.show_max_lines', 'fof-best-answer.show_max_lines', 'intVal'),
Expand Down
8 changes: 7 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"analyze": "cross-env ANALYZER=true npm run build",
"format": "prettier --write src",
"format-check": "prettier --check src"
"format-check": "prettier --check src",
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
"build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings",
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'",
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
"check-typings-coverage": "typescript-coverage-report"
}
}
6 changes: 6 additions & 0 deletions js/src/@types/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ declare module 'flarum/common/models/Discussion' {
bestAnswerSetAt(): Date;
}
}

declare module 'flarum/tags/models/Tag' {
export default interface Tag {
isQnA(): boolean;
}
}
6 changes: 6 additions & 0 deletions js/src/admin/components/BestAnswerSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export default class BestAnswerSettingsPage extends ExtensionPage {
label: app.translator.trans('fof-best-answer.admin.settings.solution_search'),
help: app.translator.trans('fof-best-answer.admin.settings.solution_search_help'),
})}
{this.buildSettingComponent({
type: 'boolean',
setting: 'fof-best-answer.search.remove_solutions_from_main_search',
label: app.translator.trans('fof-best-answer.admin.settings.remove_solutions_from_main_search'),
help: app.translator.trans('fof-best-answer.admin.settings.remove_solutions_from_main_search_help'),
})}
{this.buildSettingComponent({
type: 'boolean',
setting: 'fof-best-answer.search.display_tags',
Expand Down
1 change: 0 additions & 1 deletion js/src/forum/components/SelectBestAnswerItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default class SelectBestAnswerItem extends Component<ISelectBestAnswerIte
user: this.discussion.bestAnswerUser?.(),
time_set: this.getSetTime(this.discussion),
a: <a onclick={() => m.route.set(app.route.user(this.discussion.bestAnswerUser?.()))} />,
//a: <Link href={app.route.user(this.discussion.bestAnswerUser?.())} />,
})}
</span>
);
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Extend from 'flarum/common/extenders';
import Post from 'flarum/common/models/Post';
import User from 'flarum/common/models/User';
import Model from 'flarum/common/Model';
import Tag from 'flarum/tags/models/Tag';

export default [
...commonExtend,
Expand All @@ -17,4 +18,7 @@ export default [

new Extend.Model(User) //
.attribute<number>('bestAnswerCount'),

new Extend.Model(Tag) //
.attribute<boolean>('isQnA'),
];
2 changes: 1 addition & 1 deletion js/src/forum/extenders/extendDiscussionSearchSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DiscussionsSearchSource from 'flarum/forum/components/DiscussionsSearchSo
export default function extendDiscussionsSearchSource() {
extend(DiscussionsSearchSource.prototype, 'queryMutators', function (mutators: string[]) {
// This will only apply when using flarum/core 1.8.6 or newer
if (app.forum.attribute<boolean>('solutionSearchEnabled')) {
if (app.forum.attribute<boolean>('removeSolutionResultsFromMainSearch')) {
mutators.push('-is:solved');
}
});
Expand Down
2 changes: 0 additions & 2 deletions js/src/forum/extenders/extendIndexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Button from 'flarum/common/components/Button';

export default function extendIndexPage() {
extend(IndexPage.prototype, 'sidebarItems', function (items) {
/** @ts-ignore */
const tag = this.currentTag();

if (!tag?.isQnA?.()) return;
Expand All @@ -27,7 +26,6 @@ export default function extendIndexPage() {
return;
}

/** @ts-ignore */
const tag = this.currentTag();

if (!tag?.isQnA?.()) {
Expand Down
6 changes: 4 additions & 2 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*", "../vendor/flarum/tags/js/dist-typings/@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
"@flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
"flarum/tags": ["../vendor/flarum/tags/js/dist-typings/*"]
}
}
}
2 changes: 2 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ fof-best-answer:
When a tag is Best Answer enabled, assign permissions to each user group that may set answers (own discussion, any discussion). Permissions may be assigned globally (for any Best Answer anabled tag), or on a per tag basis.
solution_search: Solution search
solution_search_help: Enable the ability to search for discussions with Best Answers
remove_solutions_from_main_search: Remove solutions from main search
remove_solutions_from_main_search_help: Remove discussions with Best Answers from the main 'all discussions' search results
display_tags: Display tags in search results
display_tags_help: Display the tag(s) in search results for discussions with Best Answers
discussion_sidebar_jump_button: Display jump to Best Answer button in discussion sidebar
Expand Down
1 change: 1 addition & 0 deletions src/ForumAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __invoke(ForumSerializer $serializer, $model, array $attributes)
{
if ($value = $this->getBooleanSetting('fof-best-answer.search.solution_search')) {
$attributes['showTagsInSearchResults'] = $this->getBooleanSetting('fof-best-answer.search.display_tags');
$attributes['removeSolutionResultsFromMainSearch'] = $this->getBooleanSetting('fof-best-answer.search.remove_solutions_from_main_search');
}

$attributes['solutionSearchEnabled'] = $value;
Expand Down
Loading