Cluster.tsx 3.5 KB

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