Commit 2f6b57bc authored by Robert Knight's avatar Robert Knight

Implement very basic pluralization for tab count message

parent 701d921b
...@@ -125,15 +125,23 @@ function SelectionTabs({ ...@@ -125,15 +125,23 @@ function SelectionTabs({
const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0; const showNotesUnavailableMessage = selectedTab === 'note' && noteCount === 0;
// Naive simple English pluralization
const pluralize = (count: number, singular: string, plural: string) => {
return count === 1 ? singular : plural;
};
const tabCountsSummaryPieces = []; const tabCountsSummaryPieces = [];
if (annotationCount > 0) { if (annotationCount > 0) {
tabCountsSummaryPieces.push(`${annotationCount} annotations`); const term = pluralize(annotationCount, 'annotation', 'annotations');
tabCountsSummaryPieces.push(`${annotationCount} ${term}`);
} }
if (noteCount > 0) { if (noteCount > 0) {
tabCountsSummaryPieces.push(`${noteCount} notes`); const term = pluralize(noteCount, 'note', 'notes');
tabCountsSummaryPieces.push(`${noteCount} ${term}`);
} }
if (orphanCount > 0) { if (orphanCount > 0) {
tabCountsSummaryPieces.push(`${orphanCount} orphans`); const term = pluralize(noteCount, 'orphan', 'orphans');
tabCountsSummaryPieces.push(`${orphanCount} ${term}`);
} }
const tabCountsSummary = tabCountsSummaryPieces.join(', '); const tabCountsSummary = tabCountsSummaryPieces.join(', ');
......
...@@ -340,6 +340,14 @@ describe('SelectionTabs', () => { ...@@ -340,6 +340,14 @@ describe('SelectionTabs', () => {
}, },
message: '2 annotations, 3 notes, 4 orphans', message: '2 annotations, 3 notes, 4 orphans',
}, },
{
tabCounts: {
annotation: 1,
note: 1,
orphan: 1,
},
message: '1 annotation, 1 note, 1 orphan',
},
].forEach(({ tabCounts, message }) => { ].forEach(({ tabCounts, message }) => {
it('reports annotation count to screen readers', () => { it('reports annotation count to screen readers', () => {
const wrapper = createComponent({ const wrapper = createComponent({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment