ClusterPage.tsx 4.5 KB

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