Skip to content

Commit b507c5c

Browse files
authored
enhance(dev-dashboard): reuse Paginator molecule in flaws and translation dashboards (#9319)
* Use Paginator molecule in flaws and translation dashboards * Synchronize sorting appearance * Fix missing variable * Remove now unused component
1 parent 962d17d commit b507c5c

File tree

6 files changed

+78
-191
lines changed

6 files changed

+78
-191
lines changed

Diff for: client/src/flaws/index.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
color: var(--text-inactive);
5656
}
5757

58-
a {
58+
a,
59+
.current-page {
5960
padding: 10px;
6061
}
6162
}

Diff for: client/src/flaws/index.tsx

+3-50
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "./index.scss";
66

77
import { humanizeFlawName } from "../flaw-utils";
88
import { MainContentContainer } from "../ui/atoms/page-content";
9+
import { Paginator } from "../ui/molecules/paginator";
910
import { useLocale } from "../hooks";
1011

1112
interface DocumentPopularity {
@@ -578,7 +579,7 @@ function DocumentsTable({
578579
return (
579580
<th onClick={() => setSort(id)} className="sortable">
580581
{title}{" "}
581-
{filters.sort_by === id ? (filters.sort_reverse ? "🔽" : "🔼") : null}
582+
{filters.sort_by === id ? (filters.sort_reverse ? "" : "") : null}
582583
</th>
583584
);
584585
}
@@ -682,59 +683,11 @@ function DocumentsTable({
682683
</tbody>
683684
</table>
684685

685-
{pageCount > 1 && (
686-
<p className="pagination">
687-
<PageLink number={1} disabled={page === 1}>
688-
⇤ First page
689-
</PageLink>{" "}
690-
{page > 2 && <PageLink number={page - 1}>← Previous page</PageLink>}{" "}
691-
{page}{" "}
692-
{page < pageCount - 1 && (
693-
<PageLink number={page + 1} disabled={page + 1 > pageCount}>
694-
Next page →
695-
</PageLink>
696-
)}
697-
<PageLink number={pageCount} disabled={page === pageCount}>
698-
Last page ({pageCount}) ⇥
699-
</PageLink>
700-
</p>
701-
)}
686+
<Paginator last={pageCount} />
702687
</div>
703688
);
704689
}
705690

706-
function PageLink({
707-
number,
708-
disabled,
709-
children,
710-
}: {
711-
number: number;
712-
disabled?: boolean;
713-
children: React.ReactNode;
714-
}) {
715-
const [filters] = useFiltersURL();
716-
// Unfortunately TS's Partial<T> is not quite the right return type of this function,
717-
// as it implies the object could have keys set to undefined, which isn't true here.
718-
// Hence we have to use type coercion (any)
719-
const newFilters = withoutDefaultFilters({ ...filters, page: number }) as any;
720-
if (newFilters.page) {
721-
newFilters.page = String(newFilters.page);
722-
}
723-
return (
724-
<Link
725-
to={"?" + createSearchParams(newFilters).toString()}
726-
className={disabled ? "disabled" : ""}
727-
onClick={(event) => {
728-
if (disabled) {
729-
event.preventDefault();
730-
}
731-
}}
732-
>
733-
{children}
734-
</Link>
735-
);
736-
}
737-
738691
function WarnAboutNothingBuilt({ locale }) {
739692
return (
740693
<div className="notecard warning document-warnings">

Diff for: client/src/translations/differences/index.scss

+21-22
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
margin: 25px 0;
55
padding: 10px;
66

7-
h3,
87
h4 {
98
margin-top: 0;
109
}
1110

12-
h3 span.page {
13-
color: #666;
14-
margin-left: 10px;
15-
}
16-
1711
p {
1812
margin-bottom: 3px;
1913
}
2014
}
2115

16+
h3 {
17+
margin-top: 0;
18+
}
19+
20+
h3 span.page {
21+
color: var(--text-inactive);
22+
}
23+
24+
h4.subheader {
25+
margin-top: 2px;
26+
}
27+
2228
.loading {
2329
margin: 200px;
2430
text-align: center;
@@ -33,22 +39,14 @@
3339
table {
3440
width: 100%;
3541

36-
th.sortable.active {
37-
background-color: rgb(237, 237, 237);
38-
}
39-
40-
th.sortable.active.reverse {
41-
transform: rotate(-180deg);
42-
}
43-
4442
td a .url-prefix {
4543
color: rgb(159, 159, 159);
4644
font-size: 80%;
4745
margin-right: 2px;
4846
}
4947

5048
td .document-title-preview {
51-
// color: rgb(118, 118, 118);
49+
/* color: rgb(118, 118, 118); */
5250
}
5351

5452
td .last_modified.ahead a {
@@ -80,17 +78,20 @@
8078
color: rgb(159, 159, 159);
8179
}
8280

83-
a {
81+
a,
82+
.current-page {
8483
padding: 10px;
8584
}
8685
}
8786

8887
div.filter-documents {
89-
.filters {
90-
// XXX Can someone please turn this into a CSS grid
91-
float: left;
92-
width: 300px;
88+
display: grid;
89+
gap: 20px;
90+
grid-template-columns: 300px 1fr;
91+
margin: auto;
92+
width: calc(100% - 40px);
9393

94+
.filters {
9495
h4 {
9596
border-bottom: 1px solid #efefef;
9697
margin-bottom: 10px;
@@ -106,8 +107,6 @@
106107
}
107108

108109
.documents {
109-
margin-left: 300px;
110-
111110
h4.subheader {
112111
margin-top: 2px;
113112
}

Diff for: client/src/translations/differences/index.tsx

+18-55
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import relativeTime from "dayjs/plugin/relativeTime";
1212
import "./index.scss";
1313

1414
import { MainContentContainer } from "../../ui/atoms/page-content";
15+
import { Paginator } from "../../ui/molecules/paginator";
1516
import { useLocale } from "../../hooks";
1617

1718
dayjs.extend(relativeTime);
@@ -230,6 +231,7 @@ export function TranslationDifferences() {
230231
<div className="filter-documents">
231232
<FilterControls />
232233
<DocumentsTable
234+
locale={locale}
233235
counts={lastData.counts}
234236
documents={lastData.documents}
235237
sort={sort}
@@ -483,11 +485,13 @@ function matchNumericOperation(value: number, op: NumericOperation): boolean {
483485
}
484486

485487
function DocumentsTable({
488+
locale,
486489
counts,
487490
documents,
488491
sort,
489492
sortReverse,
490493
}: {
494+
locale: string;
491495
counts: Counts;
492496
documents: Document[];
493497
sort: string;
@@ -517,11 +521,9 @@ function DocumentsTable({
517521
setSearchParams(createSearchParams({ sort: id }));
518522
}
519523
}}
520-
className={`sortable ${sort === id ? "active" : ""} ${
521-
sort === id && sortReverse ? "reverse" : ""
522-
}`}
524+
className="sortable"
523525
>
524-
{title}
526+
{title} {sort === id ? (sortReverse ? "↓" : "↑") : null}
525527
</th>
526528
);
527529
}
@@ -589,10 +591,17 @@ function DocumentsTable({
589591
return (
590592
<div className="documents">
591593
<h3>
592-
Documents found ({filteredDocuments.length.toLocaleString()}){" "}
593-
{page > 1 && <span className="page">page {page}</span>}{" "}
594-
<small>of {counts.total.toLocaleString()} in total</small>
594+
Documents with differences found (
595+
{filteredDocuments.length.toLocaleString()}){" "}
596+
{pageCount > 1 && (
597+
<span className="page">
598+
page {page}/{pageCount}
599+
</span>
600+
)}
595601
</h3>
602+
<h4 className="subheader">
603+
{counts.total.toLocaleString()} total documents found ({locale})
604+
</h4>
596605

597606
{filterDifferences && !filterDifferencesOperation && (
598607
<div className="error-message">
@@ -678,19 +687,8 @@ function DocumentsTable({
678687
})}
679688
</tbody>
680689
</table>
681-
{pageCount > 1 && (
682-
<p className="pagination">
683-
<PageLink number={1} disabled={page === 1}>
684-
First page
685-
</PageLink>{" "}
686-
{page > 2 && (
687-
<PageLink number={page - 1}>Previous page ({page - 1})</PageLink>
688-
)}{" "}
689-
<PageLink number={page + 1} disabled={page + 1 > pageCount}>
690-
Next page ({page + 1})
691-
</PageLink>
692-
</p>
693-
)}
690+
691+
<Paginator last={pageCount} />
694692
</div>
695693
);
696694
}
@@ -797,38 +795,3 @@ function getGetOrdinal(n: number) {
797795
const v = n % 100;
798796
return n.toLocaleString() + (s[(v - 20) % 10] || s[v] || s[0]);
799797
}
800-
801-
function PageLink({
802-
number,
803-
disabled,
804-
children,
805-
}: {
806-
number: number;
807-
disabled?: boolean;
808-
children: React.ReactNode;
809-
}) {
810-
const [searchParams] = useSearchParams();
811-
const params = createSearchParams(searchParams);
812-
if (number > 1) {
813-
params.set("page", `${number}`);
814-
} else {
815-
params.delete("page");
816-
}
817-
return (
818-
<Link
819-
to={"?" + params.toString()}
820-
className={disabled ? "disabled" : ""}
821-
onClick={(event) => {
822-
if (disabled) {
823-
event.preventDefault();
824-
}
825-
const top = document.querySelector("div.all-translations");
826-
if (top) {
827-
top.scrollIntoView({ behavior: "smooth" });
828-
}
829-
}}
830-
>
831-
{children}
832-
</Link>
833-
);
834-
}

Diff for: client/src/translations/missing/index.tsx

+5-52
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dayjs from "dayjs";
1010
import relativeTime from "dayjs/plugin/relativeTime";
1111

1212
import { MainContentContainer } from "../../ui/atoms/page-content";
13+
import { Paginator } from "../../ui/molecules/paginator";
1314
import { useLocale } from "../../hooks";
1415

1516
dayjs.extend(relativeTime);
@@ -495,11 +496,9 @@ function DocumentsTable({
495496
setSearchParams(createSearchParams({ sort: id }));
496497
}
497498
}}
498-
className={`sortable ${sort === id ? "active" : ""} ${
499-
sort === id && sortReverse ? "reverse" : ""
500-
}`}
499+
className="sortable"
501500
>
502-
{title}
501+
{title} {sort === id ? (sortReverse ? "↓" : "↑") : null}
503502
</th>
504503
);
505504
}
@@ -622,19 +621,8 @@ function DocumentsTable({
622621
})}
623622
</tbody>
624623
</table>
625-
{pageCount > 1 && (
626-
<p className="pagination">
627-
<PageLink number={1} disabled={page === 1}>
628-
First page
629-
</PageLink>{" "}
630-
{page > 2 && (
631-
<PageLink number={page - 1}>Previous page ({page - 1})</PageLink>
632-
)}{" "}
633-
<PageLink number={page + 1} disabled={page + 1 > pageCount}>
634-
Next page ({page + 1})
635-
</PageLink>
636-
</p>
637-
)}
624+
625+
<Paginator last={pageCount} />
638626
</div>
639627
);
640628
}
@@ -702,38 +690,3 @@ function getGetOrdinal(n: number) {
702690
const v = n % 100;
703691
return n.toLocaleString() + (s[(v - 20) % 10] || s[v] || s[0]);
704692
}
705-
706-
function PageLink({
707-
number,
708-
disabled,
709-
children,
710-
}: {
711-
number: number;
712-
disabled?: boolean;
713-
children: React.ReactNode;
714-
}) {
715-
const [searchParams] = useSearchParams();
716-
const params = createSearchParams(searchParams);
717-
if (number > 1) {
718-
params.set("page", `${number}`);
719-
} else {
720-
params.delete("page");
721-
}
722-
return (
723-
<Link
724-
to={"?" + params.toString()}
725-
className={disabled ? "disabled" : ""}
726-
onClick={(event) => {
727-
if (disabled) {
728-
event.preventDefault();
729-
}
730-
const top = document.querySelector("div.all-translations");
731-
if (top) {
732-
top.scrollIntoView({ behavior: "smooth" });
733-
}
734-
}}
735-
>
736-
{children}
737-
</Link>
738-
);
739-
}

0 commit comments

Comments
 (0)