Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-column sort to Insights > Operations table #6388

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-students-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hive': minor
---

Add multi-column sort to Insights > Operations table
2 changes: 1 addition & 1 deletion packages/web/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@stripe/stripe-js": "5.5.0",
"@tanstack/react-query": "5.63.0",
"@tanstack/react-router": "1.34.9",
"@tanstack/react-table": "8.17.3",
"@tanstack/react-table": "8.20.6",
"@tanstack/router-devtools": "1.34.9",
"@theguild/editor": "1.2.5",
"@trpc/client": "10.45.2",
Expand Down
14 changes: 3 additions & 11 deletions packages/web/app/src/components/target/insights/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import {
getCoreRowModel,
getPaginationRowModel,
getSortedRowModel,
OnChangeFn,
PaginationState,
SortingState,
useReactTable,
} from '@tanstack/react-table';
import { OperationsFallback } from './Fallback';
Expand Down Expand Up @@ -169,8 +167,6 @@ type SetPaginationFn = (updater: SetStateAction<PaginationState>) => void;

function OperationsTable({
operations,
sorting,
setSorting,
pagination,
setPagination,
className,
Expand All @@ -182,8 +178,6 @@ function OperationsTable({
operations: Operation[];
pagination: PaginationState;
setPagination: SetPaginationFn;
sorting: SortingState;
setSorting: OnChangeFn<SortingState>;
className?: string;
organizationSlug: string;
projectSlug: string;
Expand All @@ -197,10 +191,8 @@ function OperationsTable({
columns,
data: operations,
state: {
sorting,
pagination,
},
onSortingChange: setSorting,
onPaginationChange: setPagination,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
Expand All @@ -221,6 +213,8 @@ function OperationsTable({

const { headers } = tableInstance.getHeaderGroups()[0];

const sortedColumnsById = tableInstance.getState().sorting.map(s => s.id);

return (
<div className={clsx('rounded-md border border-gray-800 bg-gray-900/50 p-5', className)}>
<Section.Title>Operations</Section.Title>
Expand All @@ -240,6 +234,7 @@ function OperationsTable({
<Sortable
sortOrder={header.column.getIsSorted()}
onClick={header.column.getToggleSortingHandler()}
otherColumnSorted={sortedColumnsById.some(id => id !== header.id)}
>
{name}
</Sortable>
Expand Down Expand Up @@ -395,7 +390,6 @@ function OperationsTableContainer({
}, [operationStats?.operations.nodes, operationsFilter]);

const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 20 });
const [sorting, setSorting] = useState<SortingState>([]);

const safeSetPagination = useCallback<SetPaginationFn>(
state => {
Expand All @@ -422,8 +416,6 @@ function OperationsTableContainer({
className={className}
pagination={pagination}
setPagination={safeSetPagination}
sorting={sorting}
setSorting={setSorting}
organizationSlug={organizationSlug}
projectSlug={projectSlug}
targetSlug={targetSlug}
Expand Down
10 changes: 9 additions & 1 deletion packages/web/app/src/components/v2/sortable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import { SortDirection } from '@tanstack/react-table';
export function Sortable({
children,
sortOrder,
otherColumnSorted,
onClick,
}: {
children: ReactNode;
sortOrder: SortDirection | false;
/**
* Whether another column is sorted in addition to this one.
* It's used to show a different tooltip when sorting by multiple columns.
*/
otherColumnSorted?: boolean;
onClick: ComponentProps<'button'>['onClick'];
}): ReactElement {
const tooltipText =
sortOrder === false
? 'Click to sort descending'
? 'Click to sort descending' + otherColumnSorted
? ' (hold shift to sort by multiple columns)'
: ''
: {
asc: 'Click to cancel sorting',
desc: 'Click to sort ascending',
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading