Skip to content

Commit

Permalink
fix: [AXIMST-737] add tooltip, change tag to button (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Kyrylo Hudym-Levkovych <[email protected]>
  • Loading branch information
2 people authored and GlugovGrGlib committed Apr 3, 2024
1 parent 2c5d415 commit c707b2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/course-unit/course-xblock/CourseXBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const CourseXBlock = ({
{
isContentTaxonomyTagsCountLoaded
&& contentTaxonomyTagsCount > 0
&& <div className="ml-2"><TagCount count={contentTaxonomyTagsCount} /></div>
&& <div className="ml-2"><TagCount count={contentTaxonomyTagsCount} onClick={openManageTagsModal} /></div>
}
<IconButton
alt={intl.formatMessage(messages.blockAltButtonEdit)}
Expand Down
14 changes: 11 additions & 3 deletions src/generic/tag-count/TagCount.test.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';

import TagCount from '.';

const renderComponent = (props) => render(
<IntlProvider locale="en">
<TagCount {...props} />,
</IntlProvider>,
);

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

it('should render the component with zero', () => {
render(<TagCount count={0} />);
renderComponent({ count: 0 });
expect(screen.getByText('0')).toBeInTheDocument();
});

it('should render a button with onClick', () => {
render(<TagCount count={17} onClick={() => {}} />);
renderComponent({ count: 17, onClick: () => {} });
expect(screen.getByRole('button', {
name: /17/i,
}));
Expand Down
25 changes: 21 additions & 4 deletions src/generic/tag-count/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import PropTypes from 'prop-types';
import { Icon, Button } from '@openedx/paragon';
import {
Icon, Button, OverlayTrigger, Tooltip,
} from '@openedx/paragon';
import { Tag } from '@openedx/paragon/icons';
import { useIntl } from '@edx/frontend-platform/i18n';
import classNames from 'classnames';

import messages from './messages';

const TagCount = ({ count, onClick }) => {
const intl = useIntl();

const renderContent = () => (
<>
<Icon className="mr-1 pt-1" src={Tag} />
Expand All @@ -17,9 +24,19 @@ const TagCount = ({ count, onClick }) => {
}
>
{ onClick ? (
<Button variant="tertiary" onClick={onClick}>
{renderContent()}
</Button>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={intl.formatMessage(messages.tooltipText)}>
{intl.formatMessage(messages.tooltipText)}
</Tooltip>
)}
>
<Button variant="tertiary" onClick={onClick}>
{renderContent()}
</Button>
</OverlayTrigger>

)
: renderContent()}
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/generic/tag-count/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineMessages } from '@edx/frontend-platform/i18n';

const messages = defineMessages({
tooltipText: {
id: 'course-authoring.generic.tag-count.tooltip.text',
defaultMessage: 'Manage tags',
},
});

export default messages;

0 comments on commit c707b2c

Please sign in to comment.