table icon indicating copy to clipboard operation
table copied to clipboard

v7 Feedback & Ideas

Open Grsmto opened this issue 7 years ago • 101 comments

Hi, First, I'm trying v7, it's awesome to work with Hooks! Trying it for the first time so my comments might be wrong.

Describe the bug This are more of an architecture comment than a bug: If you disable useExpanded hook, the table breaks. ~~I know in userland you can't disable this hook but the fact that this happens,~~ (edit: actually you can) probably demonstrates wrong app design: I figured out this is happening because you're building initial state within the useExpanded hook (row.cells = ...).

Expected behavior I think that adding or removing hooks should not break the entire component. Hooks should be encapsulated.

Codesandbox! https://codesandbox.io/s/nk9rmym6m4

Solution That initial state logic could be within useTable itself (tested and works fine). I can provide a PR if needed.

Grsmto avatar Feb 06 '19 19:02 Grsmto

useExpanded is actually extremely lightweight, so it's okay to use it for simple row expansion. Its useGrouping that is responsible for aggregation/pivoting.

Yeah, I need to update the sandbox with what's in master.

tannerlinsley avatar Mar 25 '19 16:03 tannerlinsley

@tannerlinsley thank you for your response. Can you please tell me how to use useExpanded for simple row expansion?

berdyshev avatar Mar 25 '19 16:03 berdyshev

Remember, all of this is in alpha and pretty hazy right now, but essentially, using the useExpanded hook will give you various .toggle() methods and expanded state that you can use to control a row's expanded state. You can also read from a row's expanded state through properties on the row model like isExpanded.

That should be adequate for implementing any custom UI for expanded rows you want, inside or outside of your actual table.

tannerlinsley avatar Mar 25 '19 16:03 tannerlinsley

@tannerlinsley thank you again. When do you plan to update the npm package and the demo with the latest code?

berdyshev avatar Mar 25 '19 21:03 berdyshev

Thanks very much for a great library. v6 is awesome for what i experimented. For V7, it uses React Hooks. And i think this is a real deal for a React Datatable! The real deal is in the simplicity, composability of Hooks, so let's prove it, right ?

Codesandbox is great and helpful, but it's not the best way to prove the change and improvement. Let's prove it in the README. Just give all API usage in a README , nothing more.

My experience with API design in general is that: If you can't put a working example in a README file, there's something more complicated than it should be.

I tried out current codesandbox examples for V7, and my feeling is like: oh my god, is this too complicated ? Or is it over-engineering, or am i too simple ? I don't know. The example doesn't hook me. I'm not sure about it, i want it to be more simple to use.

revskill10 avatar Mar 26 '19 17:03 revskill10

@tannerlinsley

using the useExpanded hook will give you various .toggle() methods and expanded state that you can use to control a row's expanded state. You can also read from a row's expanded state through properties on the row model like isExpanded.

As I understand there is no API to manage the rendering of the expanded rows, right? (maybe I can help with it in case you want it to be a part of the library?)

I ended up with something like this:

const MyTable = ({ expandable = false, renderExpandedRow, ...props }) => {
   const instance = useTable(props, ....);
   .....

   const renderRow = (row, index, style = {}) => {
    if (!row) {
      return (
        <Row {...{ style, even: Boolean(index % 2) }}>
          <Cell>Loading more...</Cell>
        </Row>
      );
    }
    prepareRow(row);
    const rowProps = row.getRowProps({ style, even: Boolean(index % 2) });
    const renderedRow = (
      <Row
        {...rowProps}
        expanded={row.isExpanded}
        onClick={() => {
          if (expandable) {
            row.toggleExpanded();
          }
        }}
      >
        {row.cells.map(cell => (
          <Cell {...cell.getCellProps()} className={cell.column.className}>
            {cell.render("Cell")}
          </Cell>
        ))}
      </Row>
    );

    if (row.isExpanded) {
      return (
        <React.Fragment key={rowProps.key}>
          {renderedRow}
          <Row
            {...rowProps}
            className={classNames(rowProps.className, "row--expanded")}
            key={`${rowProps.key}_expanded`}
          >
            {renderExpandedRow(row.original)}
          </Row>
        </React.Fragment>
      );
    }
    return renderedRow;
  };

  return <TableView ... />;
}

berdyshev avatar Mar 27 '19 10:03 berdyshev

So maybe the example isn't very clear on this, but expanded rows are not nested in the model, they are flattened into list of total rows. When you look at each row, you will see row properties that denote the depth of the row, parents, etc. This makes it 10x easier to deal with nested data and not have to write recursive renderers.

React Table strictly does not provide any markup to the user for this reason. What you have here could work great for your specific use case, but might not be what someone else needs. If we were to add it to the API, we would be 10x-ing the API by adding the needed inversion of control points that any given user would need to fully customize it.

Ultimately the v6 API is massive and extremely bloated, and yet it still doesn't support a fully customized rendering option. v7 is half the size and supports an unlimited number of rendering options. This is a perfect example of why headless UI components are so great!

tannerlinsley avatar Mar 27 '19 12:03 tannerlinsley

So maybe the example isn't very clear on this, but expanded rows are not nested in the model, they are flattened into list of total rows. When you look at each row, you will see row properties that denote the depth of the row, parents, etc.

I'm not sure but it seems you are talking about aggregation/grouping of the rows. But I'm trying to implement something like in this example https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/archives/v6-examples/react-table-sub-components.

berdyshev avatar Mar 27 '19 12:03 berdyshev

