-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from jdeniau/navigate-through-database
Navigate through database with NavigateModal
- Loading branch information
Showing
7 changed files
with
148 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createContext, useContext } from 'react'; | ||
import { ShowDatabasesResult } from '../sql/types'; | ||
|
||
export type DatabaseListContext = ShowDatabasesResult; | ||
|
||
const DatabaseListContext = createContext<DatabaseListContext | null>(null); | ||
|
||
export function DatabaseListContextProvider({ | ||
children, | ||
databaseList: DatabaseList, | ||
}: { | ||
children: React.ReactNode; | ||
databaseList: DatabaseListContext; | ||
}) { | ||
return ( | ||
<DatabaseListContext.Provider value={DatabaseList}> | ||
{children} | ||
</DatabaseListContext.Provider> | ||
); | ||
} | ||
|
||
export function useDatabaseListContext(): DatabaseListContext { | ||
const context = useContext(DatabaseListContext); | ||
|
||
if (context === null) { | ||
throw new Error( | ||
'useTableListContext must be used inside a TableListContextProvider' | ||
); | ||
} | ||
|
||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMemo } from 'react'; | ||
import { DatabaseOutlined, TableOutlined } from '@ant-design/icons'; | ||
import { useConnectionContext } from '../../../contexts/ConnectionContext'; | ||
import { useDatabaseContext } from '../../../contexts/DatabaseContext'; | ||
import { useDatabaseListContext } from '../../../contexts/DatabaseListContext'; | ||
import { useTableListContext } from '../../../contexts/TableListContext'; | ||
import NavigateModal, { NavigationItem } from './NavigateModal'; | ||
|
||
type Props = { | ||
isNavigateModalOpen: boolean; | ||
setIsNavigateModalOpen: (isOpened: boolean) => void; | ||
}; | ||
|
||
export default function NavigateModalContainer(props: Props): JSX.Element { | ||
const tableStatusList = useTableListContext(); | ||
const { currentConnectionSlug } = useConnectionContext(); | ||
const { database } = useDatabaseContext(); | ||
const databaseList = useDatabaseListContext(); | ||
|
||
const navigationItemList: Array<NavigationItem> = useMemo( | ||
() => [ | ||
...tableStatusList.map((table) => ({ | ||
key: `Table-${table.Name}`, | ||
name: table.Name, | ||
link: `/connections/${currentConnectionSlug}/${database}/tables/${table.Name}`, | ||
Icon: <TableOutlined />, | ||
})), | ||
...databaseList.map((showDatabase) => ({ | ||
key: `Database-${showDatabase.Database}`, | ||
name: showDatabase.Database, | ||
link: `/connections/${currentConnectionSlug}/${showDatabase.Database}`, | ||
Icon: <DatabaseOutlined />, | ||
})), | ||
], | ||
[currentConnectionSlug, database, databaseList, tableStatusList] | ||
); | ||
|
||
return <NavigateModal navigationItemList={navigationItemList} {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters