-
Notifications
You must be signed in to change notification settings - Fork 251
Migrate assignment summary page to react-table v8 #7630
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
Migrate assignment summary page to react-table v8 #7630
Conversation
Pull Request Test Coverage Report for Build 17030526515Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
david-yz-liu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@freyazjiner nice work, I left a few comments mainly focused on the implementation.
| cell: info => { | ||
| let marking_state = ""; | ||
| switch (row.original.marking_state) { | ||
| switch (info.row.original.marking_state) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call the parameter props, not info (to match the other examples we have).
Also, given the use of the accessorKey, it shouldn't be necessary to access props.row.original.marking_state, instead you should be able to use props.getValue().
| default: | ||
| // should not get here | ||
| marking_state = row.original.marking_state; | ||
| marking_state = info.row.original.marking_state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above
| })} | ||
| </div> | ||
| {row.getIsExpanded() && ( | ||
| <tr> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really think it makes sense to use <tr>/<td> elements here, since this isn't a "real" table. Instead, please just use a <div> that wraps the subcomponent, e.g.
<div>{renderSubComponent({row})</div>Unless that looks bad for some reason (provide screenshot).
| const renderSubComponent = ({row}) => { | ||
| return ( | ||
| <div> | ||
| <h4>{I18n.t("activerecord.models.ta", {count: 2})}</h4> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This count should be equal to the number of graders, not a hard-coded number.
| ); | ||
| return ( | ||
| <a href={path}> | ||
| {info.row.original.group_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, use the parameter name props throughout, and getValue( as well.
| size: 100, | ||
| enableResizing: true, | ||
| cell: value => value.getValue(), | ||
| meta: {className: "number"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn' exactly correct. Look at the values passed in the criteriaColumns state; there are additional attributes that are meant to be used here.
To see the difference in the UI, assign graders to specific criteria (and students) and then login as one of the graders and visit the table. Criteria that haven't been assigned should be greyed out due to the styling.
| header: () => I18n.t("activerecord.models.extra_mark.other"), | ||
| size: 100, | ||
| enableResizing: true, | ||
| cell: info => info.getValue(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though you translated this correctly, I think this is a case where the original code was redundant, so you can just delete this cell attribute and use the react table default.
| size: 32, | ||
| cell: ({row}) => { | ||
| return row.getCanExpand() ? ( | ||
| <button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty good, but can be improved:
-
All styles should go into a CSS file, not be set here
-
The spread operator (
...) is unnecessary. Just doonClick={...}etc. to pass attributes to thebutton. -
Rather than using separate unicode characters, take a look at how the original did it:
- component: https://github.com/TanStack/table/blob/v6/src/defaultProps.js#L237-L239
- CSS: https://github.com/rdubigny/react-table-v6/blob/8cffee96fad788484edf512aa8fe4fab176e803b/src/index.styl#L155-L175
You should be able to copy the styling into our CSS file as well to get the triangle icon to show up.
| getColumns = () => { | ||
| const columnHelper = createColumnHelper(); | ||
|
|
||
| const expanderColumn = columnHelper.display({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this new column definition is good but should be available more generally, not just in this file. Please (1) move it into the table.jsx file and (2) modify the defintion of Table itself so that if a subcomponent renderer prop is passed in (i.e., not undefined), then this column is automatically prepended to the columns passed in as props. This will generalize your work to all tables with subcomponents.
| Header: I18n.t("activerecord.attributes.result.marking_state"), | ||
| accessor: "marking_state", | ||
| Cell: row => { | ||
| header: I18n.t("activerecord.attributes.result.marking_state"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this have a () => ?
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText(I18n.t("activerecord.models.ta", {count: 2}))).toBeInTheDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This count should also not be hard-coded
| <div className="rt-tr-group" role="rowgroup" key={row.id}> | ||
| <div className="rt-tr -odd" role="row" key={row.id}> | ||
| {row.getVisibleCells().map(cell => { | ||
| const metaClass = cell.column.columnDef.meta?.className || ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but one of the things you should notice about the criteria column data is the headerClassName field. This should also be handled by the Table component.
| import {createColumnHelper} from "@tanstack/react-table"; | ||
| import Table from "./table/table"; | ||
|
|
||
| const renderSubComponent = ({row}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to below the AssignmentSummaryTable class. In general, I prefer having helpers below the main function.
| accessorKey: "marking_state", | ||
| size: 100, | ||
| enableResizing: true, | ||
| cell: props => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a problem with the filtering for the column: the options show the "raw" string values (in_progress, not_collected, etc.) instead of the internationalized strings.
To fix this, you can use the same approach that @ch-iv took for the instructor table: post-process the marking state values from the fetched data to transform the raw strings into the I18n.t versions. See https://github.com/MarkUsProject/Markus/blob/master/app/javascript/Components/instructor_table.jsx#L58-L79
| Header: I18n.t("activerecord.attributes.result.marking_state"), | ||
| accessor: "marking_state", | ||
| Cell: row => { | ||
| header: I18n.t("activerecord.attributes.result.marking_state"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, overall you should not change this function (since it's also used in the SubmissionTable component, which is on an older version of React table). Instead, you can make a copy of the function and move it directly into the assignment_summary file.
david-yz-liu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@freyazjiner nice work! I just left a few small comments
Changelog.md
Outdated
| - Updated Python autotest script file to include example of using `pytest.mark` to customize test marks (#7597) | ||
| - Refactor `Grader` table in `Users` to use `@tanstack/react-table` v8 (#7598) | ||
| - Updated `dependabot.yml` to add React dependency group and increase, remove old webpack ignored versions, and remove open PR limits (#7627) | ||
| - Updated the assignment summary table to use `@tanstack/react-table` v8 (#7630) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do a merge from master. When you do, you'll see that there's a new, much smaller "unreleased" section (due to a new release being made). Add this entry to the new section.
| id: col.id, | ||
| header: () => col.Header, | ||
| size: col.size || 100, | ||
| meta: {headerClassName: col.headerClassName}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should include both className and headerClassName here
david-yz-liu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @freyazjiner!
Proposed Changes
(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)
This PR updates the AssignmentSummaryTable to use React Table v8.
Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)