-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Table] Add resizeRowsByTallestCells to handle multi-column resize #1075
Conversation
it("Gets and sets the tallest cell height in the table", () => { | ||
const renderCell = () => <Cell wrapText={true}>my cell value with lots and lots of words</Cell>; | ||
it("Gets and sets the tallest cell by columns correctly", () => { | ||
const DEFAULT_RESIZE_HEIGHT = 30; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think DEFAULT_RESIZE_HEIGHT = 30
stems from the fact that the cell header height is 30; so it ends up resizing all of the cell row heights to being 30 (even though it doesn't need to). This is true even without this commit
packages/table/src/table.tsx
Outdated
const tallestByColumns = columnIndices.map((col) => locator.getTallestVisibleCellInColumn(col)); | ||
tallest = Math.max(...tallestByColumns); | ||
} else { | ||
// Use viewport columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly worried that people will think it applies to everything if you leave this blank... but probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could create a separate, explicit method if that's preferable, since the usage might not be obvious; don't have strong opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a slightly more detailed comment here. // Consider all columns currently in view
packages/table/src/table.tsx
Outdated
* Resize rows based on a given set of column indices. | ||
* If no indices are provided, default to using the columns that are currently in the viewport. | ||
*/ | ||
public resizeRowsByTallestCells(columnIndices?: number[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about one method to rule them all:
public resizeRowsByTallestCells(...columnIndices: number[]) { }
resizeRowsByTallestCells(1);
resizeRowsByTallestCells(1, 2, 3);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a limit to the number of args you can provide to a function. better to leave this as an array. some people have tables that are 10,000s cols wide. if you really want a single function then you can overload it and do some runtime type checking on the argument but I think this is fine as-is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok that's fair i suppose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, never thought about that before. TIL http://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought: I don't think this function is named quite correctly as is; no matter how many column indices you provide, you still only care about one "tallest cell" amongst all of them, right?
Is resizeRowsByTallestCell(columnIndices: number | number[])
out of the question? Then we could just follow a different code path if Arrays.isArray(columnIndices) === true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am inclined to agree with @cmslewis above. the plural felt weird to me to begin with, and now it's clear that it's not even semantically correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that suggestion @cmslewis with respect to the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts about API design and comment language. Excited to get this in!
packages/table/src/table.tsx
Outdated
* Resize rows based on a given set of column indices. | ||
* If no indices are provided, default to using the columns that are currently in the viewport. | ||
*/ | ||
public resizeRowsByTallestCells(columnIndices?: number[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, never thought about that before. TIL http://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept
packages/table/src/table.tsx
Outdated
@@ -489,15 +489,34 @@ export class Table extends AbstractComponent<ITableProps, ITableState> { | |||
); | |||
} | |||
|
|||
public resizeRowsByTallestCell(columnIndex: number) { | |||
/** | |||
* Resize rows based on a given set of column indices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for a slightly more precise description here. Something like:
/**
* Resize all rows in the table to the height of the tallest visible cell in the specified columns.
* If no indices are provided, default to using the tallest cell from all columns currently in view.
*/
packages/table/src/table.tsx
Outdated
* Resize rows based on a given set of column indices. | ||
* If no indices are provided, default to using the columns that are currently in the viewport. | ||
*/ | ||
public resizeRowsByTallestCells(columnIndices?: number[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought: I don't think this function is named quite correctly as is; no matter how many column indices you provide, you still only care about one "tallest cell" amongst all of them, right?
Is resizeRowsByTallestCell(columnIndices: number | number[])
out of the question? Then we could just follow a different code path if Arrays.isArray(columnIndices) === true
.
packages/table/src/table.tsx
Outdated
const tallestByColumns = columnIndices.map((col) => locator.getTallestVisibleCellInColumn(col)); | ||
tallest = Math.max(...tallestByColumns); | ||
} else { | ||
// Use viewport columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a slightly more detailed comment here. // Consider all columns currently in view
packages/table/src/table.tsx
Outdated
const rowHeights = Array(this.state.rowHeights.length).fill(tallest); | ||
this.invalidateGrid(); | ||
this.setState({ rowHeights }); | ||
} | ||
|
||
public resizeRowsByTallestCell(columnIndex: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under my proposal above, we wouldn't need this additional function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes to make sure we discuss before merging.
Unify api calls for resizing and improve comments for accuracyPreview: documentation | landing | table |
Re-add removed linePreview: documentation | landing | table |
packages/table/src/table.tsx
Outdated
public resizeRowsByTallestCell(columnIndex: number) { | ||
/** | ||
* Resize all rows in the table to the height of the tallest visible cell in the specified columns. | ||
* If no indices are provided, default to using the tallest cell from all columns currently in view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake: do we need to clarify "tallest visible cell" in this sentence too, or is it implicitly clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "in view" satisfies that constraint, but to y'all. Happy to make the change if it's more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change to default to using the tallest visible cell from all columns in view
? That way it doesn't really get any longer.
Update comment for clarityPreview: documentation | landing | table |
packages/table/test/tableTests.tsx
Outdated
expect(table.state.rowHeights[0]).to.equal(MAX_HEIGHT); | ||
|
||
// Resize by second column via array | ||
table.resizeRowsByTallestCells([1]); | ||
table.resizeRowsByTallestCell([1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove brackets here to test non-array syntax? (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm i see the lines above now 👍
none of the tables load in the table preview for me |
@adidahiya yeah, not sure, maybe cause I'm on a fork? |
:( sad times. I dunno if that's the cause but I gave you write access anyway so you can try it out in this repo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those changes. 👍
Closed in favor of #1078 |
Fixes #1070
Checklist
Changes proposed in this pull request:
Add a method called
resizeRowsByTallestCells
that takes in an array of column indices to resize by a set of columns. If no array is provided, the method uses the columns in the viewport.Screenshot