mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* Chore: Enable eslint react/no-render-return-value rule Eanble the rule and remove the unused render return part of: #29201 * Chore: Enable eslint react/no-children-prop rule Not linting issues after turning on this. No other file changes requried part of: #29201 * Chore: Enable eslint react/no-unknown-property rule Correct enable-background to enableBackground part of: #29201 * Chore: Enable eslint react/no-unescaped-entities rule Replaced " with " replaced ' with ' part of: #29201
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import React, { FunctionComponent, PropsWithChildren, ReactElement, useMemo } from 'react';
|
|
import { VariableHide, VariableModel } from '../types';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { variableAdapters } from '../adapters';
|
|
import { Tooltip } from '@grafana/ui';
|
|
|
|
interface Props {
|
|
variable: VariableModel;
|
|
}
|
|
|
|
export const PickerRenderer: FunctionComponent<Props> = props => {
|
|
const PickerToRender = useMemo(() => variableAdapters.get(props.variable.type).picker, [props.variable]);
|
|
|
|
if (!props.variable) {
|
|
return <div>Couldn't load variable</div>;
|
|
}
|
|
|
|
return (
|
|
<div className="gf-form">
|
|
<PickerLabel variable={props.variable} />
|
|
{props.variable.hide !== VariableHide.hideVariable && PickerToRender && (
|
|
<PickerToRender variable={props.variable} />
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
function PickerLabel({ variable }: PropsWithChildren<Props>): ReactElement | null {
|
|
const labelOrName = useMemo(() => variable.label || variable.name, [variable]);
|
|
|
|
if (variable.hide !== VariableHide.dontHide) {
|
|
return null;
|
|
}
|
|
|
|
if (variable.description) {
|
|
return (
|
|
<Tooltip content={variable.description} placement={'bottom'}>
|
|
<label
|
|
className="gf-form-label gf-form-label--variable"
|
|
aria-label={selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName)}
|
|
>
|
|
{labelOrName}
|
|
</label>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<label
|
|
className="gf-form-label gf-form-label--variable"
|
|
aria-label={selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName)}
|
|
>
|
|
{labelOrName}
|
|
</label>
|
|
);
|
|
}
|