Commit 2f101d1d by Andrej Ocenas Committed by GitHub

DataLinks: Refactor title state (#20256)

parent 758201e8
import React, { useState, ChangeEvent, useContext } from 'react'; import React, { ChangeEvent, useContext } from 'react';
import { DataLink } from '@grafana/data'; import { DataLink } from '@grafana/data';
import { FormField, Switch } from '../index'; import { FormField, Switch } from '../index';
import { VariableSuggestion } from './DataLinkSuggestions'; import { VariableSuggestion } from './DataLinkSuggestions';
...@@ -31,17 +31,12 @@ export const DataLinkEditor: React.FC<DataLinkEditorProps> = React.memo( ...@@ -31,17 +31,12 @@ export const DataLinkEditor: React.FC<DataLinkEditorProps> = React.memo(
({ index, value, onChange, onRemove, suggestions, isLast }) => { ({ index, value, onChange, onRemove, suggestions, isLast }) => {
const theme = useContext(ThemeContext); const theme = useContext(ThemeContext);
const styles = getStyles(theme); const styles = getStyles(theme);
const [title, setTitle] = useState(value.title);
const onUrlChange = (url: string, callback?: () => void) => { const onUrlChange = (url: string, callback?: () => void) => {
onChange(index, { ...value, url }, callback); onChange(index, { ...value, url }, callback);
}; };
const onTitleChange = (event: ChangeEvent<HTMLInputElement>) => { const onTitleChange = (event: ChangeEvent<HTMLInputElement>) => {
setTitle(event.target.value); onChange(index, { ...value, title: event.target.value });
};
const onTitleBlur = () => {
onChange(index, { ...value, title: title });
}; };
const onRemoveClick = () => { const onRemoveClick = () => {
...@@ -58,9 +53,8 @@ export const DataLinkEditor: React.FC<DataLinkEditorProps> = React.memo( ...@@ -58,9 +53,8 @@ export const DataLinkEditor: React.FC<DataLinkEditorProps> = React.memo(
<FormField <FormField
className="gf-form--grow" className="gf-form--grow"
label="Title" label="Title"
value={title} value={value.title}
onChange={onTitleChange} onChange={onTitleChange}
onBlur={onTitleBlur}
inputWidth={0} inputWidth={0}
labelWidth={5} labelWidth={5}
placeholder="Show details" placeholder="Show details"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment