PanelEditor: Tweak category design (#96760)

* PanelEditor: Tweak category design

* Update

* remove unused import

* Switch angle dirctions

* Fix test
This commit is contained in:
Torkel Ödegaard 2024-11-20 19:37:51 +01:00 committed by GitHub
parent fcae9c26b8
commit bd07c6cf35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 29 deletions

View File

@ -10,6 +10,7 @@ import { AxisColorMode, AxisConfig, AxisPlacement, ScaleDistribution, ScaleDistr
import { Field } from '../../components/Forms/Field'; import { Field } from '../../components/Forms/Field';
import { RadioButtonGroup } from '../../components/Forms/RadioButtonGroup/RadioButtonGroup'; import { RadioButtonGroup } from '../../components/Forms/RadioButtonGroup/RadioButtonGroup';
import { Input } from '../../components/Input/Input'; import { Input } from '../../components/Input/Input';
import { Stack } from '../../components/Layout/Stack/Stack';
import { Select } from '../../components/Select/Select'; import { Select } from '../../components/Select/Select';
import { graphFieldOptions } from '../../components/uPlot/config'; import { graphFieldOptions } from '../../components/uPlot/config';
@ -163,21 +164,20 @@ const LOG_DISTRIBUTION_OPTIONS: Array<SelectableValue<number>> = [
export const ScaleDistributionEditor = ({ value, onChange }: StandardEditorProps<ScaleDistributionConfig>) => { export const ScaleDistributionEditor = ({ value, onChange }: StandardEditorProps<ScaleDistributionConfig>) => {
const type = value?.type ?? ScaleDistribution.Linear; const type = value?.type ?? ScaleDistribution.Linear;
const log = value?.log ?? 2; const log = value?.log ?? 2;
return ( return (
<> <Stack direction="column" gap={2}>
<div style={{ marginBottom: 16 }}> <RadioButtonGroup
<RadioButtonGroup value={type}
value={type} options={DISTRIBUTION_OPTIONS}
options={DISTRIBUTION_OPTIONS} onChange={(v) => {
onChange={(v) => { onChange({
onChange({ ...value,
...value, type: v!,
type: v!, log: v === ScaleDistribution.Linear ? undefined : log,
log: v === ScaleDistribution.Linear ? undefined : log, });
}); }}
}} />
/>
</div>
{(type === ScaleDistribution.Log || type === ScaleDistribution.Symlog) && ( {(type === ScaleDistribution.Log || type === ScaleDistribution.Symlog) && (
<Field label="Log base"> <Field label="Log base">
<Select <Select
@ -193,7 +193,7 @@ export const ScaleDistributionEditor = ({ value, onChange }: StandardEditorProps
</Field> </Field>
)} )}
{type === ScaleDistribution.Symlog && ( {type === ScaleDistribution.Symlog && (
<Field label="Linear threshold"> <Field label="Linear threshold" style={{ marginBottom: 0 }}>
<Input <Input
placeholder="1" placeholder="1"
value={value?.linearThreshold} value={value?.linearThreshold}
@ -206,6 +206,6 @@ export const ScaleDistributionEditor = ({ value, onChange }: StandardEditorProps
/> />
</Field> </Field>
)} )}
</> </Stack>
); );
}; };

View File

@ -146,7 +146,7 @@ describe('PanelOptions', () => {
it('Can update', async () => { it('Can update', async () => {
const {} = setup(); const {} = setup();
await userEvent.click(screen.getByLabelText('Remove label')); await userEvent.click(screen.getByLabelText('Remove property'));
expect(screen.queryByLabelText(overrideRuleTooltipDescription)).not.toBeInTheDocument(); expect(screen.queryByLabelText(overrideRuleTooltipDescription)).not.toBeInTheDocument();
}); });

View File

@ -71,7 +71,7 @@ export const DynamicConfigValueEditor = ({
</Label> </Label>
{!isSystemOverride && ( {!isSystemOverride && (
<div> <div>
<IconButton name="times" onClick={onRemove} tooltip="Remove label" /> <IconButton name="times" onClick={onRemove} tooltip="Remove property" />
</div> </div>
)} )}
</HorizontalGroup> </HorizontalGroup>

View File

@ -120,20 +120,20 @@ export const OptionsPaneCategory = React.memo(
{/* this just provides a better experience for mouse users */} {/* this just provides a better experience for mouse users */}
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */} {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div className={headerStyles} onClick={onToggle}> <div className={headerStyles} onClick={onToggle}>
<h6 id={`button-${id}`} className={styles.title}>
{renderTitle(isExpanded)}
</h6>
<Button <Button
data-testid={selectors.components.OptionsGroup.toggle(id)} data-testid={selectors.components.OptionsGroup.toggle(id)}
type="button" type="button"
fill="text" fill="text"
size="sm" size="md"
variant="secondary" variant="secondary"
aria-expanded={isExpanded} aria-expanded={isExpanded}
className={styles.toggleButton} className={styles.toggleButton}
icon={isExpanded ? 'angle-down' : 'angle-right'} icon={isExpanded ? 'angle-down' : 'angle-up'}
onClick={onToggle} onClick={onToggle}
/> />
<h6 id={`button-${id}`} className={styles.title}>
{renderTitle(isExpanded)}
</h6>
</div> </div>
{isExpanded && ( {isExpanded && (
<div className={bodyStyles} id={id} aria-labelledby={`button-${id}`}> <div className={bodyStyles} id={id} aria-labelledby={`button-${id}`}>
@ -159,7 +159,6 @@ const getStyles = (theme: GrafanaTheme2) => ({
overflow: 'hidden', overflow: 'hidden',
lineHeight: 1.5, lineHeight: 1.5,
fontSize: '1rem', fontSize: '1rem',
paddingLeft: '6px',
fontWeight: theme.typography.fontWeightMedium, fontWeight: theme.typography.fontWeightMedium,
margin: 0, margin: 0,
}), }),
@ -167,7 +166,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
display: 'flex', display: 'flex',
cursor: 'pointer', cursor: 'pointer',
alignItems: 'center', alignItems: 'center',
padding: theme.spacing(0.5), padding: theme.spacing(0.5, 1.5),
color: theme.colors.text.primary, color: theme.colors.text.primary,
fontWeight: theme.typography.fontWeightMedium, fontWeight: theme.typography.fontWeightMedium,
@ -185,7 +184,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
padding: theme.spacing(0.5, 0, 0.5, 0), padding: theme.spacing(0.5, 0, 0.5, 0),
}), }),
body: css({ body: css({
padding: theme.spacing(1, 2, 1, 4), padding: theme.spacing(1, 2, 1, 2),
}), }),
bodyNested: css({ bodyNested: css({
position: 'relative', position: 'relative',
@ -195,7 +194,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
content: "''", content: "''",
position: 'absolute', position: 'absolute',
top: 0, top: 0,
left: '8px', left: '1px',
width: '1px', width: '1px',
height: '100%', height: '100%',
background: theme.colors.border.weak, background: theme.colors.border.weak,

View File

@ -1,7 +1,7 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { FieldConfigOptionsRegistry, GrafanaTheme2, ConfigOverrideRule } from '@grafana/data'; import { FieldConfigOptionsRegistry, GrafanaTheme2, ConfigOverrideRule } from '@grafana/data';
import { HorizontalGroup, Icon, IconButton, useStyles2 } from '@grafana/ui'; import { Button, HorizontalGroup, Icon, useStyles2 } from '@grafana/ui';
import { FieldMatcherUIRegistryItem } from '@grafana/ui/src/components/MatchersUI/types'; import { FieldMatcherUIRegistryItem } from '@grafana/ui/src/components/MatchersUI/types';
interface Props { interface Props {
@ -29,7 +29,14 @@ export const OverrideCategoryTitle = ({
<div> <div>
<HorizontalGroup justify="space-between"> <HorizontalGroup justify="space-between">
<div>{overrideName}</div> <div>{overrideName}</div>
<IconButton name="trash-alt" onClick={onOverrideRemove} tooltip="Remove override" /> <Button
variant="secondary"
fill="text"
icon="trash-alt"
onClick={onOverrideRemove}
tooltip="Remove override"
aria-label="Remove override"
/>
</HorizontalGroup> </HorizontalGroup>
{!isExpanded && ( {!isExpanded && (
<div className={styles.overrideDetails}> <div className={styles.overrideDetails}>