Skip to content

Commit

Permalink
refactor: Extract tag count component as generic
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Feb 27, 2024
1 parent 63f9d31 commit 56aefd1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/content-tags-drawer/tags-sidebar/TagsSidebar.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
.tags-sidebar {
.course-unit-sidebar-header {
padding-bottom: .25rem !important;

.course-unit-sidebar-header-count.zero-count {
opacity: .4;
}
}

.tags-sidebar-body {
Expand Down
18 changes: 3 additions & 15 deletions src/content-tags-drawer/tags-sidebar/TagsSidebarHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Icon, Stack } from '@openedx/paragon';
import { Tag } from '@openedx/paragon/icons';
import { Stack } from '@openedx/paragon';
import { useParams } from 'react-router-dom';
import { useIntl } from '@edx/frontend-platform/i18n';
import classNames from 'classnames';

import messages from '../messages';
import { useContentTaxonomyTagsCount } from '../data/apiHooks';
import TagCount from '../../generic/tag-count';

const TagsSidebarHeader = () => {
const intl = useIntl();
Expand All @@ -22,18 +21,7 @@ const TagsSidebarHeader = () => {
{intl.formatMessage(messages.tagsSidebarTitle)}
</h3>
{ isContentTaxonomyTagsCountLoaded
&& (
<div className={
classNames('course-unit-sidebar-header-count d-flex', { 'zero-count': contentTaxonomyTagsCount === 0 })
}
>
<Icon
className="mr-1 pt-1"
src={Tag}
/>
{contentTaxonomyTagsCount}
</div>
)}
&& <TagCount count={contentTaxonomyTagsCount} />}
</Stack>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/generic/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@import "./create-or-rerun-course/CreateOrRerunCourseForm";
@import "./WysiwygEditor";
@import "./course-stepper/CouseStepper";
@import "./tag-count/TagCount";
3 changes: 3 additions & 0 deletions src/generic/tag-count/TagCount.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.generic-tag-count.zero-count {
opacity: .4;
}
17 changes: 17 additions & 0 deletions src/generic/tag-count/TagCount.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import TagCount from '.';

describe('<TagCount>', () => {
it('should render the component', () => {
const count = 17;
render(<TagCount count={count} />);
expect(screen.getByText('17')).toBeInTheDocument();
});

it('should render the component with zero', () => {
const count = 0;
render(<TagCount count={count} />);
expect(screen.getByText('0')).toBeInTheDocument();
});
});
20 changes: 20 additions & 0 deletions src/generic/tag-count/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PropTypes from 'prop-types';
import { Icon } from '@openedx/paragon';
import { Tag } from '@openedx/paragon/icons';
import classNames from 'classnames';

const TagCount = ({ count }) => (
<div className={
classNames('generic-tag-count d-flex', { 'zero-count': count === 0 })
}
>
<Icon className="mr-1 pt-1" src={Tag} />
{count}
</div>
);

TagCount.propTypes = {
count: PropTypes.number.isRequired,
};

export default TagCount;

0 comments on commit 56aefd1

Please sign in to comment.