()
| 25 | import SavedDocTab from "./sidebar/saved-doc-tab"; |
| 26 | |
| 27 | export default function DatabaseGui() { |
| 28 | const DEFAULT_WIDTH = 300; |
| 29 | |
| 30 | const [defaultWidthPercentage, setDefaultWidthPercentage] = useState(25); |
| 31 | |
| 32 | useEffect(() => { |
| 33 | setDefaultWidthPercentage((DEFAULT_WIDTH / window.innerWidth) * 100); |
| 34 | }, []); |
| 35 | |
| 36 | const { databaseDriver, docDriver, extensions, containerClassName } = |
| 37 | useStudioContext(); |
| 38 | |
| 39 | const [selectedTabIndex, setSelectedTabIndex] = useState(0); |
| 40 | const { currentSchemaName } = useSchema(); |
| 41 | const [tabs, setTabs] = useState<WindowTabItemProps[]>(() => [ |
| 42 | { |
| 43 | title: "Query", |
| 44 | identifier: "query", |
| 45 | key: "query", |
| 46 | component: <QueryWindow initialName="Query" />, |
| 47 | icon: Binoculars, |
| 48 | type: "query", |
| 49 | }, |
| 50 | ]); |
| 51 | |
| 52 | const openTabInternal = useCallback((tabOption: WindowTabItemProps) => { |
| 53 | setTabs((prev) => { |
| 54 | const foundIndex = prev.findIndex( |
| 55 | (tab) => tab.identifier === tabOption.key |
| 56 | ); |
| 57 | |
| 58 | if (foundIndex >= 0) { |
| 59 | setSelectedTabIndex(foundIndex); |
| 60 | return prev; |
| 61 | } |
| 62 | setSelectedTabIndex(prev.length); |
| 63 | |
| 64 | return [...prev, tabOption]; |
| 65 | }); |
| 66 | }, []); |
| 67 | |
| 68 | const replaceTabInternal = useCallback( |
| 69 | (tabOption: WindowTabItemProps) => { |
| 70 | setTabs((prev) => { |
| 71 | const foundIndex = prev.findIndex( |
| 72 | (tab) => tab.identifier === tabOption.key |
| 73 | ); |
| 74 | |
| 75 | if (foundIndex >= 0) { |
| 76 | setSelectedTabIndex(foundIndex); |
| 77 | return prev; |
| 78 | } |
| 79 | |
| 80 | return prev.map((tab, tabIndex) => { |
| 81 | if (tabIndex === selectedTabIndex) { |
| 82 | return tabOption; |
| 83 | } |
| 84 | return tab; |
nothing calls this directly
no test coverage detected