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

Custom table elemets #141

Merged
merged 9 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
45 changes: 9 additions & 36 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build::ts": "tsc -p ./tsconfig.json",
"build::babel": "babel ./src --extensions .tsx,.ts,.js --out-dir ./dist",
"clean": "rm -rf dist && mkdir dist",
"declarations": "ttsc --emitDeclarationOnly",
"declarations": "tsc --emitDeclarationOnly",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have link/docs related to what's changing here just for my education?

Copy link
Member

@justincorrigible justincorrigible Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the TTypescript to apply absolute path handling in the "build" script, which OG TS doesn't do.
Removing this dependency would mean we cannot use absolute paths in UIKit.

ttsc is just ttypescript's tsc, which applies the patches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to use an alternative approach to this, in Arranger I prepatch TS itself, rather than using TTS.
That may solve whatever issues @ciaranschutte is finding in his local env.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, and from their Github, it's deprecated. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, that bit I hadn't realised. we'll have to update UIKit to account for that (different scope, unless this is a blocker here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting back in ttsc for build

"watch": "npm run clean && npm run build::assets && (npm run build::babel -- --watch --source-maps=inline & npm run declarations -- --watch)",
"build": "npm run clean && npm run build::assets && npm run declarations && npm run build::babel",
"publish-uikit": "cd dist && npm publish --access public"
Expand Down Expand Up @@ -87,8 +87,7 @@
"react-dom": "^18.2.0",
"react-json-view": "^1.21.3",
"ts-node-dev": "^1.1.8",
"ttypescript": "^1.5.13",
"typescript": "<4.8",
"typescript": "4.8",
"webpack": "^5.75.0"
},
"prettier": {
Expand Down
103 changes: 62 additions & 41 deletions src/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ export const Table = <TData extends object>({

return (
<TableContainer className={className}>
<TableContainerInner withFilters={withFilters} withTabs={withTabs}>
<TableContainerInner
withFilters={withFilters}
withTabs={withTabs}
withSideBorders={withSideBorders}
>
<TableStyled withSideBorders={withSideBorders}>
{withHeaders && (
<TableHead>
Expand All @@ -131,48 +135,57 @@ export const Table = <TData extends object>({
{headerGroup.headers.map((header) => {
const canSort = enableSorting && header.column.getCanSort();
const isCustomHeader = header.column.columnDef.meta?.customHeader;
const tableHeaderProps = {
key: header.id,
colSpan: header.colSpan,
width: header.getSize(),
sorted: header.column.getIsSorted(),
canSort,
};

const headerContents = header.isPlaceholder
? null
: flexRender(header.column.columnDef.header, header.getContext());
: flexRender(header.column.columnDef.header, {
...tableHeaderProps,
...header.getContext(),
});

const {
activeTab = '',
handleTabs = () => {},
tabs = [],
} = header.column.columnDef.meta?.columnTabs || {};

return (
<TableHeader
key={header.id}
colSpan={header.colSpan}
width={header.getSize()}
sorted={header.column.getIsSorted()}
canSort={canSort}
>
{!!tabs.length && (
<TableTabs activeTab={activeTab} handleTabs={handleTabs} tabs={tabs} />
)}
<SortButton
canSort={canSort}
onClick={header.column.getToggleSortingHandler()}
>
{isCustomHeader ? (
headerContents
) : (
<TableHeaderWrapper>{headerContents}</TableHeaderWrapper>
if (isCustomHeader) {
return headerContents;
} else {
return (
<TableHeader {...tableHeaderProps}>
{!!tabs.length && (
<TableTabs activeTab={activeTab} handleTabs={handleTabs} tabs={tabs} />
)}
<SortButton
canSort={canSort}
onClick={header.column.getToggleSortingHandler()}
>
{isCustomHeader ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this ever be true? Asking b/c of return on line 160

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, looks like this will always be falsey.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow this thread, but we were talking about that meta property in a different PR, coincidentally.
https://github.com/icgc-argo/rdpc-ui/pull/147/files#diff-a68ddbc20eef704019906015d66875a95925225e4642a3a4b630cb9b6399c13dR740

That line there is the one that would give a truthy value to isCustomHeader here (per 133/137).

What am I missing for what you guys are agreeing on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah! I see it now! yep!! copy pasta

headerContents
) : (
<TableHeaderWrapper>{headerContents}</TableHeaderWrapper>
)}
</SortButton>
{header.column.getCanResize() && (
<Resizer
onMouseDown={header.getResizeHandler()}
onTouchStart={header.getResizeHandler()}
className={`resizer ${
header.column.getIsResizing() ? 'isResizing' : ''
}`}
/>
)}
</SortButton>
{header.column.getCanResize() && (
<Resizer
onMouseDown={header.getResizeHandler()}
onTouchStart={header.getResizeHandler()}
className={`resizer ${
header.column.getIsResizing() ? 'isResizing' : ''
}`}
/>
)}
</TableHeader>
);
</TableHeader>
);
}
})}
</TableRow>
))}
Expand All @@ -190,14 +203,22 @@ export const Table = <TData extends object>({
>
{row.getVisibleCells().map((cell) => {
const isCustomCell = cell.column.columnDef.meta?.customCell;
const cellContents = flexRender(cell.column.columnDef.cell, cell.getContext());
return (
<TableCell key={cell.id} width={cell.column.getSize()}>
{isCustomCell ? (
cellContents
) : (
<TableCellWrapper>{cellContents}</TableCellWrapper>
)}

const tableCellProps = {
key: cell.id,
width: cell.column.getSize(),
};

const cellContents = flexRender(cell.column.columnDef.cell, {
...tableCellProps,
...cell.getContext(),
});

return isCustomCell ? (
cellContents
) : (
<TableCell {...tableCellProps}>
<TableCellWrapper>{cellContents}</TableCellWrapper>
</TableCell>
);
})}
Expand Down
27 changes: 26 additions & 1 deletion src/Table/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,40 @@ export const TableContainer = styled(TableContainerComp, {
background: ${COLORS.BACKGROUND};
`;

/*
* stop cells from having overlapping border if we have side borders on our container
*/
const sideBordersStyle = css`
border-right: 1px solid ${colors.grey_2};
border-left: 1px solid ${colors.grey_2};

table,
tr td:first-of-type,
tr th:first-of-type {
border-left: none;
}
table,
tr td:last-of-type,
tr th:last-of-type {
border-right: none;
}
`;

const TableContainerInnerComp = (
props: React.PropsWithChildren<{ className?: string; withFilters?: boolean; withTabs?: boolean }>,
props: React.PropsWithChildren<{
className?: string;
withFilters?: boolean;
withTabs?: boolean;
withSideBorders?: boolean;
}>,
) => <div {...props} className={clsx(TABLE_CLASSES.TABLE_CONTAINER_INNER, props.className)} />;
export const TableContainerInner = styled(TableContainerInnerComp, {
shouldForwardProp: (prop) => isPropValid(prop),
})`
width: 100%;
max-width: 100%;
overflow-x: auto;
${(props) => props.withSideBorders && sideBordersStyle};
${(props) =>
props.withFilters &&
`
Expand Down
Loading