mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add addLogSearchLinkClickedCallbacks
to plugin API (#28254)
- Added `addLogSearchLinkClickedCallbacks` which allows plugins/TCs to register a callback when a search link is clicked and before a search log is created
This commit is contained in:
parent
66de6a43a8
commit
8aff94dadb
@ -3,7 +3,7 @@
|
|||||||
// docs/CHANGELOG-JAVASCRIPT-PLUGIN-API.md whenever you change the version
|
// docs/CHANGELOG-JAVASCRIPT-PLUGIN-API.md whenever you change the version
|
||||||
// using the format described at https://keepachangelog.com/en/1.0.0/.
|
// using the format described at https://keepachangelog.com/en/1.0.0/.
|
||||||
|
|
||||||
export const PLUGIN_API_VERSION = "1.35.0";
|
export const PLUGIN_API_VERSION = "1.36.0";
|
||||||
|
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import { h } from "virtual-dom";
|
import { h } from "virtual-dom";
|
||||||
@ -83,7 +83,10 @@ import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer
|
|||||||
import { replaceTagRenderer } from "discourse/lib/render-tag";
|
import { replaceTagRenderer } from "discourse/lib/render-tag";
|
||||||
import { addTagsHtmlCallback } from "discourse/lib/render-tags";
|
import { addTagsHtmlCallback } from "discourse/lib/render-tags";
|
||||||
import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
|
import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
|
||||||
import { addSearchResultsCallback } from "discourse/lib/search";
|
import {
|
||||||
|
addLogSearchLinkClickedCallbacks,
|
||||||
|
addSearchResultsCallback,
|
||||||
|
} from "discourse/lib/search";
|
||||||
import Sharing from "discourse/lib/sharing";
|
import Sharing from "discourse/lib/sharing";
|
||||||
import { addAdminSidebarSectionLink } from "discourse/lib/sidebar/admin-sidebar";
|
import { addAdminSidebarSectionLink } from "discourse/lib/sidebar/admin-sidebar";
|
||||||
import { addSectionLink as addCustomCommunitySectionLink } from "discourse/lib/sidebar/custom-community-section-links";
|
import { addSectionLink as addCustomCommunitySectionLink } from "discourse/lib/sidebar/custom-community-section-links";
|
||||||
@ -2313,6 +2316,22 @@ class PluginApi {
|
|||||||
addSearchResultsCallback(callback);
|
addSearchResultsCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a callback to search before logging the search record. Return false to prevent logging.
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* api.addLogSearchLinkClickedCallbacks((params) => {
|
||||||
|
* if (params.searchResultId === "foo") {
|
||||||
|
* return false;
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
addLogSearchLinkClickedCallbacks(callback) {
|
||||||
|
addLogSearchLinkClickedCallbacks(callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a suggestion shortcut to search menu panel.
|
* Add a suggestion shortcut to search menu panel.
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,15 @@ import I18n from "discourse-i18n";
|
|||||||
const translateResultsCallbacks = [];
|
const translateResultsCallbacks = [];
|
||||||
const MAX_RECENT_SEARCHES = 5; // should match backend constant with the same name
|
const MAX_RECENT_SEARCHES = 5; // should match backend constant with the same name
|
||||||
|
|
||||||
|
const logSearchLinkClickedCallbacks = [];
|
||||||
|
|
||||||
|
export function addLogSearchLinkClickedCallbacks(fn) {
|
||||||
|
logSearchLinkClickedCallbacks.push(fn);
|
||||||
|
}
|
||||||
|
export function resetLogSearchLinkClickedCallbacks() {
|
||||||
|
logSearchLinkClickedCallbacks.clear();
|
||||||
|
}
|
||||||
|
|
||||||
export function addSearchResultsCallback(callback) {
|
export function addSearchResultsCallback(callback) {
|
||||||
translateResultsCallbacks.push(callback);
|
translateResultsCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
@ -259,6 +268,14 @@ export function updateRecentSearches(currentUser, term) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function logSearchLinkClick(params) {
|
export function logSearchLinkClick(params) {
|
||||||
|
if (
|
||||||
|
logSearchLinkClickedCallbacks.length &&
|
||||||
|
!logSearchLinkClickedCallbacks.some((fn) => fn(params))
|
||||||
|
) {
|
||||||
|
// Return early if any callbacks return false
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ajax("/search/click", {
|
ajax("/search/click", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
|
@ -53,6 +53,7 @@ import PreloadStore from "discourse/lib/preload-store";
|
|||||||
import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
|
import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
|
||||||
import { clearTopicFooterDropdowns } from "discourse/lib/register-topic-footer-dropdown";
|
import { clearTopicFooterDropdowns } from "discourse/lib/register-topic-footer-dropdown";
|
||||||
import { clearTagsHtmlCallbacks } from "discourse/lib/render-tags";
|
import { clearTagsHtmlCallbacks } from "discourse/lib/render-tags";
|
||||||
|
import { resetLogSearchLinkClickedCallbacks } from "discourse/lib/search";
|
||||||
import { clearAdditionalAdminSidebarSectionLinks } from "discourse/lib/sidebar/admin-sidebar";
|
import { clearAdditionalAdminSidebarSectionLinks } from "discourse/lib/sidebar/admin-sidebar";
|
||||||
import { resetDefaultSectionLinks as resetTopicsSectionLinks } from "discourse/lib/sidebar/custom-community-section-links";
|
import { resetDefaultSectionLinks as resetTopicsSectionLinks } from "discourse/lib/sidebar/custom-community-section-links";
|
||||||
import { resetSidebarPanels } from "discourse/lib/sidebar/custom-sections";
|
import { resetSidebarPanels } from "discourse/lib/sidebar/custom-sections";
|
||||||
@ -236,6 +237,7 @@ export function testCleanup(container, app) {
|
|||||||
clearExtraHeaderIcons();
|
clearExtraHeaderIcons();
|
||||||
clearExtraHeaderButtons();
|
clearExtraHeaderButtons();
|
||||||
resetOnKeyUpCallbacks();
|
resetOnKeyUpCallbacks();
|
||||||
|
resetLogSearchLinkClickedCallbacks();
|
||||||
resetItemSelectCallbacks();
|
resetItemSelectCallbacks();
|
||||||
resetUserMenuTabs();
|
resetUserMenuTabs();
|
||||||
resetLinkLookup();
|
resetLinkLookup();
|
||||||
|
@ -7,6 +7,10 @@ in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [1.36.0] - 2024-08-06
|
||||||
|
|
||||||
|
- Added `addLogSearchLinkClickedCallbacks` which allows plugins/TCs to register a callback when a search link is clicked and before a search log is created
|
||||||
|
|
||||||
## [1.35.0] - 2024-07-30
|
## [1.35.0] - 2024-07-30
|
||||||
|
|
||||||
- Added `registerBehaviorTransformer` which allows registering a transformer callback to override behavior defined in Discourse modules
|
- Added `registerBehaviorTransformer` which allows registering a transformer callback to override behavior defined in Discourse modules
|
||||||
|
Loading…
Reference in New Issue
Block a user