2020-03-10 02:53:41 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-04-27 02:09:05 -05:00
|
|
|
import { getTagColorsFromName, Icon, Tooltip } from '@grafana/ui';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
|
|
|
2020-06-04 06:44:48 -05:00
|
|
|
import { VariableOption, VariableTag } from '../../types';
|
2020-03-10 02:53:41 -05:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
multi: boolean;
|
|
|
|
values: VariableOption[];
|
|
|
|
selectedValues: VariableOption[];
|
|
|
|
tags: VariableTag[];
|
|
|
|
highlightIndex: number;
|
|
|
|
onToggle: (option: VariableOption, clearOthers: boolean) => void;
|
|
|
|
onToggleAll: () => void;
|
|
|
|
onToggleTag: (tag: VariableTag) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class VariableOptions extends PureComponent<Props> {
|
|
|
|
onToggle = (option: VariableOption) => (event: React.MouseEvent<HTMLAnchorElement>) => {
|
|
|
|
const clearOthers = event.shiftKey || event.ctrlKey || event.metaKey;
|
|
|
|
this.handleEvent(event);
|
|
|
|
this.props.onToggle(option, clearOthers);
|
|
|
|
};
|
|
|
|
|
|
|
|
onToggleAll = (event: React.MouseEvent<HTMLAnchorElement>) => {
|
|
|
|
this.handleEvent(event);
|
|
|
|
this.props.onToggleAll();
|
|
|
|
};
|
|
|
|
|
|
|
|
onToggleTag = (tag: VariableTag) => (event: React.MouseEvent<HTMLAnchorElement>) => {
|
|
|
|
this.handleEvent(event);
|
|
|
|
this.props.onToggleTag(tag);
|
|
|
|
};
|
|
|
|
|
|
|
|
handleEvent(event: React.MouseEvent<HTMLAnchorElement>) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { multi, values, tags } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`${multi ? 'variable-value-dropdown multi' : 'variable-value-dropdown single'}`}
|
2020-04-27 02:09:05 -05:00
|
|
|
aria-label={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownDropDown}
|
2020-03-10 02:53:41 -05:00
|
|
|
>
|
|
|
|
<div className="variable-options-wrapper">
|
|
|
|
<div className="variable-options-column">
|
|
|
|
{this.renderMultiToggle()}
|
|
|
|
{values.map((option, index) => this.renderOption(option, index))}
|
|
|
|
</div>
|
|
|
|
{this.renderTags(tags)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTags(tags: VariableTag[]) {
|
|
|
|
if (tags.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="variable-options-column">
|
|
|
|
<div className="variable-options-column-header text-center">Tags</div>
|
|
|
|
{tags.map(tag => this.renderTag(tag))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTag(tag: VariableTag) {
|
|
|
|
const { color, borderColor } = getTagColorsFromName(tag.text.toString());
|
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
key={`${tag.text}`}
|
|
|
|
className={`${tag.selected ? 'variable-option-tag pointer selected' : 'variable-option-tag pointer'}`}
|
|
|
|
onClick={this.onToggleTag(tag)}
|
|
|
|
>
|
2020-11-04 06:34:40 -06:00
|
|
|
<span className="variable-option-icon"></span>
|
2020-03-10 02:53:41 -05:00
|
|
|
<span className="label-tag" style={{ backgroundColor: color, borderColor }}>
|
@grafana/ui: Create Icon component and replace part of the icons (#23402)
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Resolve type errors resulted from merge
* Part2: Unicons implementation (#23266)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Icons update
* Add optional chaining to for isFontAwesome variable
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Part3: Unicons implementation (#23356)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Implment icons in Tabs
* Implement icons in search items and empty list
* Update buttons
* Update button-related snapshot tests
* Update icons in modals and page headers
* Create anfular wrapper and update all icons on search screen
* Update sizing, remove colors, update snapshot tests
* Remove color prop from icon, remove color implemetation in mono icons
* Remove color props from monochrome icons
* Complete update of icons for search screen
* Update icons for infor tooltips, playlist, permissions
* Support temporarly font awesome icons used in enterprise grafana
* Part1: Unicons implementation (#23197)
* Create a new Icon component
* Update icons in main sidebar
* Update icons in Useful links and in react components on main site
* Update icons in Useful links and in main top navigation
* Adjust sizing
* Update panel navigation and timepicker
* Update icons in Panel menu
* NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
* Update icons in add panel widget
* Resolve merge conflict
* Fix part of the test errors and type errors
* Fix storybook errors
* Update getAvailableIcons import in storybook knobs
* Fix import path
* Fix SyntaxError: Cannot use import statement outside a module in test environment error
* Remove dynamic imports
* Remove types as using @ts-ignore
* Update snapshot test
* Add @iconscout/react-unicons to the shouldExclude list as it is blundled with es2015 syntax
* Remove color prop from icon, remove color implemetation in mono icons
* Update navbar styling
* Move toPascalCase to utils/string
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Update icons in Explore
* Update icons in alerting
* Update + and x buttons
* Update icons in configurations and settings
* Update close icons
* Update icons in rich history
* Update alert messages
* Add optional chaining to for isFontAwesome variable
* Remove icon mock, set up jest.config
* Fix navbar plus icon
* Fir enable-bacground to enableBackgournd
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* Merge remote branch origin master to icons-unicons
* Revert "Merge remote branch origin master to icons-unicons"
This reverts commit 3f25d50a39a940883fefe73ce51219139c1ed37f.
* Size-up dashnav icons
* Fix alerting icons, panel headers, update tests
* Fix typecheck error
* Adjustments - add panel icon, spacing
* Set TerserPlugin sourceMap to false to prevent running out of memory when publishing storybook
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2020-04-08 07:33:31 -05:00
|
|
|
{tag.text}
|
|
|
|
<Icon name="tag-alt" />
|
|
|
|
|
2020-03-10 02:53:41 -05:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderOption(option: VariableOption, index: number) {
|
|
|
|
const { highlightIndex } = this.props;
|
|
|
|
const selectClass = option.selected ? 'variable-option pointer selected' : 'variable-option pointer';
|
|
|
|
const highlightClass = index === highlightIndex ? `${selectClass} highlighted` : selectClass;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<a key={`${option.value}`} className={highlightClass} onClick={this.onToggle(option)}>
|
|
|
|
<span className="variable-option-icon"></span>
|
2020-04-27 02:09:05 -05:00
|
|
|
<span aria-label={selectors.pages.Dashboard.SubMenu.submenuItemValueDropDownOptionTexts(`${option.text}`)}>
|
2020-03-10 02:53:41 -05:00
|
|
|
{option.text}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderMultiToggle() {
|
|
|
|
const { multi, selectedValues } = this.props;
|
|
|
|
|
|
|
|
if (!multi) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip content={'Clear selections'} placement={'top'}>
|
|
|
|
<a
|
|
|
|
className={`${
|
|
|
|
selectedValues.length > 1
|
|
|
|
? 'variable-options-column-header many-selected'
|
|
|
|
: 'variable-options-column-header'
|
|
|
|
}`}
|
|
|
|
onClick={this.onToggleAll}
|
|
|
|
data-placement="top"
|
|
|
|
>
|
|
|
|
<span className="variable-option-icon"></span>
|
|
|
|
Selected ({selectedValues.length})
|
|
|
|
</a>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|