Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): ajout du filtre UAI (connu ou inconnu) #3278

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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