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

[Table] Add resizeRowsByTallestCells to handle multi-column resize #1075

Closed
wants to merge 4 commits into from
Closed

[Table] Add resizeRowsByTallestCells to handle multi-column resize #1075

wants to merge 4 commits into from

Conversation

philcchen
Copy link
Contributor

Fixes #1070

Checklist

  • Include tests

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

table-resize

@philcchen philcchen changed the title Add resizeRowsByTallestCells to handle multi-column resize [Table] Add resizeRowsByTallestCells to handle multi-column resize May 10, 2017
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;
Copy link
Contributor Author

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

const tallestByColumns = columnIndices.map((col) => locator.getTallestVisibleCellInColumn(col));
tallest = Math.max(...tallestByColumns);
} else {
// Use viewport columns
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

* 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[]) {
Copy link
Contributor

@giladgray giladgray May 10, 2017

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);

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@cmslewis cmslewis left a 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!

* 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[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -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.
Copy link
Contributor

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.
 */

* 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[]) {
Copy link
Contributor

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.

const tallestByColumns = columnIndices.map((col) => locator.getTallestVisibleCellInColumn(col));
tallest = Math.max(...tallestByColumns);
} else {
// Use viewport columns
Copy link
Contributor

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

const rowHeights = Array(this.state.rowHeights.length).fill(tallest);
this.invalidateGrid();
this.setState({ rowHeights });
}

public resizeRowsByTallestCell(columnIndex: number) {
Copy link
Contributor

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.

Copy link
Contributor

@cmslewis cmslewis left a 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.

@philcchen
Copy link
Contributor Author

Unify api calls for resizing and improve comments for accuracy

Preview: documentation | landing | table
Coverage: core | datetime

@philcchen
Copy link
Contributor Author

Re-add removed line

Preview: documentation | landing | table
Coverage: core | datetime

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@philcchen
Copy link
Contributor Author

Update comment for clarity

Preview: documentation | landing | table
Coverage: core | datetime

expect(table.state.rowHeights[0]).to.equal(MAX_HEIGHT);

// Resize by second column via array
table.resizeRowsByTallestCells([1]);
table.resizeRowsByTallestCell([1]);
Copy link
Contributor

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)

Copy link
Contributor

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 👍

@adidahiya
Copy link
Contributor

none of the tables load in the table preview for me

@philcchen
Copy link
Contributor Author

@adidahiya yeah, not sure, maybe cause I'm on a fork?

@adidahiya
Copy link
Contributor

:( 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.

Copy link
Contributor

@cmslewis cmslewis left a 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. 👍

@philcchen
Copy link
Contributor Author

Closed in favor of #1078

@philcchen philcchen closed this May 11, 2017
@philcchen philcchen deleted the pchen/multi-column-resize branch May 11, 2017 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants