Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable selecting variable values in time machine #12678

Merged
merged 2 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## v2.0.0-alpha.7 [unreleased]

### Features

1. [12663](https://github.com/influxdata/influxdb/pull/12663): Insert flux function near cursor in flux editor
1. [12678](https://github.com/influxdata/influxdb/pull/12678): Enable the use of variables in the Data Explorer and Cell Editor Overlay

### Bug Fixes

Expand Down
41 changes: 11 additions & 30 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 49 additions & 87 deletions ui/src/clockface/components/dropdowns/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Libraries
import React, {Component, CSSProperties, MouseEvent} from 'react'
import classnames from 'classnames'
import {isUndefined, isNull} from 'lodash'

// Components
import {ClickOutside} from 'src/shared/components/ClickOutside'
Expand Down Expand Up @@ -80,9 +79,6 @@ class Dropdown extends Component<Props, State> {
const {widthPixels} = this.props
const width = widthPixels ? `${widthPixels}px` : '100%'

this.validateChildCount()
this.validateMode()

return (
<ClickOutside onClickOutside={this.collapseMenu}>
<div className={this.containerClassName} style={{width}}>
Expand Down Expand Up @@ -130,23 +126,29 @@ class Dropdown extends Component<Props, State> {
buttonColor,
buttonSize,
icon,
mode,
titleText,
buttonTestID,
} = this.props

const {expanded} = this.state
const children: JSX.Element[] = this.props.children

const selectedChild = children.find(child => child.props.id === selectedID)
const isLoading = status === ComponentStatus.Loading

let resolvedStatus = status
let dropdownLabel

if (isLoading) {
dropdownLabel = <WaitingText text="Loading" />
} else if (selectedChild) {
dropdownLabel = selectedChild.props.children
} else if (mode === DropdownMode.ActionList) {
dropdownLabel = titleText
} else {
dropdownLabel = titleText
resolvedStatus = ComponentStatus.Disabled
}

return (
Expand All @@ -156,7 +158,7 @@ class Dropdown extends Component<Props, State> {
size={buttonSize}
icon={icon}
onClick={this.toggleMenu}
status={status}
status={resolvedStatus}
title={titleText}
testID={buttonTestID}
>
Expand All @@ -174,55 +176,52 @@ class Dropdown extends Component<Props, State> {
children,
testID,
} = this.props

const {expanded} = this.state

if (expanded) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @alexpaxton @mavarius, could I get your opinion on this change? I removed the validation / dev assertion that a Dropdown must have at least 1 child.

I needed to display a dropdown that loads its items asynchronously. So it may no have any items (either hasn't been loaded, or has been loaded but no results were returned).

Screen Shot 2019-03-18 at 8 58 59 AM

Screen Shot 2019-03-18 at 8 59 08 AM

return (
<div
className={`dropdown--menu-container dropdown--${menuColor}`}
style={this.menuStyle}
>
<FancyScrollbar
autoHide={false}
autoHeight={true}
maxHeight={maxMenuHeight}
>
<div
className="dropdown--menu"
data-testid={`dropdown--menu ${testID}`}
>
{menuHeader && menuHeader}
{React.Children.map(children, (child: JSX.Element) => {
if (this.childTypeIsValid(child)) {
if (child.type === DropdownItem) {
return (
<DropdownItem
{...child.props}
key={child.props.id}
selected={child.props.id === selectedID}
onClick={this.handleItemClick}
>
{child.props.children}
</DropdownItem>
)
}

return (
<DropdownDivider {...child.props} key={child.props.id} />
)
} else {
throw new Error(
'Expected children of type <Dropdown.Item /> or <Dropdown.Divider />'
)
}
})}
</div>
</FancyScrollbar>
</div>
)
if (!expanded) {
return null
}

return null
return (
<div
className={`dropdown--menu-container dropdown--${menuColor}`}
style={this.menuStyle}
>
<FancyScrollbar
autoHide={false}
autoHeight={true}
maxHeight={maxMenuHeight}
>
<div
className="dropdown--menu"
data-testid={`dropdown--menu ${testID}`}
>
{menuHeader && menuHeader}
{React.Children.map(children, (child: JSX.Element) => {
if (child.type === DropdownItem) {
return (
<DropdownItem
{...child.props}
key={child.props.id}
selected={child.props.id === selectedID}
onClick={this.handleItemClick}
>
{child.props.children}
</DropdownItem>
)
} else if (child.type === DropdownDivider) {
return <DropdownDivider {...child.props} key={child.props.id} />
} else {
throw new Error(
'Expected children of type <Dropdown.Item /> or <Dropdown.Divider />'
)
}
})}
</div>
</FancyScrollbar>
</div>
)
}

private get menuStyle(): CSSProperties {
Expand All @@ -245,48 +244,11 @@ class Dropdown extends Component<Props, State> {
}
}

private get shouldHaveChildren(): boolean {
const {status} = this.props

return (
status === ComponentStatus.Default || status === ComponentStatus.Valid
)
}

private handleItemClick = (value: any): void => {
const {onChange} = this.props
onChange(value)
this.collapseMenu()
}

private validateChildCount = (): void => {
const {children} = this.props

if (this.shouldHaveChildren && React.Children.count(children) === 0) {
throw new Error(
'Dropdowns require at least 1 child element. We recommend using Dropdown.Item and/or Dropdown.Divider.'
)
}
}

private validateMode = (): void => {
const {mode, selectedID, titleText} = this.props

if (mode === DropdownMode.ActionList && titleText === '') {
throw new Error('Dropdowns in ActionList mode require a titleText prop.')
}

if (
mode === DropdownMode.Radio &&
this.shouldHaveChildren &&
(isUndefined(selectedID) || isNull(selectedID))
) {
throw new Error('Dropdowns in Radio mode require a selectedID prop.')
}
}

private childTypeIsValid = (child: JSX.Element): boolean =>
child.type === DropdownItem || child.type === DropdownDivider
}

export default Dropdown
4 changes: 4 additions & 0 deletions ui/src/clockface/components/dropdowns/DropdownButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
}
}

.dropdown--button.button-disabled {
font-style: italic;
}

.dropdown--button.button-xs {
@include buttonSizing($form-xs-padding, $form-xs-font);
}
Expand Down
Loading