ClusterPage.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React, { Suspense } from 'react';
  2. import { Routes, Navigate, Route, Outlet } from 'react-router-dom';
  3. import useAppParams from 'lib/hooks/useAppParams';
  4. import { ClusterFeaturesEnum } from 'generated-sources';
  5. import {
  6. clusterBrokerRelativePath,
  7. clusterConnectorsRelativePath,
  8. clusterConnectsRelativePath,
  9. clusterConsumerGroupsRelativePath,
  10. clusterKsqlDbRelativePath,
  11. ClusterNameRoute,
  12. clusterSchemasRelativePath,
  13. clusterTopicsRelativePath,
  14. clusterConfigRelativePath,
  15. getNonExactPath,
  16. } from 'lib/paths';
  17. import ClusterContext from 'components/contexts/ClusterContext';
  18. import PageLoader from 'components/common/PageLoader/PageLoader';
  19. import { useClusters } from 'lib/hooks/api/clusters';
  20. import { GlobalSettingsContext } from 'components/contexts/GlobalSettingsContext';
  21. const Brokers = React.lazy(() => import('components/Brokers/Brokers'));
  22. const Topics = React.lazy(() => import('components/Topics/Topics'));
  23. const Schemas = React.lazy(() => import('components/Schemas/Schemas'));
  24. const Connect = React.lazy(() => import('components/Connect/Connect'));
  25. const KsqlDb = React.lazy(() => import('components/KsqlDb/KsqlDb'));
  26. const ClusterConfigPage = React.lazy(
  27. () => import('components/ClusterPage/ClusterConfigPage')
  28. );
  29. const ConsumerGroups = React.lazy(
  30. () => import('components/ConsumerGroups/ConsumerGroups')
  31. );
  32. const ClusterPage: React.FC = () => {
  33. const { clusterName } = useAppParams<ClusterNameRoute>();
  34. const appInfo = React.useContext(GlobalSettingsContext);
  35. const { data } = useClusters();
  36. const contextValue = React.useMemo(() => {
  37. const cluster = data?.find(({ name }) => name === clusterName);
  38. const features = cluster?.features || [];
  39. return {
  40. isReadOnly: cluster?.readOnly || false,
  41. hasKafkaConnectConfigured: features.includes(
  42. ClusterFeaturesEnum.KAFKA_CONNECT
  43. ),
  44. hasSchemaRegistryConfigured: features.includes(
  45. ClusterFeaturesEnum.SCHEMA_REGISTRY
  46. ),
  47. isTopicDeletionAllowed: features.includes(
  48. ClusterFeaturesEnum.TOPIC_DELETION
  49. ),
  50. hasKsqlDbConfigured: features.includes(ClusterFeaturesEnum.KSQL_DB),
  51. };
  52. }, [clusterName, data]);
  53. return (
  54. <Suspense fallback={<PageLoader />}>
  55. <ClusterContext.Provider value={contextValue}>
  56. <Suspense fallback={<PageLoader />}>
  57. <Routes>
  58. <Route
  59. path={getNonExactPath(clusterBrokerRelativePath)}
  60. element={<Brokers />}
  61. />
  62. <Route
  63. path={getNonExactPath(clusterTopicsRelativePath)}
  64. element={<Topics />}
  65. />
  66. <Route
  67. path={getNonExactPath(clusterConsumerGroupsRelativePath)}
  68. element={<ConsumerGroups />}
  69. />
  70. {contextValue.hasSchemaRegistryConfigured && (
  71. <Route
  72. path={getNonExactPath(clusterSchemasRelativePath)}
  73. element={<Schemas />}
  74. />
  75. )}
  76. {contextValue.hasKafkaConnectConfigured && (
  77. <Route
  78. path={getNonExactPath(clusterConnectsRelativePath)}
  79. element={<Connect />}
  80. />
  81. )}
  82. {contextValue.hasKafkaConnectConfigured && (
  83. <Route
  84. path={getNonExactPath(clusterConnectorsRelativePath)}
  85. element={<Connect />}
  86. />
  87. )}
  88. {contextValue.hasKsqlDbConfigured && (
  89. <Route
  90. path={getNonExactPath(clusterKsqlDbRelativePath)}
  91. element={<KsqlDb />}
  92. />
  93. )}
  94. {appInfo.hasDynamicConfig && (
  95. <Route
  96. path={getNonExactPath(clusterConfigRelativePath)}
  97. element={<ClusterConfigPage />}
  98. />
  99. )}
  100. <Route
  101. path="/"
  102. element={<Navigate to={clusterBrokerRelativePath} replace />}
  103. />
  104. </Routes>
  105. <Outlet />
  106. </Suspense>
  107. </ClusterContext.Provider>
  108. </Suspense>
  109. );
  110. };
  111. export default ClusterPage;