How to send query text to backend when the user presses the Enter key in the QueryField?

I am developing backend plugin and trying to send query to backend after user press the enter key. My code below:

interface Props {
    queryText: string;
    onBlur?: () => void;
    onRunQuery?: () => void;
    onChange: (v: string) => void;
    datasource: MyDataSource;
    context: MyQuery;
    timeRange?: TimeRange;
    suggestions: boolean;
}

export const MyQueryField: React.FC<Props> = ({
                                                    queryText,
                                                    onBlur,
                                                    onRunQuery,
                                                    onChange,
                                                    datasource,
                                                    context,
                                                    timeRange,
                                                    suggestions,
                                                }) => {

    const onTypeahead = async (input: TypeaheadInput): Promise<TypeaheadOutput> => {
        return datasource.languageProvider.getSuggestions(input, context, timeRange);
    };

    const willApplySuggestion = (suggestion: string, {typeaheadContext, typeaheadText}: SuggestionsState): string => {
        return suggestion;
    }

    return (
        <QueryField
            query={queryText}
            cleanText={datasource.languageProvider.cleanText}
            onTypeahead={suggestions ? onTypeahead : undefined}
            onWillApplySuggestion={suggestions ? willApplySuggestion : undefined}
            onRunQuery={onRunQuery}
            onChange={onChange}
            onBlur={onBlur}
            portalOrigin="plugin"
        />
    );
};
1 Like

Not quite what you’re looking for, but I think you can run the query with Shift+Enter.

Is there a way to make QueryField single line, so that pressing the Enter key runs the query instead of creating a new line? It seems that NewlinePlugin is responsible for this, but I can’t find a way to disable this plugin.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.