Skip to content

Conversation

@williaster
Copy link
Contributor

@williaster williaster commented Apr 30, 2020

to: @milesj @stefhatcher @hayes @alecklandgraf
cc @schillerk

Description

This PR

  • adds a new row size to DataTable: xLarge
  • improves the rowHeight type from string to a union of possible string
  • tries to fix some conditions which lead to infinite re-renders from forceUpdate calls in componentDidUpdate

Motivation and Context

I've been trying to upgrade to lunar v3 and some of our tables are pretty broken, especially for dynamic row height. Adding an additional fixed row height will alleviate some of these issues for us, and I'm hoping the forceUpdate logic may help. I'm not sure if there have been regressions, but it's pretty easy to generate a stack trace in the storybook now. Go here, expand the row, then sort a column 😱

I couldn't think of a great way to remove the force updates, but I tried to clean it up a bit. You can still get the stack trace from resizing the window many times, unfortunately the AutoSizer doesn't support a debounce property 😢

Testing

  • CI
  • functional
    • xLarge row height renders as expected
    • expanding a row + sorting no longer gives a stack trace

Screenshots

xLarge (no story changes)
image

Checklist

  • My code follows the style guide of this project.
  • I have updated or added documentation accordingly.
  • I have read the CONTRIBUTING document.

@airbnb-bot
Copy link
Collaborator

Size Changes

Package Diff ESM Prev ESM CJS Prev CJS
core +0.0% 562.7 KB 562.57 KB 704.52 KB 704.38 KB

Compared to master. File sizes are unminified and ungzipped.

View raw build stats

Previous (master)

{
  "apollo": {
    "esm": 10832,
    "lib": 14147
  },
  "app-shell": {
    "esm": 12906,
    "lib": 19874
  },
  "composer": {
    "esm": 68247,
    "lib": 101805
  },
  "core": {
    "esm": 576067,
    "lib": 721289
  },
  "forms": {
    "esm": 36180,
    "lib": 48408
  },
  "icons": {
    "esm": 156355,
    "lib": 205626
  },
  "layouts": {
    "esm": 15298,
    "lib": 20770
  },
  "metrics": {
    "esm": 5467,
    "lib": 7729
  },
  "test-utils": {
    "esm": 4279,
    "lib": 5937
  }
}

Current

{
  "apollo": {
    "esm": 10832,
    "lib": 14147
  },
  "app-shell": {
    "esm": 12906,
    "lib": 19874
  },
  "composer": {
    "esm": 68247,
    "lib": 101805
  },
  "core": {
    "esm": 576205,
    "lib": 721427
  },
  "forms": {
    "esm": 36180,
    "lib": 48408
  },
  "icons": {
    "esm": 156355,
    "lib": 205626
  },
  "layouts": {
    "esm": 15298,
    "lib": 20770
  },
  "metrics": {
    "esm": 5467,
    "lib": 7729
  },
  "test-utils": {
    "esm": 4279,
    "lib": 5937
  }
}

const { sortBy, sortDirection } = this.state;
const dimensionsChanged = width !== prevProps.width || height !== prevProps.height;
const sortChanged =
sortBy !== prevState.sortBy ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already invoke this.cache.clearAll(); when updating sortBy or sortByDirection, so this was doing a double update

@williaster williaster force-pushed the chris--datatable-timeout-n-xlarge branch from 5c74d88 to 1376e36 Compare May 1, 2020 00:13

type HeightMap = {
[key: string]: number;
[key in RowHeightOptions]: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@stefhatcher stefhatcher changed the title new(DataTable): Add xLarge row size, fix forceUpdate logic new(DataTable): Add xLarge row size. Fix forceUpdate logic. May 1, 2020
@stefhatcher stefhatcher merged commit ebab32b into master May 1, 2020
@stefhatcher stefhatcher deleted the chris--datatable-timeout-n-xlarge branch May 1, 2020 19:35
if (dynamicRowHeight) {
// We need to make sure the cache is cleared before React tries to re-render.
window.setTimeout(() => {
if (this.timeoutId) window.clearTimeout(this.timeoutId);
Copy link
Contributor

Choose a reason for hiding this comment

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

If a timer is already set, shouldn't that one just run instead of clearing and creating a new one?

export type DataTableRef = (instance: DataTable) => void;
export type TableRef = React.RefObject<Table>;
export type RowHeightOptions = string;
export type RowHeightOptions = 'micro' | 'small' | 'regular' | 'large' | 'xLarge' | 'jumbo';
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets just call it xlarge for consistency.

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