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

Add table and column loading options #473

Merged
merged 66 commits into from
Jan 27, 2017
Merged

Conversation

michael-yx-wu
Copy link
Contributor

@michael-yx-wu michael-yx-wu commented Jan 12, 2017

Checklist

  • Include tests
  • Update documentation

Changes proposed in this pull request:

Make it easier to set the loading state on common sections of the table such as the headers and body by specifying loading options on Table and Column, components higher up in the hierarchy. Only exposing a loading prop on cell components results in needing to define a cellRenderer function just to conditionally set the loading state.

When loadingOptions are specified on both Table and Column and loading is also specified on Cell, the lowest component takes precedence. This allows users to manually make changes to the overall loading appearance of the table.

In the following example,

private render() {
  <Table loadingOptions={[ "cells", "column-header" ]}>
    <Column loadingOptions={[ "cells" ]} />
    <Column />
    <Column />
  </Table>
}

private cellRenderer = (row: number, col: number) => {
  return <Cell loading={row === 0 && col === 0} />;
}

All column / row headers and body cells show the loadings state except:

  • col1 header cell
  • all col1 cells except the first one

@blueprint-bot
Copy link

Implement loading behavior in headers and body

Preview: docs | table
Coverage: core | datetime

@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from 3ef3811 to 9b77cbe Compare January 13, 2017 00:05
@blueprint-bot
Copy link

Set default column loading options

Preview: docs | table
Coverage: core | datetime

@blueprint-bot
Copy link

Merge branch 'mw/table-header-loading' into mw/table-loading-options

Preview: docs | table
Coverage: core | datetime

@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from e668650 to f0b3e5e Compare January 16, 2017 20:32
@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from 32be46e to de72ce6 Compare January 27, 2017 07:17
return listOfSubsets;
}

function testLoadingOptionOverrides(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test describes the expected loading option override behavior for all types of cells. is it clear that this is the case, or should i leave a comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

comments are always appreciated, esp in a file with so much complex code.

i suspect there are some nice refactors that could be done to clean this up, but i recognize that you're basically out of time 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.

i refactored a bit before i put this commit up. i think this is probably easiest to read version of this function.

The expect cell loading function in `cellTestUtils.ts` now makes a more
complete set of assertions given the expected loading state of a cell.

This commit also introduces an exhaustive set tests for all possible
loading option combinations.
@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from de72ce6 to 2c9ae40 Compare January 27, 2017 07:24
@blueprint-bot
Copy link

Add exhaustive list of loading option tests

Preview: docs | table
Coverage: core | datetime

return listOfSubsets;
}

function testLoadingOptionOverrides(
Copy link
Contributor

Choose a reason for hiding this comment

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

comments are always appreciated, esp in a file with so much complex code.

i suspect there are some nice refactors that could be done to clean this up, but i recognize that you're basically out of time here :(

loading = cellLoading;
} else {
loading = this.hasLoadingOption(columnProps.loadingOptions, ColumnLoadingOption.CELLS);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i tend to prefer ternary ifs for this pattern so you can define the variable as a const and immediately assign the correct value.

const loading = (cellLoading == null)
    ? this.hasLoadingOption(columnProps.loadingOptions, ColumnLoadingOption.CELLS)
    : cellLoading; 

*/
allTableLoadingOptions.forEach((tableLoadingOptions: TableLoadingOption[]) => {
allColumnLoadingOptions.forEach((columnLoadingOptions: ColumnLoadingOption[]) => {
allRowLoadingOptions.forEach((rowLoadingOptions: RowLoadingOption[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't need types on the params here. can they not be inferred from forEach?

allColumnLoadingOptions.forEach((columnLoadingOptions: ColumnLoadingOption[]) => {
allRowLoadingOptions.forEach((rowLoadingOptions: RowLoadingOption[]) => {
it(`table: ${tableLoadingOptions}, column: ${columnLoadingOptions}, row: ${rowLoadingOptions}`, () => {
const isCellLoading = (index: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

pull this function out (define at root level) cuz it's essentially static.

renderColumnHeader={renderColumnHeader}
/>
</Table>,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

could even define a quick helper component <TableLoadingOptionsTester> that does this composition, so it doesn't have to be redefined in each test run.

cellType: CellType,
cellLoading: (index: number) => boolean,
columnLoadingOptions: ColumnLoadingOption[],
tableLoadingOptions: TableLoadingOption[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

put closing paren in line with open:

function name(
   args,
   ...,
) {

columnLoadingOptions: ColumnLoadingOption[],
tableLoadingOptions: TableLoadingOption[]) {

// tslint:disable-next-line:prefer-for-of
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't need to disable this? seems like valid usage.

expectCellLoading(columnHeaders.item(i), CellType.COLUMN_HEADER);
}

const rowHeaders = tableHarness.element.querySelectorAll(".bp-table-row-headers .bp-table-header");
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use .queryAll() instead of querySelectorAll() (from dom4 polyfill) which returns an Array, then simply do rowHeaders.forEach(...)

expect(headerNameText.children.length).to.equal(1);
} else {
expect(cell.children.length).to.equal(1);
expect(cell.querySelector(`.${Classes.SKELETON}`)).to.not.be.null;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is identical to line 24

: cell.querySelector(".bp-table-row-name");
expect(headerNameText).to.not.be.null;
expect(headerNameText.textContent).to.equal("");
expect(headerNameText.children.length).to.equal(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the one child? .pt-skeleton? can you make that explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a test that the child is a skeleton

@giladgray giladgray added the P0 label Jan 27, 2017
@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from 7c363fa to 7b97042 Compare January 27, 2017 20:25
@blueprint-bot
Copy link

Be explicit about single child loading condition

Preview: docs | table
Coverage: core | datetime

@blueprint-bot
Copy link

Include undefined loading options

Preview: docs | table
Coverage: core | datetime

} else {
expect(cell.children.length).to.equal(1);
expect(cell.querySelector(`.${Classes.SKELETON}`)).to.not.be.null;
expect(cell.children[0].classList.contains(Classes.SKELETON)).to.not.be.null;
Copy link
Contributor

Choose a reason for hiding this comment

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

wait why back to this format?
did my comments lead us in a circle? 😶

you're testing too much here and it's not helping.
it should be sufficient to assert that a selector exists, for example:
.bp-table-row-name .pt-skeleton

Copy link
Contributor Author

@michael-yx-wu michael-yx-wu Jan 27, 2017

Choose a reason for hiding this comment

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

i wanted to be explicit about where the skeleton exists, hence the single child test. it's nested further down in header cells vs. normal cells

Copy link
Contributor Author

Choose a reason for hiding this comment

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

L31 and L34 are slightly different in this sense.

@michael-yx-wu michael-yx-wu force-pushed the mw/table-loading-options branch from 04b97e6 to dd737f8 Compare January 27, 2017 21:27
@blueprint-bot
Copy link

Include undefined loading options

Preview: docs | table
Coverage: core | datetime

@giladgray
Copy link
Contributor

😅 let's do this!

@blueprint-bot
Copy link

Stop relying on dom structure in cell test

Preview: docs | table
Coverage: core | datetime

@giladgray giladgray merged commit 5c7417b into master Jan 27, 2017
@giladgray giladgray deleted the mw/table-loading-options branch January 27, 2017 21:55
@giladgray giladgray mentioned this pull request Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants