From 235dd7644d48e40bef588df843715b562255573f Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 16 Apr 2018 18:06:34 -0700 Subject: [PATCH] Implement TemplateControlDropdown in TemplateControlBar --- .../components/TemplateControlBar.tsx | 68 +++---------------- .../components/TemplateControlDropdown.tsx | 4 ++ 2 files changed, 14 insertions(+), 58 deletions(-) diff --git a/ui/src/dashboards/components/TemplateControlBar.tsx b/ui/src/dashboards/components/TemplateControlBar.tsx index caa5665a6f..905ff410eb 100644 --- a/ui/src/dashboards/components/TemplateControlBar.tsx +++ b/ui/src/dashboards/components/TemplateControlBar.tsx @@ -1,14 +1,10 @@ import React, {SFC} from 'react' import classnames from 'classnames' -import calculateSize from 'calculate-size' +import uuid from 'uuid' import Authorized, {EDITOR_ROLE} from 'src/auth/Authorized' -import Dropdown from 'src/shared/components/Dropdown' - -const minTempVarDropdownWidth = 146 -const maxTempVarDropdownWidth = 300 -const tempVarDropdownPadding = 30 +import TemplateControlDropdown from 'src/dashboards/components/TemplateControlDropdown' interface TemplateValue { value: string @@ -38,59 +34,15 @@ const TemplateControlBar: SFC = ({
{templates && templates.length ? ( - templates.map(({id, values, tempVar}) => { - const items = values.map(value => ({...value, text: value.value})) - const itemValues = values.map(value => value.value) - const selectedItem = items.find(item => item.selected) || items[0] - const selectedText = selectedItem && selectedItem.text - let customDropdownWidth = 0 - if (itemValues.length > 1) { - const longest = itemValues.reduce( - (a, b) => (a.length > b.length ? a : b) - ) - const longestLengthPixels = - calculateSize(longest, { - font: 'Monospace', - fontSize: '12px', - }).width + tempVarDropdownPadding - - if ( - longestLengthPixels > minTempVarDropdownWidth && - longestLengthPixels < maxTempVarDropdownWidth - ) { - customDropdownWidth = longestLengthPixels - } else if (longestLengthPixels > maxTempVarDropdownWidth) { - customDropdownWidth = maxTempVarDropdownWidth - } - } - - // TODO: change Dropdown to a MultiSelectDropdown, `selected` to - // the full array, and [item] to all `selected` values when we update - // this component to support multiple values - return ( -
0 - ? {minWidth: customDropdownWidth} - : null - } - > - - -
- ) - }) + templates.map(template => ( + + )) ) : ( -
+
This dashboard does not have any Template Variables
)} diff --git a/ui/src/dashboards/components/TemplateControlDropdown.tsx b/ui/src/dashboards/components/TemplateControlDropdown.tsx index ff2b334e93..9485f362e5 100644 --- a/ui/src/dashboards/components/TemplateControlDropdown.tsx +++ b/ui/src/dashboards/components/TemplateControlDropdown.tsx @@ -19,6 +19,10 @@ interface Props { onSelectTemplate: (id: string) => void } +// TODO: change Dropdown to a MultiSelectDropdown, `selected` to +// the full array, and [item] to all `selected` values when we update +// this component to support multiple values + const TemplateControlDropdown: SFC = ({template, onSelectTemplate}) => { const dropdownItems = template.values.map(value => ({ ...value,