Skip to content

Commit d43fe80

Browse files
authored
fix sorting (#161)
1 parent bd18b84 commit d43fe80

5 files changed

Lines changed: 27 additions & 56 deletions

File tree

client/request.http

Lines changed: 0 additions & 4 deletions
This file was deleted.

client/src/pages/admin/NgosList/components/columns.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export const columns: ColumnDef<NgoVM>[] = [
136136
enableSorting: true,
137137
filterFn: (row, id, value) => {
138138
const rowValue = row.getValue<string | undefined>(id);
139-
if (!rowValue) return true;
140139
if (!Array.isArray(value) || value.length !== 2) return true; // fallback if invalid
141140

142141
if (!rowValue) return false;

client/src/pages/mentor/MenteesList/components/columns.tsx

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import { Link } from "@tanstack/react-router";
66
import { type ColumnDef } from "@tanstack/react-table";
77
import type { MenteeVM } from "../types";
88
import type { FinalProgramModel } from "@/services/api/types";
9+
import { format } from "date-fns";
910

1011
export const columns: ColumnDef<MenteeVM>[] = [
1112
{
1213
accessorKey: "name",
1314
header: ({ column }) => (
14-
<DataTableColumnHeader
15-
column={column}
16-
title="Nume ONG"
17-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
18-
/>
15+
<DataTableColumnHeader column={column} title="Nume ONG" />
1916
),
2017
cell: ({ row }) => {
2118
return (
@@ -26,35 +23,27 @@ export const columns: ColumnDef<MenteeVM>[] = [
2623
</div>
2724
);
2825
},
29-
enableSorting: false,
26+
enableSorting: true,
3027
},
3128
{
3229
accessorKey: "ongIdentificationNumber",
3330
header: ({ column }) => (
34-
<DataTableColumnHeader
35-
column={column}
36-
title="CIF"
37-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
38-
/>
31+
<DataTableColumnHeader column={column} title="CIF" />
3932
),
4033
cell: ({ row }) => <div>{row.original.ongIdentificationNumber ?? "-"}</div>,
4134
enableSorting: false,
4235
},
4336
{
4437
accessorKey: "createdAt",
4538
header: ({ column }) => (
46-
<DataTableColumnHeader
47-
column={column}
48-
title="DATĂ ÎNREGISTRARE"
49-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
50-
/>
39+
<DataTableColumnHeader column={column} title="DATĂ ÎNREGISTRARE" />
5140
),
5241
cell: ({ row }) => {
5342
return formatDate(row.original.createdAt);
5443
},
55-
enableSorting: false,
44+
enableSorting: true,
5645
filterFn: (row, id, value) => {
57-
const rowValue = row.getValue<string>(id);
46+
const rowValue = format(row.getValue<string>(id), "yyyy-MM-dd");
5847

5948
if (!Array.isArray(value) || value.length !== 2) return true; // fallback if invalid
6049

@@ -65,15 +54,10 @@ export const columns: ColumnDef<MenteeVM>[] = [
6554
{
6655
accessorKey: "ngoPrograms",
6756
header: ({ column }) => (
68-
<DataTableColumnHeader
69-
column={column}
70-
title="PROGRAME ASOCIATE"
71-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
72-
/>
57+
<DataTableColumnHeader column={column} title="PROGRAME ASOCIATE" />
7358
),
7459
cell: ({ row }) => (
7560
<div className="flex flex-wrap gap-2">
76-
1222
7761
{row.original.ngoPrograms?.map(({ id, name, endDate }) => (
7862
<Badge
7963
key={id}
@@ -101,35 +85,23 @@ export const columns: ColumnDef<MenteeVM>[] = [
10185
{
10286
accessorKey: "county",
10387
header: ({ column }) => (
104-
<DataTableColumnHeader
105-
column={column}
106-
title="JUDEȚ"
107-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
108-
/>
88+
<DataTableColumnHeader column={column} title="JUDEȚ" />
10989
),
11090
cell: ({ row }) => <span>{row.original.county}</span>,
111-
enableSorting: false,
91+
enableSorting: true,
11292
},
11393
{
11494
accessorKey: "city",
11595
header: ({ column }) => (
116-
<DataTableColumnHeader
117-
column={column}
118-
title="LOCALITATE"
119-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
120-
/>
96+
<DataTableColumnHeader column={column} title="LOCALITATE" />
12197
),
12298
cell: ({ row }) => <span>{row.original.city}</span>,
123-
enableSorting: false,
99+
enableSorting: true,
124100
},
125101
{
126102
accessorKey: "domains",
127103
header: ({ column }) => (
128-
<DataTableColumnHeader
129-
column={column}
130-
title="DOMENIU DE ACTIVITATE"
131-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
132-
/>
104+
<DataTableColumnHeader column={column} title="DOMENIU DE ACTIVITATE" />
133105
),
134106
cell: ({ row }) => {
135107
return row.original.domains?.length ? (
@@ -151,25 +123,25 @@ export const columns: ColumnDef<MenteeVM>[] = [
151123
{
152124
accessorKey: "lastEvaluationDate",
153125
header: ({ column }) => (
154-
<DataTableColumnHeader
155-
column={column}
156-
title="ULTIMA EVALUARE"
157-
className="whitespace-nowrap py-4 text-sm font-bold text-gray-900 "
158-
/>
126+
<DataTableColumnHeader column={column} title="ULTIMA EVALUARE" />
159127
),
160128
cell: ({ row }) => {
161129
return row.original.lastEvaluationDate
162130
? formatDate(row.original.lastEvaluationDate)
163131
: "-";
164132
},
165-
enableSorting: false,
133+
enableSorting: true,
166134
filterFn: (row, id, value) => {
167-
const rowValue = row.getValue<string>(id);
168-
135+
const rowValue = row.getValue<string | undefined>(id);
169136
if (!Array.isArray(value) || value.length !== 2) return true; // fallback if invalid
170137

138+
if (!rowValue) return false;
139+
171140
const [min, max] = value;
172-
return rowValue >= min && rowValue <= max;
141+
return (
142+
format(rowValue, "yyyy-MM-dd") >= min &&
143+
format(rowValue, "yyyy-MM-dd") <= max
144+
);
173145
},
174146
},
175147
{

client/src/pages/mentor/MenteesList/components/table.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const menteeMapper = (mentees: FinalDetailedUserModel[]): MenteeVM[] =>
3131
county: ngo.county,
3232
city: ngo.city,
3333
domains: ngo?.domains?.map((d) => d.name) ?? [],
34-
lastEvaluationDate: ngo.reports?.at(-1)?.createdAt,
34+
lastEvaluationDate:
35+
ngo.reports && ngo.reports.length > 0
36+
? ngo.reports[ngo.reports.length - 1].createdAt
37+
: undefined,
3538
})
3639
);
3740
export function MenteesTable() {

client/src/pages/mentor/MenteesList/components/toolbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function MenteesDataTableToolbar({
122122
title={"Localitate"}
123123
options={availableCities}
124124
multiple={false}
125+
disabled={!county}
125126
/>
126127
{isFiltered && (
127128
<Button

0 commit comments

Comments
 (0)