mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 07:23:11 +08:00
Variable: Limit variable name to 50 characters (#55406)
Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> Co-authored-by: kay delaney <kay@grafana.com>
This commit is contained in:
@ -26,7 +26,7 @@ import { VariableTextField } from './VariableTextField';
|
||||
import { VariableTypeSelect } from './VariableTypeSelect';
|
||||
import { VariableValuesPreview } from './VariableValuesPreview';
|
||||
import { changeVariableName, variableEditorMount, variableEditorUnMount } from './actions';
|
||||
import { OnPropChangeArguments } from './types';
|
||||
import { OnPropChangeArguments, VariableNameConstraints } from './types';
|
||||
|
||||
const mapStateToProps = (state: StoreState, ownProps: OwnProps) => ({
|
||||
editor: getVariablesState(ownProps.identifier.rootStateKey, state).editor,
|
||||
@ -149,8 +149,10 @@ export class VariableEditorEditorUnConnected extends PureComponent<Props> {
|
||||
onChange={this.onNameChange}
|
||||
name="Name"
|
||||
placeholder="name"
|
||||
required
|
||||
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.generalNameInputV2}
|
||||
maxLength={VariableNameConstraints.MaxSize}
|
||||
required
|
||||
tooltip="Variable name cannot be longer than 50 characters"
|
||||
/>
|
||||
<VariableTypeSelect onChange={this.onTypeChange} type={this.props.variable.type} />
|
||||
</InlineFieldRow>
|
||||
|
@ -15,6 +15,7 @@ interface VariableTextFieldProps {
|
||||
grow?: boolean;
|
||||
onBlur?: (event: FormEvent<HTMLInputElement>) => void;
|
||||
interactive?: boolean;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
export function VariableTextField({
|
||||
@ -30,6 +31,7 @@ export function VariableTextField({
|
||||
tooltip,
|
||||
grow,
|
||||
interactive,
|
||||
maxLength,
|
||||
}: PropsWithChildren<VariableTextFieldProps>): ReactElement {
|
||||
return (
|
||||
<InlineField interactive={interactive} label={name} labelWidth={labelWidth ?? 12} tooltip={tooltip} grow={grow}>
|
||||
@ -43,6 +45,7 @@ export function VariableTextField({
|
||||
onBlur={onBlur}
|
||||
width={grow ? undefined : width ?? 25}
|
||||
data-testid={testId}
|
||||
maxLength={maxLength}
|
||||
required={required}
|
||||
/>
|
||||
</InlineField>
|
||||
|
@ -1,5 +1,9 @@
|
||||
import { VariableModel } from '../types';
|
||||
|
||||
export enum VariableNameConstraints {
|
||||
MaxSize = 50,
|
||||
}
|
||||
|
||||
export interface OnPropChangeArguments<Model extends VariableModel = VariableModel> {
|
||||
propName: keyof Model;
|
||||
propValue: any;
|
||||
|
Reference in New Issue
Block a user