From 76698b018886cf273559c3d400c00943cf73f36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez=20Mu=C3=B1oz?= Date: Mon, 30 Oct 2023 17:56:08 +0100 Subject: [PATCH] fixes cost surfaces sorting --- .../inventory-panel/cost-surfaces/index.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx index e82991610c..e6e9dba948 100644 --- a/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/cost-surfaces/index.tsx @@ -64,18 +64,18 @@ const InventoryPanelCostSurface = ({ noData: noDataMessage }: { noData: string } const filteredData = useMemo(() => { let sortedData = allProjectCostSurfacesQuery.data; - if (filters.sort === '-name') { - sortedData = orderBy(allProjectCostSurfacesQuery.data, 'name', 'desc'); + switch (filters.sort) { + case 'name': + sortedData = orderBy(allProjectCostSurfacesQuery.data, 'name', 'asc'); + break; + case '-name': + sortedData = orderBy(allProjectCostSurfacesQuery.data, 'name', 'desc'); + break; } - if (search) { - sortedData = sortedData.filter((cs) => - cs.name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) - ); - } - - // the API assumes the default sort is ascending - return sortedData; + return sortedData.filter((cs) => + cs.name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) + ); }, [filters, allProjectCostSurfacesQuery.data, search]); const costSurfaceIds = filteredData?.map((cs) => cs.id);