Skip to content

DataTable onSelect fix datum argument undefined #6750

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

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

jcfilben
Copy link
Collaborator

What does this PR do?

Fixes an issue where the second argument ('datum') passed to onSelect was always undefined.

Where should the reviewer start?

What testing has been done on this PR?

Added a jest test and tested with the following story:

import React from 'react';
import { Box, DataTable, Text, Meter } from 'grommet';

export const Test = () => (
  <DataTable
    onSelect={(selected, datum) => console.log({ selected, datum })}
    onClickRow="select"
    columns={[
      {
        property: 'name',
        header: <Text>Name</Text>,
        primary: true,
      },
      {
        property: 'percent',
        header: 'Complete',
        render: (datum) => (
          <Box pad={{ vertical: 'xsmall' }}>
            <Meter
              values={[{ value: datum.percent }]}
              thickness="small"
              size="small"
            />
          </Box>
        ),
      },
    ]}
    data={[
      { name: 'Alan', percent: 20 },
      { name: 'Bryan', percent: 30 },
      { name: 'Chris', percent: 40 },
      { name: 'Eric', percent: 80 },
    ]}
  />
);

export default {
  title: 'Visualizations/DataTable/Test',
};

How should this be manually tested?

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Closes #6727

Screenshots (if appropriate)

Do the grommet docs need to be updated?

no

Should this PR be mentioned in the release notes?

yes

Is this change backwards compatible or is it a breaking change?

backwards compatible

@jcfilben jcfilben requested a review from taysea April 14, 2023 17:43
Copy link
Contributor

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

I think the second argument should be the datum instead of the primaryValue, according to the documentation.

Copy link
Collaborator

@taysea taysea left a comment

Choose a reason for hiding this comment

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

Good fix.

@ericsoderberghp ericsoderberghp merged commit f1ea50d into grommet:master Apr 17, 2023
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.

DataTable onSelect is not passing the "datum" argument
3 participants