Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split large files #783

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions client/src/pages/databases/CollectionsTab.tsx
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}
/>
);
};
145 changes: 4 additions & 141 deletions client/src/pages/databases/Databases.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import { useContext, useEffect, useState, useRef } from 'react';
import { useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useNavigationHook } from '@/hooks';
import RouteTabList from '@/components/customTabList/RouteTabList';
import DatabaseTree from '@/pages/databases/tree';
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 { dataContext, authContext } from '@/context';
import Collections from './collections/Collections';
import { dataContext } from '@/context';
import StatusIcon from '@/components/status/StatusIcon';
import { ConsistencyLevelEnum, DYNAMIC_FIELD } from '@/consts';
import { ALL_ROUTER_TYPES } from '@/router/consts';
import { makeStyles } from '@mui/styles';
import { LoadingType } from '@/components/status/StatusIcon';
import type { Theme } from '@mui/material/styles';
import type { SearchParams, QueryState } from './types';
import type { CollectionObject, CollectionFullObject } from '@server/types';
import type { ITab } from '@/components/customTabList/Types';
import { DatabasesTab } from './DatabasesTab';
import { CollectionsTabs } from './CollectionsTab';

const DEFAULT_TREE_WIDTH = 230;

Expand Down Expand Up @@ -355,7 +346,7 @@ const Databases = () => {
/>
)}
{collectionName && (
<CollectionTabs
<CollectionsTabs
collectionPage={collectionPage}
collectionName={collectionName}
tabClass={classes.tab}
Expand All @@ -378,132 +369,4 @@ const Databases = () => {
);
};

// Database tab pages
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}
/>
);
};

// Collection tab pages
const CollectionTabs = (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}
/>
);
};

export default Databases;
45 changes: 45 additions & 0 deletions client/src/pages/databases/DatabasesTab.tsx
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}
/>
);
};
Loading