mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ButtonCascader: Fix error in Explore (#21585)
* Add children and remove nullified icon * Revert data format with children * Update test * Revert styles * Update types
This commit is contained in:
parent
59469e14cf
commit
fef31acbf2
@ -29,5 +29,9 @@ const getKnobs = () => {
|
|||||||
|
|
||||||
export const simple = () => {
|
export const simple = () => {
|
||||||
const { disabled, text, options } = getKnobs();
|
const { disabled, text, options } = getKnobs();
|
||||||
return <ButtonCascader disabled={disabled} options={options} value={['A']} expandIcon={null} buttonText={text} />;
|
return (
|
||||||
|
<ButtonCascader disabled={disabled} options={options} value={['A']}>
|
||||||
|
{text}
|
||||||
|
</ButtonCascader>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Button } from '../Forms/Button';
|
|
||||||
import { Icon } from '../Icon/Icon';
|
import { Icon } from '../Icon/Icon';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -8,10 +7,10 @@ import { CascaderOption } from '../Cascader/Cascader';
|
|||||||
|
|
||||||
export interface ButtonCascaderProps {
|
export interface ButtonCascaderProps {
|
||||||
options: CascaderOption[];
|
options: CascaderOption[];
|
||||||
buttonText: string;
|
children: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
expandIcon?: React.ReactNode;
|
|
||||||
value?: string[];
|
value?: string[];
|
||||||
|
fieldNames?: { label: string; value: string; children: string };
|
||||||
|
|
||||||
loadData?: (selectedOptions: CascaderOption[]) => void;
|
loadData?: (selectedOptions: CascaderOption[]) => void;
|
||||||
onChange?: (value: string[], selectedOptions: CascaderOption[]) => void;
|
onChange?: (value: string[], selectedOptions: CascaderOption[]) => void;
|
||||||
@ -19,9 +18,9 @@ export interface ButtonCascaderProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ButtonCascader: React.FC<ButtonCascaderProps> = props => (
|
export const ButtonCascader: React.FC<ButtonCascaderProps> = props => (
|
||||||
<RCCascader {...props} fieldNames={{ label: 'label', value: 'value', children: 'items' }}>
|
<RCCascader {...props} expandIcon={null}>
|
||||||
<Button variant="secondary" disabled={props.disabled}>
|
<button className="gf-form-label gf-form-label--btn" disabled={props.disabled}>
|
||||||
{props.buttonText} <Icon name="caret-down" />
|
{props.children} <Icon name="caret-down" />
|
||||||
</Button>
|
</button>
|
||||||
</RCCascader>
|
</RCCascader>
|
||||||
);
|
);
|
||||||
|
@ -32,6 +32,7 @@ export interface CascaderOption {
|
|||||||
items?: CascaderOption[];
|
items?: CascaderOption[];
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
children?: CascaderOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const disableDivFocus = css(`
|
const disableDivFocus = css(`
|
||||||
@ -186,6 +187,7 @@ export class Cascader extends React.PureComponent<CascaderProps, CascaderState>
|
|||||||
onBlur={this.onBlurCascade}
|
onBlur={this.onBlurCascade}
|
||||||
value={rcValue}
|
value={rcValue}
|
||||||
fieldNames={{ label: 'label', value: 'value', children: 'items' }}
|
fieldNames={{ label: 'label', value: 'value', children: 'items' }}
|
||||||
|
expandIcon={null}
|
||||||
>
|
>
|
||||||
<div className={disableDivFocus}>
|
<div className={disableDivFocus}>
|
||||||
<Input
|
<Input
|
||||||
|
@ -135,13 +135,13 @@ export class InfluxLogsQueryField extends React.PureComponent<Props, State> {
|
|||||||
<div className="gf-form-inline gf-form-inline--nowrap">
|
<div className="gf-form-inline gf-form-inline--nowrap">
|
||||||
<div className="gf-form flex-shrink-0">
|
<div className="gf-form flex-shrink-0">
|
||||||
<ButtonCascader
|
<ButtonCascader
|
||||||
buttonText={cascadeText}
|
|
||||||
options={measurements}
|
options={measurements}
|
||||||
disabled={!hasMeasurement}
|
disabled={!hasMeasurement}
|
||||||
value={[measurement, field]}
|
value={[measurement, field]}
|
||||||
onChange={this.onMeasurementsChange}
|
onChange={this.onMeasurementsChange}
|
||||||
expandIcon={null}
|
>
|
||||||
/>
|
{cascadeText}
|
||||||
|
</ButtonCascader>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-shrink-1 flex-flow-column-nowrap">
|
<div className="flex-shrink-1 flex-flow-column-nowrap">
|
||||||
{measurement && (
|
{measurement && (
|
||||||
|
@ -151,12 +151,12 @@ export class LokiQueryFieldForm extends React.PureComponent<LokiQueryFieldFormPr
|
|||||||
<ButtonCascader
|
<ButtonCascader
|
||||||
options={logLabelOptions || []}
|
options={logLabelOptions || []}
|
||||||
disabled={buttonDisabled}
|
disabled={buttonDisabled}
|
||||||
buttonText={chooserText}
|
|
||||||
onChange={this.onChangeLogLabels}
|
onChange={this.onChangeLogLabels}
|
||||||
loadData={onLoadOptions}
|
loadData={onLoadOptions}
|
||||||
expandIcon={null}
|
|
||||||
onPopupVisibleChange={isVisible => isVisible && onLabelsRefresh && onLabelsRefresh()}
|
onPopupVisibleChange={isVisible => isVisible && onLabelsRefresh && onLabelsRefresh()}
|
||||||
/>
|
>
|
||||||
|
{chooserText}
|
||||||
|
</ButtonCascader>
|
||||||
</div>
|
</div>
|
||||||
<div className="gf-form gf-form--grow">
|
<div className="gf-form gf-form--grow">
|
||||||
<QueryField
|
<QueryField
|
||||||
|
@ -9,7 +9,7 @@ describe('groupMetricsByPrefix()', () => {
|
|||||||
expect(groupMetricsByPrefix(['foo_metric'])).toMatchObject([
|
expect(groupMetricsByPrefix(['foo_metric'])).toMatchObject([
|
||||||
{
|
{
|
||||||
value: 'foo',
|
value: 'foo',
|
||||||
items: [
|
children: [
|
||||||
{
|
{
|
||||||
value: 'foo_metric',
|
value: 'foo_metric',
|
||||||
},
|
},
|
||||||
@ -22,7 +22,7 @@ describe('groupMetricsByPrefix()', () => {
|
|||||||
expect(groupMetricsByPrefix(['foo_metric'], { foo_metric: [{ type: 'TYPE', help: 'my help' }] })).toMatchObject([
|
expect(groupMetricsByPrefix(['foo_metric'], { foo_metric: [{ type: 'TYPE', help: 'my help' }] })).toMatchObject([
|
||||||
{
|
{
|
||||||
value: 'foo',
|
value: 'foo',
|
||||||
items: [
|
children: [
|
||||||
{
|
{
|
||||||
value: 'foo_metric',
|
value: 'foo_metric',
|
||||||
title: 'foo_metric\nTYPE\nmy help',
|
title: 'foo_metric\nTYPE\nmy help',
|
||||||
@ -44,7 +44,7 @@ describe('groupMetricsByPrefix()', () => {
|
|||||||
expect(groupMetricsByPrefix([':foo_metric:'])).toMatchObject([
|
expect(groupMetricsByPrefix([':foo_metric:'])).toMatchObject([
|
||||||
{
|
{
|
||||||
value: RECORDING_RULES_GROUP,
|
value: RECORDING_RULES_GROUP,
|
||||||
items: [
|
children: [
|
||||||
{
|
{
|
||||||
value: ':foo_metric:',
|
value: ':foo_metric:',
|
||||||
},
|
},
|
||||||
|
@ -52,7 +52,7 @@ export function groupMetricsByPrefix(metrics: string[], metadata?: PromMetricsMe
|
|||||||
const rulesOption = {
|
const rulesOption = {
|
||||||
label: 'Recording rules',
|
label: 'Recording rules',
|
||||||
value: RECORDING_RULES_GROUP,
|
value: RECORDING_RULES_GROUP,
|
||||||
items: ruleNames
|
children: ruleNames
|
||||||
.slice()
|
.slice()
|
||||||
.sort()
|
.sort()
|
||||||
.map(name => ({ label: name, value: name })),
|
.map(name => ({ label: name, value: name })),
|
||||||
@ -69,7 +69,7 @@ export function groupMetricsByPrefix(metrics: string[], metadata?: PromMetricsMe
|
|||||||
const prefixIsMetric = metricsForPrefix.length === 1 && metricsForPrefix[0] === prefix;
|
const prefixIsMetric = metricsForPrefix.length === 1 && metricsForPrefix[0] === prefix;
|
||||||
const children = prefixIsMetric ? [] : metricsForPrefix.sort().map(m => addMetricsMetadata(m, metadata));
|
const children = prefixIsMetric ? [] : metricsForPrefix.sort().map(m => addMetricsMetadata(m, metadata));
|
||||||
return {
|
return {
|
||||||
items: children,
|
children,
|
||||||
label: prefix,
|
label: prefix,
|
||||||
value: prefix,
|
value: prefix,
|
||||||
};
|
};
|
||||||
@ -198,7 +198,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
|||||||
onChangeMetrics = (values: string[], selectedOptions: CascaderOption[]) => {
|
onChangeMetrics = (values: string[], selectedOptions: CascaderOption[]) => {
|
||||||
let query;
|
let query;
|
||||||
if (selectedOptions.length === 1) {
|
if (selectedOptions.length === 1) {
|
||||||
if (selectedOptions[0].items.length === 0) {
|
if (selectedOptions[0].children.length === 0) {
|
||||||
query = selectedOptions[0].value;
|
query = selectedOptions[0].value;
|
||||||
} else {
|
} else {
|
||||||
// Ignore click on group
|
// Ignore click on group
|
||||||
@ -254,7 +254,10 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
|||||||
const histogramOptions = histogramMetrics.map((hm: any) => ({ label: hm, value: hm }));
|
const histogramOptions = histogramMetrics.map((hm: any) => ({ label: hm, value: hm }));
|
||||||
const metricsOptions =
|
const metricsOptions =
|
||||||
histogramMetrics.length > 0
|
histogramMetrics.length > 0
|
||||||
? [{ label: 'Histograms', value: HISTOGRAM_GROUP, items: histogramOptions, isLeaf: false }, ...metricsByPrefix]
|
? [
|
||||||
|
{ label: 'Histograms', value: HISTOGRAM_GROUP, children: histogramOptions, isLeaf: false },
|
||||||
|
...metricsByPrefix,
|
||||||
|
]
|
||||||
: metricsByPrefix;
|
: metricsByPrefix;
|
||||||
|
|
||||||
// Hint for big disabled lookups
|
// Hint for big disabled lookups
|
||||||
@ -299,13 +302,9 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
|||||||
<>
|
<>
|
||||||
<div className="gf-form-inline gf-form-inline--nowrap flex-grow-1">
|
<div className="gf-form-inline gf-form-inline--nowrap flex-grow-1">
|
||||||
<div className="gf-form flex-shrink-0">
|
<div className="gf-form flex-shrink-0">
|
||||||
<ButtonCascader
|
<ButtonCascader options={metricsOptions} disabled={buttonDisabled} onChange={this.onChangeMetrics}>
|
||||||
options={metricsOptions}
|
{chooserText}
|
||||||
buttonText={chooserText}
|
</ButtonCascader>
|
||||||
disabled={buttonDisabled}
|
|
||||||
onChange={this.onChangeMetrics}
|
|
||||||
expandIcon={null}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="gf-form gf-form--grow flex-shrink-1">
|
<div className="gf-form gf-form--grow flex-shrink-1">
|
||||||
<QueryField
|
<QueryField
|
||||||
|
Loading…
Reference in New Issue
Block a user