diff --git a/web/src/App.js b/web/src/App.js index 84eb6670..b540b3ee 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -1,15 +1,17 @@ import React from 'react'; import './index.css'; import Screen from './Screen'; -import { CurrentWidgetProvider } from './widgets/useCurrentWidget'; +import { CurrentWidgetProvider, CurrentDatabaseProvider } from './utility/globalState'; import { SocketProvider } from './utility/SocketProvider'; function App() { return ( - - - + + + + + ); } diff --git a/web/src/Screen.js b/web/src/Screen.js index 0ae1da23..a91ec273 100644 --- a/web/src/Screen.js +++ b/web/src/Screen.js @@ -3,7 +3,7 @@ import theme from './theme'; import styled from 'styled-components'; import FilesTabsPanel from './FilesTabsPanel'; import WidgetIconPanel from './widgets/WidgetIconPanel'; -import useCurrentWidget from './widgets/useCurrentWidget'; +import { useCurrentWidget } from './utility/globalState'; import WidgetContainer from './widgets/WidgetContainer'; const BodyDiv = styled.div` @@ -31,6 +31,7 @@ const LeftPanel = styled.div` bottom: ${theme.statusBar.height}px; width: ${theme.leftPanel.width}px; background-color: ${theme.leftPanel.background}; + display: flex; `; const TabsPanel = styled.div` diff --git a/web/src/appobj/AppObjectList.js b/web/src/appobj/AppObjectList.js index 0e804978..e447a32f 100644 --- a/web/src/appobj/AppObjectList.js +++ b/web/src/appobj/AppObjectList.js @@ -3,10 +3,10 @@ import styled from 'styled-components'; import { showMenu } from '../modals/DropDownMenu'; import { AppObjectCore } from './AppObjects'; -export function AppObjectList({ list, makeAppObj, SubItems }) { +export function AppObjectList({ list, makeAppObj, SubItems, onObjectClick }) { return (list || []).map(x => { const appobj = makeAppObj(x); - let res = ; + let res = ; if (SubItems) { res = ( <> diff --git a/web/src/appobj/AppObjects.js b/web/src/appobj/AppObjects.js index d3122f74..eef49fd0 100644 --- a/web/src/appobj/AppObjects.js +++ b/web/src/appobj/AppObjects.js @@ -6,7 +6,7 @@ const AppObjectDiv = styled.div` padding: 5px; &:hover { background-color: lightblue; - }; + } cursor: pointer; `; @@ -14,7 +14,7 @@ const IconWrap = styled.span` margin-right: 10px; `; -export function AppObjectCore({ title, Icon, Menu, data, makeAppObj }) { +export function AppObjectCore({ title, Icon, Menu, data, makeAppObj, onClick }) { const handleContextMenu = event => { if (!Menu) return; @@ -23,7 +23,7 @@ export function AppObjectCore({ title, Icon, Menu, data, makeAppObj }) { }; return ( - + onClick(data) : undefined}> diff --git a/web/src/appobj/databaseAppObject.js b/web/src/appobj/databaseAppObject.js index 20a01e16..6adaf779 100644 --- a/web/src/appobj/databaseAppObject.js +++ b/web/src/appobj/databaseAppObject.js @@ -1,5 +1,5 @@ import React from 'react'; -import { MicrosoftIcon, SqliteIcon, PostgreSqlIcon, MySqlIcon, ServerIcon, DatabaseIcon } from '../icons'; +import { DatabaseIcon } from '../icons'; import { DropDownMenuItem } from '../modals/DropDownMenu'; import showModal from '../modals/showModal'; import ConnectionModal from '../modals/ConnectionModal'; diff --git a/web/src/utility/globalState.js b/web/src/utility/globalState.js new file mode 100644 index 00000000..e8cdbd0d --- /dev/null +++ b/web/src/utility/globalState.js @@ -0,0 +1,26 @@ +import React from 'react'; + +function createGlobalState(defaultValue) { + const Context = React.createContext(); + + function Provider({ children }) { + const [currentvalue, setCurrentValue] = React.useState(defaultValue); + return {children}; + } + + function useValue() { + return React.useContext(Context)[0]; + } + + function useSetValue() { + return React.useContext(Context)[1]; + } + + return [Provider, useValue, useSetValue]; +} + +const [CurrentWidgetProvider, useCurrentWidget, useSetCurrentWidget] = createGlobalState('database'); +export { CurrentWidgetProvider, useCurrentWidget, useSetCurrentWidget }; + +const [CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabase] = createGlobalState(null); +export { CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabase }; diff --git a/web/src/widgets/DatabaseWidget.js b/web/src/widgets/DatabaseWidget.js index bb232e89..0e30335f 100644 --- a/web/src/widgets/DatabaseWidget.js +++ b/web/src/widgets/DatabaseWidget.js @@ -1,31 +1,57 @@ import React from 'react'; +import styled from 'styled-components'; + import useModalState from '../modals/useModalState'; import ConnectionModal from '../modals/ConnectionModal'; import useFetch from '../utility/useFetch'; import { AppObjectList } from '../appobj/AppObjectList'; import connectionAppObject from '../appobj/connectionAppObject'; import databaseAppObject from '../appobj/databaseAppObject'; +import { useSetCurrentDatabase, useCurrentDatabase } from '../utility/globalState'; + +const MainContainer = styled.div` + position: relative; + display: flex; + flex-flow: column wrap; + flex: 1; +`; + +const InnerContainer = styled.div` + flex: 1 0; + overflow: scroll; +`; function SubDatabaseList({ data }) { + const setDb = useSetCurrentDatabase(); + const handleDatabaseClick = database => { + setDb({ + ...database, + connection: data, + }); + }; const { _id } = data; const databases = useFetch({ url: `server-connections/list-databases?id=${_id}`, reloadTrigger: `database-list-changed-${_id}`, }); - return + return ; } export default function DatabaseWidget() { + const db = useCurrentDatabase(); const modalState = useModalState(); const connections = useFetch({ url: 'connections/list', reloadTrigger: 'connection-list-changed', }); return ( - <> - - - - + + + + + + + tables of {db && db.name} + ); } diff --git a/web/src/widgets/WidgetContainer.js b/web/src/widgets/WidgetContainer.js index 0de1d4e5..a3ec04ea 100644 --- a/web/src/widgets/WidgetContainer.js +++ b/web/src/widgets/WidgetContainer.js @@ -1,5 +1,5 @@ import React from 'react'; -import useCurrentWidget from './useCurrentWidget'; +import { useCurrentWidget } from '../utility/globalState'; import DatabaseWidget from './DatabaseWidget'; export default function WidgetContainer() { diff --git a/web/src/widgets/WidgetIconPanel.js b/web/src/widgets/WidgetIconPanel.js index 0ebdedce..1336782e 100644 --- a/web/src/widgets/WidgetIconPanel.js +++ b/web/src/widgets/WidgetIconPanel.js @@ -2,7 +2,7 @@ import React from 'react'; import theme from '../theme'; import styled from 'styled-components'; import { FontIcon } from '../icons'; -import useCurrentWidget, { useSetCurrentWidget } from './useCurrentWidget'; +import { useCurrentWidget, useSetCurrentWidget } from '../utility/globalState'; const IconWrapper = styled.div` color: ${theme.widgetMenu.iconFontColor}; diff --git a/web/src/widgets/useCurrentWidget.js b/web/src/widgets/useCurrentWidget.js deleted file mode 100644 index e5228af0..00000000 --- a/web/src/widgets/useCurrentWidget.js +++ /dev/null @@ -1,20 +0,0 @@ -import React from "react"; - -const CurrentWidgetProviderContext = React.createContext(); - -export function CurrentWidgetProvider({ children }) { - const [currentWidget, setCurrentWidget] = React.useState('database'); - return ( - - {children} - - ); -} - -export default function useCurrentWidget() { - return React.useContext(CurrentWidgetProviderContext)[0]; -} - -export function useSetCurrentWidget() { - return React.useContext(CurrentWidgetProviderContext)[1]; -}