-
Notifications
You must be signed in to change notification settings - Fork 253
Upgrade Grade Breakdown Summary Table to react-table v8 #7800
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
Merged
david-yz-liu
merged 14 commits into
MarkUsProject:master
from
lizzie-liu:upgrade-grade-breakdown-summary-table-v8
Jan 27, 2026
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c8e2ac7
refactor grade-breakdown-summary-table to react-table v8
lizzie-liu e2fa2e9
removing old comments
lizzie-liu fb81726
updated grade breakdown summary table to have hidden column position …
lizzie-liu cd6464a
allow Table to respect initialState columnVisibility without breaking…
lizzie-liu e8479a2
update changelog
lizzie-liu caf4841
updated table to conditionally render filter row (so it doesn't appea…
lizzie-liu 5ae26c9
added tests for grade breakdown summary table
lizzie-liu 3347219
added some more tests
lizzie-liu 78ba08a
adding some tests to ensure graph legend and table sorted by position
lizzie-liu 21f77b5
fixing tests for coverage
lizzie-liu 116a2fd
Merge branch 'master' into upgrade-grade-breakdown-summary-table-v8
lizzie-liu 791f95c
removed unnecessary column rendering and sorting
lizzie-liu 9ee3d6a
Merge branch 'upgrade-grade-breakdown-summary-table-v8' of https://gi…
lizzie-liu 4f3e6be
Merge branch 'master' into upgrade-grade-breakdown-summary-table-v8
lizzie-liu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 43 additions & 23 deletions
66
app/javascript/Components/Assessment_Chart/grade_breakdown_chart.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,61 @@ | ||
| import React from "react"; | ||
| import {Bar} from "react-chartjs-2"; | ||
| import {chartScales} from "../Helpers/chart_helpers"; | ||
| import ReactTable from "react-table"; | ||
| import Table from "../table/table"; | ||
| import {createColumnHelper} from "@tanstack/react-table"; | ||
| import PropTypes from "prop-types"; | ||
| import {CoreStatistics} from "./core_statistics"; | ||
| import {FractionStat} from "./fraction_stat"; | ||
|
|
||
| const columnHelper = createColumnHelper(); | ||
|
|
||
| export class GradeBreakdownChart extends React.Component { | ||
| render() { | ||
| const columns = [ | ||
| columnHelper.accessor("position", { | ||
| id: "position", | ||
| header: () => null, | ||
| cell: () => null, | ||
| size: 0, | ||
| enableSorting: true, | ||
|
||
| enableColumnFilter: false, | ||
| meta: { | ||
| className: "rt-hidden", | ||
| headerClassName: "rt-hidden", | ||
| }, | ||
| }), | ||
| columnHelper.accessor("name", { | ||
| header: this.props.item_name, | ||
| minSize: 150, | ||
| enableSorting: true, | ||
| enableColumnFilter: false, | ||
| }), | ||
| columnHelper.accessor("average", { | ||
| header: I18n.t("average"), | ||
| enableSorting: false, | ||
| enableColumnFilter: false, | ||
| cell: info => ( | ||
| <FractionStat | ||
| numerator={info.row.original.average} | ||
| denominator={info.row.original.max_mark} | ||
| /> | ||
| ), | ||
| }), | ||
| ]; | ||
| let summary_table = ""; | ||
| if (this.props.show_stats) { | ||
| summary_table = ( | ||
| <div className="flex-row-expand"> | ||
| <div className="grade-breakdown-summary-table"> | ||
| <ReactTable | ||
| <Table | ||
| data={this.props.summary} | ||
| columns={[ | ||
| { | ||
| Header: this.props.item_name, | ||
| accessor: "name", | ||
| minWidth: 150, | ||
| }, | ||
| { | ||
| Header: I18n.t("average"), | ||
| accessor: "average", | ||
| sortable: false, | ||
| filterable: false, | ||
| Cell: row => ( | ||
| <FractionStat | ||
| numerator={row.original.average} | ||
| denominator={row.original.max_mark} | ||
| /> | ||
| ), | ||
| }, | ||
| ]} | ||
| defaultSorted={[{id: "position"}]} | ||
| SubComponent={row => ( | ||
| columns={columns} | ||
| initialState={{ | ||
| sorting: [{id: "position"}], | ||
| columnVisibility: {position: false}, | ||
| }} | ||
| getRowCanExpand={() => true} | ||
| renderSubComponent={({row}) => ( | ||
| <div className="grade-stats-breakdown grid-2-col"> | ||
| <CoreStatistics | ||
| average={row.original.average} | ||
|
|
||
158 changes: 158 additions & 0 deletions
158
app/javascript/Components/__tests__/grade_breakdown_chart.test.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import React from "react"; | ||
| import {render, screen} from "@testing-library/react"; | ||
| import {GradeBreakdownChart} from "../Assessment_Chart/grade_breakdown_chart"; | ||
|
|
||
| jest.mock("react-chartjs-2", () => ({ | ||
| Bar: jest.fn(() => <div data-testid="bar-chart">Bar Chart</div>), | ||
| })); | ||
|
|
||
| jest.mock("../Assessment_Chart/fraction_stat", () => ({ | ||
| FractionStat: ({numerator, denominator}) => ( | ||
| <div data-testid="fraction-stat"> | ||
| {numerator}/{denominator} | ||
| </div> | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock("../Assessment_Chart/core_statistics", () => ({ | ||
| CoreStatistics: () => <div data-testid="core-statistics" />, | ||
| })); | ||
|
|
||
| jest.mock("../table/table", () => { | ||
| return function MockTable(props) { | ||
| const firstRow = props.data[0]; | ||
|
|
||
| // Execute getRowCanExpand | ||
| if (props.getRowCanExpand) { | ||
| props.getRowCanExpand(); | ||
| } | ||
|
|
||
| // Execute hidden column callbacks (header & cell) | ||
| const renderedCells = props.columns.map(col => { | ||
| if (typeof col.header === "function") { | ||
| col.header(); | ||
| } | ||
|
|
||
| if (typeof col.cell === "function") { | ||
| return <div key={col.id || col.accessor}>{col.cell({row: {original: firstRow}})}</div>; | ||
| } | ||
|
|
||
| return null; | ||
| }); | ||
|
|
||
| return ( | ||
| <div data-testid="mock-table"> | ||
| <div data-testid="table-columns">{props.columns.length} columns</div> | ||
| <div data-testid="table-data">{props.data.length} rows</div> | ||
| {renderedCells} | ||
|
|
||
| {props.renderSubComponent && props.renderSubComponent({row: {original: firstRow}})} | ||
| </div> | ||
| ); | ||
| }; | ||
| }); | ||
|
|
||
| describe("GradeBreakdownChart when summary data exists", () => { | ||
| const defaultProps = { | ||
| show_stats: true, | ||
| summary: [ | ||
| { | ||
| name: "Quiz 1", | ||
| position: 1, | ||
| average: 85, | ||
| median: 87, | ||
| max_mark: 100, | ||
| standard_deviation: 10, | ||
| num_zeros: 2, | ||
| }, | ||
| { | ||
| name: "Quiz 2", | ||
| position: 2, | ||
| average: 90, | ||
| median: 92, | ||
| max_mark: 100, | ||
| standard_deviation: 8, | ||
| num_zeros: 1, | ||
| }, | ||
| ], | ||
| chart_title: "Grade Distribution", | ||
| distribution_data: { | ||
| labels: ["0-10", "11-20", "21-30"], | ||
| datasets: [{data: [5, 10, 15]}], | ||
| }, | ||
| item_name: "Test Quiz", | ||
| num_groupings: 50, | ||
| create_link: "/quizzes/new", | ||
| }; | ||
|
|
||
| it("renders the bar chart", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| expect(screen.getByTestId("bar-chart")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders the summary table when show_stats is true", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| expect(screen.getByTestId("mock-table")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("does not render the summary table when show_stats is false", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} show_stats={false} />); | ||
| expect(screen.queryByTestId("mock-table")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("passes correct number of columns to table", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| // 3 columns: position (hidden), name, average | ||
| expect(screen.getByTestId("table-columns")).toHaveTextContent("3 columns"); | ||
| }); | ||
|
|
||
| it("passes summary data to table", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| expect(screen.getByTestId("table-data")).toHaveTextContent("2 rows"); | ||
| }); | ||
|
|
||
| it("renders FractionStat for average column", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| expect(screen.getByTestId("fraction-stat")).toHaveTextContent("85/100"); | ||
| }); | ||
|
|
||
| it("renders CoreStatistics when row is expanded", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
| expect(screen.getByTestId("core-statistics")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("sorts legend labels and tables rows by position", () => { | ||
| render(<GradeBreakdownChart {...defaultProps} />); | ||
|
|
||
| const BarMock = require("react-chartjs-2").Bar; | ||
| const barProps = BarMock.mock.calls[0][0]; | ||
| const sortFn = barProps.options.plugins.legend.labels.sort; | ||
|
|
||
| const a = {text: "Quiz 2"}; | ||
| const b = {text: "Quiz 1"}; | ||
| expect(sortFn(a, b)).toBeGreaterThan(0); | ||
|
|
||
| const table = screen.getByTestId("mock-table"); | ||
| expect(table).toBeInTheDocument(); | ||
| expect(screen.getByTestId("table-columns")).toHaveTextContent("3 columns"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("GradeBreakdownChart when summary data is empty", () => { | ||
| const emptyProps = { | ||
| show_stats: true, | ||
| summary: [], | ||
| chart_title: "Grade Distribution", | ||
| distribution_data: { | ||
| labels: ["0-10", "11-20", "21-30"], | ||
| datasets: [{data: [5, 10, 15]}], | ||
| }, | ||
| item_name: "Test Quiz", | ||
| num_groupings: 50, | ||
| create_link: "/quizzes/new", | ||
| }; | ||
| it("does not render the summary table", () => { | ||
| render(<GradeBreakdownChart {...emptyProps} />); | ||
| expect(screen.queryByTestId("mock-table")).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
All of the rendering attributes are unnecessary, as the column will be hidden through the visibility setting.