-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ryjiang <[email protected]>
- Loading branch information
1 parent
89dbb3a
commit 17d3214
Showing
3 changed files
with
152 additions
and
141 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,103 @@ | ||
import { useContext } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import RouteTabList from '@/components/customTabList/RouteTabList'; | ||
import Partitions from './collections/partitions/Partitions'; | ||
import Schema from './collections/schema/Schema'; | ||
import Data from './collections/data/CollectionData'; | ||
import Segments from './collections/segments/Segments'; | ||
import Properties from './collections/properties/Properties'; | ||
import Search from './collections/search/Search'; | ||
import { authContext } from '@/context'; | ||
import type { SearchParams, QueryState } from './types'; | ||
import type { CollectionObject, CollectionFullObject } from '@server/types'; | ||
import type { ITab } from '@/components/customTabList/Types'; | ||
|
||
// Collection tab pages | ||
export const CollectionsTabs = (props: { | ||
collectionPage: string; // current collection page | ||
collectionName: string; // current collection name | ||
tabClass: string; // tab class | ||
collections: CollectionObject[]; // collections | ||
searchParams: SearchParams; // search params | ||
setSearchParams: (params: SearchParams) => void; // set search params | ||
queryState: QueryState; // query state | ||
setQueryState: (state: QueryState) => void; // set query state | ||
}) => { | ||
// props | ||
const { | ||
collectionPage, | ||
collectionName, | ||
tabClass, | ||
collections, | ||
searchParams, | ||
setSearchParams, | ||
queryState, | ||
setQueryState, | ||
} = props; | ||
|
||
// context | ||
const { isManaged } = useContext(authContext); | ||
// i18n | ||
const { t: collectionTrans } = useTranslation('collection'); | ||
|
||
const collection = collections.find( | ||
i => i.collection_name === collectionName | ||
) as CollectionFullObject; | ||
|
||
// collection tabs | ||
const collectionTabs: ITab[] = [ | ||
{ | ||
label: collectionTrans('schemaTab'), | ||
component: <Schema />, | ||
path: `schema`, | ||
}, | ||
{ | ||
label: collectionTrans('searchTab'), | ||
component: ( | ||
<Search | ||
collections={collections} | ||
collectionName={collectionName} | ||
searchParams={searchParams} | ||
setSearchParams={setSearchParams} | ||
/> | ||
), | ||
path: `search`, | ||
}, | ||
{ | ||
label: collectionTrans('dataTab'), | ||
component: <Data queryState={queryState} setQueryState={setQueryState} />, | ||
path: `data`, | ||
}, | ||
{ | ||
label: collectionTrans('partitionTab'), | ||
component: <Partitions />, | ||
path: `partitions`, | ||
}, | ||
]; | ||
|
||
if (!isManaged) { | ||
collectionTabs.push( | ||
{ | ||
label: collectionTrans('segmentsTab'), | ||
component: <Segments />, | ||
path: `segments`, | ||
}, | ||
{ | ||
label: collectionTrans('propertiesTab'), | ||
component: <Properties type="collection" target={collection} />, | ||
path: `properties`, | ||
} | ||
); | ||
} | ||
|
||
// get active collection tab | ||
const activeColTab = collectionTabs.findIndex(t => t.path === collectionPage); | ||
|
||
return ( | ||
<RouteTabList | ||
tabs={collectionTabs} | ||
wrapperClass={tabClass} | ||
activeIndex={activeColTab !== -1 ? activeColTab : 0} | ||
/> | ||
); | ||
}; |
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,45 @@ | ||
import { useContext } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import RouteTabList from '@/components/customTabList/RouteTabList'; | ||
import Properties from './collections/properties/Properties'; | ||
import { authContext } from '@/context'; | ||
import Collections from './collections/Collections'; | ||
import type { ITab } from '@/components/customTabList/Types'; | ||
|
||
// Database tab pages | ||
export const DatabasesTab = (props: { | ||
databasePage: string; // current database page | ||
databaseName: string; | ||
tabClass: string; // tab class | ||
}) => { | ||
// context | ||
const { isManaged } = useContext(authContext); | ||
const { databaseName, tabClass, databasePage } = props; | ||
const { t: collectionTrans } = useTranslation('collection'); | ||
|
||
const dbTab: ITab[] = [ | ||
{ | ||
label: collectionTrans('collections'), | ||
component: <Collections />, | ||
path: `collections`, | ||
}, | ||
]; | ||
|
||
if (!isManaged) { | ||
dbTab.push({ | ||
label: collectionTrans('properties'), | ||
component: <Properties type="database" target={databaseName} />, | ||
path: `properties`, | ||
}); | ||
} | ||
|
||
const actionDbTab = dbTab.findIndex(t => t.path === databasePage); | ||
|
||
return ( | ||
<RouteTabList | ||
tabs={dbTab} | ||
wrapperClass={tabClass} | ||
activeIndex={actionDbTab !== -1 ? actionDbTab : 0} | ||
/> | ||
); | ||
}; |