Skip to content

Commit 16d2f38

Browse files
Display full descendant count on taxonomy tag list page [FC-0036] (#826)
1 parent 76bb8e8 commit 16d2f38

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/taxonomy/tag-list/TagListTable.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const SubTagsExpanded = ({ taxonomyId, parentTagValue }) => {
2424
<ul style={{ listStyleType: 'none' }}>
2525
{subTagsData.data.results.map(tagData => (
2626
<li key={tagData.id} style={{ paddingLeft: `${(tagData.depth - 1) * 30}px` }}>
27-
{tagData.value} <span className="text-secondary-500">{tagData.childCount > 0 ? `(${tagData.childCount})` : null}</span>
27+
{tagData.value} <span className="text-secondary-500">{tagData.descendantCount > 0 ? `(${tagData.descendantCount})` : null}</span>
2828
</li>
2929
))}
3030
</ul>
@@ -48,14 +48,15 @@ OptionalExpandLink.propTypes = DataTable.ExpandRow.propTypes;
4848
const TagValue = ({ row }) => (
4949
<>
5050
<span>{row.original.value}</span>
51-
<span className="text-secondary-500">{` (${row.original.childCount})`}</span>
51+
<span className="text-secondary-500">{` (${row.original.descendantCount})`}</span>
5252
</>
5353
);
5454
TagValue.propTypes = {
5555
row: Proptypes.shape({
5656
original: Proptypes.shape({
5757
value: Proptypes.string.isRequired,
5858
childCount: Proptypes.number.isRequired,
59+
descendantCount: Proptypes.number.isRequired,
5960
}).isRequired,
6061
}).isRequired,
6162
};

src/taxonomy/tag-list/TagListTable.test.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IntlProvider } from '@edx/frontend-platform/i18n';
33
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
44
import { initializeMockApp } from '@edx/frontend-platform';
55
import { AppProvider } from '@edx/frontend-platform/react';
6-
import { render, waitFor } from '@testing-library/react';
6+
import { render, waitFor, within } from '@testing-library/react';
77
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
88
import MockAdapter from 'axios-mock-adapter';
99

@@ -35,22 +35,25 @@ const mockTagsResponse = {
3535
results: [
3636
{
3737
...tagDefaults,
38-
value: 'two level tag 1',
38+
value: 'root tag 1',
3939
child_count: 1,
40+
descendant_count: 14,
4041
_id: 1001,
4142
sub_tags_url: '/request/to/load/subtags/1',
4243
},
4344
{
4445
...tagDefaults,
45-
value: 'two level tag 2',
46+
value: 'root tag 2',
4647
child_count: 1,
48+
descendant_count: 10,
4749
_id: 1002,
4850
sub_tags_url: '/request/to/load/subtags/2',
4951
},
5052
{
5153
...tagDefaults,
52-
value: 'two level tag 3',
54+
value: 'root tag 3',
5355
child_count: 1,
56+
descendant_count: 5,
5457
_id: 1003,
5558
sub_tags_url: '/request/to/load/subtags/3',
5659
},
@@ -75,7 +78,7 @@ const subTagsResponse = {
7578
},
7679
],
7780
};
78-
const subTagsUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000&parent_tag=two+level+tag+1';
81+
const subTagsUrl = 'http://localhost:18010/api/content_tagging/v1/taxonomies/1/tags/?full_depth_threshold=10000&parent_tag=root+tag+1';
7982

8083
describe('<TagListTable />', () => {
8184
beforeAll(async () => {
@@ -112,10 +115,12 @@ describe('<TagListTable />', () => {
112115
axiosMock.onGet(rootTagsListUrl).reply(200, mockTagsResponse);
113116
const result = render(<RootWrapper />);
114117
await waitFor(() => {
115-
expect(result.getByText('two level tag 1')).toBeInTheDocument();
118+
expect(result.getByText('root tag 1')).toBeInTheDocument();
116119
});
117120
const rows = result.getAllByRole('row');
118121
expect(rows.length).toBe(3 + 1); // 3 items plus header
122+
expect(within(rows[0]).getAllByRole('columnheader')[0].textContent).toEqual('Tag name');
123+
expect(within(rows[1]).getAllByRole('cell')[0].textContent).toEqual('root tag 1 (14)');
119124
});
120125

121126
it('should render page correctly with subtags', async () => {

src/taxonomy/tag-list/data/types.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* @typedef {Object} TagData
1414
* @property {number} childCount
15+
* @property {number} descendantCount
1516
* @property {number} depth
1617
* @property {string} externalId
1718
* @property {number} id

0 commit comments

Comments
 (0)