integrations: Properly pass data-categories as a JSON array.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-11-21 13:08:53 -08:00 committed by Tim Abbott
parent 77cac403ee
commit 801e267e00
3 changed files with 10 additions and 7 deletions

View File

@ -107,7 +107,7 @@
class="integration-lozenge integration-{{ integration.name }} legacy"{% else %}
class="integration-lozenge integration-{{ integration.name }}"
{% endif %}
data-categories="{{ integration.categories }}"
data-categories='{{ integration.get_translated_categories()|tojson }}'
data-name="{{ integration.name }}">
<img class="integration-logo" src="{{ integration.logo_url }}"
alt="{{ integration.display_name }} logo"/>

View File

@ -118,7 +118,9 @@ const update_integrations = _.debounce(() => {
const display_name = INTEGRATIONS.get($integration.attr("data-name"));
const display =
common.phrase_match(state.query, display_name) &&
($integration.attr("data-categories").includes(CATEGORIES.get(state.category)) ||
(JSON.parse($integration.attr("data-categories")).includes(
CATEGORIES.get(state.category),
) ||
state.category === "all");
if (display) {
@ -140,11 +142,9 @@ function hide_catalog_show_integration() {
).clone(false);
$lozenge_icon.removeClass("legacy");
const categories = $(`.integration-${CSS.escape(state.integration)}`)
.attr("data-categories")
.slice(1, -1)
.split(",")
.map((category) => category.trim().slice(1, -1));
const categories = JSON.parse(
$(`.integration-${CSS.escape(state.integration)}`).attr("data-categories"),
);
function show_integration(doc) {
$("#integration-instructions-group .name").text(INTEGRATIONS.get(state.integration));

View File

@ -139,6 +139,9 @@ class Integration:
return None
def get_translated_categories(self) -> list[str]:
return [str(category) for category in self.categories]
class BotIntegration(Integration):
DEFAULT_LOGO_STATIC_PATH_PNG = "generated/bots/{name}/logo.png"