Skip to content

Commit

Permalink
fix: fix marche publiques sort (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImenOuidou authored Nov 7, 2024
1 parent 6fb2557 commit 36f4ed5
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { formatSiret } from "../../../../../helpers/utils";
import { formatUpperCase } from "../../../../../utils/entreprise/entreprise";
import { getCodePostal } from "../../../../../utils/establishment/establishment";

// Suppose this function is imported or defined
export const getCity = (marche) =>
marche?.etablissement?.libellecommuneetablissement ||
marche?.etablissement?.libellecommune2etablissement;
Expand All @@ -25,22 +24,39 @@ export const useSortableData = (items, config = null) => {
if (sortConfig.key === "city") {
aValue = getCodePostal(a?.etablissement); // Retrieve city using getCity
bValue = getCodePostal(b?.etablissement);
console.log(bValue);
} else if (sortConfig.key === "acheteur") {
aValue = getAcheteur(a);
bValue = getAcheteur(b);
} else if (
sortConfig.key === "montant" ||
sortConfig.key === "dureeMois"
) {
// Convertir 'montant' en nombre
aValue = parseFloat(a[sortConfig.key]);
bValue = parseFloat(b[sortConfig.key]);
} else {
aValue = a[sortConfig.key];
bValue = b[sortConfig.key];
}

if (aValue < bValue) {
return sortConfig.direction === "ascending" ? -1 : 1;
}
if (aValue > bValue) {
return sortConfig.direction === "ascending" ? 1 : -1;
// Gérer les valeurs nulles ou indéfinies
if (aValue == null) return 1;
if (bValue == null) return -1;

// Comparaison appropriée en fonction du type
if (typeof aValue === "number" && typeof bValue === "number") {
return sortConfig.direction === "ascending"
? aValue - bValue
: bValue - aValue;
} else {
if (aValue < bValue) {
return sortConfig.direction === "ascending" ? -1 : 1;
}
if (aValue > bValue) {
return sortConfig.direction === "ascending" ? 1 : -1;
}
return 0;
}
return 0;
});
}
return sortableItems;
Expand Down

0 comments on commit 36f4ed5

Please sign in to comment.