Skip to content
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

NEO-2115 // update Table row selection #444

Merged
merged 27 commits into from
Jul 11, 2024

Conversation

joe-s-avaya
Copy link
Contributor

@joe-s-avaya joe-s-avaya commented Jul 8, 2024

Link to updated Table story

Before tagging the team for a review, I have done the following:

  • run yarn all locally: ensures that all tests pass, formatting is done, types pass, and builds pass
  • reviewed my code changes
  • updated the link at the top of this PR (or remove it if not applicable)
  • added any important information to this PR (description, images, GIFs, ect.)
  • done an accessibility check on my work (tested with Chrome's axe Dev Tools, Mac's VoiceOver, etc.)
  • tagged @avaya-dux/dux-design if any visual changes have occurred
  • tagged @avaya-dux/dux-devs

This makes several updates to row selection in the Table component. Most notably that the header checkbox now selects/deselects the page's rows, not the entire tables.

Figma link

@avaya-dux/dux-design: Review table selection visuals.

  • "Select all" checkbox appropriately appears and updates.
  • Chevron next to the checkbox is visually appropriate (sizing, spacing, etc.).

@avaya-dux/dux-devs: Review table selection logic.

  • review code and test logic
  • review use-cases spreadsheet and ensure all use-cases are handled
  • review updates to Menu components and stories to ensure nothing has inappropriately changed.
    • IMPORTANT: all current "Menu Item" components will not be fully a11y due to them not being <button>s. We'll need to figure out how to fix that soon.

Summary by CodeRabbit

  • New Features
    • Enhanced row selection functionality in tables, including selecting visible rows, clearing selections, and toggling row states.
  • Improvements
    • Updated table header translations for better clarity on selection actions.
  • Bug Fixes
    • Simplified row selection logic in test cases to improve reliability.
    • Improved checkbox label references for better test accuracy.

@joe-s-avaya joe-s-avaya self-assigned this Jul 8, 2024
Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

The changes introduce new logic for managing the selection of visible rows in a table, update translations for table headers, and adjust tests for row selection actions. Specific enhancements include new state variables and functions for handling row visibility and selection, expanded translations, and refined test setups for better clarity.

Changes

Files Change Summaries
src/components/Table/.../TableHeader.tsx Introduced logic for selecting visible rows, added new state variables and functions for row selection.
src/components/Table/helpers/default-data.ts Updated translations for table header actions like selecting all items and clearing selections.
src/components/Table/Table.test.jsx Simplified defaultSelectedRowIds prop, adjusted test setups for row deletion, and updated checkbox labels.
src/components/Table/types/TranslationTypes.ts Added new properties to ITableHeaderTranslations for enhanced translations related to table headers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TableHeader
    participant Table
    User->>TableHeader: Select all rows on page
    TableHeader->>Table: Get current page rows
    Table->>TableHeader: Return visible page rows
    TableHeader->>Table: Toggle selection for visible rows
    Table-->>User: Rows on page selected
    User->>TableHeader: Clear all visible rows
    TableHeader->>Table: Get current page rows
    Table->>TableHeader: Return visible page rows
    TableHeader->>Table: Deselect visible rows
    Table-->>User: Rows on page deselected
Loading

Poem

In a table where rows align,
Selection's magic starts to shine.
With code so swift, they toggle on,
And with a click, they're swiftly gone.
Translation's voice now clear and bright,
Guides the user, day and night.
🌟🗂️✨🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jul 8, 2024

Deploy Preview for neo-react-library-storybook ready!

Name Link
🔨 Latest commit b79fa8f
🔍 Latest deploy log https://app.netlify.com/sites/neo-react-library-storybook/deploys/66902535e31a220008d5f42d
😎 Deploy Preview https://deploy-preview-444--neo-react-library-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@joe-s-avaya joe-s-avaya marked this pull request as ready for review July 9, 2024 14:14
@joe-s-avaya joe-s-avaya requested review from a team July 9, 2024 14:15
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b58ddb6 and d37f459.

