Skip to content

Commit

Permalink
refactor: Use useContentTaxonomyTagsData to get tagsCount
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Sep 25, 2024
1 parent 1db25e8 commit 0ec25b4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/library-authoring/component-info/ComponentManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Collapsible, Icon, Stack } from '@openedx/paragon';
Expand All @@ -7,13 +8,34 @@ import { useLibraryBlockMetadata } from '../data/apiHooks';
import StatusWidget from '../generic/status-widget';
import messages from './messages';
import { ContentTagsDrawer } from '../../content-tags-drawer';
import { useContentTaxonomyTagsData } from '../../content-tags-drawer/data/apiHooks';

interface ComponentManagementProps {
usageKey: string;
}
const ComponentManagement = ({ usageKey }: ComponentManagementProps) => {
const intl = useIntl();
const { data: componentMetadata } = useLibraryBlockMetadata(usageKey);
const { data: componentTags } = useContentTaxonomyTagsData(usageKey);

const tagsCount = React.useMemo(() => {
if (!componentTags) {
return 0;
}
let result = 0;
componentTags.taxonomies.forEach((taxonomy) => {
const countedTags : string[] = [];
taxonomy.tags.forEach((tagData) => {
tagData.lineage.forEach((tag) => {

Check warning on line 29 in src/library-authoring/component-info/ComponentManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentManagement.tsx#L25-L29

Added lines #L25 - L29 were not covered by tests
if (!countedTags.includes(tag)) {
result += 1;
countedTags.push(tag);

Check warning on line 32 in src/library-authoring/component-info/ComponentManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentManagement.tsx#L31-L32

Added lines #L31 - L32 were not covered by tests
}
});
});
});
return result;

Check warning on line 37 in src/library-authoring/component-info/ComponentManagement.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/component-info/ComponentManagement.tsx#L37

Added line #L37 was not covered by tests
}, [componentTags]);

if (!componentMetadata) {
return null;
Expand All @@ -31,7 +53,7 @@ const ComponentManagement = ({ usageKey }: ComponentManagementProps) => {
title={(
<Stack gap={1} direction="horizontal">
<Icon src={Tag} />
{intl.formatMessage(messages.manageTabTagsTitle, { count: componentMetadata.tagsCount })}
{intl.formatMessage(messages.manageTabTagsTitle, { count: tagsCount })}
</Stack>
)}
className="border-0"
Expand Down

0 comments on commit 0ec25b4

Please sign in to comment.