Skip to content

PF4 Please provide a lightweight composable component set for tables #2358

@idevat

Description

@idevat

Patternfly-table provides heavyweight component Table. This component tries to provide complex functionality to ease a development. But my experience with this component is a bit painful and I would welcome a set of simple composable components beside this super "smart" component. Let me elaborate it a bit.

As can be seen for example in issue #1399, component Table does not allow the developer to control some details. It tries to make things universal. In the case of issue #1399 it is about a control over the keys. It can fit to some use cases but not to all.

Sometimes, a particular use case could be achieved much more easily with set of simple tools. Actually, I haven't yet encountered a case where the current Table component saved me the hard work that a set of simple components couldn't handle. On the contrary. But it is true that my experience with this component is not extensive.

Most of the examples in https://www.patternfly.org/v4/documentation/react/components/table/ could be implemented with a set of simple components, I guess. Just a note, I haven't found the difference between First cell as header table and Simple table. When I looked into the code I found { title: 'Header cell', cellTransforms: [headerCol('selectable')] } but I have no idea what it should do (without more detailed study).

Take for example the issue #2357. If a user had components similar to these:

const PFTable = ({ children }) => (
  <table className="pf-c-table pf-m-grid-md">
    {children}
  </table>
);

const PFCompoundExpansionToggle = ({ expanded, onClick, children }) => (
  <td
    className={
      `pf-c-table__compound-expansion-toggle ${expanded ? "pf-m-expanded" : ""}`
    }
  >
    <button
      className="pf-c-button pf-m-link"
      type="button"
      onClick={onClick}
    >
      {children}
    </button>
  </td>
);

const PFExpandableRow = ({ children }) => (
  <tr className="pf-c-table__expandable-row pf-m-expanded">
    {children}
  </tr>
);

the implementation of task from issue #2357 might look like this:

const ClusterRow = ({ cluster }) => {
  const [expanded, setExpanded] = React.useState(false);
  return (
    <React.Fragment>
      <tr>
        <td>{cluster.name}</td>
        <PFCompoundExpansionToggle
          expanded={expanded}
          onClick={() => setExpanded(!expanded)}
        >
          {cluster.nodeList.length}
        </PFCompoundExpansionToggle>
      </tr>
      {expanded && (
        <PFExpandableRow>
          <td colSpan={2}>Nodes</td>
        </PFExpandableRow>
      )}
    </React.Fragment>
  );
};

const ClusterList = ({ clusterList }) => (
  <PFTable>
    <thead>
      <tr>
        <th>Cluster</th>
        <th>Nodes</th>
      </tr>
    </thead>
    <tbody>
      {clusterList.map(cluster => (
        <ClusterRow cluster={cluster} key={cluster.name} />
      ))}
    </tbody>
  </PFTable>
);

export default () => {
  const clusterList = [
    { name: "cluster-1", nodeList: ["one", "two"] },
    { name: "cluster-2", nodeList: ["one", "two", "three"] },
  ];
  return (
    <ClusterList clusterList={clusterList} />
  );
};

It is much more straightforward. There is simpler state logic. It's just React, the reader doesn't need to know a specific Table configuration (rows), which is itself a complex system. Maybe, there are some use cases where the component Table is effective. But it would be great to have a set of simpler composable components for the rest of use cases.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions