mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	integrations: Fix jQuery .data mishandling translated category names.
Apparently `.data("category")` would be come back as a single-element
array for some French translations, rather than a string.
We fix this by using `.attr("data-category")` across this file, which
is our preferred coding pattern anyway.
			
			
This commit is contained in:
		@@ -15,7 +15,7 @@ const CATEGORIES = new Map();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function load_data() {
 | 
					function load_data() {
 | 
				
			||||||
    for (const integration of $(".integration-lozenge")) {
 | 
					    for (const integration of $(".integration-lozenge")) {
 | 
				
			||||||
        const name = $(integration).data("name");
 | 
					        const name = $(integration).attr("data-name");
 | 
				
			||||||
        const display_name = $(integration).find(".integration-name").text().trim();
 | 
					        const display_name = $(integration).find(".integration-name").text().trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (display_name && name) {
 | 
					        if (display_name && name) {
 | 
				
			||||||
@@ -24,7 +24,7 @@ function load_data() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const category of $(".integration-category")) {
 | 
					    for (const category of $(".integration-category")) {
 | 
				
			||||||
        const name = $(category).data("category");
 | 
					        const name = $(category).attr("data-category");
 | 
				
			||||||
        const display_name = $(category).text().trim();
 | 
					        const display_name = $(category).text().trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (display_name && name) {
 | 
					        if (display_name && name) {
 | 
				
			||||||
@@ -115,10 +115,10 @@ const update_integrations = _.debounce(() => {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$integration.hasClass("integration-create-your-own")) {
 | 
					        if (!$integration.hasClass("integration-create-your-own")) {
 | 
				
			||||||
            const display_name = INTEGRATIONS.get($integration.data("name"));
 | 
					            const display_name = INTEGRATIONS.get($integration.attr("data-name"));
 | 
				
			||||||
            const display =
 | 
					            const display =
 | 
				
			||||||
                common.phrase_match(state.query, display_name) &&
 | 
					                common.phrase_match(state.query, display_name) &&
 | 
				
			||||||
                ($integration.data("categories").includes(CATEGORIES.get(state.category)) ||
 | 
					                ($integration.attr("data-categories").includes(CATEGORIES.get(state.category)) ||
 | 
				
			||||||
                    state.category === "all");
 | 
					                    state.category === "all");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (display) {
 | 
					            if (display) {
 | 
				
			||||||
@@ -141,7 +141,7 @@ function hide_catalog_show_integration() {
 | 
				
			|||||||
    $lozenge_icon.removeClass("legacy");
 | 
					    $lozenge_icon.removeClass("legacy");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const categories = $(`.integration-${CSS.escape(state.integration)}`)
 | 
					    const categories = $(`.integration-${CSS.escape(state.integration)}`)
 | 
				
			||||||
        .data("categories")
 | 
					        .attr("data-categories")
 | 
				
			||||||
        .slice(1, -1)
 | 
					        .slice(1, -1)
 | 
				
			||||||
        .split(",")
 | 
					        .split(",")
 | 
				
			||||||
        .map((category) => category.trim().slice(1, -1));
 | 
					        .map((category) => category.trim().slice(1, -1));
 | 
				
			||||||
@@ -324,13 +324,13 @@ function integration_events() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    $(".integration-instruction-block").on("click", "a .integration-category", (e) => {
 | 
					    $(".integration-instruction-block").on("click", "a .integration-category", (e) => {
 | 
				
			||||||
        e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
        const category = $(e.target).data("category");
 | 
					        const category = $(e.target).attr("data-category");
 | 
				
			||||||
        dispatch("SHOW_CATEGORY", {category});
 | 
					        dispatch("SHOW_CATEGORY", {category});
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $(".integrations a .integration-category").on("click", (e) => {
 | 
					    $(".integrations a .integration-category").on("click", (e) => {
 | 
				
			||||||
        e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
        const category = $(e.target).data("category");
 | 
					        const category = $(e.target).attr("data-category");
 | 
				
			||||||
        dispatch("CHANGE_CATEGORY", {category});
 | 
					        dispatch("CHANGE_CATEGORY", {category});
 | 
				
			||||||
        toggle_categories_dropdown();
 | 
					        toggle_categories_dropdown();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -338,7 +338,7 @@ function integration_events() {
 | 
				
			|||||||
    $(".integrations a .integration-lozenge").on("click", (e) => {
 | 
					    $(".integrations a .integration-lozenge").on("click", (e) => {
 | 
				
			||||||
        if (!$(e.target).closest(".integration-lozenge").hasClass("integration-create-your-own")) {
 | 
					        if (!$(e.target).closest(".integration-lozenge").hasClass("integration-create-your-own")) {
 | 
				
			||||||
            e.preventDefault();
 | 
					            e.preventDefault();
 | 
				
			||||||
            const integration = $(e.target).closest(".integration-lozenge").data("name");
 | 
					            const integration = $(e.target).closest(".integration-lozenge").attr("data-name");
 | 
				
			||||||
            dispatch("SHOW_INTEGRATION", {integration});
 | 
					            dispatch("SHOW_INTEGRATION", {integration});
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user