MCPcopy Create free account
hub / github.com/bytebase/dbhub / RunButton

Function RunButton

frontend/src/components/tool/RunButton.tsx:12–69  ·  view source on GitHub ↗
({ onClick, disabled = false, loading = false }: RunButtonProps)

Source from the content-addressed store, hash-verified

10}
11
12export function RunButton({ onClick, disabled = false, loading = false }: RunButtonProps) {
13 const onClickRef = useRef(onClick);
14 const disabledRef = useRef(disabled);
15 const loadingRef = useRef(loading);
16
17 // Keep refs updated
18 useEffect(() => {
19 onClickRef.current = onClick;
20 disabledRef.current = disabled;
21 loadingRef.current = loading;
22 }, [onClick, disabled, loading]);
23
24 useEffect(() => {
25 const handleKeyDown = (event: KeyboardEvent) => {
26 // Check for Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
27 if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
28 // Check if the event originated from CodeMirror editor
29 const target = event.target as HTMLElement;
30 const isInCodeMirror = target.closest('.cm-editor') !== null;
31
32 // Only handle if NOT in CodeMirror (let SqlEditor handle it when focused)
33 if (!isInCodeMirror && !disabledRef.current && !loadingRef.current) {
34 event.preventDefault();
35 onClickRef.current();
36 }
37 }
38 };
39
40 window.addEventListener('keydown', handleKeyDown);
41
42 return () => {
43 window.removeEventListener('keydown', handleKeyDown);
44 };
45 }, []); // Empty deps - listener is set up once
46
47 // Detect OS for shortcut display
48 const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent);
49 const shortcutKey = isMac ? '⌘' : 'Ctrl';
50
51 return (
52 <Button onClick={onClick} disabled={disabled || loading}>
53 {loading ? (
54 <>
55 <Spinner className="size-4" />
56 Running...
57 </>
58 ) : (
59 <>
60 <PlayIcon className="size-4" />
61 Run
62 <span className="ml-2 text-xs text-muted-foreground">
63 {shortcutKey}+Enter
64 </span>
65 </>
66 )}
67 </Button>
68 );
69}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected