Adds Proptypes to AddDropDownButton Component

Also refactors to use the url that is passed in as the key for the link.
This means that we don't have to pass in a key value.
This commit is contained in:
Alex Corey 2019-11-11 14:00:06 -05:00
parent d91aa8c6cf
commit 95cdddd670
3 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import React, { useState, useRef, useEffect } from 'react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Dropdown, DropdownPosition } from '@patternfly/react-core';
import { ToolbarAddButton } from '@components/PaginatedDataList';
@ -30,7 +31,7 @@ function AddDropDownButton({ dropdownItems }) {
dropdownItems={dropdownItems.map(item => (
<Link
className="pf-c-dropdown__menu-item"
key={item.key}
key={item.url}
to={item.url}
>
{item.label}
@ -41,5 +42,14 @@ function AddDropDownButton({ dropdownItems }) {
);
}
AddDropDownButton.propTypes = {
dropdownItems: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
})
).isRequired,
};
export { AddDropDownButton as _AddDropDownButton };
export default AddDropDownButton;

View File

@ -152,12 +152,10 @@ class InventoriesList extends Component {
key="add"
dropdownItems={[
{
key: 'inventory',
label: i18n._(t`Inventory`),
url: `${match.url}/inventory/add/`,
},
{
key: 'smart-inventory',
label: i18n._(t`Smart Inventory`),
url: `${match.url}/smart_inventory/add/`,
},

View File

@ -166,12 +166,10 @@ class TemplatesList extends Component {
key="add"
dropdownItems={[
{
key: 'template',
label: i18n._(t`Template`),
url: `${match.url}/template/add/`,
},
{
key: 'workflow_template',
label: i18n._(t`Workflow Template`),
url: `${match.url}/_workflow/add/`,
},