Files selected for processing (11)
  • src/components/Menu/Menu.stories.tsx (3 hunks)
  • src/components/Menu/Menu.tsx (1 hunks)
  • src/components/Menu/MenuItemButton/MenuItemButton.tsx (1 hunks)
  • src/components/Menu/MenuItemButton/index.ts (1 hunks)
  • src/components/Menu/Menu_shim.css (1 hunks)
  • src/components/Menu/index.ts (1 hunks)
  • src/components/Table/Table.test.jsx (2 hunks)
  • src/components/Table/TableComponents/TableHeader.tsx (4 hunks)
  • src/components/Table/Table_shim.css (1 hunks)
  • src/components/Table/helpers/default-data.ts (1 hunks)
  • src/components/Table/types/TranslationTypes.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • src/components/Menu/Menu.tsx
  • src/components/Menu/MenuItemButton/MenuItemButton.tsx
  • src/components/Menu/MenuItemButton/index.ts
  • src/components/Menu/Menu_shim.css
  • src/components/Menu/index.ts
Additional comments not posted (19)
src/components/Table/helpers/default-data.ts (1)

23-26: Translation strings added correctly.

The new translation strings clearSelection, clearAllVisibleItems, and selectAllVisibleItems are correctly added and follow the existing structure.

src/components/Table/types/TranslationTypes.ts (1)

35-38: New properties added correctly.

The new properties clearSelection, clearAllVisibleItems, and selectAllVisibleItems are correctly added to the ITableHeaderTranslations interface and follow the existing structure.

src/components/Table/Table_shim.css (5)

2-7: Button styles applied correctly.

The styles for buttons include color, display, font-weight, padding, and margin adjustments. These changes are correctly applied and enhance the button appearance.


11-13: Media queries applied correctly.

The media queries for light and dark color schemes correctly adjust the button color based on the user's preference.

Also applies to: 17-21


39-39: Table cell border style applied correctly.

The border style for table cells is correctly applied, ensuring a consistent appearance.


43-45: Pagination styles applied correctly.

The styles for pagination include display, flex-direction, height, and alignment adjustments. These changes are correctly applied and enhance the pagination layout.

Also applies to: 47-51


54-82: Checkbox column styles applied correctly.

The styles for the checkbox column include padding, width, hover effects, and dropdown menu adjustments. These changes are correctly applied and enhance the checkbox column appearance.

src/components/Table/TableComponents/TableHeader.tsx (7)

5-5: New import added correctly.

The MenuItemButton import is correctly added to support the new functionality.


35-39: New destructured properties added correctly.

The page and toggleRowSelected properties are correctly added to the destructured properties.


44-54: Logic for visible rows added correctly.

The logic for visibleRows, allVisibleRowsAreSelected, and allVisibleRowsDeselected is correctly added and ensures proper handling of visible rows.


56-62: Function for selecting visible rows added correctly.

The selectVisibleRows function is correctly added and ensures proper selection of visible rows.


73-78: Checkbox checked value logic added correctly.

The logic for determining the checkbox checked value is correctly added and ensures proper handling of the checkbox state.


94-108: Function for toggling all visible rows added correctly.

The toggleAllVisibleRows function is correctly added and ensures proper toggling of all visible rows.


114-159: Checkbox and menu for selecting rows added correctly.

The checkbox and menu for selecting rows are correctly added and ensure proper handling of row selection.

src/components/Menu/Menu.stories.tsx (2)

7-7: Import statement for MenuItemButton is correctly added.

The import statement is correctly added to include the new MenuItemButton component.


253-254: Props defaultIsOpen and closeOnBlur are correctly added to Menu.

The new props defaultIsOpen and closeOnBlur are correctly added and used.

src/components/Table/Table.test.jsx (3)

252-252: Simplified defaultSelectedRowIds prop.

The defaultSelectedRowIds prop is simplified to include only one ID, making the test setup more straightforward.


317-325: Updated test setup for deleting rows.

The test setup now uses EditableData and includes clearer checkbox label references, improving clarity and functionality.


329-329: Updated checkbox label reference for better readability.

The checkbox label reference is updated to use a variable, enhancing readability and maintainability.

@yangAtSpoken
Copy link
Contributor

yangAtSpoken commented Jul 9, 2024

Screenshot 2024-07-09 at 1 14 10 PM

