-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(explorer): type-based sorting (#3340)
- Loading branch information
Showing
4 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
The columns in the Explore tab table are now sorted correctly according to their types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...lorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/utils/typeSortingFn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { bigIntSort } from "@latticexyz/common/utils"; | ||
import { AbiType } from "@latticexyz/config"; | ||
import { Row } from "@tanstack/react-table"; | ||
import { TDataRow } from "../../../../../queries/useTableDataQuery"; | ||
|
||
export function typeSortingFn(rowA: Row<TDataRow>, rowB: Row<TDataRow>, columnId: string, type?: AbiType) { | ||
const a = rowA.getValue(columnId); | ||
const b = rowB.getValue(columnId); | ||
|
||
if (type?.startsWith("uint") || type?.startsWith("int")) { | ||
const aBig = BigInt(a?.toString() || "0"); | ||
const bBig = BigInt(b?.toString() || "0"); | ||
return bigIntSort(aBig, bBig); | ||
} | ||
|
||
if (typeof a === "bigint" || typeof b === "bigint") { | ||
const aBig = BigInt(a?.toString() || "0"); | ||
const bBig = BigInt(b?.toString() || "0"); | ||
return bigIntSort(aBig, bBig); | ||
} | ||
|
||
if (a == null) return 1; | ||
if (b == null) return -1; | ||
|
||
return a < b ? -1 : a > b ? 1 : 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters