Skip to content

Commit

Permalink
fix: mise a jour de la règle du switch sur SIFA
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomarom committed Jan 3, 2025
1 parent e6ae291 commit c250004
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
26 changes: 7 additions & 19 deletions ui/modules/mon-espace/SIFA/SIFAPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function SIFAPage(props: SIFAPageProps) {
const parseFilter = (key: string, value: string | string[] | undefined) => {
switch (key) {
case "only_sifa_missing_fields":
return value === "true" ? "true" : undefined;
return value === "true";
case "source":
case "formation_libelle_long":
return defaultFilterParser(value)?.flat();
Expand All @@ -86,7 +86,7 @@ function SIFAPage(props: SIFAPageProps) {
}
};

const filters: Record<string, string[] | string> = {};
const filters: SIFAFilterType = {};

const filterKeys = ["formation_libelle_long", "source", "only_sifa_missing_fields"];

Expand Down Expand Up @@ -177,25 +177,15 @@ function SIFAPage(props: SIFAPageProps) {
);
};

const handleMissingSifaChange = (checked: boolean) => {
router.push(
{
pathname: router.pathname,
query: { ...router.query, only_sifa_missing_fields: checked },
},
undefined,
{ shallow: true }
);
};

const handleFilterChange = (newFilters: SIFAFilterType) => {
setPagination({ ...pagination, pageIndex: 0 });

const mergedFilters = {
...(newFilters.source && newFilters.source.length && { source: newFilters.source }),
...(newFilters.formation_libelle_long &&
newFilters.formation_libelle_long.length && { formation_libelle_long: newFilters.formation_libelle_long }),
...(newFilters.only_sifa_missing_fields && { only_sifa_missing_fields: newFilters.only_sifa_missing_fields }),
...(newFilters.source && newFilters.source.length ? { source: newFilters.source } : {}),
...(newFilters.formation_libelle_long && newFilters.formation_libelle_long.length
? { formation_libelle_long: newFilters.formation_libelle_long }
: {}),
...(newFilters.only_sifa_missing_fields ? { only_sifa_missing_fields: newFilters.only_sifa_missing_fields } : {}),
};
const queryFilters = Object.entries(mergedFilters).reduce(
(acc, [key, values]) => {
Expand All @@ -216,7 +206,6 @@ function SIFAPage(props: SIFAPageProps) {
delete updatedQuery[key];
}
});

setFilters(mergedFilters);

router.push(
Expand Down Expand Up @@ -470,7 +459,6 @@ function SIFAPage(props: SIFAPageProps) {
onPaginationChange={handlePaginationChange}
onSearchChange={handleSearchChange}
onFilterChange={handleFilterChange}
onSifaMissingFilterChange={handleMissingSifaChange}
onSortChange={handleSortChange}
total={data?.total || 0}
availableFilters={data?.filters || {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const SIFAEffectifsFilterPanel: React.FC<SIFAEffectifsFilterPanelProps> = ({
resetFilters,
}) => {
const [openFilter, setOpenFilter] = useState<string | null>(null);

const handleCheckboxChange = (filterKey: string, selectedValues: string[]) => {
const updatedFilters = { ...filters, [filterKey]: selectedValues };
onFilterChange(updatedFilters);
Expand Down Expand Up @@ -71,11 +70,7 @@ const SIFAEffectifsFilterPanel: React.FC<SIFAEffectifsFilterPanelProps> = ({
</Button>
</Stack>
<Stack direction="row" spacing={4} wrap="wrap">
<Switch
variant="icon"
checked={filters.only_sifa_missing_fields as boolean}
onChange={handleMissingSifaChange}
/>
<Switch variant="icon" isChecked={filters.only_sifa_missing_fields} onChange={handleMissingSifaChange} />
<Text flexGrow={1}>Afficher uniquement les données manquantes pour SIFA</Text>
</Stack>
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface EffectifsTableProps {
onSearchChange: (search: string) => void;
onFilterChange: (filters: SIFAFilterType) => void;
onSortChange: (sort: SortingState) => void;
onSifaMissingFilterChange: (checked: boolean) => void;
total: number;
availableFilters: SIFAFilterType;
resetFilters: () => void;
Expand Down

0 comments on commit c250004

Please sign in to comment.