Use Case review: the last use case does not seem working. My understand of this use case is: when all rows cross all pages are selected, clicking a header checkbox of any page, will de-select all items cross all pages. What actually happens is only rows of the clicked page are deselected. By the way, this use case does not seem reasonable to me if my understanding is correct.

@yangAtSpoken

This comment was marked as outdated.

yangAtSpoken
yangAtSpoken previously approved these changes Jul 9, 2024
Copy link
Contributor

@yangAtSpoken yangAtSpoken left a comment

Choose a reason for hiding this comment

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

The Table update looks great to me despite of all the naming suggestions. However, I do not see that we need a MenuItemButton component as MenuItem has onClick callback already.

src/components/Menu/MenuItemButton/MenuItemButton.tsx Outdated Show resolved Hide resolved
src/components/Table/Table.test.jsx Show resolved Hide resolved
toggleAllRowsSelected,
toggleSortBy,
} = instance;

const [visibleRows, allVisibleRowsAreSelected, allVisibleRowsDeselected] =
Copy link
Contributor

Choose a reason for hiding this comment

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

"visible" and "shown" are not accurate to me. If the page is not selected, all rows in that page are not visible/shown to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent call! As they say, naming is the hardest problem in software, and your recommendations are a significant improvement; thanks for being thorough! I have made the updates that you recommended.

toggleAllRowsSelected,
toggleSortBy,
} = instance;

