Skip to content

Commit

Permalink
feat: Taxonomy card menu added. Export menu item added
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Oct 18, 2023
1 parent 4a917fe commit 0bdfbb1
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
@import "course-updates/CourseUpdates";
@import "export-page/CourseExportPage";
@import "import-page/CourseImportPage";
@import "taxonomy/TaxonomyCard.scss";
41 changes: 36 additions & 5 deletions src/taxonomy/TaxonomyCard.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import React from 'react';
import React, { useState } from 'react';
import {
Badge,
IconButton,
Card,
OverlayTrigger,
Popover,
ModalPopup,
Menu,
Icon,
MenuItem,
} from '@edx/paragon';
import { MoreVert } from '@edx/paragon/icons';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import messages from './messages';
import './TaxonomyCard.scss';

const TaxonomyCard = ({ className, original, intl }) => {
const {
id, name, description, systemDefined, orgsCount,
} = original;

const [menuIsOpen, setMenuIsOpen] = useState(false);
const [menuTarget, setMenuTarget] = useState(null);

const orgsCountEnabled = () => orgsCount !== undefined && orgsCount !== 0;

const getSystemBadgeToolTip = () => (
Expand Down Expand Up @@ -53,10 +61,33 @@ const TaxonomyCard = ({ className, original, intl }) => {
return undefined;
};

const onClickExport = () => {
setMenuIsOpen(false);
};

const getHeaderActions = () => (
// Menu button
// TODO Add functionality to this menu
undefined
<>
<IconButton
variant="primary"
onClick={() => setMenuIsOpen(true)}
ref={setMenuTarget}
src={MoreVert}
iconAs={Icon}
alt={intl.formatMessage(messages.taxonomyMenuAlt, { name })}
data-testid={`taxonomy-card-menu-button-${id}`}
/>
<ModalPopup
positionRef={menuTarget}
isOpen={menuIsOpen}
onClose={() => setMenuIsOpen(false)}
>
<Menu data-testid={`taxonomy-card-menu-${id}`}>
<MenuItem className="taxonomy-menu-item" onClick={onClickExport}>
{intl.formatMessage(messages.taxonomyCardExportMenu)}
</MenuItem>
</Menu>
</ModalPopup>
</>
);

return (
Expand Down
17 changes: 17 additions & 0 deletions src/taxonomy/TaxonomyCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@
text-overflow: ellipsis;
white-space: nowrap;
}

.taxonomy-menu-item:focus {
/**
* There is a bug in the menu that auto focus the first item.
* We convert the focus style to a normal style.
*/
background-color: white !important;
font-weight: normal !important;
}

.taxonomy-menu-item:focus:hover {
/**
* Check the previous block about the focus.
* This enable a normal hover to focused items.
*/
background-color: $light-500 !important;
}
}
22 changes: 21 additions & 1 deletion src/taxonomy/TaxonomyCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n';
import { initializeMockApp } from '@edx/frontend-platform';
import { AppProvider } from '@edx/frontend-platform/react';
import { render } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import PropTypes from 'prop-types';

import initializeStore from '../store';
Expand All @@ -12,6 +12,7 @@ import TaxonomyCard from './TaxonomyCard';
let store;

const data = {
id: 1,
name: 'Taxonomy 1',
description: 'This is a description',
};
Expand Down Expand Up @@ -81,4 +82,23 @@ describe('<TaxonomyCard />', async () => {
const { getByText } = render(<TaxonomyCardComponent original={cardData} />);
expect(getByText('Assigned to 6 orgs')).toBeInTheDocument();
});

test('should open and close menu on button click', () => {
const { getByTestId, getByText } = render(<TaxonomyCardComponent original={data} />);

// Menu closed
expect(() => getByTestId('taxonomy-card-menu-1')).toThrow();

// Click on the menu button to open
fireEvent.click(getByTestId('taxonomy-card-menu-button-1'));

// Menu open
expect(getByTestId('taxonomy-card-menu-1')).toBeInTheDocument();

// Click on any element to close the menu
fireEvent.click(getByText('Export'));

// Menu closed
expect(() => getByTestId('taxonomy-card-menu-1')).toThrow();
});
});
8 changes: 8 additions & 0 deletions src/taxonomy/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const messages = defineMessages({
id: 'course-authoring.taxonomy-list.popover.system-defined.body',
defaultMessage: 'This is a system-level taxonomy and is enabled by default.',
},
taxonomyCardExportMenu: {
id: 'course-authoring.taxonomy-list.menu.export.label',
defaultMessage: 'Export',
},
taxonomyMenuAlt: {
id: 'course-authoring.taxonomy-list.menu.alt',
defaultMessage: '{name} menu',
},
});

export default messages;

0 comments on commit 0bdfbb1

Please sign in to comment.