Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Remove LG column functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Dec 7, 2023
1 parent b1e76b5 commit ac79cde
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 214 deletions.
2 changes: 1 addition & 1 deletion src/analytics/version/useVersionAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { VERSION } from "gql/queries";

type Action =
| { name: "Filter Tasks"; filterBy: string }
| { name: "Filter Tasks"; filterBy: string | string[] }
| {
name: "Sort Tasks Table";
sortBy:
Expand Down
37 changes: 20 additions & 17 deletions src/components/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import TableLoader from "./TableLoader";
declare module "@tanstack/table-core" {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface ColumnMeta<TData extends RowData, TValue> {
filterComponent?: (column: any) => JSX.Element;
search?: {
"data-cy"?: string;
placeholder?: string;
};
sortComponent?: (column: any) => JSX.Element;
treeSelect?: {
"data-cy"?: string;
// Configures whether or not the tree select should be filtered to only represent values found in the table.
// Note that this may not be very performant for large tables.
filterOptions?: boolean;
options: TreeDataEntry[];
};
// Overcome react-table's column width limitations
Expand Down Expand Up @@ -66,41 +67,43 @@ export const BaseTable = <T extends LGRowData>({
{table.getHeaderGroups().map((headerGroup) => (
<HeaderRow key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const { columnDef } = header.column;
const { columnDef } = header.column ?? {};
const { meta } = columnDef;
return (
<HeaderCell
key={header.id}
header={header}
style={
columnDef?.meta?.width && { width: columnDef?.meta?.width }
}
style={meta?.width && { width: columnDef?.meta?.width }}
>
{flexRender(columnDef.header, header.getContext())}
{columnDef?.meta?.sortComponent?.({
column: header.column,
})}
{columnDef?.meta?.filterComponent?.({
column: header.column,
})}
{header.column.getCanFilter() &&
(columnDef?.meta?.treeSelect ? (
(meta?.treeSelect ? (
<TableFilterPopover
data-cy={columnDef?.meta?.treeSelect?.["data-cy"]}
data-cy={meta.treeSelect?.["data-cy"]}
onConfirm={(value) =>
header.column.setFilterValue(value)
}
options={columnDef?.meta?.treeSelect?.options}
options={
meta.treeSelect?.filterOptions
? meta.treeSelect.options.filter(
({ value }) =>
!!header.column
.getFacetedUniqueValues()
.get(value)
)
: meta.treeSelect.options
}
value={
(header?.column?.getFilterValue() as string[]) ?? []
}
/>
) : (
<TableSearchPopover
data-cy={columnDef?.meta?.search?.["data-cy"]}
data-cy={meta?.search?.["data-cy"]}
onConfirm={(value) =>
header.column.setFilterValue(value)
}
placeholder={columnDef?.meta?.search?.placeholder}
placeholder={meta?.search?.placeholder}
value={
(header?.column?.getFilterValue() as string) ?? ""
}
Expand Down
119 changes: 0 additions & 119 deletions src/components/Table/LGFilters.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { useLeafyGreenTable } from "@leafygreen-ui/table";
import {
getFacetedUniqueValues,
getFilteredRowModel,
filterFns,
} from "@tanstack/react-table";
import Icon from "components/Icon";
import { SettingsCard, SettingsCardTitle } from "components/SettingsCard";
import { ShortenedRouterLink } from "components/styles";
import { BaseTable } from "components/Table/BaseTable";
import { getColumnTreeSelectFilterProps } from "components/Table/LGFilters";
import { getSubscriberText } from "constants/subscription";
import { size } from "constants/tokens";
import {
Expand Down Expand Up @@ -77,15 +77,21 @@ export const UserSubscriptions: React.FC<{}> = () => {
() => [
{
accessorKey: "resourceType",
id: "resourceType",
cell: ({ getValue }) => {
const resourceType = getValue();
return resourceTypeToCopy[resourceType] ?? resourceType;
},
enableColumnFilter: true,
filterFn: filterFns.arrIncludesSome,
header: "Type",
...getColumnTreeSelectFilterProps({
"data-cy": "status-filter-popover",
tData: resourceTypeTreeData,
}),
meta: {
treeSelect: {
"data-cy": "status-filter-popover",
filterOptions: true,
options: resourceTypeTreeData,
},
},
},
{
header: "ID",
Expand Down Expand Up @@ -113,10 +119,15 @@ export const UserSubscriptions: React.FC<{}> = () => {
{
accessorKey: "trigger",
header: "Event",
...getColumnTreeSelectFilterProps({
"data-cy": "trigger-filter-popover",
tData: triggerTreeData,
}),
enableColumnFilter: true,
filterFn: filterFns.arrIncludesSome,
meta: {
treeSelect: {
"data-cy": "trigger-filter-popover",
filterOptions: true,
options: triggerTreeData,
},
},
cell: ({ getValue }) => {
const trigger = getValue();
return triggerToCopy[trigger] ?? trigger;
Expand Down Expand Up @@ -149,6 +160,9 @@ export const UserSubscriptions: React.FC<{}> = () => {
columns,
containerRef: tableContainerRef,
data: subscriptions ?? [],
defaultColumn: {
enableColumnFilter: false,
},
getFacetedUniqueValues: getFacetedUniqueValues(),
getFilteredRowModel: getFilteredRowModel(),
hasSelectableRows: true,
Expand Down
Loading

0 comments on commit ac79cde

Please sign in to comment.