forked from deephaven/web-client-ui
-
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.
ListView table support (deephaven#1909)
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
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
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,62 @@ | ||
import { | ||
ListView as ListViewBase, | ||
ListViewProps as ListViewPropsBase, | ||
NormalizedItemData, | ||
} from '@deephaven/components'; | ||
import { dh as DhType } from '@deephaven/jsapi-types'; | ||
import { Settings } from '@deephaven/jsapi-utils'; | ||
import { LIST_VIEW_ROW_HEIGHT } from '@deephaven/utils'; | ||
import useFormatter from '../useFormatter'; | ||
import useViewportData from '../useViewportData'; | ||
import { useItemRowDeserializer } from './utils'; | ||
|
||
export interface ListViewProps extends Omit<ListViewPropsBase, 'children'> { | ||
table: DhType.Table; | ||
/* The column of values to use as item keys. Defaults to the first column. */ | ||
keyColumn?: string; | ||
/* The column of values to display as primary text. Defaults to the `keyColumn` value. */ | ||
labelColumn?: string; | ||
|
||
// TODO #1890 : descriptionColumn, iconColumn | ||
|
||
settings?: Settings; | ||
} | ||
|
||
export function ListView({ | ||
table, | ||
keyColumn: keyColumnName, | ||
labelColumn: labelColumnName, | ||
settings, | ||
...props | ||
}: ListViewProps): JSX.Element { | ||
const { getFormattedString: formatValue } = useFormatter(settings); | ||
|
||
const deserializeRow = useItemRowDeserializer({ | ||
table, | ||
keyColumnName, | ||
labelColumnName, | ||
formatValue, | ||
}); | ||
|
||
const { viewportData, onScroll } = useViewportData< | ||
NormalizedItemData, | ||
DhType.Table | ||
>({ | ||
reuseItemsOnTableResize: true, | ||
table, | ||
itemHeight: LIST_VIEW_ROW_HEIGHT, | ||
deserializeRow, | ||
}); | ||
|
||
return ( | ||
<ListViewBase | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
onScroll={onScroll} | ||
> | ||
{viewportData.items} | ||
</ListViewBase> | ||
); | ||
} | ||
|
||
export default ListView; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './ListView'; | ||
export * from './Picker'; |