Skip to content

Commit 06d0040

Browse files
authored
Implement custom no data component for all react tables (#7557)
1 parent d85f047 commit 06d0040

File tree

12 files changed

+47
-4
lines changed

12 files changed

+47
-4
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### ✨ New features and improvements
88
- Improved layout and labeling in the assignment settings form for both standard and timed assessments. (#7531)
9+
- Design improvement of tables when the data is empty. (#7557)
910
- Improved Assignment view for students (#7533)
1011
- Maintain font size in grading view (#7525)
1112

app/assets/stylesheets/common/core.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ th.required::after {
457457
width: 100%;
458458
}
459459

460+
.rt-no-data {
461+
background-color: $background-support;
462+
margin: 0;
463+
padding: 1em 0;
464+
text-align: center;
465+
}
466+
460467
// Styling patches for react-keyed-file-browser
461468
.div.rendered-react-keyed-file-browser div.action-bar ul.item-actions {
462469
overflow: auto;

app/javascript/Components/Helpers/table_helpers.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,7 @@ export function getMarkingStates(data) {
229229
});
230230
return markingStates;
231231
}
232+
233+
export function customNoDataComponent({children}) {
234+
return <p className="rt-no-data">{children}</p>;
235+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from "react";
2+
import {render, screen, fireEvent, within} from "@testing-library/react";
3+
import ReactTable from "react-table";
4+
5+
describe("Default React Table", () => {
6+
it("shows the default no data text when no data is provided", async () => {
7+
render(<ReactTable columns={[]} data={[]} />);
8+
await screen.findByText("No rows found");
9+
});
10+
11+
it("shows a custom no data text when set", async () => {
12+
const customNoDataText = "custom no data text";
13+
render(<ReactTable columns={[]} data={[]} noDataText={customNoDataText} />);
14+
await screen.findByText(customNoDataText);
15+
});
16+
});

app/javascript/Components/__tests__/instructor_table.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("For the InstructorTable's display of instructors", () => {
8787
});
8888

8989
it("No rows found is shown", async () => {
90-
await screen.findByText("No rows found");
90+
await screen.findByText(I18n.t("instructors.empty_table"));
9191
});
9292
});
9393
});

app/javascript/Components/__tests__/student_table.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe("For the StudentTable's display of students", () => {
264264
});
265265

266266
it("No rows found is shown", async () => {
267-
await screen.findByText("No rows found");
267+
await screen.findByText(I18n.t("students.empty_table"));
268268
});
269269
});
270270

app/javascript/Components/__tests__/ta_table.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe("For the TATable's display of TAs", () => {
9999
});
100100

101101
it("No rows found is shown", async () => {
102-
await screen.findByText("No rows found");
102+
await screen.findByText(I18n.t("tas.empty_table"));
103103
});
104104
});
105105

app/javascript/Components/instructor_table.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class InstructorTable extends React.Component {
100100
]}
101101
filterable
102102
loading={this.state.loading}
103+
noDataText={I18n.t("instructors.empty_table")}
103104
/>
104105
);
105106
}

app/javascript/Components/student_table.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class RawStudentTable extends React.Component {
221221
]}
222222
filterable
223223
loading={loading}
224+
noDataText={I18n.t("students.empty_table")}
224225
{...this.props.getCheckboxProps()}
225226
/>
226227
</div>
@@ -306,6 +307,7 @@ class StudentsActionBox extends React.Component {
306307
);
307308
};
308309
}
310+
309311
StudentsActionBox.propTypes = {
310312
onSubmit: PropTypes.func,
311313
disabled: PropTypes.bool,
@@ -321,8 +323,10 @@ RawStudentTable.propTypes = {
321323
};
322324

323325
let StudentTable = withSelection(RawStudentTable);
326+
324327
function makeStudentTable(elem, props) {
325328
const root = createRoot(elem);
326329
root.render(<StudentTable {...props} />);
327330
}
331+
328332
export {StudentTable, StudentsActionBox, makeStudentTable};

app/javascript/Components/ta_table.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class TATable extends React.Component {
127127
]}
128128
filterable
129129
loading={this.state.loading}
130+
noDataText={I18n.t("tas.empty_table")}
130131
/>
131132
);
132133
}

0 commit comments

Comments
 (0)