Skip to content

Commit

Permalink
move connection list into header
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Feb 24, 2024
1 parent a6e1e06 commit 7c776d4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
52 changes: 29 additions & 23 deletions src/component/Connection/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from 'react-router-dom';
import { ReactElement, useContext } from 'react';
import { Button } from 'antd';
import { Button, Menu } from 'antd';
import { ConnectionContext } from '../../Contexts';

export default function Nav(): ReactElement {
Expand All @@ -10,30 +10,36 @@ export default function Nav(): ReactElement {
currentConnectionName,
} = useContext(ConnectionContext);

return (
<nav className="nav nav-pills flex-column">
{connectionNameList.map((connection, i) => (
<Button
block
type={connection === currentConnectionName ? 'primary' : 'link'}
>
<Link
key={i}
onClick={() => {
setCurrentConnectionName(connection);
}}
to="/tables"
>
{/* {connection.config.host &&
connection.config.host.substr(0, 1).toUpperCase()} */}
if (!connectionNameList.length) {
return null;
}

const items = connectionNameList.map((connection) => ({
key: connection,
label: (
<Link
onClick={() => {
setCurrentConnectionName(connection);
}}
to="/tables"
>
{connection}
</Link>
),
}));

{connection}
</Link>
</Button>
))}
<Button type="link" block>
return (
<>
<Button style={{ margin: '0 10px' }}>
<Link to="/connect">new…</Link>
</Button>
</nav>

<Menu
mode="horizontal"
selectedKeys={[currentConnectionName]}
items={items}
style={{ flex: 1, minWidth: 0 }}
/>
</>
);
}
4 changes: 4 additions & 0 deletions src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Debug from '../component/Debug';
import ThemeSelector from '../component/ThemeSelector';
import { Layout } from 'antd';
import { getSetting } from '../theme';
import ConnectionNav from '../component/Connection/Nav';

const Header = styled(Layout.Header)`
display: flex;
Expand All @@ -32,6 +33,9 @@ export default function Root() {
<Debug />
<Header>
<h2>Tiana Tables</h2>

<ConnectionNav />

<div>
Theme: <ThemeSelector />
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/routes/tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { styled } from 'styled-components';
import { getSetting } from '../theme';
import DatabaseSelector from '../component/DatabaseSelector';
import TableList from '../component/TableList';
import ConnectionNav from '../component/Connection/Nav';

const ContentDiv = styled.div`
display: flex;
Expand All @@ -14,7 +13,6 @@ const LeftPanelDiv = styled.div`
min-width: 200px;
overflow: auto;
padding: 0 10px;
border-left: 1px solid ${(props) => getSetting(props.theme, 'foreground')};
border-right: 1px solid ${(props) => getSetting(props.theme, 'foreground')};
`;

Expand All @@ -27,7 +25,6 @@ const RightPanelDiv = styled.div`
export function Tables() {
return (
<ContentDiv>
<ConnectionNav />
<LeftPanelDiv>
<DatabaseSelector />
<TableList />
Expand Down

0 comments on commit 7c776d4

Please sign in to comment.