Skip to content

Commit

Permalink
feat(api+admin): added a DISABLE_CANDIDACIES_PAGE_COUNTERS feature
Browse files Browse the repository at this point in the history
  • Loading branch information
agarbe committed Sep 3, 2024
1 parent 1cdd9c4 commit f85761a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAuth } from "@/components/auth/auth";
import { useFeatureflipping } from "@/components/feature-flipping/featureFlipping";
import {
CandidacyCountByStatus,
CandidacyStatusFilter,
Expand All @@ -16,6 +17,7 @@ const CandidacyLayoutSideMenu = ({
const candidacyStatus = searchParams.get("status");
const searchFilter = searchParams.get("search") || "";
const { isAdmin } = useAuth();
const { isFeatureActive } = useFeatureflipping();

const hrefSideMenu = (status: CandidacyStatusFilter) => {
const params = new URLSearchParams();
Expand All @@ -32,96 +34,101 @@ const CandidacyLayoutSideMenu = ({
const isActive = (status: CandidacyStatusFilter) =>
candidacyStatus === status;

const showCounters = !isFeatureActive("DISABLE_CANDIDACIES_PAGE_COUNTERS");

const getCounterText = (status: CandidacyStatusFilter) =>
showCounters ? `(${candidaciesByStatusCount?.[status] ?? 0})` : "";

const sideMenuItems = [
{
linkProps: {
href: hrefSideMenu("ACTIVE_HORS_ABANDON"),
},
expandedByDefault: true,
isActive: isActive("ACTIVE_HORS_ABANDON"),
text: `Toutes les candidatures actives (${candidaciesByStatusCount?.ACTIVE_HORS_ABANDON ?? 0})`,
text: `Toutes les candidatures actives ${getCounterText("ACTIVE_HORS_ABANDON")}`,
items: [
{
linkProps: {
href: hrefSideMenu("VALIDATION_HORS_ABANDON"),
},
text: `Nouvelles candidatures (${candidaciesByStatusCount?.VALIDATION_HORS_ABANDON ?? 0})`,
text: `Nouvelles candidatures ${getCounterText("VALIDATION_HORS_ABANDON")}`,
isActive: isActive("VALIDATION_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("PRISE_EN_CHARGE_HORS_ABANDON"),
},
text: `Candidatures prises en charge (${candidaciesByStatusCount?.PRISE_EN_CHARGE_HORS_ABANDON ?? 0})`,
text: `Candidatures prises en charge ${getCounterText("PRISE_EN_CHARGE_HORS_ABANDON")}`,
isActive: isActive("PRISE_EN_CHARGE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("PARCOURS_ENVOYE_HORS_ABANDON"),
},
text: `Parcours envoyés (${candidaciesByStatusCount?.PARCOURS_ENVOYE_HORS_ABANDON ?? 0})`,
text: `Parcours envoyés ${getCounterText("PARCOURS_ENVOYE_HORS_ABANDON")}`,
isActive: isActive("PARCOURS_ENVOYE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("PARCOURS_CONFIRME_HORS_ABANDON"),
},
text: `Parcours confirmés par le candidat (${candidaciesByStatusCount?.PARCOURS_CONFIRME_HORS_ABANDON ?? 0})`,
text: `Parcours confirmés par le candidat ${getCounterText("PARCOURS_CONFIRME_HORS_ABANDON")}`,
isActive: isActive("PARCOURS_CONFIRME_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DOSSIER_FAISABILITE_ENVOYE_HORS_ABANDON"),
},
text: `Dossiers de faisabilité envoyés (${candidaciesByStatusCount?.DOSSIER_FAISABILITE_ENVOYE_HORS_ABANDON ?? 0})`,
text: `Dossiers de faisabilité envoyés ${getCounterText("DOSSIER_FAISABILITE_ENVOYE_HORS_ABANDON")}`,
isActive: isActive("DOSSIER_FAISABILITE_ENVOYE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DOSSIER_FAISABILITE_INCOMPLET_HORS_ABANDON"),
},
text: `Dossiers de faisabilité incomplets (${candidaciesByStatusCount?.DOSSIER_FAISABILITE_INCOMPLET_HORS_ABANDON ?? 0})`,
text: `Dossiers de faisabilité incomplets ${getCounterText("DOSSIER_FAISABILITE_INCOMPLET_HORS_ABANDON")}`,
isActive: isActive("DOSSIER_FAISABILITE_INCOMPLET_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DOSSIER_FAISABILITE_RECEVABLE_HORS_ABANDON"),
},
text: `Dossiers de faisabilité recevables (${candidaciesByStatusCount?.DOSSIER_FAISABILITE_RECEVABLE_HORS_ABANDON ?? 0})`,
text: `Dossiers de faisabilité recevables ${getCounterText("DOSSIER_FAISABILITE_RECEVABLE_HORS_ABANDON")}`,
isActive: isActive("DOSSIER_FAISABILITE_RECEVABLE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DEMANDE_FINANCEMENT_ENVOYE_HORS_ABANDON"),
},
text: `Demandes de prise en charge envoyées (${candidaciesByStatusCount?.DEMANDE_FINANCEMENT_ENVOYE_HORS_ABANDON ?? 0})`,
text: `Demandes de prise en charge envoyées ${getCounterText("DEMANDE_FINANCEMENT_ENVOYE_HORS_ABANDON")}`,
isActive: isActive("DEMANDE_FINANCEMENT_ENVOYE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DOSSIER_DE_VALIDATION_ENVOYE_HORS_ABANDON"),
},
text: `Dossiers de validation envoyés (${candidaciesByStatusCount?.DOSSIER_DE_VALIDATION_ENVOYE_HORS_ABANDON ?? 0})`,
text: `Dossiers de validation envoyés ${getCounterText("DOSSIER_DE_VALIDATION_ENVOYE_HORS_ABANDON")}`,
isActive: isActive("DOSSIER_DE_VALIDATION_ENVOYE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DOSSIER_DE_VALIDATION_SIGNALE_HORS_ABANDON"),
},
text: `Dossiers de validation signalés (${candidaciesByStatusCount?.DOSSIER_DE_VALIDATION_SIGNALE_HORS_ABANDON ?? 0})`,
text: `Dossiers de validation signalés ${getCounterText("DOSSIER_DE_VALIDATION_SIGNALE_HORS_ABANDON")}`,
isActive: isActive("DOSSIER_DE_VALIDATION_SIGNALE_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("DEMANDE_PAIEMENT_ENVOYEE_HORS_ABANDON"),
},
text: `Demandes de paiement envoyées (${candidaciesByStatusCount?.DEMANDE_PAIEMENT_ENVOYEE_HORS_ABANDON ?? 0})`,
text: `Demandes de paiement envoyées ${getCounterText("DEMANDE_PAIEMENT_ENVOYEE_HORS_ABANDON")}`,
isActive: isActive("DEMANDE_PAIEMENT_ENVOYEE_HORS_ABANDON"),
},
],
},
{
text: `Toutes les candidatures en jury (${candidaciesByStatusCount?.JURY_HORS_ABANDON ?? 0})`,
text: `Toutes les candidatures en jury ${getCounterText("JURY_HORS_ABANDON")}`,
linkProps: {
href: hrefSideMenu("JURY_HORS_ABANDON"),
},
Expand All @@ -130,43 +137,43 @@ const CandidacyLayoutSideMenu = ({
linkProps: {
href: hrefSideMenu("JURY_PROGRAMME_HORS_ABANDON"),
},
text: `Jurys programmés (${candidaciesByStatusCount?.JURY_PROGRAMME_HORS_ABANDON ?? 0})`,
text: `Jurys programmés ${getCounterText("JURY_PROGRAMME_HORS_ABANDON")}`,
isActive: isActive("JURY_PROGRAMME_HORS_ABANDON"),
},
{
linkProps: {
href: hrefSideMenu("JURY_PASSE_HORS_ABANDON"),
},
text: `Résultats renseignés (${candidaciesByStatusCount?.JURY_PASSE_HORS_ABANDON ?? 0})`,
text: `Résultats renseignés ${getCounterText("JURY_PASSE_HORS_ABANDON")}`,
isActive: isActive("JURY_PASSE_HORS_ABANDON"),
},
],
isActive: isActive("JURY_HORS_ABANDON"),
},

{
text: `Toutes les candidatures non recevables (${candidaciesByStatusCount?.DOSSIER_FAISABILITE_NON_RECEVABLE_HORS_ABANDON ?? 0})`,
text: `Toutes les candidatures non recevables ${getCounterText("DOSSIER_FAISABILITE_NON_RECEVABLE_HORS_ABANDON")}`,
linkProps: {
href: hrefSideMenu("DOSSIER_FAISABILITE_NON_RECEVABLE_HORS_ABANDON"),
},
isActive: isActive("DOSSIER_FAISABILITE_NON_RECEVABLE_HORS_ABANDON"),
},
{
text: `Toutes les candidatures abandonnées (${candidaciesByStatusCount?.ABANDON ?? 0})`,
text: `Toutes les candidatures abandonnées ${getCounterText("ABANDON")}`,
linkProps: {
href: hrefSideMenu("ABANDON"),
},
isActive: isActive("ABANDON"),
},
{
text: `Toutes les candidatures réorientées (${candidaciesByStatusCount?.REORIENTEE ?? 0})`,
text: `Toutes les candidatures réorientées ${getCounterText("REORIENTEE")}`,
linkProps: {
href: hrefSideMenu("REORIENTEE"),
},
isActive: isActive("REORIENTEE"),
},
{
text: `Toutes les candidatures supprimées (${candidaciesByStatusCount?.ARCHIVE_HORS_ABANDON_HORS_REORIENTATION ?? 0})`,
text: `Toutes les candidatures supprimées ${getCounterText("ARCHIVE_HORS_ABANDON_HORS_REORIENTATION")}`,
linkProps: {
href: hrefSideMenu("ARCHIVE_HORS_ABANDON_HORS_REORIENTATION"),
},
Expand All @@ -176,7 +183,7 @@ const CandidacyLayoutSideMenu = ({

if (isAdmin) {
sideMenuItems.push({
text: `Tous les projets en cours d'édition (${candidaciesByStatusCount?.PROJET_HORS_ABANDON ?? 0})`,
text: `Tous les projets en cours d'édition ${getCounterText("PROJET_HORS_ABANDON")}`,
linkProps: {
href: hrefSideMenu("PROJET_HORS_ABANDON"),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useFeatureflipping } from "@/components/feature-flipping/featureFlipping";
import { useGraphQlClient } from "@/components/graphql/graphql-client/GraphqlClient";
import { graphql } from "@/graphql/generated";
import { CandidacyStatusFilter } from "@/graphql/generated/graphql";
Expand Down Expand Up @@ -87,13 +88,15 @@ export const useCandidacies = ({
}) => {
const RECORDS_PER_PAGE = 10;
const { graphqlClient } = useGraphQlClient();
const { isFeatureActive } = useFeatureflipping();
const offset = (currentPage - 1) * RECORDS_PER_PAGE;
const { data: getCandidacyByStatusResponse } = useQuery({
queryKey: ["getCandidacyByStatusCount", searchFilter],
queryFn: () =>
graphqlClient.request(getCandidacyByStatusCount, {
searchFilter,
}),
enabled: !isFeatureActive("DISABLE_CANDIDACIES_PAGE_COUNTERS"),
});

const { data: getCandidaciesByStatusResponse } = useQuery({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INSERT INTO
features ("key", "label")
values
(
'DISABLE_CANDIDACIES_PAGE_COUNTERS',
'Désactivation de l''affichage des compteurs dans la liste des candidature'
)

0 comments on commit f85761a

Please sign in to comment.