Create type for menu item action
Also renaming “MenuOption” to be “MenuItem”pull/10616/head
parent
14225f67d9
commit
cd73ef416d
|
@ -5,7 +5,7 @@ import {bindActionCreators} from 'redux'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import MenuTooltipButton, {
|
import MenuTooltipButton, {
|
||||||
MenuOption,
|
MenuItem,
|
||||||
} from 'src/shared/components/MenuTooltipButton'
|
} from 'src/shared/components/MenuTooltipButton'
|
||||||
import CustomTimeIndicator from 'src/shared/components/CustomTimeIndicator'
|
import CustomTimeIndicator from 'src/shared/components/CustomTimeIndicator'
|
||||||
import Authorized, {EDITOR_ROLE} from 'src/auth/Authorized'
|
import Authorized, {EDITOR_ROLE} from 'src/auth/Authorized'
|
||||||
|
@ -96,21 +96,21 @@ class LayoutCellMenu extends Component<Props, State> {
|
||||||
{queries.length ? (
|
{queries.length ? (
|
||||||
<MenuTooltipButton
|
<MenuTooltipButton
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
menuOptions={this.editMenuOptions}
|
menuItems={this.editMenuItems}
|
||||||
informParent={this.handleToggleSubMenu}
|
informParent={this.handleToggleSubMenu}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<Authorized requiredRole={EDITOR_ROLE}>
|
<Authorized requiredRole={EDITOR_ROLE}>
|
||||||
<MenuTooltipButton
|
<MenuTooltipButton
|
||||||
icon="duplicate"
|
icon="duplicate"
|
||||||
menuOptions={this.cloneMenuOptions}
|
menuItems={this.cloneMenuItems}
|
||||||
informParent={this.handleToggleSubMenu}
|
informParent={this.handleToggleSubMenu}
|
||||||
/>
|
/>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<MenuTooltipButton
|
<MenuTooltipButton
|
||||||
icon="trash"
|
icon="trash"
|
||||||
theme="danger"
|
theme="danger"
|
||||||
menuOptions={this.deleteMenuOptions}
|
menuItems={this.deleteMenuItems}
|
||||||
informParent={this.handleToggleSubMenu}
|
informParent={this.handleToggleSubMenu}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -133,7 +133,7 @@ class LayoutCellMenu extends Component<Props, State> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private get editMenuOptions(): MenuOption[] {
|
private get editMenuItems(): MenuItem[] {
|
||||||
const {
|
const {
|
||||||
cell,
|
cell,
|
||||||
dataExists,
|
dataExists,
|
||||||
|
@ -166,11 +166,11 @@ class LayoutCellMenu extends Component<Props, State> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
private get cloneMenuOptions(): MenuOption[] {
|
private get cloneMenuItems(): MenuItem[] {
|
||||||
return [{text: 'Clone Cell', action: this.handleCloneCell, disabled: false}]
|
return [{text: 'Clone Cell', action: this.handleCloneCell, disabled: false}]
|
||||||
}
|
}
|
||||||
|
|
||||||
private get deleteMenuOptions(): MenuOption[] {
|
private get deleteMenuItems(): MenuItem[] {
|
||||||
return [{text: 'Confirm', action: this.handleDeleteCell, disabled: false}]
|
return [{text: 'Confirm', action: this.handleDeleteCell, disabled: false}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@ import {ClickOutside} from 'src/shared/components/ClickOutside'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
|
||||||
export interface MenuOption {
|
type MenuItemAction = () => void
|
||||||
|
|
||||||
|
export interface MenuItem {
|
||||||
text: string
|
text: string
|
||||||
action: () => void
|
action: MenuItemAction
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +15,7 @@ interface Props {
|
||||||
theme?: string
|
theme?: string
|
||||||
icon: string
|
icon: string
|
||||||
informParent: () => void
|
informParent: () => void
|
||||||
menuOptions: MenuOption[]
|
menuItems: MenuItem[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
@ -54,11 +56,11 @@ export default class MenuTooltipButton extends Component<Props, State> {
|
||||||
informParent()
|
informParent()
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleMenuItemClick = menuItemAction => (): void => {
|
private handleMenuItemClick = (action: MenuItemAction) => (): void => {
|
||||||
const {informParent} = this.props
|
const {informParent} = this.props
|
||||||
|
|
||||||
this.setState({expanded: false})
|
this.setState({expanded: false})
|
||||||
menuItemAction()
|
action()
|
||||||
informParent()
|
informParent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ export default class MenuTooltipButton extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private get renderMenu(): JSX.Element {
|
private get renderMenu(): JSX.Element {
|
||||||
const {menuOptions, theme} = this.props
|
const {menuItems, theme} = this.props
|
||||||
const {expanded} = this.state
|
const {expanded} = this.state
|
||||||
|
|
||||||
if (expanded === false) {
|
if (expanded === false) {
|
||||||
|
@ -96,7 +98,7 @@ export default class MenuTooltipButton extends Component<Props, State> {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`dash-graph-context--menu ${theme}`}>
|
<div className={`dash-graph-context--menu ${theme}`}>
|
||||||
{menuOptions.map((option, i) => (
|
{menuItems.map((option, i) => (
|
||||||
<div
|
<div
|
||||||
key={i}
|
key={i}
|
||||||
className={`dash-graph-context--menu-item${
|
className={`dash-graph-context--menu-item${
|
||||||
|
|
Loading…
Reference in New Issue