Fixed issue with topic entity summary panel not showing schema fields (#9877)

This commit is contained in:
Aniket Katkar 2023-01-24 15:39:34 +05:30 committed by GitHub
parent 8894b9adf5
commit 8829e6d976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 27 deletions

View File

@ -12,7 +12,7 @@
*/
import { Col, Divider, Row, Typography } from 'antd';
import { isArray } from 'lodash';
import { isArray, isEmpty } from 'lodash';
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { getTopicByFqn } from 'rest/topicsAPI';
@ -62,9 +62,9 @@ function TopicSummary({ entityDetails }: TopicSummaryProps) {
''
);
const { partitions } = res;
const { partitions, messageSchema } = res;
setTopicDetails({ ...entityDetails, partitions });
setTopicDetails({ ...entityDetails, partitions, messageSchema });
} catch {
showErrorToast(
t('server.entity-details-fetch-error', {
@ -126,9 +126,7 @@ function TopicSummary({ entityDetails }: TopicSummaryProps) {
</Typography.Text>
</Col>
<Col span={24}>
{entityDetails.messageSchema?.schemaFields ? (
<SummaryList formattedEntityData={formattedSchemaFieldsData} />
) : (
{isEmpty(topicDetails.messageSchema?.schemaFields) ? (
<div className="m-y-md">
<Typography.Text
className="text-gray"
@ -136,6 +134,8 @@ function TopicSummary({ entityDetails }: TopicSummaryProps) {
{t('message.no-data-available')}
</Typography.Text>
</div>
) : (
<SummaryList formattedEntityData={formattedSchemaFieldsData} />
)}
</Col>
</Row>

View File

@ -14,7 +14,10 @@
import { act, render, screen } from '@testing-library/react';
import React from 'react';
import { getTopicByFqn } from 'rest/topicsAPI';
import { mockTopicEntityDetails } from '../mocks/TopicSummary.mock';
import {
mockTopicByFqnResponse,
mockTopicEntityDetails,
} from '../mocks/TopicSummary.mock';
import TopicSummary from './TopicSummary.component';
jest.mock(
@ -34,7 +37,7 @@ jest.mock('../SummaryList/SummaryList.component', () =>
);
jest.mock('rest/topicsAPI', () => ({
getTopicByFqn: jest.fn().mockImplementation(() => ({ partitions: 128 })),
getTopicByFqn: jest.fn().mockImplementation(() => mockTopicByFqnResponse),
}));
describe('TopicSummary component tests', () => {
@ -76,19 +79,11 @@ describe('TopicSummary component tests', () => {
expect(summaryList).toBeInTheDocument();
});
it('No data message should be shown in case not schemaFields are available in topic details', async () => {
it('No data message should be shown in case no schemaFields are available in topic details', async () => {
(getTopicByFqn as jest.Mock).mockImplementation(() => Promise.resolve({}));
await act(async () => {
render(
<TopicSummary
entityDetails={{
...mockTopicEntityDetails,
messageSchema: {
...mockTopicEntityDetails.messageSchema,
schemaFields: undefined,
},
}}
/>
);
render(<TopicSummary entityDetails={mockTopicEntityDetails} />);
});
const summaryList = screen.queryByTestId('SummaryList');

View File

@ -38,6 +38,17 @@ export const mockTopicEntityDetails: Topic = {
deleted: false,
href: 'http://openmetadata-server:8585/api/v1/services/messagingServices/5d6f73f0-1811-49c8-8d1d-7a478ffd8177',
},
partitions: 0,
cleanupPolicies: [CleanupPolicy.Delete],
replicationFactor: 4,
maximumMessageSize: 208,
retentionSize: 1068320655,
tags: [],
followers: [],
};
export const mockTopicByFqnResponse = {
partitions: 128,
messageSchema: {
schemaText:
'{"namespace":"openmetadata.kafka","type":"record","name":"Product","fields":[{"name":"product_id","type":"int"}]}',
@ -90,11 +101,4 @@ export const mockTopicEntityDetails: Topic = {
},
],
},
partitions: 0,
cleanupPolicies: [CleanupPolicy.Delete],
replicationFactor: 4,
maximumMessageSize: 208,
retentionSize: 1068320655,
tags: [],
followers: [],
};