1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add table sorting

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-05-14 11:53:39 +03:00
parent 38343af2ef
commit f9fda30045
4 changed files with 134 additions and 5 deletions

View File

@ -100,7 +100,7 @@ export function InstalledExtensions({ extensions, uninstall }: Props) {
disabled={isUninstalling} disabled={isUninstalling}
onClick={() => extension.isEnabled = true} onClick={() => extension.isEnabled = true}
> >
<Icon material="published"/> <Icon material="check_circle"/>
<span className="title">Enable</span> <span className="title">Enable</span>
</MenuItem> </MenuItem>
)} )}
@ -108,7 +108,7 @@ export function InstalledExtensions({ extensions, uninstall }: Props) {
disabled={isUninstalling} disabled={isUninstalling}
onClick={() => uninstall(extension)} onClick={() => uninstall(extension)}
> >
<Icon material="remove"/> <Icon material="delete"/>
<span className="title">Uninstall</span> <span className="title">Uninstall</span>
</MenuItem> </MenuItem>
</MenuActions> </MenuActions>

View File

@ -7,11 +7,11 @@
@apply overflow-hidden font-bold; @apply overflow-hidden font-bold;
border-bottom: thin solid var(--hrColor); border-bottom: thin solid var(--hrColor);
color: var(--textColorAccent); color: var(--textColorAccent);
padding-top: 6px;
height: 33px; height: 33px;
} }
.tr:last-child { .tr {
border-bottom: thin solid var(--hrColor);
} }
.th { .th {

View File

@ -3,6 +3,7 @@ import React from "react";
import { useCallback, useMemo } from "react"; import { useCallback, useMemo } from "react";
import { useFlexLayout, useSortBy, useTable, UseTableOptions } from "react-table"; import { useFlexLayout, useSortBy, useTable, UseTableOptions } from "react-table";
import { FixedSizeList } from "react-window"; import { FixedSizeList } from "react-window";
import { Icon } from "../icon";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
interface Props extends UseTableOptions<any> { interface Props extends UseTableOptions<any> {
@ -69,8 +70,16 @@ export function Table({ columns, data, virtual, headless }: Props) {
{headerGroups.map(headerGroup => ( {headerGroups.map(headerGroup => (
<div {...headerGroup.getHeaderGroupProps()} key={headerGroup.getHeaderGroupProps().key} className={styles.tr}> <div {...headerGroup.getHeaderGroupProps()} key={headerGroup.getHeaderGroupProps().key} className={styles.tr}>
{headerGroup.headers.map(column => ( {headerGroup.headers.map(column => (
<div key={column.getHeaderProps().key} className={styles.tr}> <div {...column.getHeaderProps(column.getSortByToggleProps())} key={column.getHeaderProps().key} className={styles.tr}>
{column.render("Header")} {column.render("Header")}
{/* Sort direction indicator */}
<span>
{column.isSorted
? column.isSortedDesc
? <Icon material="arrow_drop_down" small/>
: <Icon material="arrow_drop_up" small/>
: !column.disableSortBy && <Icon material="arrow_drop_down" small className={styles.disabledArrow}/>}
</span>
</div> </div>
))} ))}
</div> </div>

120
types/react-table.config.d.ts vendored Normal file
View File

@ -0,0 +1,120 @@
import {
UseColumnOrderInstanceProps,
UseColumnOrderState,
UseExpandedHooks,
UseExpandedInstanceProps,
UseExpandedOptions,
UseExpandedRowProps,
UseExpandedState,
UseFiltersColumnOptions,
UseFiltersColumnProps,
UseFiltersInstanceProps,
UseFiltersOptions,
UseFiltersState,
UseGlobalFiltersColumnOptions,
UseGlobalFiltersInstanceProps,
UseGlobalFiltersOptions,
UseGlobalFiltersState,
UseGroupByCellProps,
UseGroupByColumnOptions,
UseGroupByColumnProps,
UseGroupByHooks,
UseGroupByInstanceProps,
UseGroupByOptions,
UseGroupByRowProps,
UseGroupByState,
UsePaginationInstanceProps,
UsePaginationOptions,
UsePaginationState,
UseResizeColumnsColumnOptions,
UseResizeColumnsColumnProps,
UseResizeColumnsOptions,
UseResizeColumnsState,
UseRowSelectHooks,
UseRowSelectInstanceProps,
UseRowSelectOptions,
UseRowSelectRowProps,
UseRowSelectState,
UseRowStateCellProps,
UseRowStateInstanceProps,
UseRowStateOptions,
UseRowStateRowProps,
UseRowStateState,
UseSortByColumnOptions,
UseSortByColumnProps,
UseSortByHooks,
UseSortByInstanceProps,
UseSortByOptions,
UseSortByState
} from "react-table";
declare module "react-table" {
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
export interface TableOptions<D extends Record<string, unknown>>
extends UseExpandedOptions<D>,
UseFiltersOptions<D>,
UseGlobalFiltersOptions<D>,
UseGroupByOptions<D>,
UsePaginationOptions<D>,
UseResizeColumnsOptions<D>,
UseRowSelectOptions<D>,
UseRowStateOptions<D>,
UseSortByOptions<D>,
// note that having Record here allows you to add anything to the options, this matches the spirit of the
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
// feature set, this is a safe default.
Record<string, any> {}
export interface Hooks<D extends Record<string, unknown> = Record<string, unknown>>
extends UseExpandedHooks<D>,
UseGroupByHooks<D>,
UseRowSelectHooks<D>,
UseSortByHooks<D> {}
export interface TableInstance<D extends Record<string, unknown> = Record<string, unknown>>
extends UseColumnOrderInstanceProps<D>,
UseExpandedInstanceProps<D>,
UseFiltersInstanceProps<D>,
UseGlobalFiltersInstanceProps<D>,
UseGroupByInstanceProps<D>,
UsePaginationInstanceProps<D>,
UseRowSelectInstanceProps<D>,
UseRowStateInstanceProps<D>,
UseSortByInstanceProps<D> {}
export interface TableState<D extends Record<string, unknown> = Record<string, unknown>>
extends UseColumnOrderState<D>,
UseExpandedState<D>,
UseFiltersState<D>,
UseGlobalFiltersState<D>,
UseGroupByState<D>,
UsePaginationState<D>,
UseResizeColumnsState<D>,
UseRowSelectState<D>,
UseRowStateState<D>,
UseSortByState<D> {}
export interface ColumnInterface<D extends Record<string, unknown> = Record<string, unknown>>
extends UseFiltersColumnOptions<D>,
UseGlobalFiltersColumnOptions<D>,
UseGroupByColumnOptions<D>,
UseResizeColumnsColumnOptions<D>,
UseSortByColumnOptions<D> {}
export interface ColumnInstance<D extends Record<string, unknown> = Record<string, unknown>>
extends UseFiltersColumnProps<D>,
UseGroupByColumnProps<D>,
UseResizeColumnsColumnProps<D>,
UseSortByColumnProps<D> {}
export interface Cell<D extends Record<string, unknown> = Record<string, unknown>, V = any>
extends UseGroupByCellProps<D>,
UseRowStateCellProps<D> {}
export interface Row<D extends Record<string, unknown> = Record<string, unknown>>
extends UseExpandedRowProps<D>,
UseGroupByRowProps<D>,
UseRowSelectRowProps<D>,
UseRowStateRowProps<D> {}
}