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

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Jan 10, 2024
1 parent 04a44ba commit fb0e788
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/components/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
TableBody,
type TableProps,
TableHead,
LGTableDataType,
VirtualItem,
LeafyGreenTableRow,
} from "@leafygreen-ui/table";
Expand Down Expand Up @@ -49,13 +48,13 @@ declare module "@tanstack/table-core" {
}

type SpruceTableProps = {
className?: string;
"data-cy-row"?: string;
"data-cy-table"?: string;
emptyComponent?: React.ReactNode;
loading?: boolean;
/** estimated number of rows the table will have */
loadingRows?: number;
className?: string;
};

export const BaseTable = forwardRef(
Expand All @@ -74,6 +73,8 @@ export const BaseTable = forwardRef(
) => {
const { virtualRows } = table;
const { rows } = table.getRowModel();
const hasVirtualRows = virtualRows && virtualRows.length > 0;

return (
<>
<StyledTable
Expand Down Expand Up @@ -143,7 +144,16 @@ export const BaseTable = forwardRef(
numRows={loadingRows}
/>
)}
<RenderRows rows={rows} virtualRows={virtualRows} />
{hasVirtualRows
? virtualRows.map((vr) => {
const row = rows[vr.index];
return (
<RenderableRow row={row} key={row.id} virtualRow={vr} />
);
})
: rows.map((row) => (
<RenderableRow row={row} key={row.id} virtualRow={null} />
))}
</TableBody>
</StyledTable>
{!loading &&
Expand All @@ -154,34 +164,11 @@ export const BaseTable = forwardRef(
}
);

const RenderRows = <T extends LGRowData>({
rows,
virtualRows,
}: {
virtualRows?: VirtualItem[];
rows: LeafyGreenTableRow<LGTableDataType<T>>[];
}) => {
const hasVirtualRows = virtualRows && virtualRows.length > 0;
return (
<>
{!hasVirtualRows &&
rows.map((row) => (
<RenderableRow row={row} key={row.id} virtualRow={null} />
))}
{hasVirtualRows &&
virtualRows.map((vr) => {
const row = rows[vr.index];
return <RenderableRow row={row} key={row.id} virtualRow={vr} />;
})}
</>
);
};

const RenderableRow = <T extends LGRowData>({
row,
virtualRow,
}: {
row: LeafyGreenTableRow<LGTableDataType<T>>;
row: LeafyGreenTableRow<T>;
virtualRow: VirtualItem;
}) => (
<Row
Expand Down
3 changes: 3 additions & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export type DisplayTask = {
/** Distro models an environment configuration for a host. */
export type Distro = {
__typename?: "Distro";
adminOnly: Scalars["Boolean"]["output"];
aliases: Array<Scalars["String"]["output"]>;
arch: Arch;
authorizedKeysFile: Scalars["String"]["output"];
Expand Down Expand Up @@ -429,6 +430,8 @@ export type DistroInfo = {
};

export type DistroInput = {
/** TODO: require adminOnly field upon completion of DEVPROD-3533 */
adminOnly?: InputMaybe<Scalars["Boolean"]["input"]>;
aliases: Array<Scalars["String"]["input"]>;
arch: Arch;
authorizedKeysFile: Scalars["String"]["input"];
Expand Down

0 comments on commit fb0e788

Please sign in to comment.