Skip to content

Commit

Permalink
feat(dashboards): add variable control bar for selecting values
Browse files Browse the repository at this point in the history
Co-Authored-By: Alex Paxton <thealexpaxton@gmail.com>
  • Loading branch information
AlirieGray and alexpaxton committed Mar 15, 2019
1 parent 71bc904 commit 0688ce5
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## v2.0.0-alpha.6 [unreleased]

### Features

1. [12496](https://github.com/influxdata/influxdb/pull/12496): Add ability to import a dashboard
1. [12524](https://github.com/influxdata/influxdb/pull/12524): Add ability to import a dashboard from org view
1. [12531](https://github.com/influxdata/influxdb/pull/12531): Add ability to export a dashboard and a task
1. [12615](https://github.com/influxdata/influxdb/pull/12615): Add `run` subcommand to influxd binary. This is also the default when no subcommand is specified.

1. [12523](https://github.com/influxdata/influxdb/pull/12523): Add ability to save a query as a variable from the Data Explorer.
1. [12655](https://github.com/influxdata/influxdb/pull/12655): Add a variable control bar to dashboards to select values for variables.

### Bug Fixes

Expand Down
9 changes: 6 additions & 3 deletions ui/src/clockface/components/empty_state/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ErrorHandling} from 'src/shared/decorators/errors'

interface PassedProps {
children: JSX.Element | JSX.Element[]
className?: string
}

interface DefaultProps {
Expand All @@ -36,12 +37,14 @@ class EmptyState extends Component<Props> {
public static SubText = EmptyStateSubText

public render() {
const {children, size, testID} = this.props
const {children, size, testID, className} = this.props

const className = `empty-state empty-state--${size}`
const classname = className
? `empty-state empty-state--${size} ${className}`
: `empty-state empty-state--${size}`

return (
<div className={className} data-testid={testID}>
<div className={classname} data-testid={testID}>
{children}
</div>
)
Expand Down
13 changes: 13 additions & 0 deletions ui/src/dashboards/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ interface OwnProps {
showTemplateControlBar: boolean
zoomedTimeRange: QueriesModels.TimeRange
onRenameDashboard: (name: string) => Promise<void>
toggleVariablesControlBar: () => void
isShowingVariablesControlBar: boolean
isHidden: boolean
}

Expand Down Expand Up @@ -69,6 +71,8 @@ class DashboardHeader extends Component<Props> {
zoomedTimeRange: {upper: zoomedUpper, lower: zoomedLower},
isHidden,
onAddNote,
toggleVariablesControlBar,
isShowingVariablesControlBar,
} = this.props

return (
Expand All @@ -94,6 +98,15 @@ class DashboardHeader extends Component<Props> {
lower: zoomedLower || lower,
}}
/>
<Button
text="Variables"
onClick={toggleVariablesControlBar}
color={
isShowingVariablesControlBar
? ComponentColor.Primary
: ComponentColor.Default
}
/>
<Button
icon={IconFont.ExpandA}
titleText="Enter Presentation Mode"
Expand Down
16 changes: 15 additions & 1 deletion ui/src/dashboards/components/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import VEO from 'src/dashboards/components/VEO'
import {Overlay} from 'src/clockface'
import {HoverTimeProvider} from 'src/dashboards/utils/hoverTime'
import NoteEditorContainer from 'src/dashboards/components/NoteEditorContainer'
import VariablesControlBar from 'src/dashboards/components/variablesControlBar/VariablesControlBar'

// Actions
import * as dashboardActions from 'src/dashboards/actions/v2'
Expand Down Expand Up @@ -105,6 +106,7 @@ interface State {
scrollTop: number
windowHeight: number
isShowingVEO: boolean
isShowingVariablesControlBar: boolean
}

@ErrorHandling
Expand All @@ -116,6 +118,7 @@ class DashboardPage extends Component<Props, State> {
scrollTop: 0,
windowHeight: window.innerHeight,
isShowingVEO: false,
isShowingVariablesControlBar: false,
}
}

Expand Down Expand Up @@ -163,7 +166,7 @@ class DashboardPage extends Component<Props, State> {
handleChooseAutoRefresh,
handleClickPresentationButton,
} = this.props
const {isShowingVEO} = this.state
const {isShowingVEO, isShowingVariablesControlBar} = this.state

return (
<Page titleTag={this.pageTitle}>
Expand All @@ -182,7 +185,12 @@ class DashboardPage extends Component<Props, State> {
handleChooseAutoRefresh={handleChooseAutoRefresh}
handleChooseTimeRange={this.handleChooseTimeRange}
handleClickPresentationButton={handleClickPresentationButton}
toggleVariablesControlBar={this.toggleVariablesControlBar}
isShowingVariablesControlBar={isShowingVariablesControlBar}
/>
{isShowingVariablesControlBar && (
<VariablesControlBar dashboardID={dashboard.id} />
)}
{!!dashboard && (
<DashboardComponent
inView={this.inView}
Expand Down Expand Up @@ -322,6 +330,12 @@ class DashboardPage extends Component<Props, State> {
this.setState({windowHeight: window.innerHeight})
}

private toggleVariablesControlBar = (): void => {
this.setState({
isShowingVariablesControlBar: !this.state.isShowingVariablesControlBar,
})
}

private get pageTitle(): string {
const {dashboard} = this.props

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@import 'src/style/modules';

.variable-dropdown {
display: flex;
flex-direction: row;
height: $form-sm-height;
}

.variable-dropdown--dropdown {
.button {
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
}
}

.variable-dropdown--label {
user-select: none;
line-height: $form-sm-height;
font-size: $form-sm-font;
font-weight: 600;
color: $c-comet;
white-space: nowrap;
overflow: hidden;
padding: 0 $form-sm-padding;
border-radius: $radius 0 0 $radius;
background-color: $g3-castle;
background-attachment: fixed;

> span {
@include gradient-h($c-comet, $c-laser);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Libraries
import React, {PureComponent} from 'react'
import {Dropdown, DropdownMenuColors} from 'src/clockface'

// Styles
import 'src/dashboards/components/variablesControlBar/VariableDropdown.scss'

interface Props {
name: string
variableID: string
values: string[] //todo
initialSelected: string // todo
onSelect: (variableID: string, value: string) => void // todo
}

interface State {
selectedValue: any // todo
}

class VariableDropdown extends PureComponent<Props, State> {
constructor(props) {
super(props)

this.state = {
selectedValue: this.props.initialSelected,
}
}

render() {
const {name} = this.props
const {selectedValue} = this.state

return (
<div className="variable-dropdown">
{/* TODO: Add variable description to title attribute when it is ready */}
<div className="variable-dropdown--label">
<span>{name}</span>
</div>
<Dropdown
selectedID={selectedValue}
onChange={this.handleSelect}
widthPixels={140}
customClass="variable-dropdown--dropdown"
menuColor={DropdownMenuColors.Amethyst}
>
{this.dropdownItems}
</Dropdown>
</div>
)
}

private get dropdownItems(): JSX.Element[] {
const {values} = this.props

return values.map(v => {
return (
<Dropdown.Item key={v} id={v} value={v}>
{v}
</Dropdown.Item>
)
})
}

private handleSelect = (value: string) => {
const {variableID, onSelect} = this.props
onSelect(variableID, value)
}
}

export default VariableDropdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@import 'src/style/modules';

$variables-control-bar--height: $page-header-size -
(($page-header-size - $form-sm-height) / 2);

$variables-control-bar--gutter: $ix-marg-a;

.variables-control-bar {
min-height: $variables-control-bar--height;
display: flex;
align-items: flex-start;
flex-wrap: wrap;
padding: 0 ($page-gutter - ($variables-control-bar--gutter / 2));
padding-bottom: (($page-header-size - $form-sm-height) / 2) -
$variables-control-bar--gutter;

/* Adjust height of Page Contents when control bar is present */
& + .page-contents {
height: calc(
100% - #{$variables-control-bar--height + $page-header-size}
) !important;
}

.variable-dropdown {
margin: 0 $variables-control-bar--gutter / 2;
margin-bottom: $variables-control-bar--gutter;
}
}

.variables-control-bar--empty {
background-color: $g3-castle;
border-radius: $radius;
height: 100%;
justify-content: center;
}
Loading

0 comments on commit 0688ce5

Please sign in to comment.