Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: Adding Schema (Value) and Schema (Key) tab to the Topic details view #4020

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import styled from 'styled-components';

export const Wrapper = styled.div`
width: 100%;
background-color: ${({ theme }) => theme.layout.stuffColor};
padding: 16px;
display: flex;
justify-content: center;
align-items: stretch;
gap: 2px;
max-height: 700px;

& > * {
background-color: ${({ theme }) => theme.default.backgroundColor};
padding: 24px;
overflow-y: scroll;
}

p {
color: ${({ theme }) => theme.schema.backgroundColor.p};
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import useAppParams from 'lib/hooks/useAppParams';
import { RouteParamsClusterTopic } from 'lib/paths';
import { useAppDispatch, useAppSelector } from 'lib/hooks/redux';
import { resetLoaderById } from 'redux/reducers/loader/loaderSlice';
import {
fetchLatestSchema,
getSchemaLatest,
getAreSchemaLatestFulfilled,
getAreSchemaLatestRejected,
SCHEMA_LATEST_FETCH_ACTION,
} from 'redux/reducers/schemas/schemasSlice';
import LatestVersionItem from '../../../Schemas/Details/LatestVersion/LatestVersionItem';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please use absolute path here instead of an relative path ?

cause that way it will not cause any issues if we displaced the component that this Schema uses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no worries let me fix that, when I'm home from vacation at my computer with this code 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mgrdich let's chill with the review, we might not need it, as I asked to raise a PR for an example, since we wanted to achieve something similar but not that similar :))

import PageLoader from 'components/common/PageLoader/PageLoader';

import * as S from './Schema.styled';

export enum SchemaType {
Value,
Key,
}

interface SchemaProps {
type: SchemaType;
}

export const Schema: React.FC<SchemaProps> = ({ type }) => {
const dispatch = useAppDispatch();
const { clusterName, topicName } = useAppParams<RouteParamsClusterTopic>();
const subject = topicName + '-' + SchemaType[type].toLowerCase();
React.useEffect(() => {
dispatch(fetchLatestSchema({ clusterName, subject }));
return () => {
dispatch(resetLoaderById(SCHEMA_LATEST_FETCH_ACTION));
};
}, [clusterName, dispatch, subject]);

const schema = useAppSelector(getSchemaLatest);
const isFetched = useAppSelector(getAreSchemaLatestFulfilled);
const isRejected = useAppSelector(getAreSchemaLatestRejected);

if (!isFetched && !isRejected) {
return <PageLoader />;
}

if (isRejected || !schema) {
return (
<S.Wrapper>
<p>
No {SchemaType[type].toLowerCase()} schema available for {topicName} at {clusterName}
</p>
</S.Wrapper>
);
}

return <LatestVersionItem schema={schema} />;
};
32 changes: 31 additions & 1 deletion kafka-ui-react-app/src/components/Topics/Topic/Topic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
clusterTopicConsumerGroupsRelativePath,
clusterTopicEditRelativePath,
clusterTopicMessagesRelativePath,
clusterTopicSchemaValueRelativePath,
clusterTopicSchemaKeyRelativePath,
clusterTopicSettingsRelativePath,
clusterTopicsPath,
clusterTopicStatisticsRelativePath,
Expand Down Expand Up @@ -33,6 +35,7 @@ import SlidingSidebar from 'components/common/SlidingSidebar';
import useBoolean from 'lib/hooks/useBoolean';

import Messages from './Messages/Messages';
import { Schema, SchemaType } from './Schema/Schema';
import Overview from './Overview/Overview';
import Settings from './Settings/Settings';
import TopicConsumerGroups from './ConsumerGroups/TopicConsumerGroups';
Expand All @@ -54,7 +57,7 @@ const Topic: React.FC = () => {
const recreateTopic = useRecreateTopic({ clusterName, topicName });
const { data } = useTopicDetails({ clusterName, topicName });

const { isReadOnly, isTopicDeletionAllowed } =
const { isReadOnly, isTopicDeletionAllowed, hasSchemaRegistryConfigured } =
React.useContext(ClusterContext);

const deleteTopicHandler = async () => {
Expand Down Expand Up @@ -189,6 +192,21 @@ const Topic: React.FC = () => {
>
Messages
</ActionNavLink>
{ hasSchemaRegistryConfigured ?
<>
<NavLink
to={clusterTopicSchemaValueRelativePath}
className={({ isActive }) => (isActive ? 'is-active' : '')}
>
Schema (Value)
</NavLink>
<NavLink
to={clusterTopicSchemaKeyRelativePath}
className={({ isActive }) => (isActive ? 'is-active' : '')}
>
Schema (Key)
</NavLink>
</> : null }
<NavLink
to={clusterTopicConsumerGroupsRelativePath}
className={({ isActive }) => (isActive ? 'is-active' : '')}
Expand All @@ -215,6 +233,18 @@ const Topic: React.FC = () => {
path={clusterTopicMessagesRelativePath}
element={<Messages />}
/>
{ hasSchemaRegistryConfigured ?
<>
<Route
path={clusterTopicSchemaValueRelativePath}
element={<Schema type={SchemaType.Value} />}
/>
<Route
path={clusterTopicSchemaKeyRelativePath}
element={<Schema type={SchemaType.Key} />}
/>
</>
: null }
<Route
path={clusterTopicSettingsRelativePath}
element={<Settings />}
Expand Down
18 changes: 18 additions & 0 deletions kafka-ui-react-app/src/lib/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export const clusterTopicCopyPath = (
// Topics topic
export const clusterTopicSettingsRelativePath = 'settings';
export const clusterTopicMessagesRelativePath = 'messages';
export const clusterTopicSchemaValueRelativePath = 'schema-value';
export const clusterTopicSchemaKeyRelativePath = 'schema-key';
export const clusterTopicConsumerGroupsRelativePath = 'consumer-groups';
export const clusterTopicStatisticsRelativePath = 'statistics';
export const clusterTopicEditRelativePath = 'edit';
Expand All @@ -167,6 +169,22 @@ export const clusterTopicMessagesPath = (
clusterName,
topicName
)}/${clusterTopicMessagesRelativePath}`;
export const clusterTopicSchemaValuePath = (
clusterName: ClusterName = RouteParams.clusterName,
topicName: TopicName = RouteParams.topicName
) =>
`${clusterTopicPath(
clusterName,
topicName
)}/${clusterTopicSchemaValueRelativePath}`;
export const clusterTopicSchemaKeyPath = (
clusterName: ClusterName = RouteParams.clusterName,
topicName: TopicName = RouteParams.topicName
) =>
`${clusterTopicPath(
clusterName,
topicName
)}/${clusterTopicSchemaKeyRelativePath}`;
export const clusterTopicEditPath = (
clusterName: ClusterName = RouteParams.clusterName,
topicName: TopicName = RouteParams.topicName
Expand Down