MCPcopy Create free account
hub / github.com/bytebase/bytebase / TabList

Function TabList

frontend/src/react/components/sql-editor/TabList.tsx:62–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60 * right-click context menu delegated to TabContextMenu.
61 */
62export function TabList() {
63 const { t } = useTranslation();
64 const createWorksheet = useSQLEditorStore((s) => s.createWorksheet);
65
66 // Zustand's selector subscribes to in-place tab mutations because
67 // `updateTab` reassigns / triggers an immer produce on `tabsById`,
68 // bumping the slice identity.
69 const tabs = useOpenTabList();
70 const currentTabId = useSQLEditorTabState((s) => s.currentTabId);
71
72 const scrollRef = useRef<HTMLDivElement>(null);
73 const contextMenuRef = useRef<TabContextMenuHandle>(null);
74
75 const [loading, setLoading] = useState(false);
76 const [scrollState, setScrollState] = useState({
77 moreLeft: false,
78 moreRight: false,
79 });
80 const [pendingClose, setPendingClose] = useState<PendingClose | null>(null);
81
82 const recalculateScrollState = useCallback(() => {
83 contextMenuRef.current?.hide();
84 const el = scrollRef.current;
85 if (!el) return;
86 const { scrollWidth, offsetWidth, scrollLeft } = el;
87 setScrollState({
88 moreLeft: scrollLeft > 0,
89 moreRight:
90 scrollWidth > offsetWidth
91 ? scrollLeft + offsetWidth < scrollWidth
92 : false,
93 });
94 }, []);
95
96 // Initial measure + resize observer.
97 useLayoutEffect(() => {
98 recalculateScrollState();
99 const el = scrollRef.current;
100 if (!el) return;
101 const ro = new ResizeObserver(() => recalculateScrollState());
102 ro.observe(el);
103 return () => ro.disconnect();
104 }, [recalculateScrollState]);
105
106 // Prevent the trackpad / horizontal wheel from triggering browser
107 // back/forward navigation when the tab list can't scroll further.
108 useEffect(() => {
109 const el = scrollRef.current;
110 if (!el) return;
111 const handler = (e: WheelEvent) => {
112 const maxX = el.scrollWidth - el.clientWidth;
113 const target = el.scrollLeft + e.deltaX;
114 if (target < 0 || target > maxX) {
115 e.preventDefault();
116 }
117 };
118 el.addEventListener("wheel", handler, { passive: false });
119 return () => el.removeEventListener("wheel", handler);

Callers

nothing calls this directly

Calls 10

observeMethod · 0.95
disconnectMethod · 0.95
useOpenTabListFunction · 0.90
useSQLEditorTabStateFunction · 0.90
getSQLEditorTabsStateFunction · 0.90
cnFunction · 0.90
resolveMethod · 0.80
removeFunction · 0.70
tFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected