Skip to content

Conversation

@tylernoseworthy
Copy link
Contributor

@tylernoseworthy tylernoseworthy commented Aug 17, 2022

WHY are these changes introduced?

We are currently using the DataTable, but there was a requirement in our current project for the first 2 columns within the table to be fixed.

WHAT is this pull request doing?

This PR adds a fixFirstColumns prop in favour of the hasFixedFirstColumn prop, which now has a deprecation warning if still being used in development. In the event that hasFixedFirstColumn is still being used, we will default to showing 1 fixed column. Additionally, if a number defined in fixFirstColumns exceeds or is equal to the amount of columns within the table, no fixed columns will be rendered.

Before

data table before changes

After

Without sticky header

data table without sticky header

With sticky header

data table with sticky header

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import React from 'react';
import {Page, Card, DataTable} from '../src';

export function Playground() {
  return (
    const rows = [
    [
      'Emerald Silk Gown',
      'Formalwear',
      "Jill's formal",
      10,
      '$875.00',
      124689,
      140,
      '$426.00',
      '$122,500.00',
    ],
    [
      'Mauve Cashmere Scarf',
      'Accessories',
      "Jack's Accessories",
      253,
      '$230.00',
      124533,
      83,
      '$620.00',
      '$19,090.00',
    ],
    [
      'Navy Merino Wool Blazer with khaki chinos and yellow belt',
      'Ensembles',
      'Avocado Fashions',
      23,
      '$445.00',
      124518,
      32,
      '$353.00',
      '$14,240.00',
    ],
    [
      'Socks',
      'Essentials',
      'Avocado Fashions',
      465,
      '$4.00',
      124518,
      32,
      '$3.00',
      '$140.00',
    ],
  ];

  return (
    <Page title="Sales by product">
      <Card>
        <DataTable
          columnContentTypes={[
            'text',
            'text',
            'text',
            'numeric',
            'numeric',
            'numeric',
            'numeric',
            'numeric',
            'numeric',
          ]}
          headings={[
            'Product',
            'Category',
            'Vendor',
            'Orders',
            'Price',
            'SKU Number',
            'Net quantity',
            'Shipping',
            'Net sales',
          ]}
          rows={rows}
          totals={['', '', '', '', '', '', 255, '$1399', '$155,830.00']}
          initialSortColumnIndex={4}
          stickyHeader
          fixedFirstColumns={3}
          truncate
          showTotalsInFooter
          footerContent={`Showing ${rows.length} of ${rows.length} results`}
        />
      </Card>
    </Page>
  );
}

🎩 checklist

@tylernoseworthy
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

size-limit report 📦

Path Size
polaris-react-cjs 200.65 KB (+0.1% 🔺)
polaris-react-esm 128.92 KB (+0.15% 🔺)
polaris-react-esnext 183.02 KB (+0.11% 🔺)
polaris-react-css 40.6 KB (+0.01% 🔺)

@tylernoseworthy
Copy link
Contributor Author

/snapit

@github-actions

This comment was marked as outdated.

@nickpresta nickpresta force-pushed the data-table-fixed-nth-column branch from afb8c75 to 6befc7d Compare August 18, 2022 19:12
@nickpresta
Copy link
Member

/snapit

},
} as ComponentMeta<typeof DataTable>;

function sortRows(rows, index, direction) {
Copy link
Member

Choose a reason for hiding this comment

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

We also wanted to fix these examples since the sorting doesn't really work.

@github-actions

This comment was marked as outdated.

@nickpresta nickpresta force-pushed the data-table-fixed-nth-column branch from 6befc7d to 346500a Compare August 18, 2022 19:20
@nickpresta
Copy link
Member

/snapit

@nickpresta nickpresta force-pushed the data-table-fixed-nth-column branch from 346500a to 5febd6e Compare August 18, 2022 19:53
@github-actions

This comment was marked as outdated.

@nickpresta
Copy link
Member

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @nickpresta! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/polaris@0.0.0-snapshot-release-20220818200014
yarn add @shopify/polaris-tokens@0.0.0-snapshot-release-20220818200014
yarn add @shopify/stylelint-polaris@0.0.0-snapshot-release-20220818200014

@tylernoseworthy tylernoseworthy changed the title [DataTable] Add fixed nth column functionality [DataTable] Add fixedFirstColumns prop Aug 22, 2022
@tylernoseworthy tylernoseworthy force-pushed the data-table-fixed-nth-column branch from e957733 to c096ff5 Compare August 22, 2022 20:43
@tylernoseworthy tylernoseworthy force-pushed the data-table-fixed-nth-column branch from c096ff5 to 836af11 Compare August 22, 2022 20:44
@tylernoseworthy tylernoseworthy force-pushed the data-table-fixed-nth-column branch from 836af11 to a890b01 Compare August 22, 2022 20:53
@nickpresta
Copy link
Member

I left comments on the stories that changed in Chromatic -- it would be great for someone else to take a look and verify my comments and accept the changes.

@nickpresta nickpresta marked this pull request as ready for review August 23, 2022 13:40
content,
contentType,
firstColumn,
nthColumn,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wondering if this should just be called fixed or fixedColumn

Copy link

@ryanpdaley ryanpdaley left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@tylernoseworthy tylernoseworthy force-pushed the data-table-fixed-nth-column branch from 783adf0 to c923912 Compare August 23, 2022 14:31
@tylernoseworthy
Copy link
Contributor Author

tylernoseworthy commented Aug 23, 2022

Just leaving a comment about a UI issue that potentially could happen if you pass a number of fixedFirstColumns that exceeds the table width. This causes there to be an overflow of the table which hides the scrollable table. I am thinking this is an edge case that should be handled by who ever uses the component, seeing as having 2+ fixed columns on certain screen sizes isn't the greatest experience.

Screen Shot 2022-08-23 at 9 42 30 AM

Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Hey @tylernoseworthy 👋🏽 This works great on large screen but needs to be limited to 1 fixed column (or none at all) on small screens. Currently the table breaks on small screens:

Screen Shot 2022-08-23 at 11 53 10 AM

'@shopify/polaris': minor
---

Added `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Added `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed
- Added a `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed
- Deprecated the `DataTable` `fixedFirstColumn` prop

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this caused a bit of a kerfuffle in the generated changelog. Can we reduce this to a single line without bullets? Not as fancy, but might improve how changesets renders it

Screen Shot 2022-08-26 at 6 29 08 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samrose3 Am I able to make that change directly on that branch? or is there a special command I have to run?

Copy link
Member

Choose a reason for hiding this comment

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

You can just modify the changeset file directly (.changeset/lazy-nails-relax.md) no command needed 👍

@nickpresta
Copy link
Member

@chloerice Thanks for the feedback! I'd like to understand a bit better -- is there a reason this needs to be baked into Polaris? The fixedFirstColumns prop is configurable, and the default state is to have no fixed columns, which means by default things are fine on small screens, and any consumer opting into fixedFirstColumns behavior could handle the responsiveness themselves.

We don't seem to take a stance of overriding props when certain combinations wouldn't look great on small screens - for example grid, button group, index table require the consumer to make an explicit choice about how to handle small screens.

For the data table, it would mean changing the fixedFirstColumns prop to something like 0 or 1 on small screens.

Thanks for any context!

@chloerice
Copy link
Member

chloerice commented Aug 23, 2022

@chloerice Thanks for the feedback! I'd like to understand a bit better -- is there a reason this needs to be baked into Polaris? The fixedFirstColumns prop is configurable, and the default state is to have no fixed columns, which means by default things are fine on small screens, and any consumer opting into fixedFirstColumns behavior could handle the responsiveness themselves.

We don't seem to take a stance of overriding props when certain combinations wouldn't look great on small screens - for example grid, button group, index table require the consumer to make an explicit choice about how to handle small screens.

For the data table, it would mean changing the fixedFirstColumns prop to something like 0 or 1 on small screens.

Thanks for any context!

Hey @nickpresta! I think that approach of putting the onus on consumers is fine, as long the documentation for that prop calls it out and its examples show how to implement it.

],
];
const [sortedRows, setSortedRows] = useState(rows);
const showFixedColumns = useMedia('screen and (max-width: 850px)');
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 noticed this will not work when editing in codesandbox because of the useMedia hook. Is this something we should be worried about?

Copy link
Member

Choose a reason for hiding this comment

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

Hey @tylernoseworthy you'll need to copy and paste the hook into the bottom of the example instead of importing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to do it before merging 😅. I'll follow up with a another PR to fix the example for codesandbox.

@tylernoseworthy tylernoseworthy merged commit ae7345f into main Aug 25, 2022
@tylernoseworthy tylernoseworthy deleted the data-table-fixed-nth-column branch August 25, 2022 13:53
@github-actions github-actions bot mentioned this pull request Aug 25, 2022
tylernoseworthy added a commit that referenced this pull request Aug 29, 2022
#### Related PR: #6976
<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

### WHY are these changes introduced?

A `useMedia` hook was introduced for a `DataTable` example as an import.
This however breaks the example when a user want's to view this within
codesandbox.

<!--
  Context about the problem that’s being addressed.
-->

### WHAT is this pull request doing?

This adds a `useMedia` hook to the bottom of the example

### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

### 🎩 checklist

- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [x] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
nickpresta pushed a commit that referenced this pull request Aug 31, 2022
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @shopify/polaris-icons@6.0.0

### Major Changes

-   [#7012](#7012) [`bd00ef4ed`](bd00ef4) Thanks [@leileu](https://github.com/leileu)! - Adding Metafields icon to polaris

### Minor Changes

-   [#7013](#7013) [`1e0645f33`](1e0645f) Thanks [@jpmarra](https://github.com/jpmarra)! - Added IdentityCard icon


-   [#7028](#7028) [`635bcfeb7`](635bcfe) Thanks [@joelzwarrington](https://github.com/joelzwarrington)! - add vertical viewport icon variations

## @shopify/polaris@10.1.0

### Minor Changes

-   [#6976](#6976) [`ae7345f0c`](ae7345f) Thanks [@tylernoseworthy](https://github.com/tylernoseworthy)! - - Added a `fixedFirstColumns` prop to `DataTable` so that multiple columns can be fixed
    -   Deprecated the `DataTable` `fixedFirstColumn` prop


-   [#7043](#7043) [`60086a61f`](60086a6) Thanks [@philschoefer](https://github.com/philschoefer)! - Updates to `DataTable`

    -   Fixed `DataTable` cell content not wrapping when the `truncate` prop is `false`
    -   Added support for setting the `DataTable` `truncate` prop without having to set the `fixedFirstColumns` prop

### Patch Changes

-   [#7022](#7022) [`716956df6`](716956d) Thanks [@QuintonC](https://github.com/QuintonC)! - Fixed visual bug for avatar shape prop


-   [#7038](#7038) [`d1a33d8b0`](d1a33d8) Thanks [@kyledurand](https://github.com/kyledurand)! - Applied default background color to image avatar


-   [#6993](#6993) [`fa840e4a9`](fa840e4) Thanks [@kyledurand](https://github.com/kyledurand)! - Removed deprecation from Layout.AnnotatedSection


-   [#7003](#7003) [`2b5f7d0fc`](2b5f7d0) Thanks [@mrcthms](https://github.com/mrcthms)! - Fix visual bug for sortable, selectable index table headings

-   Updated dependencies \[[`bd00ef4ed`](bd00ef4), [`1e0645f33`](1e0645f), [`635bcfeb7`](635bcfe)]:
    -   @shopify/polaris-icons@6.0.0

## polaris.shopify.com@0.14.0

### Minor Changes

-   [#7018](#7018) [`a8087a358`](a8087a3) Thanks [@alex-page](https://github.com/alex-page)! - Generate assets once with a seperate script


-   [#6934](#6934) [`793e26f4d`](793e26f) Thanks [@alex-page](https://github.com/alex-page)! - Use @shopify/polaris-icons instead of /icons and copy-icons


-   [#7049](#7049) [`7a548a00a`](7a548a0) Thanks [@alex-page](https://github.com/alex-page)! - Move search to the server side

### Patch Changes

-   [#7015](#7015) [`e612cbccb`](e612cbc) Thanks [@lgriffee](https://github.com/lgriffee)! - Update navigation column in breakpoints table for MD breakpoint


-   [#7027](#7027) [`a805116a6`](a805116) Thanks [@sarahill](https://github.com/sarahill)! - Updated design guidance for typography

-   Updated dependencies \[[`716956df6`](716956d), [`ae7345f0c`](ae7345f), [`60086a61f`](60086a6), [`bd00ef4ed`](bd00ef4), [`d1a33d8b0`](d1a33d8), [`fa840e4a9`](fa840e4), [`2b5f7d0fc`](2b5f7d0), [`1e0645f33`](1e0645f), [`635bcfeb7`](635bcfe)]:
    -   @shopify/polaris@10.1.0
    -   @shopify/polaris-icons@6.0.0

## polaris-for-figma@0.0.11

### Patch Changes

-   Updated dependencies \[[`716956df6`](716956d), [`ae7345f0c`](ae7345f), [`60086a61f`](60086a6), [`d1a33d8b0`](d1a33d8), [`fa840e4a9`](fa840e4), [`2b5f7d0fc`](2b5f7d0)]:
    -   @shopify/polaris@10.1.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

5 participants