const [visibleRows, allVisibleRowsAreSelected, allVisibleRowsDeselected] =
useMemo(() => {
const shownRows = page.map((row) => row.original);
Copy link
Contributor

Choose a reason for hiding this comment

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

shownRows => pageRows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

const [visibleRows, allVisibleRowsAreSelected, allVisibleRowsDeselected] =
useMemo(() => {
const shownRows = page.map((row) => row.original);
const visibleRowsSelected =
Copy link
Contributor

Choose a reason for hiding this comment

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

allRowsSelected or allPageRowsSelected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

const shownRows = page.map((row) => row.original);
const visibleRowsSelected =
shownRows.length && shownRows.every((row) => selectedRowIds[row.id]);
const visibleRowsNotSelected = shownRows.every(
Copy link
Contributor

Choose a reason for hiding this comment

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

allRowsNoteSlected or noRowsSelected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

return [shownRows, visibleRowsSelected, visibleRowsNotSelected];
}, [page, selectedRowIds]);

const selectVisibleRows = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

selectPageRows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

}, [page, selectedRowIds]);

const selectVisibleRows = useCallback(
(set: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

selected: bolean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -69,19 +91,73 @@ export const TableHeader = <T extends Record<string, any>>({
checkboxCheckedValue,
rowsById,
]);
const toggleAllVisibleRows = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

togglePageRows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@yangAtSpoken yangAtSpoken dismissed their stale review July 9, 2024 18:25

Have to retract the approval as I forgot the MenuItemButton keyboard problem.

@joe-s-avaya
Copy link
Contributor Author

Need to do some refactoring, closing for now and will re-open.

@joe-s-avaya
Copy link
Contributor Author

Possibly out of scope

@Justin-Avaya, this is all out of scope for this PR as my changes did not cause this. However, this many inconsistencies is particularly worrying and I've thus made a jira issue to resolve these. I'll bring this up with the team in standup tomorrow so we can schedule it.

@joe-s-avaya joe-s-avaya reopened this Jul 10, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d37f459 and c8dbb9f.

Files selected for processing (2)
  • src/components/Menu/Menu.stories.tsx (1 hunks)
  • src/components/Table/TableComponents/TableHeader.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/components/Menu/Menu.stories.tsx
  • src/components/Table/TableComponents/TableHeader.tsx

@joe-s-avaya
Copy link
Contributor Author

Use Case review: the last use case does not seem working. My understand of this use case is: when all rows cross all pages are selected, clicking a header checkbox of any page, will de-select all items cross all pages. What actually happens is only rows of the clicked page are deselected. By the way, this use case does not seem reasonable to me if my understanding is correct.

@yangAtSpoken good catch, I'll talk to Matt about it as he is the one who defined these use-cases

@joe-s-avaya
Copy link
Contributor Author

functional Can not move focus to the last menu item with keyboard.

@yangAtSpoken can't reproduce. I must have broken it and then fixed it all without realizing it 😅

Copy link

@Justin-Avaya Justin-Avaya left a comment

Choose a reason for hiding this comment

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

  • "Select all" checkbox appropriately appears and updates.
  • Chevron next to the checkbox is visually appropriate (sizing, spacing, etc.).

✅ Approved

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c8dbb9f and 07283e0.

Files selected for processing (1)
  • src/components/Table/TableComponents/TableHeader.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/Table/TableComponents/TableHeader.tsx

@enrique-prado
Copy link
Contributor

From a UX perspective I think we are missing a "deselect all rows" option. If the user selects all rows and then decides to unselect them then he/she is forced to go to every page and deselect them. For tables with many pages that's not very usable.

@matthewAvaya
Copy link

matthewAvaya commented Jul 10, 2024

  • After selecting Select all items (10) from the header dropdown, the banner to clear all selections is missing. This light blue banner is displayed anytime a user selects one of the dropdown items from the header dropdown of the checkbox.
Screen Shot 2024-07-10 at 2 34 03 PM
  • Change copy Select all items to Select all items in the table
  • Change copy Clear all selections to Clear all items

Copy link
Contributor

@enrique-prado enrique-prado left a comment

Choose a reason for hiding this comment

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

There seems to be an issue with the "Clear all selections" option. All my comments are related to that.

</>
) : (
<>
{translations.selectAll} ({rows.length})
Copy link
Contributor

Choose a reason for hiding this comment

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

We also need an menu option to clear all selected rows. See my comments about UX in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2024-07-11 10 49 32

@@ -20,7 +20,10 @@ export const translations: ITableTranslations = {
header: {
clearSort: "Clear Sort",
filterColumn: "Filter Column",
selectAll: "select all",
clearSelection: "Clear all selections",
Copy link
Contributor

Choose a reason for hiding this comment

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

I never saw this string in all my testing. Is it missing from your logic? Perhaps a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2024-07-11 10 49 32

@joe-s-avaya
Copy link
Contributor Author

@matthewAvaya

  • After selecting Select all items (10) from the header dropdown, the banner to clear all selections is missing. This light blue banner is displayed anytime a user selects one of the dropdown items from the header dropdown of the checkbox.

This is not included in this PR. It will be added in the next one.

  • Change copy Select all items to Select all items in the table

Updated

  • Change copy Clear all selections to Clear all items

Updated

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07283e0 and 8edc7ba.

Files selected for processing (1)
  • src/components/Table/helpers/default-data.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/Table/helpers/default-data.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8edc7ba and 70f8c44.

Files selected for processing (1)
  • src/components/Table/Table.test.jsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/Table/Table.test.jsx

Copy link
Contributor

@yangAtSpoken yangAtSpoken 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.

@matthewAvaya
Copy link

@matthewAvaya

  • After selecting Select all items (10) from the header dropdown, the banner to clear all selections is missing. This light blue banner is displayed anytime a user selects one of the dropdown items from the header dropdown of the checkbox.

This is not included in this PR. It will be added in the next one.

  • Change copy Select all items to Select all items in the table

Updated

  • Change copy Clear all selections to Clear all items

Updated

I like the new copy that you added to the dropdown.
Screen Shot 2024-07-11 at 10 32 55 AM

For clearing, let's use a similar copy.

  • Clear all items on page (5)
  • Clear all items in the table (10)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 70f8c44 and b79fa8f.

Files selected for processing (3)
  • src/components/Table/TableComponents/TableHeader.tsx (3 hunks)
  • src/components/Table/helpers/default-data.ts (1 hunks)
  • src/components/Table/types/TranslationTypes.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/components/Table/TableComponents/TableHeader.tsx
  • src/components/Table/helpers/default-data.ts
  • src/components/Table/types/TranslationTypes.ts

@joe-s-avaya
Copy link
Contributor Author

@matthewAvaya

For clearing, let's use a similar copy.

  • Clear all items on page (5)
  • Clear all items in the table (10)

Updated

@joe-s-avaya joe-s-avaya merged commit c3cffa4 into main Jul 11, 2024
8 checks passed
@joe-s-avaya joe-s-avaya deleted the NEO-2115-update-table-select-all branch July 11, 2024 20:46
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