Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit aa2e68a

Browse files
committed
Merge branch '212-sorting-time-column-doesnt-work-beta'
2 parents cb5b866 + e7372ff commit aa2e68a

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"react-dom": "18.2.0",
6464
"react-csv": "2.2.2",
6565
"react-popper": "2.3.0",
66-
"@tanstack/react-table": "8.3.1",
66+
"@tanstack/react-table": "8.3.3",
6767
"@tanstack/match-sorter-utils": "8.1.1",
6868
"react-select": "5.4.0",
6969
"react-color": "2.19.3",

src/cdm/HeaderActionModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SortedType } from "cdm/DatabaseModel";
21
import { HeaderMenuProps } from "cdm/HeaderModel";
32

43
export type HeaderActionResponse = {

src/components/DefaultHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
5454
const created: boolean = false;
5555
/** Properties of header */
5656
const { column, header, table } = headerProps;
57+
5758
/** Column values */
5859
const { id, dataType, options, position, label, config } =
5960
column.columnDef as TableColumn;

src/components/Table.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
getFilteredRowModel,
66
getExpandedRowModel,
77
ColumnDef,
8-
ColumnResizeMode,
98
ColumnOrderState,
109
flexRender,
1110
Table,
@@ -29,7 +28,6 @@ import {
2928
ActionTypes,
3029
DatabaseCore,
3130
DatabaseLimits,
32-
DnDConfiguration,
3331
MetadataColumns,
3432
ResizeConfiguration,
3533
} from "helpers/Constants";
@@ -48,12 +46,14 @@ import { DndProvider } from "react-dnd";
4846
import { HTML5Backend } from "react-dnd-html5-backend";
4947
import TableCell from "components/TableCell";
5048
import getInitialColumnSizing from "components/behavior/InitialColumnSizeRecord";
49+
import customSortingFn from "components/behavior/CustomSortingFn";
5150

5251
const defaultColumn: Partial<ColumnDef<RowDataType>> = {
5352
minSize: DatabaseLimits.MIN_COLUMN_HEIGHT,
5453
maxSize: DatabaseLimits.MAX_COLUMN_HEIGHT,
5554
cell: DefaultCell,
5655
header: DefaultHeader,
56+
sortingFn: customSortingFn,
5757
};
5858

5959
/**
@@ -179,6 +179,7 @@ export function Table(tableData: TableDataType) {
179179
columnSizing: columnSizing,
180180
sorting: sorting,
181181
},
182+
182183
onSortingChange: setSorting,
183184
onColumnSizingChange: (updater) => {
184185
let list: ColumnSizingState = null;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Row } from "@tanstack/react-table";
2+
import { RowDataType } from "cdm/FolderModel";
3+
4+
function customSortingFn(rowA: Row<RowDataType>, rowB: Row<RowDataType>, columnId: string): number {
5+
const a = rowA.getValue(columnId);
6+
const b = rowB.getValue(columnId);
7+
if (areEqual(a, b)) {
8+
return 0;
9+
}
10+
if (a == null) {
11+
return -1;
12+
}
13+
14+
if (b == null) {
15+
return 1;
16+
}
17+
18+
return fallback(a, b);
19+
}
20+
function areEqual(a: any, b: any): boolean {
21+
// It is necessary?
22+
if (a == null && b == null) {
23+
return true;
24+
}
25+
return a === b;
26+
}
27+
28+
function fallback(a: any, b: any): number {
29+
return isNaN(a)
30+
? a.localeCompare(b)
31+
: a - b;
32+
}
33+
34+
export default customSortingFn;

src/components/portals/CalendarPortal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
5656
popperContainer={CalendarContainer}
5757
onBlur={() => setShowDatePicker(false)}
5858
autoFocus
59+
placeholderText="Pick a date..."
5960
/>
6061
) : (
6162
<span className={`${c("calendar")}`} onClick={handleOnClick}>
6263
{DateTime.isDateTime(calendarState)
6364
? (calendarState as unknown as DateTime).toFormat("yyyy-MM-dd")
64-
: "Pick a date..."}
65+
: null}
6566
</span>
6667
);
6768
};

src/components/portals/CalendarTimePortal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
4444
<span className="calendar-time">
4545
{DateTime.isDateTime(calendarTimeState)
4646
? (calendarTimeState as DateTime).toFormat("yyyy-MM-dd h:mm a")
47-
: "Invalid metadata date!"}
47+
: null}
4848
</span>
4949
) : (
5050
<div className="calendar-time">

0 commit comments

Comments
 (0)