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: various minor fixes (alpha panel) #17258

Merged
merged 4 commits into from
May 24, 2019
Merged

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented May 23, 2019

Since we added id to the PanelProps, the react table has thrown errors. This PR fixes:

  • explicitly sets properties that get sent to MultiGrid to trigger refresh
  • removes noisy logging in column header
  • adds overflow:hidden to cell properties
  • adds a simple test

Object.assign(props, propOverrides);

const tree = renderer.create(<Table {...props} />);
const instance = (tree.getInstance() as unknown) as Table;
Copy link
Member

Choose a reason for hiding this comment

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

That is an interesting Typescript going on here:)

Copy link
Member Author

Choose a reason for hiding this comment

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

any better options? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

The enzyme version lets you simply cast... but it does not actually render:
https://github.com/grafana/grafana/blob/master/public/app/features/teams/TeamMembers.test.tsx#L28

Copy link
Member

Choose a reason for hiding this comment

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

I gotcha. Was just confused with that syntax ;)

{
...this.props /** Force MultiGrid to update when data changes */
}
{...refreshKeys}
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 about this approach as it's sort of hacky to push props to a component that are not handled by it. Shouldn't we use key instead that would be an outcome of the changed properties? You could generate it in getDerivedStateFromProps and pass it to MultiGrid in render.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find it in the docs right now... but this was their recommendation on how do get things to update when the data changes. key alone does not work because MultiGrid includes 4 Grids that don't have any context to know what changed besides the ...rest parameters.

This whole file needs to be revisited. It was my first attempt at anything non-trivial in react and blindly copied over a lot of angular code :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Check:
https://github.com/bvaughn/react-virtualized#pure-components

Essentially to get MultiGrid to update the inner Grids, you either add pass-through props, or call forceUpdateGrids directly

Copy link
Member

Choose a reason for hiding this comment

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

Cool, I get it, thanks!

//
console.log('COLUMN', column.name, theme);
}
) {}
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this empty constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't remove it because it sets all the private properties that get used below

    private mapper: ValueMapper,
    private style: ColumnStyle,
    private theme: GrafanaTheme,
    private column: Field,
    private replaceVariables: InterpolateFunction,
    private fmt?: ValueFormatter

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know you can set properties this way, that's very cool!

* grafana/master:
  Singlestat: fixes issue with value placement and line wraps (grafana#17249)
  Devenv: Update Graphite port in dev datasources (grafana#17255)
@@ -283,8 +283,9 @@ export class Table extends Component<Props, State> {
}

// Force MultiGrid to rerender if these options change
// See: https://github.com/bvaughn/react-virtualized#pass-thru-props
Copy link
Member

Choose a reason for hiding this comment

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

Cool, thanks

@ryantxu ryantxu merged commit 2a52dbf into grafana:master May 24, 2019
@ryantxu ryantxu deleted the table-fixes branch May 24, 2019 15:49
markelog added a commit that referenced this pull request May 25, 2019
* master: (28 commits)
  Feature: do dev environment via makefile (#17136)
  devenv: adds auth proxy load test (#17271)
  Table: various minor fixes (alpha panel) (#17258)
  Singlestat: fixes issue with value placement and line wraps (#17249)
  Devenv: Update Graphite port in dev datasources (#17255)
  Chore: bump grafana-ui version (#17256)
  Release: Updated latest.json
  Auth: Logout disabled user (#17166)
  docs: fixes typo in provisioning docs (#17248)
  CloudWatch: Made region visible for AWS Cloudwatch Expressions (#17243)
  Panel: Pass transparency prop down to React panels. (#17235)
  Build: Fix filter for building msi during release (#17236)
  DataSourcePlugin: Avoid anuglar injector if only one parameter (#17239)
  Alerting: Support for configuring content field for Discord alert notifier (#17017)
  Explore: Update the way Loki retrieve log context (#17204)
  Docs: Fix grammar in docs (#17233)
  LDAP: consistently name the LDAP entities (#17203)
  Panels: Show Drilldown links in top-left corner of custom React panels (#17142)
  Build: Fix final prompt for @grafana/ui npm publish confirmation
  Docs: Updated versions selector
  ...
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.

2 participants