Skip to content

Commit

Permalink
INN 2967 Create expanded rows layout (#1305)
Browse files Browse the repository at this point in the history
* Add expanded option

* Disable sorting for now

* Update type
  • Loading branch information
anafilipadealmeida committed Apr 29, 2024
1 parent 6a97f2a commit 937b889
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo } from 'react';
import { Fragment, useMemo } from 'react';
import { FunctionRunStatusIcon } from '@inngest/components/FunctionRunStatusIcon';
import { Skeleton } from '@inngest/components/Skeleton';
import { IDCell, StatusCell, TextCell, TimeCell } from '@inngest/components/Table';
Expand All @@ -11,8 +11,10 @@ import {
createColumnHelper,
flexRender,
getCoreRowModel,
getExpandedRowModel,
useReactTable,
type OnChangeFn,
type Row,
type SortingState,
} from '@tanstack/react-table';

Expand All @@ -29,9 +31,18 @@ type RunsTableProps = {
sorting?: SortingState;
setSorting?: OnChangeFn<SortingState>;
isLoading?: boolean;
renderSubComponent: (props: { id: string }) => React.ReactElement;
getRowCanExpand: (row: Row<Run>) => boolean;
};

export default function RunsTable({ data = [], isLoading, sorting, setSorting }: RunsTableProps) {
export default function RunsTable({
data = [],
isLoading,
sorting,
setSorting,
getRowCanExpand,
renderSubComponent,
}: RunsTableProps) {
// Render 8 empty lines for skeletons when data is loading
const tableData = useMemo(() => (isLoading ? Array(8).fill({}) : data), [isLoading, data]);

Expand All @@ -50,6 +61,8 @@ export default function RunsTable({ data = [], isLoading, sorting, setSorting }:
data: tableData,
columns: tableColumns,
getCoreRowModel: getCoreRowModel(),
getExpandedRowModel: getExpandedRowModel(),
getRowCanExpand,
manualSorting: true,
onSortingChange: setSorting,
state: {
Expand All @@ -72,7 +85,7 @@ export default function RunsTable({ data = [], isLoading, sorting, setSorting }:
{headerGroup.headers.map((header) => (
<th
key={header.id}
className={cn(tableColumnStyles, 'text-sm font-semibold text-slate-500 ')}
className={cn(tableColumnStyles, 'text-left text-sm font-semibold text-slate-500')}
>
{header.isPlaceholder ? null : (
<div
Expand Down Expand Up @@ -105,13 +118,26 @@ export default function RunsTable({ data = [], isLoading, sorting, setSorting }:
)}
{!isEmpty &&
table.getRowModel().rows.map((row) => (
<tr key={row.id} className="h-12">
{row.getVisibleCells().map((cell) => (
<td className={tableColumnStyles} key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
<Fragment key={row.id}>
<tr
key={row.id}
className="h-12 cursor-pointer hover:bg-sky-50"
onClick={row.getToggleExpandedHandler()}
>
{row.getVisibleCells().map((cell) => (
<td className={tableColumnStyles} key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
{row.getIsExpanded() && (
<tr>
<td colSpan={row.getVisibleCells().length}>
{renderSubComponent({ id: row.id })}
</td>
</tr>
)}
</Fragment>
))}
</tbody>
<tfoot>
Expand Down Expand Up @@ -147,6 +173,7 @@ const columns = [
);
},
header: 'Status',
enableSorting: false,
}),
columnHelper.accessor('id', {
cell: (info) => {
Expand All @@ -159,6 +186,7 @@ const columns = [
);
},
header: 'Run ID',
enableSorting: false,
}),
columnHelper.accessor('queuedAt', {
cell: (info) => {
Expand All @@ -173,6 +201,7 @@ const columns = [
);
},
header: 'Queued At',
enableSorting: false,
}),
columnHelper.accessor('endedAt', {
cell: (info) => {
Expand All @@ -187,6 +216,7 @@ const columns = [
);
},
header: 'Ended At',
enableSorting: false,
}),
columnHelper.accessor('durationMS', {
cell: (info) => {
Expand All @@ -199,5 +229,6 @@ const columns = [
);
},
header: 'Duration',
enableSorting: false,
}),
];
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const GetRunsDocument = graphql(`
}
`);

const renderSubComponent = ({ id }: { id: string }) => {
/* TODO: Render the timeline instead */
return <p>Subrow {id}</p>;
};

export default function RunsPage() {
const [filteredStatus, setFilteredStatus, removeFilteredStatus] =
useStringArraySearchParam('filterStatus');
Expand Down Expand Up @@ -75,8 +80,13 @@ export default function RunsPage() {
{/* TODO: wire button */}
<Button label="Refresh" appearance="text" btnAction={refetch} icon={<RiLoopLeftLine />} />
</div>
{/* @ts-ignore */}
<RunsTable data={runs} isLoading={fetchingRuns} />
<RunsTable
//@ts-ignore
data={runs}
isLoading={fetchingRuns}
renderSubComponent={renderSubComponent}
getRowCanExpand={() => true}
/>
</main>
);
}

0 comments on commit 937b889

Please sign in to comment.