-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ParamDropdown and WidgetHeader
new file for WidgetHeader
- Loading branch information
Showing
11 changed files
with
159 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Dropdown, | ||
DropdownItem, | ||
DropdownList, | ||
MenuToggle, | ||
Text, | ||
Tooltip | ||
} from '@patternfly/react-core'; | ||
|
||
|
||
const ParamDropdown = (props) => { | ||
const { | ||
defaultValue, | ||
handleSelect, | ||
tooltip, | ||
dropdownItems | ||
} = props; | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
const [value, setValue] = useState(defaultValue || 'Group data by?'); | ||
|
||
const dropOnSelect = (event) => { | ||
setIsOpen(!isOpen); | ||
handleSelect(event.target.innerText); | ||
setValue(event.target.innerText); | ||
} | ||
|
||
useEffect(()=>{ | ||
setValue(defaultValue) | ||
}, [defaultValue, setValue]) | ||
|
||
return ( | ||
// TODO this formatting of the dropdown labels is ugly as hell | ||
<React.Fragment> | ||
<div data-id='widget-param-dropdown'> | ||
<Text component='h3'>{tooltip}</Text> | ||
<Tooltip content={tooltip}> | ||
<Dropdown | ||
isOpen={isOpen} | ||
onSelect={dropOnSelect} | ||
onOpenChange={() => setIsOpen(false)} | ||
toggle={toggleRef => ( | ||
<MenuToggle | ||
id="toggle-dropdown" | ||
ref={toggleRef} | ||
onClick={() => setIsOpen(!isOpen)} | ||
isExpanded={isOpen} | ||
> | ||
{value} | ||
</MenuToggle> | ||
)} | ||
ouiaId="BasicDropdown" | ||
shouldFocusToggleOnSelect | ||
> | ||
<DropdownList> | ||
{dropdownItems && dropdownItems.map((item) => ( | ||
<DropdownItem onClick={dropOnSelect} key={item}> | ||
{item} | ||
</DropdownItem> | ||
))} | ||
<></> | ||
</DropdownList> | ||
</Dropdown> | ||
</Tooltip> | ||
</div> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
ParamDropdown.propTypes = { | ||
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
dropdownItems: PropTypes.array, | ||
handleSelect: PropTypes.func, | ||
tooltip: PropTypes.string | ||
}; | ||
|
||
export default ParamDropdown; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Button, | ||
CardHeader, | ||
Title, | ||
} from '@patternfly/react-core'; | ||
import { PficonHistoryIcon, TimesIcon, PencilAltIcon } from '@patternfly/react-icons'; | ||
|
||
const WidgetHeader = (props) => { | ||
const { | ||
id, | ||
getDataFunc, | ||
onDeleteClick, | ||
title, | ||
actions, | ||
onEditClick | ||
} = props; | ||
|
||
const headerActions = ( | ||
<React.Fragment> | ||
{actions ? actions : []} | ||
{getDataFunc && | ||
<Button variant="plain" onClick={() => {getDataFunc()}} title="Refresh" aria-label="Refresh" isInline> | ||
<PficonHistoryIcon /> | ||
</Button> | ||
} | ||
{onEditClick && | ||
<Button variant="plain" onClick={() => {onEditClick()}} title="Edit" aria-label="Edit" isInline> | ||
<PencilAltIcon /> | ||
</Button> | ||
} | ||
{onDeleteClick && | ||
<Button variant="plain" onClick={() => {onDeleteClick()}} title="Remove from dashboard" aria-label="Delete" isInline> | ||
<TimesIcon /> | ||
</Button> | ||
} | ||
</React.Fragment> | ||
); | ||
|
||
return ( | ||
<CardHeader id={id} data-id="widget-header" actions={{ actions: headerActions }}> | ||
<Title headingLevel='h2'>{title}</Title> | ||
</CardHeader> | ||
); | ||
} | ||
|
||
WidgetHeader.propTypes = { | ||
id: PropTypes.string, | ||
getDataFunc: PropTypes.func, | ||
onDeleteClick: PropTypes.func, | ||
title: PropTypes.string, | ||
actions: PropTypes.array, | ||
onEditClick: PropTypes.func | ||
} | ||
|
||
export default WidgetHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.