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

fix: DataGrid reformatted to table and aria-sort added #2998

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

dreamwasp
Copy link
Contributor

@dreamwasp dreamwasp commented Dec 16, 2024

Overview

Refactors the DataTable + DataList components to properly be semantic HTML tables and adds aria-sort to the appropriate controls

PR Checklist

  • Related to designs:
  • Related to JIRA ticket: GM-945
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

  1. Navigate to the DataList
  2. Test that it still works as intended (filter, select, sort actions specifically)
  3. Turn on VO and see that you can navigate it as a table (instructions here
  4. You can also inspect to see no errors and in console and that it is the correct table structure
  5. Go to DataTable
  6. Test that it still works as intended (filter, sort actions specifically)
  7. Turn on VO and see that you can navigate it as a table ((instructions here)
  8. Go to List and see that they look the same as before

PR Links and Envs

Repository PR Link PR Env
Monolith Monolith PR Monolith Env
Portal Portal Link Portal Env

@dreamwasp dreamwasp changed the title DataTable reqork DataTable rework Dec 16, 2024
Copy link

nx-cloud bot commented Dec 16, 2024

View your CI Pipeline Execution ↗ for commit 0e23544.


☁️ Nx Cloud last updated this comment at 2025-01-24 22:03:03 UTC

@dreamwasp dreamwasp changed the title DataTable rework fix: DataGrid reformatted to table and aria-sort added Jan 22, 2025
@dreamwasp dreamwasp marked this pull request as ready for review January 23, 2025 21:24
@dreamwasp dreamwasp requested a review from a team as a code owner January 23, 2025 21:24
Copy link
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

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

Preview works and looks great!
VO now recognizes the table as a table and appropriately semantic rows, headers, and cells. Filtering sounds good too. And the aria-sort shows up as well for sorting.

As I was going through the code to get an understanding of the changes, I was wondering about naming conventions — to try and separate out how components could be tied to their semantic HTML counterpart.

Left some thoughts for clean up but functionally, the changes look great :)

@@ -92,7 +108,8 @@ export const Row: DataRow = ({
}

return (
<ListCol {...colProps}>
// TO-DO: Fix type issues
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the type issues fixed?
I don't see any locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oop, they are! will remove

return (
<ListRow expanded={expanded} renderExpanded={renderExpandedContent}>
<ListRow
as="tr"
Copy link
Contributor

Choose a reason for hiding this comment

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

Food for thought: since both HeaderRow.tsx and Row.tsx are specific to tables, would renaming these components and folder to be table-specific make sense?

e.g. Tables/TableHeader.tsx and Tables/TableRow.tsx respectively?

Copy link
Contributor

Choose a reason for hiding this comment

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

And then maybe move over TableHeader.tsx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

love it, will change

variant={variant}
scrollable={scrollable}
ref={ref}
as="tr"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can HeaderEl be a styled tr instead? atm it's a styled div. See:
https://github.com/Codecademy/gamut/blob/cass-gm-945-i/packages/gamut/src/List/elements.tsx

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it should be like HeaderRowEl?

Copy link
Contributor

Choose a reason for hiding this comment

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

going into a rabbit hole of sorts — so feel free to disregard lol
but headerVariants seem like it's not used for anything else and only applies a borderBottom to table.
So maybe lump that into the CSS styling and do away with this variant altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great call out, will refactor!

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 found out this is different between DataList v DataTable so keeping the variants as is but refactored to tr


return (
<ListHeader>
<TableHeader>
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this fragment needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ill check!

header: {
...headerStyles,
},
// Keeping this within variants for typing purposes, we we use this behaviorally despite it not needing specific styling
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra "we" in this sentence

</>
);

const content =
isEmpty || loading ? (
<Box
as="table"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this as needed? looks like the parent element sets the as and content seems like it could be other elements

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, can this Box and the parent Box actually be combined?

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'll test it out! i think we were using it for some positioning reason, but i think i've changed this enough that we don't need it anymore


export interface RowProps
extends Partial<PublicListProps<ComponentProps<typeof RowEl>>> {
header?: boolean;
/** This is an internal prop that is largely only used for the DataTable component */
Copy link
Contributor

Choose a reason for hiding this comment

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

Since RowProps are used for DataRow, used in DataGrid, would be more accurate to say used for the "DataTable and DataList components"?

const { onClick, role, tabIndex, ...rowProps } = rest;
const wrapperProps =
!renderExpanded && !onClick
(!renderExpanded && !onClick) || isTable
? { ...rowConfig, ...rowProps }
: { spacing: keepSpacingWhileExpanded ? rowConfig.spacing : undefined };
let content = children;
const renderNumbering = isOl && renderExpanded === undefined && !onClick;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is there a falsy value other than undefined for renderExpanded?

If not, maybe !renderExpanded && !onClick can be a variable, like isNotInterative?

@@ -381,7 +385,7 @@ export const ColEl = styled(
system.layout
);

export const StickyColumnWrapper = styled.div(
export const StickyColumnWrapper = styled.th(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider renaming to StickyHeaderWrapper? Or StickyHeaderColWrapper?

Copy link
Contributor

@LinKCoding LinKCoding left a comment

Choose a reason for hiding this comment

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

Working and looking great tho!

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://67940dcabd733f4782173391--gamut-preview.netlify.app

Deploy Logs

@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/[email protected]
@codecademy/[email protected]
@codecademy/[email protected]

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.

3 participants