diff --git a/querybook/webapp/components/CodeMirrorTooltip/CodeMirrorTooltip.tsx b/querybook/webapp/components/CodeMirrorTooltip/CodeMirrorTooltip.tsx index 995288d53..5782b54fd 100644 --- a/querybook/webapp/components/CodeMirrorTooltip/CodeMirrorTooltip.tsx +++ b/querybook/webapp/components/CodeMirrorTooltip/CodeMirrorTooltip.tsx @@ -20,7 +20,7 @@ export interface ICodeMirrorTooltipProps { suggestionText?: string; openTableModal?: () => any; - onAcceptSuggestion?: () => void; + onAcceptSuggestion?: (suggestion: string) => void; hide: () => any; } diff --git a/querybook/webapp/components/CodeMirrorTooltip/SuggestionTooltip.tsx b/querybook/webapp/components/CodeMirrorTooltip/SuggestionTooltip.tsx index 1c961a1ad..302f0039a 100644 --- a/querybook/webapp/components/CodeMirrorTooltip/SuggestionTooltip.tsx +++ b/querybook/webapp/components/CodeMirrorTooltip/SuggestionTooltip.tsx @@ -1,9 +1,9 @@ -import React from 'react'; +import React, { useCallback, useMemo } from 'react'; import { Button } from 'ui/Button/Button'; interface IProps { suggestionText: string; - onAcceptSuggestion: () => void; + onAcceptSuggestion: (suggestion: string) => void; } const SUGGESTION_MAX_LENGTH = 20; @@ -12,10 +12,17 @@ export const SuggestionTooltip: React.FunctionComponent = ({ suggestionText, onAcceptSuggestion, }) => { - const truncatedSuggestion = - suggestionText.length > SUGGESTION_MAX_LENGTH - ? suggestionText.slice(0, SUGGESTION_MAX_LENGTH) + '...' - : suggestionText; + const truncatedSuggestion = useMemo( + () => + suggestionText.length > SUGGESTION_MAX_LENGTH + ? suggestionText.slice(0, SUGGESTION_MAX_LENGTH - 3) + '...' + : suggestionText, + [suggestionText] + ); + + const onClick = useCallback(() => { + onAcceptSuggestion(suggestionText); + }, [onAcceptSuggestion, suggestionText]); return (
@@ -25,7 +32,7 @@ export const SuggestionTooltip: React.FunctionComponent = ({