Skip to content

Commit

Permalink
feat(ui): ajout du filtre UAI (connu ou inconnu) (#3278)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenfares authored Oct 12, 2023
1 parent 57fe8f9 commit 22b9fab
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
17 changes: 17 additions & 0 deletions ui/modules/organismes/OrganismesFilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import FiltreOrganismesEtat from "./filters/FiltreOrganismeEtat";
import FiltreOrganismesNature from "./filters/FiltreOrganismeNature";
import FiltreOrganismeRegions from "./filters/FiltreOrganismeRegions";
import FiltreOrganismeTransmission from "./filters/FiltreOrganismeTransmission";
import FiltreOrganismeUai from "./filters/FiltreOrganismeUai";
import FiltreYesNo from "./filters/FiltreYesNo";
import {
OrganismesFilters,
Expand All @@ -25,6 +26,7 @@ import {
} from "./models/organismes-filters";

export interface OrganismeFiltersListVisibilityProps {
showFilterUai?: boolean;
showFilterNature?: boolean;
showFilterTransmission?: boolean;
showFilterQualiopi?: boolean;
Expand Down Expand Up @@ -103,6 +105,16 @@ const OrganismesFilterPanel = (props: OrganismeFiltersListVisibilityProps) => {
}
};

const isAllowedToShowFilterUAI = (type: OrganisationType) => {
switch (type) {
case "ADMINISTRATEUR":
return true;

default:
return false;
}
};

return (
<Stack spacing="0.5">
<Text fontSize="zeta" fontWeight="extrabold">
Expand All @@ -127,6 +139,11 @@ const OrganismesFilterPanel = (props: OrganismeFiltersListVisibilityProps) => {
<FiltreOrganismesNature value={organismesFilters.nature} onChange={(nature) => updateState({ nature })} />
)}

{/* FILTRE UAI */}
{props?.showFilterUai && isAllowedToShowFilterUAI(auth?.organisation?.type) && (
<FiltreOrganismeUai value={organismesFilters.etatUAI} onChange={(etatUAI) => updateState({ etatUAI })} />
)}

{/* FILTRE TRANSMISSION */}
{props?.showFilterTransmission && (
<FiltreOrganismeTransmission
Expand Down
41 changes: 41 additions & 0 deletions ui/modules/organismes/filters/FiltreOrganismeUai.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CheckboxGroup, Stack, Checkbox } from "@chakra-ui/react";
import { useState } from "react";

import SimpleOverlayMenu from "@/modules/dashboard/SimpleOverlayMenu";

import { OrganismesFilterButton } from "./OrganismesFilterButton";

interface FiltreOrganismeUaiProps {
value: boolean[];
onChange: (value: boolean[]) => void;
}

function FiltreOrganismeUai(props: FiltreOrganismeUaiProps) {
const [isOpen, setIsOpen] = useState(false);
const etatUAI = props.value;

return (
<div>
<OrganismesFilterButton isOpen={isOpen} setIsOpen={setIsOpen} buttonLabel="UAI" badge={etatUAI?.length} />
{isOpen && (
<SimpleOverlayMenu onClose={() => setIsOpen(false)} width="auto" p="3w">
<CheckboxGroup
value={props.value?.map((item) => item.toString())}
onChange={(value) => props.onChange(value.map((v: string) => (v === "true" ? true : false)))}
>
<Stack>
<Checkbox value="true" key="connu" fontSize="mini" size="sm">
Connu
</Checkbox>
<Checkbox value="false" key="inconnu" fontSize="mini" size="sm">
Inconnu
</Checkbox>
</Stack>
</CheckboxGroup>
</SimpleOverlayMenu>
)}
</div>
);
}

export default FiltreOrganismeUai;
21 changes: 16 additions & 5 deletions ui/modules/organismes/models/organismes-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface OrganismesFiltersQuery {
ferme: string;
regions?: string;
departements?: string;
etatUAI: string;
}

export interface OrganismesFilters {
Expand All @@ -20,6 +21,7 @@ export interface OrganismesFilters {
ferme: boolean[];
regions: string[];
departements: string[];
etatUAI: boolean[];
}

export function parseOrganismesFiltersFromQuery(query: OrganismesFiltersQuery): OrganismesFilters {
Expand All @@ -31,6 +33,7 @@ export function parseOrganismesFiltersFromQuery(query: OrganismesFiltersQuery):
ferme: query.ferme?.split(",").map((item) => (item === "true" ? true : false)) ?? [],
regions: query.regions?.split(",") ?? [],
departements: query.departements?.split(",") ?? [],
etatUAI: query.etatUAI?.split(",").map((item) => (item === "true" ? true : false)) ?? [],
};
}

Expand All @@ -45,6 +48,7 @@ export function convertOrganismesFiltersToQuery(
ferme: organismesFilters.ferme?.join(","),
regions: organismesFilters.regions?.join(","),
departements: organismesFilters.departements?.join(","),
etatUAI: organismesFilters.etatUAI?.join(","),
});
}

Expand Down Expand Up @@ -86,11 +90,18 @@ export function filterOrganismesArrayFromOrganismesFilters(
return organismesFilters.departements?.includes(item.adresse.departement);
});

if (organismesFilters.transmission?.length && organismesFilters.transmission?.length === 1)
filteredOrganismes = filteredOrganismes?.filter((item) => {
if (organismesFilters.transmission?.[0] === true) return item.last_transmission_date;
if (organismesFilters.transmission?.[0] === false) return !item.last_transmission_date;
});
if (organismesFilters.transmission?.length && organismesFilters.transmission?.length > 0)
filteredOrganismes = filteredOrganismes?.filter(
(item) =>
organismesFilters.transmission?.some(
(filter) => (!!filter && !!item.last_transmission_date) || (!filter && !item.last_transmission_date)
)
);

if (organismesFilters.etatUAI?.length && organismesFilters.etatUAI?.length > 0)
filteredOrganismes = filteredOrganismes?.filter(
(item) => organismesFilters.etatUAI?.some((filter) => (!!filter && !!item.uai) || (!filter && !item.uai))
);

return filteredOrganismes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function OrganismesACompleterPanelContent({ organismes }: { organismes: Organism
showFilterTransmission
showFilterLocalisation
showFilterEtat
showFilterUai
/>
</Stack>
);
Expand Down

0 comments on commit 22b9fab

Please sign in to comment.