From 93d471f408728273f55f67dc723a7c22380c1e53 Mon Sep 17 00:00:00 2001 From: GneyHabub Date: Tue, 9 Mar 2021 13:42:03 +0300 Subject: [PATCH] Implement readonly flag logic --- .../ClustersWidget/ClusterWidget.tsx | 4 ++ .../components/Schemas/Details/Details.tsx | 40 ++++++++++--------- .../Schemas/Details/DetailsContainer.ts | 2 + .../src/components/Schemas/List/List.tsx | 21 +++++----- .../components/Schemas/List/ListContainer.tsx | 22 ++++++++-- .../src/components/Topics/Details/Details.tsx | 11 +++-- .../Topics/Details/DetailsContainer.ts | 2 + .../src/components/Topics/List/List.tsx | 22 ++++++---- .../components/Topics/List/ListContainer.ts | 2 + .../src/redux/reducers/clusters/selectors.ts | 6 +++ 10 files changed, 91 insertions(+), 41 deletions(-) diff --git a/kafka-ui-react-app/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx b/kafka-ui-react-app/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx index c5b0007288..9e7fa5403c 100644 --- a/kafka-ui-react-app/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx +++ b/kafka-ui-react-app/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx @@ -17,6 +17,7 @@ const ClusterWidget: React.FC = ({ bytesInPerSec, bytesOutPerSec, onlinePartitionCount, + readOnly, }, }) => (
@@ -29,6 +30,9 @@ const ClusterWidget: React.FC = ({ > {status}
+ {readOnly && ( +
readonly
+ )} {name} diff --git a/kafka-ui-react-app/src/components/Schemas/Details/Details.tsx b/kafka-ui-react-app/src/components/Schemas/Details/Details.tsx index 1753b11e66..8465538ea6 100644 --- a/kafka-ui-react-app/src/components/Schemas/Details/Details.tsx +++ b/kafka-ui-react-app/src/components/Schemas/Details/Details.tsx @@ -12,6 +12,7 @@ export interface DetailsProps { clusterName: ClusterName; versions: SchemaSubject[]; isFetched: boolean; + isReadOnly?: boolean | undefined; fetchSchemaVersions: ( clusterName: ClusterName, schemaName: SchemaName @@ -24,6 +25,7 @@ const Details: React.FC = ({ fetchSchemaVersions, versions, isFetched, + isReadOnly, }) => { React.useEffect(() => { fetchSchemaVersions(clusterName, schema.subject as SchemaName); @@ -54,24 +56,26 @@ const Details: React.FC = ({ -
- - -
+ {!isReadOnly && ( +
+ + +
+ )} diff --git a/kafka-ui-react-app/src/components/Schemas/Details/DetailsContainer.ts b/kafka-ui-react-app/src/components/Schemas/Details/DetailsContainer.ts index 072d2a44f8..fa6aae88de 100644 --- a/kafka-ui-react-app/src/components/Schemas/Details/DetailsContainer.ts +++ b/kafka-ui-react-app/src/components/Schemas/Details/DetailsContainer.ts @@ -6,6 +6,7 @@ import { getSchema, getSortedSchemaVersions, } from 'redux/reducers/schemas/selectors'; +import { getClustersReadonlyStatus } from 'redux/reducers/clusters/selectors'; import { fetchSchemaVersions } from 'redux/actions'; import Details from './Details'; @@ -28,6 +29,7 @@ const mapStateToProps = ( versions: getSortedSchemaVersions(state), isFetched: getIsSchemaVersionFetched(state), clusterName, + isReadOnly: getClustersReadonlyStatus(clusterName)(state), }); const mapDispatchToProps = { diff --git a/kafka-ui-react-app/src/components/Schemas/List/List.tsx b/kafka-ui-react-app/src/components/Schemas/List/List.tsx index c7366d1f66..2853898181 100644 --- a/kafka-ui-react-app/src/components/Schemas/List/List.tsx +++ b/kafka-ui-react-app/src/components/Schemas/List/List.tsx @@ -7,9 +7,10 @@ import ListItem from './ListItem'; export interface ListProps { schemas: SchemaSubject[]; + isReadOnly?: boolean | undefined; } -const List: React.FC = ({ schemas }) => { +const List: React.FC = ({ schemas, isReadOnly }) => { const { clusterName } = useParams<{ clusterName: string }>(); return ( @@ -17,14 +18,16 @@ const List: React.FC = ({ schemas }) => { Schema Registry
-
- - Create Schema - -
+ {!isReadOnly && ( +
+ + Create Schema + +
+ )}
diff --git a/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx b/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx index 2925987540..02e325e665 100644 --- a/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx +++ b/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx @@ -1,10 +1,26 @@ import { connect } from 'react-redux'; -import { RootState } from 'redux/interfaces'; +import { RootState, ClusterName } from 'redux/interfaces'; import { getSchemaList } from 'redux/reducers/schemas/selectors'; +import { getClustersReadonlyStatus } from 'redux/reducers/clusters/selectors'; +import { RouteComponentProps, withRouter } from 'react-router-dom'; import List from './List'; -const mapStateToProps = (state: RootState) => ({ +interface RouteProps { + clusterName: ClusterName; +} + +type OwnProps = RouteComponentProps; + +const mapStateToProps = ( + state: RootState, + { + match: { + params: { clusterName }, + }, + }: OwnProps +) => ({ schemas: getSchemaList(state), + isReadOnly: getClustersReadonlyStatus(clusterName)(state), }); -export default connect(mapStateToProps)(List); +export default withRouter(connect(mapStateToProps)(List)); diff --git a/kafka-ui-react-app/src/components/Topics/Details/Details.tsx b/kafka-ui-react-app/src/components/Topics/Details/Details.tsx index 1b1cb9903f..eebc0ea5d8 100644 --- a/kafka-ui-react-app/src/components/Topics/Details/Details.tsx +++ b/kafka-ui-react-app/src/components/Topics/Details/Details.tsx @@ -18,9 +18,10 @@ import SettingsEditButton from './Settings/SettingsEditButton'; interface Props extends Topic, TopicDetails { clusterName: ClusterName; topicName: TopicName; + isReadOnly: boolean | undefined; } -const Details: React.FC = ({ clusterName, topicName }) => { +const Details: React.FC = ({ clusterName, topicName, isReadOnly }) => { return (
@@ -33,9 +34,11 @@ const Details: React.FC = ({ clusterName, topicName }) => { {topicName}
- + {!isReadOnly && ( + + )}
diff --git a/kafka-ui-react-app/src/components/Topics/Details/DetailsContainer.ts b/kafka-ui-react-app/src/components/Topics/Details/DetailsContainer.ts index f62a34f987..9050876278 100644 --- a/kafka-ui-react-app/src/components/Topics/Details/DetailsContainer.ts +++ b/kafka-ui-react-app/src/components/Topics/Details/DetailsContainer.ts @@ -1,5 +1,6 @@ import { connect } from 'react-redux'; import { ClusterName, RootState, TopicName } from 'redux/interfaces'; +import { getClustersReadonlyStatus } from 'redux/reducers/clusters/selectors'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import Details from './Details'; @@ -20,6 +21,7 @@ const mapStateToProps = ( ) => ({ clusterName, topicName, + isReadOnly: getClustersReadonlyStatus(clusterName)(state), }); export default withRouter(connect(mapStateToProps)(Details)); diff --git a/kafka-ui-react-app/src/components/Topics/List/List.tsx b/kafka-ui-react-app/src/components/Topics/List/List.tsx index ad6a286e90..62ef92ef95 100644 --- a/kafka-ui-react-app/src/components/Topics/List/List.tsx +++ b/kafka-ui-react-app/src/components/Topics/List/List.tsx @@ -9,9 +9,15 @@ interface Props { clusterName: ClusterName; topics: TopicWithDetailedInfo[]; externalTopics: TopicWithDetailedInfo[]; + isReadOnly?: boolean | undefined; } -const List: React.FC = ({ clusterName, topics, externalTopics }) => { +const List: React.FC = ({ + clusterName, + topics, + externalTopics, + isReadOnly, +}) => { const [showInternal, setShowInternal] = React.useState(true); const handleSwitch = () => setShowInternal(!showInternal); @@ -38,12 +44,14 @@ const List: React.FC = ({ clusterName, topics, externalTopics }) => {
- - Add a Topic - + {!isReadOnly && ( + + Add a Topic + + )}
diff --git a/kafka-ui-react-app/src/components/Topics/List/ListContainer.ts b/kafka-ui-react-app/src/components/Topics/List/ListContainer.ts index 3dde5c455e..0168991fc9 100644 --- a/kafka-ui-react-app/src/components/Topics/List/ListContainer.ts +++ b/kafka-ui-react-app/src/components/Topics/List/ListContainer.ts @@ -4,6 +4,7 @@ import { getTopicList, getExternalTopicList, } from 'redux/reducers/topics/selectors'; +import { getClustersReadonlyStatus } from 'redux/reducers/clusters/selectors'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import List from './List'; @@ -24,6 +25,7 @@ const mapStateToProps = ( clusterName, topics: getTopicList(state), externalTopics: getExternalTopicList(state), + isReadOnly: getClustersReadonlyStatus(clusterName)(state), }); export default withRouter(connect(mapStateToProps)(List)); diff --git a/kafka-ui-react-app/src/redux/reducers/clusters/selectors.ts b/kafka-ui-react-app/src/redux/reducers/clusters/selectors.ts index e6667fc3e0..b330f2f67a 100644 --- a/kafka-ui-react-app/src/redux/reducers/clusters/selectors.ts +++ b/kafka-ui-react-app/src/redux/reducers/clusters/selectors.ts @@ -24,3 +24,9 @@ export const getOnlineClusters = createSelector(getClusterList, (clusters) => export const getOfflineClusters = createSelector(getClusterList, (clusters) => clusters.filter(({ status }) => status === ServerStatus.OFFLINE) ); + +export const getClustersReadonlyStatus = (clusterName: string) => + createSelector( + getClusterList, + (clusters) => clusters.find(({ name }) => name === clusterName)?.readOnly + );