-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboards): add variable control bar for selecting values
Co-Authored-By: Alex Paxton <thealexpaxton@gmail.com>
- Loading branch information
1 parent
243f1ea
commit 260c612
Showing
9 changed files
with
345 additions
and
6 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
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
34 changes: 34 additions & 0 deletions
34
ui/src/dashboards/components/variablesControlBar/VariableDropdown.scss
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,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; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
ui/src/dashboards/components/variablesControlBar/VariableDropdown.tsx
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,93 @@ | ||
// Libraries | ||
import React, {PureComponent} from 'react' | ||
import {connect} from 'react-redux' | ||
import _ from 'lodash' | ||
|
||
// Components | ||
import {Dropdown, DropdownMenuColors} from 'src/clockface' | ||
|
||
// Utils | ||
import { | ||
getValuesForVariable, | ||
getSelectedValueForVariable, | ||
} from 'src/variables/selectors' | ||
|
||
// Styles | ||
import 'src/dashboards/components/variablesControlBar/VariableDropdown.scss' | ||
|
||
// Types | ||
import {AppState} from 'src/types/v2' | ||
|
||
interface StateProps { | ||
values: string[] | ||
selectedValue: string | ||
} | ||
|
||
interface OwnProps { | ||
name: string | ||
variableID: string | ||
dashboardID: string | ||
onSelect: (variableID: string, value: string) => void | ||
} | ||
|
||
type Props = StateProps & OwnProps | ||
|
||
class VariableDropdown extends PureComponent<Props> { | ||
render() { | ||
const {name, selectedValue} = this.props | ||
|
||
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) | ||
} | ||
} | ||
|
||
const mstp = (state: AppState, props: OwnProps): StateProps => { | ||
const {dashboardID, variableID} = props | ||
|
||
const values = getValuesForVariable(state, variableID, dashboardID) | ||
|
||
const selectedValue = getSelectedValueForVariable( | ||
state, | ||
variableID, | ||
dashboardID | ||
) | ||
|
||
return {values, selectedValue} | ||
} | ||
|
||
export default connect<StateProps, {}, OwnProps>( | ||
mstp, | ||
null | ||
)(VariableDropdown) |
35 changes: 35 additions & 0 deletions
35
ui/src/dashboards/components/variablesControlBar/VariablesControlBar.scss
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,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; | ||
} |
Oops, something went wrong.