Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Terra Table #177

Merged
merged 32 commits into from
Apr 7, 2017
Merged

Terra Table #177

merged 32 commits into from
Apr 7, 2017

Conversation

nagrawal3
Copy link
Contributor

@nagrawal3 nagrawal3 commented Mar 28, 2017

Summary

Terra Table React Component

Thanks for contributing to Terra.
@cerner/terra

#57

import Markdown from 'terra-markdown';
import ReadMe from 'terra-table/docs/README.md';
// Component Source
// eslint-disable-next-line import/no-webpack-loader-syntax, import/first, import/no-unresolved, import/extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of disabling just the next-line, eslint allows you to disable blocks of code.

/* eslint-disable import/no-webpack-loader-syntax, import/first, import/no-unresolved, import/extensions */
import TableSrc from '!raw-loader!terra-table/src/Table';
import SingleSelectableRowsSrc from '!raw-loader!terra-table/src/SingleSelectableRows';
import TableHeaderSrc from '!raw-loader!terra-table/src/TableHeader';
....
/* eslint-enable import/no-webpack-loader-syntax, import/first, import/no-unresolved, import/extensions */

[![NPM version](http://img.shields.io/npm/v/terra-table.svg)](https://www.npmjs.org/package/terra-table)
[![Build Status](https://travis-ci.org/cerner/terra-core.svg?branch=master)](https://travis-ci.org/cerner/terra-core)

{insert description}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: please update

@@ -0,0 +1,145 @@
@import './variables';
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 we should consolidate this will Table.scss.

}

.terra-Table-sort-indicator {
float: right;
Copy link
Contributor

Choose a reason for hiding this comment

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

@import './mixins';
@import './terra-table';

[data-column-min-width='tiny'] {
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 make these css classes instead of using attribute selectors?

<div>
{display}
<span className={ascSortInd}>{iconUp}</span>
<span className={descSortInd}>{iconDown}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of updating css visibility, can we render only the sort/icon we need?


const defaultProps = {
isSelected: false,
isSelectable: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

false?

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 keep it undefined because, if Table is non-selectable, then there is no need to define this attribute for every row.

Copy link
Contributor

@tbiethman tbiethman Mar 30, 2017

Choose a reason for hiding this comment

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

You can just remove it from the defaultProps altogether. It'll be undefined if not passed in. I don't think you need to default isSelected either, but you should probably add a default for height.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the default for isSelectable. Cannot add default for height as it will set the maximum height on the row and by default we are not setting restrictions on height

@Matt-Butler
Copy link
Contributor

Selectable table rows are not keyboard accessible.

@Matt-Butler
Copy link
Contributor

We probably want to update the cursor to pointer for selectable rows:
selectable_rows

@@ -0,0 +1,3 @@
# Themeable Variables

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no themeable sass variables, this file can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* Content to be displayed for the row cell
*/
display: PropTypes.any.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Change this to content. It is easier to reason about what this is an matches with other react components we have.

$terra-table-thead-border-width: 1px !default;
$terra-table-tr-border-color: $terra-grey-30 !default;
$terra-table-tr-border-width: 1px !default;
$terra-table-cell-max-height-tiny: 26px;
Copy link
Contributor

Choose a reason for hiding this comment

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

The max-height and min-width values should be set in rem units.

@nagrawal3
Copy link
Contributor Author

Updated the code with changes as per above comments


return (
<td {...customProps} className={contentClassName}>
<div>{content}</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to wrap the content in an extra

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By default, the minimum height set on the table cell is the minimum height required by the content in the cell. Therefore in order to restrict the maximum height of the cell I have to add extra div tag.

<Table.HeaderContent content={'Column Heading 3'} key={3} minWidth={'large'} />
</Table.Header>
<Table.Rows>
<Table.Row key={0}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that it's not good practice to set the key equal to the index of the array, and this section of code feels like it's doing just that, even though there isn't a map or forEach function being called. Could we generate unique ids for these keys instead of using the numbers 1, 2, and 3? I used shortid to generate it in one of my code changes for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should leave it up to the user to set keys. Setting a random key is actually worse than just using the index since keys help React identify which items have changed, are added, or are removed.
Check this thread for some more information.
facebook/react#1342

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally agree on that. For this example, it feels too closely like it's setting the key equal to the value of it's array index, which also is not a good practice for assigning keys to react components. I feel like a developer would look at this example, and think that it could use the map function for example, and assign the key equal to the numerical index of that given element.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I didn't pay enough attention to see that this is an example. +1 to using non-index keys in the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed in commit bb5f8be

import React from 'react';
import Table from 'terra-table';

const shortid = require('shortid');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should consumers be providing these keys rather than us generating them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I know there was some discussion about this before. I just want to understand why we do this.

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 are generating the keys in example files only, we are not generating the keys in the code.

Copy link
Contributor

@tbiethman tbiethman Apr 5, 2017

Choose a reason for hiding this comment

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

I still hesitate doing random key generation, even in examples, because we know this is a pattern we don't want to perpetuate. Can we make the examples slightly more meaningful, allowing us to make use of keys that'd make sense? Something like:

<Table isStriped={false}>
  <Table.Header>
    <Table.HeaderContent content={'Name'} key="NAME" minWidth={'small'} />
    <Table.HeaderContent content={'Address'} key="ADDRESS" minWidth={'medium'} />
    <Table.HeaderContent content={'Phone'} key="PHONE_NUMBER" minWidth={'large'} />
  </Table.Header>
  <Table.Rows>
    <Table.Row key="PERSON_0">
      <Table.RowContent content="John Smith" key="NAME" />
      <Table.RowContent content="123 Adams Drive" key="ADDRESS" />
      <Table.RowContent content="111-222-3333" key="PHONE_NUMBER" />
    </Table.Row>
    <Table.Row key="PERSON_1">
      <Table.RowContent content="Jane Smith" key="NAME" />
      <Table.RowContent content="321 Drive Street" key="ADDRESS" />
      <Table.RowContent content="111-222-3333" key="PHONE_NUMBER" />
    </Table.Row>
    <Table.Row key="PERSON_2">
      <Table.RowContent content="Dave Smith" key="NAME" />
      <Table.RowContent content="213 Raymond Road" key="ADDRESS" />
      <Table.RowContent content="111-222-3333" key="PHONE_NUMBER" />
    </Table.Row>
  </Table.Rows>
</Table>

We want to get the point across that the key structure should match the schema of whatever data structure is being presented.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Tyler's comment. That can allow us to get rid of the additional dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this to the war room tomorrow. In my component, I'm finding a need to generate random keys, and so far, this is the best solution I found.

@@ -26,6 +26,8 @@
"react-dom": "^15.4.2",
"react-intl": "^2.2.3",
"react-router": "^3.0.2",
"shortid": "^2.2.8",
"terra-application": "^0.x",
Copy link
Contributor

Choose a reason for hiding this comment

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

We are deprecating terra-application. Please remove this line.

@@ -26,6 +26,7 @@
"react-dom": "^15.4.2",
"react-intl": "^2.2.3",
"react-router": "^3.0.2",
"shortid": "^2.2.8",
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we done some analysis about adding this as a dependency?


<Table isStriped={false}>
<Table.Header>
<Table.HeaderContent display={'Column Heading 1'} key={1} minWidth={'small'} />
Copy link
Contributor

Choose a reason for hiding this comment

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

The examples are using a content prop instead of display. Should this be updated to switch display prop to content

@bjankord bjankord merged commit 33fc98e into cerner:master Apr 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants