Details component refactored

This commit is contained in:
Guzel Kafizova 2021-02-17 16:23:37 +03:00
parent f50800e10c
commit 8ee4426db0
8 changed files with 71 additions and 76 deletions

View file

@ -1,10 +1,10 @@
import { SchemaSubject } from 'generated-sources';
import React from 'react';
import { SchemaSubject } from 'generated-sources';
import { ClusterName, SchemaName } from 'redux/interfaces';
import JSONViewer from 'components/common/JSONViewer/JSONViewer';
import { clusterSchemasPath } from 'lib/paths';
import Breadcrumb from '../../common/Breadcrumb/Breadcrumb';
import { clusterSchemasPath } from '../../../lib/paths';
import SchemaVersion from './SchemaVersion';
import LatestVersionItem from './LatestVersionItem';
interface DetailsProps {
schema: SchemaSubject;
@ -31,18 +31,16 @@ const Details: React.FC<DetailsProps> = ({
return (
<div className="section">
<div className="level">
<div className="level-item level-left">
<Breadcrumb
links={[
{
href: clusterSchemasPath(clusterName),
label: 'Schema Registry',
},
]}
>
{schema.subject}
</Breadcrumb>
</div>
<Breadcrumb
links={[
{
href: clusterSchemasPath(clusterName),
label: 'Schema Registry',
},
]}
>
{schema.subject}
</Breadcrumb>
</div>
<div className="box">
<div className="level">
@ -83,34 +81,7 @@ const Details: React.FC<DetailsProps> = ({
</button>
</div>
</div>
<div className="tile is-ancestor mt-1">
<div className="tile is-4 is-parent">
<div className="tile is-child">
<table className="table is-fullwidth">
<tbody>
<tr>
<td>ID</td>
<td>{schema.id}</td>
</tr>
<tr>
<td>Subject</td>
<td>{schema.subject}</td>
</tr>
<tr>
<td>Compatibility</td>
<td>{schema.compatibilityLevel}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="tile is-parent">
<div className="tile is-child box py-1">
<JSONViewer data={JSON.parse(schema.schema as string)} />
</div>
</div>
</div>
<LatestVersionItem schema={schema} />
</div>
<div className="box">
<table className="table is-striped is-fullwidth">
@ -122,11 +93,9 @@ const Details: React.FC<DetailsProps> = ({
</tr>
</thead>
<tbody>
{versions
.sort((a: SchemaSubject, b: SchemaSubject) => a.id - b.id)
.map((version) => (
<SchemaVersion key={version.id} version={version} />
))}
{versions.map((version) => (
<SchemaVersion key={version.id} version={version} />
))}
</tbody>
</table>
</div>

View file

@ -2,8 +2,8 @@ import { connect } from 'react-redux';
import { ClusterName, RootState } from 'redux/interfaces';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { getSchema, getSchemaVersions } from 'redux/reducers/schemas/selectors';
import { fetchSchemaVersions } from 'redux/actions';
import Details from './Details';
import { fetchSchemaVersions } from '../../../redux/actions';
interface RouteProps {
clusterName: ClusterName;

View file

@ -0,0 +1,43 @@
import React from 'react';
import { SchemaSubject } from 'generated-sources';
import JSONViewer from 'components/common/JSONViewer/JSONViewer';
interface LatestVersionProps {
schema: SchemaSubject;
}
const LatestVersionItem: React.FC<LatestVersionProps> = ({
schema: { id, subject, schema, compatibilityLevel },
}) => {
return (
<div className="tile is-ancestor mt-1">
<div className="tile is-4 is-parent">
<div className="tile is-child">
<table className="table is-fullwidth">
<tbody>
<tr>
<td>ID</td>
<td>{id}</td>
</tr>
<tr>
<td>Subject</td>
<td>{subject}</td>
</tr>
<tr>
<td>Compatibility</td>
<td>{compatibilityLevel}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="tile is-parent">
<div className="tile is-child box py-1">
<JSONViewer data={JSON.parse(schema as string)} />
</div>
</div>
</div>
);
};
export default LatestVersionItem;

View file

@ -1,5 +1,5 @@
import { SchemaSubject } from 'generated-sources';
import React from 'react';
import { SchemaSubject } from 'generated-sources';
import Breadcrumb from '../../common/Breadcrumb/Breadcrumb';
import ListItem from './ListItem';

View file

@ -1,5 +1,5 @@
import { SchemaSubject } from 'generated-sources';
import React from 'react';
import { SchemaSubject } from 'generated-sources';
import { NavLink } from 'react-router-dom';
interface ListItemProps {

View file

@ -1,7 +1,7 @@
import React from 'react';
import { format } from 'date-fns';
import JSONTree from 'react-json-tree';
import { TopicMessage } from 'generated-sources';
import JSONViewer from 'components/common/JSONViewer/JSONViewer';
export interface MessageItemProp {
partition: TopicMessage['partition'];
@ -21,28 +21,7 @@ const MessageItem: React.FC<MessageItemProp> = ({
<td style={{ width: 150 }}>{offset}</td>
<td style={{ width: 100 }}>{partition}</td>
<td style={{ wordBreak: 'break-word' }}>
{content && (
<JSONTree
data={content}
hideRoot
invertTheme={false}
theme={{
tree: ({ style }) => ({
style: {
...style,
backgroundColor: undefined,
marginLeft: 0,
marginTop: 0,
},
}),
value: ({ style }) => ({
style: { ...style, marginLeft: 0 },
}),
base0D: '#3273dc',
base0B: '#363636',
}}
/>
)}
{content && <JSONViewer data={content as { [key: string]: string }} />}
</td>
</tr>
);

View file

@ -32,7 +32,7 @@ const MessagesTable: React.FC<MessagesTableProp> = ({ messages, onNext }) => {
partition={partition}
offset={offset}
timestamp={timestamp}
content={content as Record<string, unknown>}
content={content as { [key: string]: string }}
/>
)
)}

View file

@ -1,6 +1,7 @@
import { createSelector } from 'reselect';
import { RootState, SchemasState } from 'redux/interfaces';
import { createFetchingSelector } from 'redux/reducers/loader/selectors';
import { SchemaSubject } from 'generated-sources';
const schemasState = ({ schemas }: RootState): SchemasState => schemas;
@ -38,5 +39,8 @@ export const getSchema = createSelector(
export const getSchemaVersions = createSelector(
schemasState,
({ currentSchemaVersions }) => currentSchemaVersions
({ currentSchemaVersions }) =>
currentSchemaVersions.sort(
(a: SchemaSubject, b: SchemaSubject) => a.id - b.id
)
);