Collection.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { useTranslation } from 'react-i18next';
  2. import { useNavigationHook } from '../../hooks/Navigation';
  3. import { ALL_ROUTER_TYPES } from '../../router/Types';
  4. import CustomTabList from '../../components/customTabList/CustomTabList';
  5. import { ITab } from '../../components/customTabList/Types';
  6. import Partitions from '../partitions/partitions';
  7. import { useHistory, useLocation, useParams } from 'react-router-dom';
  8. import { useMemo } from 'react';
  9. import { parseLocationSearch } from '../../utils/Format';
  10. import Structure from '../structure/Structure';
  11. enum TAB_EMUM {
  12. 'partition',
  13. 'structure',
  14. }
  15. const Collection = () => {
  16. const { collectionName = '' } = useParams<{
  17. collectionName: string;
  18. }>();
  19. useNavigationHook(ALL_ROUTER_TYPES.COLLECTION_DETAIL, { collectionName });
  20. const history = useHistory();
  21. const location = useLocation();
  22. const { t: collectionTrans } = useTranslation('collection');
  23. const activeTabIndex = useMemo(() => {
  24. const { activeIndex } = location.search
  25. ? parseLocationSearch(location.search)
  26. : { activeIndex: TAB_EMUM.partition };
  27. return Number(activeIndex);
  28. }, [location]);
  29. const handleTabChange = (activeIndex: number) => {
  30. const path = location.pathname;
  31. history.push(`${path}?activeIndex=${activeIndex}`);
  32. };
  33. const tabs: ITab[] = [
  34. {
  35. label: collectionTrans('structureTab'),
  36. component: <Structure collectionName={collectionName} />,
  37. },
  38. {
  39. label: collectionTrans('partitionTab'),
  40. component: <Partitions collectionName={collectionName} />,
  41. },
  42. ];
  43. return (
  44. <section className="page-wrapper">
  45. <CustomTabList
  46. tabs={tabs}
  47. activeIndex={activeTabIndex}
  48. handleTabChange={handleTabChange}
  49. />
  50. </section>
  51. );
  52. };
  53. export default Collection;