-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This isn't working, running into a weird error: ``` import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js"; ``` with react-virtualized and vite. See bvaughn/react-virtualized#1635 bvaughn/react-virtualized#1632 https://github.com/uber/baseweb/issues/4129 Seems like react-virtualized is an inactive project, so probably should just switch to a more active full featured table library
- Loading branch information
1 parent
7c9d3f9
commit c6c76ed
Showing
8 changed files
with
182 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 @@ | ||
import React from "react"; | ||
import { useAppSelector } from "hooks"; | ||
import { ArrowTableGrid } from "./arrow-viewer/ArrowTableGrid"; | ||
|
||
export const TableGrid = () => { | ||
const data = useAppSelector((s) => s.sqlQuery.data); | ||
const status = useAppSelector((s) => s.sqlQuery.status); | ||
return status == "completed" ? ( | ||
<ArrowTableGrid table={data} width={300} height={800}></ArrowTableGrid> | ||
) : null; | ||
}; |
101 changes: 101 additions & 0 deletions
101
src/features/sqlEditor/components/arrow-viewer/ArrowTableGrid.tsx
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,101 @@ | ||
// From github.com/cwharris/arrow-viewer | ||
import {Table as ArrowTable} from "apache-arrow"; | ||
|
||
import { valueToString } from "utils/arrow-utils" | ||
|
||
import { Table, Column, AutoSizer, Index } from "react-virtualized"; | ||
|
||
import "react-virtualized/styles.css"; | ||
import { defaultRowRenderer, TableCellProps, TableHeaderProps, TableHeaderRowProps, TableRowProps } from "react-virtualized/dist/es/Table"; | ||
|
||
export function ArrowTableGrid({ | ||
table, | ||
width, | ||
height, | ||
}: { | ||
table: ArrowTable; | ||
width: number; | ||
height: number; | ||
}): JSX.Element { | ||
return ( | ||
<AutoSizer> | ||
{(size) => ( | ||
<Table | ||
{...size} | ||
height={height - 10} | ||
rowHeight={28} | ||
headerHeight={40} | ||
rowStyle={rowStyle} | ||
rowCount={table.length} | ||
rowGetter={({ index }: Index) => table.get(index)} | ||
rowRenderer={(props: TableRowProps) => { | ||
// console.log(props); | ||
|
||
return defaultRowRenderer({ | ||
...props, | ||
style: { ...props.style, width: props.style.width - 15 }, | ||
}); | ||
}} | ||
headerStyle={headerStyle()} | ||
headerRowRenderer={({ | ||
className, | ||
columns, | ||
style, | ||
}: TableHeaderRowProps) => ( | ||
<div | ||
role="row" | ||
className={className} | ||
style={{ ...style, ...headerStyle(), width: size.width }} | ||
> | ||
{columns} | ||
</div> | ||
)} | ||
> | ||
{table.schema.fields.map((field, idx) => { | ||
// console.log(field, idx); | ||
|
||
return ( | ||
<Column | ||
key={idx} | ||
width={25} | ||
minWidth={25} | ||
flexGrow={1} | ||
dataKey={idx.toString()} | ||
label={`${field.toString()}`} | ||
columnData={table.getColumn(field.name).toArray()} | ||
cellDataGetter={(props) => { | ||
// console.log(props); | ||
const d = props.rowData[idx]; | ||
// console.log(d); | ||
return d; | ||
}} | ||
cellRenderer={({ cellData }: TableCellProps) => | ||
valueToString(cellData) | ||
} | ||
headerRenderer={({ | ||
label, | ||
}: TableHeaderProps) => label} | ||
/> | ||
); | ||
})} | ||
</Table> | ||
)} | ||
</AutoSizer> | ||
); | ||
} | ||
|
||
const headerStyle = () => | ||
({ textAlign: "right", textTransform: "none" } as React.CSSProperties); | ||
|
||
const rowStyle = ({ index }: Index) => | ||
index % 2 === 0 | ||
? { | ||
...headerStyle(), | ||
borderBottom: "1px solid #e0e0e0", | ||
backgroundColor: "#fff", | ||
} | ||
: { | ||
...headerStyle(), | ||
borderBottom: "1px solid #e0e0e0", | ||
backgroundColor: "#fafafa", | ||
}; |
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
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,6 @@ | ||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' | ||
import type { RootState, Dispatch } from 'store/store' | ||
|
||
// Use throughout your app instead of plain `useDispatch` and `useSelector` | ||
export const useAppDispatch = () => useDispatch<Dispatch>() | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector |
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
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,22 @@ | ||
// from import { valueToString } from "apache-arrow/util/pretty"; | ||
export function valueToString(x) { | ||
if (x === null) { | ||
return 'null'; | ||
} | ||
if (x === undefined) { | ||
return 'undefined'; | ||
} | ||
switch (typeof x) { | ||
case 'number': return `${x}`; | ||
case 'bigint': return `${x}`; | ||
case 'string': return `"${x}"`; | ||
} | ||
// If [Symbol.toPrimitive] is implemented (like in BN) | ||
// use it instead of JSON.stringify(). This ensures we | ||
// print BigInts, Decimals, and Binary in their native | ||
// representation | ||
if (typeof x[Symbol.toPrimitive] === 'function') { | ||
return x[Symbol.toPrimitive]('string'); | ||
} | ||
return ArrayBuffer.isView(x) ? `[${x}]` : JSON.stringify(x); | ||
} |