From 9fdc5770b0e335a45dced819da0a3a1c41c3bf1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= Date: Wed, 19 Feb 2025 15:12:49 +0100 Subject: [PATCH] startups: allow filtering out investigations Closes #21046. --- _includes/startups-filters.html | 7 +++ _layouts/startups.html | 5 ++ assets/additional/js/search-startup.js | 73 ++++++++++++++------------ 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/_includes/startups-filters.html b/_includes/startups-filters.html index fe718d0b039b..ea3da57d96b5 100644 --- a/_includes/startups-filters.html +++ b/_includes/startups-filters.html @@ -37,4 +37,11 @@

Ces services sont déployés à l'ensemble du territoire national et ont atteint un seuil d'impact significatif.

+
+
+ + +

Les investigations sont des services numériques en devenir. À ce stade, l'équipe est souvent réduite.

+
+
diff --git a/_layouts/startups.html b/_layouts/startups.html index bdeb64749da3..da4dc5f9339d 100644 --- a/_layouts/startups.html +++ b/_layouts/startups.html @@ -192,4 +192,9 @@

{{ counter }} { document.querySelectorAll(".select-impact").forEach((selectElement) => { createNationalImpactSelect(selectElement, data, nationalImpactValue); }); + + filters.excludeInvestigations = urlParams.get("exclude-investigations") == "true"; + + setupExcludeInvestigations(); + diff --git a/assets/additional/js/search-startup.js b/assets/additional/js/search-startup.js index 1a972e4e8968..acdf6ca89d6e 100644 --- a/assets/additional/js/search-startup.js +++ b/assets/additional/js/search-startup.js @@ -116,9 +116,15 @@ const filterCards = (startups) => { ) .filter((startup) => filters.is_national_impact ? startupHasNationalImpact(startup) : true, + ) + .filter((startup) => + filters.excludeInvestigations ? startupIsNotInvestigation(startup) : true, ); }; +const startupIsNotInvestigation = (startup) => + startup.phase !== "investigation"; + const startupHasNationalImpact = (startup) => startup.events.find((event) => event.name === "national_impact"); @@ -238,16 +244,10 @@ const createIncubatorSelect = (selectElement, data, incubators, initValue) => { selectElement.value = initValue; onIncubatorChange(initValue); } - selectElement.addEventListener("change", (e) => { - const value = e.target.value; + selectElement.addEventListener("change", ({ target: { value } }) => { onIncubatorChange(value); - const urlParams = new URLSearchParams(window.location.search); - urlParams.set("incubateur", value); - history.replaceState( - null, - null, - `${window.location.origin + window.location.pathname}?${urlParams}`, - ); + + setLocationParam("incubateur", value); }); }; @@ -274,13 +274,8 @@ const createUsertypesSelect = (selectElement, data, initValue) => { selectElement.addEventListener("change", (e) => { const value = e.target.value; onUsertypesChange(value); - const urlParams = new URLSearchParams(window.location.search); - urlParams.set("usertypes", value); - history.replaceState( - null, - null, - `${window.location.origin + window.location.pathname}?${urlParams}`, - ); + + setLocationParam("usertypes", value); }); }; @@ -303,16 +298,10 @@ const createThematiquesSelect = (selectElement, data, initValue) => { selectElement.value = initValue; onThematiquesChange(initValue); } - selectElement.addEventListener("change", (e) => { - const value = e.target.value; + selectElement.addEventListener("change", ({ target: { value } }) => { onThematiquesChange(value); - const urlParams = new URLSearchParams(window.location.search); - urlParams.set("thematiques", value); - history.replaceState( - null, - null, - `${window.location.origin + window.location.pathname}?${urlParams}`, - ); + + setLocationParam("thematiques", value); }); }; @@ -327,15 +316,31 @@ const createNationalImpactSelect = (selectElement, data, initValue) => { }, 1000); onNationalImpactChange(true); } - selectElement.addEventListener("change", (e) => { - const value = selectElement.checked; + selectElement.addEventListener("change", ({ target: { value } }) => { onNationalImpactChange(value); - const urlParams = new URLSearchParams(window.location.search); - urlParams.set("national_impact", value); - history.replaceState( - null, - null, - `${window.location.origin + window.location.pathname}?${urlParams}`, - ); + + setLocationParam("national_impact", value); }); }; + +function setLocationParam(param, value) { + const url = new URL(window.location); + + url.searchParams.set(param, value); + + history.replaceState(null, null, url); +} + +function setupExcludeInvestigations() { + const toggle = document.getElementById("exclude-investigations-toggle"); + + toggle.checked = filters.excludeInvestigations; + + toggle.addEventListener("change", ({ target: { checked: value } }) => { + filters.excludeInvestigations = value; + + setLocationParam("exclude-investigations", value); + + updateCards(data); + }); +}