Files
grafana/public/app/features/dashboard/components/PanelEditor/getPanelFrameOptions.tsx
Adam Simpson c57924e332 A11y: Fix remaining focus issues with Switch (#48376)
* refactor: replace uses of checked prop for <Switch> with value prop

* fix: remove spaces from ids

The ID format is stated as follows([source][1]):

> ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]),
hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Since `QueryHeaderSwitch` is used in two places I created a new variable that replaces spaces with a dash in the label.

[1]: https://www.w3.org/TR/html401/types.html#type-name

* fix: allow Switch in AlertingSettings to be focused by keyboard

* fix: allow Switch in PromSettings to be focused by keyboard

Fixes #46472

Co-authored-by: Elfo404 <me@giordanoricci.com>
2022-05-02 13:50:44 +00:00

152 lines
4.9 KiB
TypeScript

import React from 'react';
import { DataLinksInlineEditor, Input, RadioButtonGroup, Select, Switch, TextArea } from '@grafana/ui';
import { getPanelLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
import { RepeatRowSelect } from '../RepeatRowSelect/RepeatRowSelect';
import { OptionsPaneCategoryDescriptor } from './OptionsPaneCategoryDescriptor';
import { OptionsPaneItemDescriptor } from './OptionsPaneItemDescriptor';
import { OptionPaneRenderProps } from './types';
export function getPanelFrameCategory(props: OptionPaneRenderProps): OptionsPaneCategoryDescriptor {
const { panel, onPanelConfigChange } = props;
const descriptor = new OptionsPaneCategoryDescriptor({
title: 'Panel options',
id: 'Panel options',
isOpenDefault: true,
});
return descriptor
.addItem(
new OptionsPaneItemDescriptor({
title: 'Title',
value: panel.title,
popularRank: 1,
render: function renderTitle() {
return (
<Input
id="PanelFrameTitle"
defaultValue={panel.title}
onBlur={(e) => onPanelConfigChange('title', e.currentTarget.value)}
/>
);
},
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Description',
description: panel.description,
value: panel.description,
render: function renderDescription() {
return (
<TextArea
id="description-text-area"
defaultValue={panel.description}
onBlur={(e) => onPanelConfigChange('description', e.currentTarget.value)}
/>
);
},
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Transparent background',
render: function renderTransparent() {
return (
<Switch
value={panel.transparent}
id="transparent-background"
onChange={(e) => onPanelConfigChange('transparent', e.currentTarget.checked)}
/>
);
},
})
)
.addCategory(
new OptionsPaneCategoryDescriptor({
title: 'Panel links',
id: 'Panel links',
isOpenDefault: false,
itemsCount: panel.links?.length,
}).addItem(
new OptionsPaneItemDescriptor({
title: 'Panel links',
render: function renderLinks() {
return (
<DataLinksInlineEditor
links={panel.links}
onChange={(links) => onPanelConfigChange('links', links)}
getSuggestions={getPanelLinksVariableSuggestions}
data={[]}
/>
);
},
})
)
)
.addCategory(
new OptionsPaneCategoryDescriptor({
title: 'Repeat options',
id: 'Repeat options',
isOpenDefault: false,
})
.addItem(
new OptionsPaneItemDescriptor({
title: 'Repeat by variable',
description:
'Repeat this panel for each value in the selected variable. This is not visible while in edit mode. You need to go back to dashboard and then update the variable or reload the dashboard.',
render: function renderRepeatOptions() {
return (
<RepeatRowSelect
id="repeat-by-variable-select"
repeat={panel.repeat}
onChange={(value?: string | null) => {
onPanelConfigChange('repeat', value);
}}
/>
);
},
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Repeat direction',
showIf: () => !!panel.repeat,
render: function renderRepeatOptions() {
const directionOptions = [
{ label: 'Horizontal', value: 'h' },
{ label: 'Vertical', value: 'v' },
];
return (
<RadioButtonGroup
options={directionOptions}
value={panel.repeatDirection || 'h'}
onChange={(value) => onPanelConfigChange('repeatDirection', value)}
/>
);
},
})
)
.addItem(
new OptionsPaneItemDescriptor({
title: 'Max per row',
showIf: () => Boolean(panel.repeat && panel.repeatDirection === 'h'),
render: function renderOption() {
const maxPerRowOptions = [2, 3, 4, 6, 8, 12].map((value) => ({ label: value.toString(), value }));
return (
<Select
menuShouldPortal
options={maxPerRowOptions}
value={panel.maxPerRow}
onChange={(value) => onPanelConfigChange('maxPerRow', value.value)}
/>
);
},
})
)
);
}