Most of what I said remains the same. The expanded state that is used for grouping/aggregation can also be used for sub components. It all depends on how you choose to render the expanded state.

tannerlinsley avatar Mar 27 '19 12:03 tannerlinsley

@tannerlinsley would you be able to publish the new version with the latest code, please?

berdyshev avatar Apr 05 '19 08:04 berdyshev

My feedback: We've been using v6. I just reviewed the examples of v7 and I have some limited experience with hooks. I think v7 is looking awesome but it is also a huge sea-change from v6. So much so that IMO it should be a new github project not an upgrade from 6 to 7. I am concerned how many users of ReactTable are going to be surprised when they upgrade 6 to 7 on a whim and the API is completely changed. Not 30% changed, but 100%! lol. Could you instead create another github project and then refer ReactTable users to the new project going forward in the README? Maybe "React-Tabular" or "React-Cell" or "React-xcell" haha.

I think you could then adapt current ReactTable API to use the new v7 project as a dependency and provide the user visuals on top of the hooked ReactTable but would actually have a v6 compatible API. Basically swapping out the old v6 behavior code for the hook code. Existing ReactTable users would experience only a bump in the road going to v7 but would also have a stepping stone to switching to their own visual styles using hooks. Would this be the best of both worlds?

I have my doubts people on my team are going to understand hooks anytime soon, they can barely wrap their heads around React vDOM :(. It's unfortunate, but it is the truth of most developers and companies that like to hire cheap "talent" (but they do understand v6 React-Table).

This is food for thought. I really appreciate your work into ReactTable! Both v6 and v7 are awesome!!

guru-florida avatar May 08 '19 14:05 guru-florida

@guru-florida that's good feedback. To help with your concern, my plans for v7 are not to only release what you currently see today as the v7 headless core, but also build and release a migration-centric kitchen-sink component along side it. This component's purpose will be to almost replicate the API and experience of the v6 component, but using the new v7 core under the hood. My hope is that this will help people migrate to v7, but easily be able to break out of the "training wheels" component when they are ready.

As for your concern with hooks, I feel obligated to put in my 2 cents: Hooks are React. I wouldn't consider them an addon or alternative syntax. They are core, just like the component API. While this may be painful, it shouldn't be any different than when people were forced to learn the HOC or render-prop patterns, except for they'll be learning core React patterns and utilities that will make their react code safer, faster, easier to write/compose/extract/share, and aligned with the rest of the React ecosystem. I know this can be a hard pill to swallow for companies or larger orgs with many employees, but trust me, your future selves will applaud you for learning and writing new code in React hooks ASAP.

Thanks for your feedback! Keep it coming!

tannerlinsley avatar May 08 '19 14:05 tannerlinsley

@tannerlinsley Thanks. I wasn't aware of your migration plan and it's essentially the same thing so glad to hear.

I agree 100% with your second paragraph too but it's easier said than done in my case. I don't have control over who is hired so I have to deal with the hand I've been given. TL;DR version they just aren't that interested in learning it. Old habits. What can ya do right? ....just move on....so in 3 more days I move on to another company. for reals. haha :)

I already use HOC and hooks, etc so I loved the new v7 design immediately and would migrate to it now but no time with me gone in 3 days. I am sure I'll be using it on the next project though.

guru-florida avatar May 08 '19 16:05 guru-florida

Feedback:

  • defaultState is not exported. Don't know how to define default state for own plugins.
  • in column.Filter func, next method header.setFilter accepting arguments flipped way
  • in column.Filter func, next field header.filterValue always empty

AskAlexSharov avatar May 09 '19 11:05 AskAlexSharov

Have you considered TypeScript?

Having third party type definitions for a very important component like tables (data grids) can be a bit unnerving.

With official type definitions when user of the react-table updates the library, the user can be somewhat certain the update does not break the behavior since it type checks.

Ciantic avatar May 10 '19 15:05 Ciantic

@Ciantic Yes, I have. A few things hold me back on that though:

  • I simply am not good enough with TS yet to be productive compared to my current status quo.
  • Using TS would severely limit the amount of people that would be able to contribute to the project, at least until TS gains the majority share of the JS ecosystem.

I have no qualms with moving to TS when the time is right, but in the meantime I will encourage integration tests for stability in its stead.

tannerlinsley avatar May 10 '19 15:05 tannerlinsley

@AskAlexSharov, would you like to submit a PR to improve those experiences?

tannerlinsley avatar May 10 '19 15:05 tannerlinsley

@tannerlinsley I am trying to sort desc on first user click. In v7 passing defaultSortDesc=true as a prop to the Table or Column only allows to flip between 'sort desc' and 'sort unset' states, which makes it impossible to sort ascending.

Is this a bug or am I misusing the property?

dmitriigaidarji avatar May 14 '19 12:05 dmitriigaidarji

Sounds like a bug.

Tanner Linsley On May 14, 2019, 6:11 AM -0600, Dmitrii Gaidarji [email protected], wrote:

@tannerlinsley I am trying to sort desc on first user click. In v7 passing defaultSortDesc=true as a prop to the Table or Column only allows to flip between 'sort desc' and 'sort unset' states, which makes it impossible to sort ascending. Is this a bug or am I misusing the prop property? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

tannerlinsley avatar May 14 '19 12:05 tannerlinsley

@tannerlinsley thanks for the quick response! I've fixed it for myself and shared the code for you #1341

dmitriigaidarji avatar May 14 '19 14:05 dmitriigaidarji