Fix #3727 Usage queries tab UI issues (#3737)

This commit is contained in:
Sachin Chaurasiya 2022-03-30 15:53:11 +05:30 committed by GitHub
parent 227d81951c
commit f8922e97a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 34 deletions

View File

@ -11,7 +11,12 @@
* limitations under the License.
*/
import { findByText, getByTestId, render } from '@testing-library/react';
import {
findByText,
getByTestId,
queryByTestId,
render,
} from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import QueryCard from './QueryCard';
@ -54,4 +59,28 @@ describe('Test QueryCard Component', () => {
expect(query).toBeInTheDocument();
expect(copyQueryButton).toBeInTheDocument();
});
it('Should not render header if user is undefined', async () => {
const { container } = render(
<QueryCard query={{ ...mockQueryData, user: undefined }} />,
{
wrapper: MemoryRouter,
}
);
const queryHeader = queryByTestId(container, 'query-header');
expect(queryHeader).not.toBeInTheDocument();
});
it('Should not render header if duration is undefined', async () => {
const { container } = render(
<QueryCard query={{ ...mockQueryData, duration: undefined }} />,
{
wrapper: MemoryRouter,
}
);
const queryHeader = queryByTestId(container, 'query-header');
expect(queryHeader).not.toBeInTheDocument();
});
});

View File

@ -12,6 +12,7 @@
*/
import classNames from 'classnames';
import { isUndefined } from 'lodash';
import React, { FC, HTMLAttributes, useState } from 'react';
import { Link } from 'react-router-dom';
import { getUserPath } from '../../constants/constants';
@ -31,40 +32,42 @@ const QueryCard: FC<QueryCardProp> = ({ className, query }) => {
<div
className="tw-cursor-pointer"
onClick={() => setExpanded((pre) => !pre)}>
<div
className="tw-flex tw-py-1 tw-justify-between"
data-testid="query-header">
<p>
Last run by{' '}
<Link
className="button-comp"
to={getUserPath(query.user?.name as string)}>
<button className="tw-font-medium tw-text-grey-body ">
{query.user?.displayName ?? query.user?.name}
</button>{' '}
</Link>
and took{' '}
<span className="tw-font-medium">{query.duration} seconds</span>
</p>
{!isUndefined(query.user) && !isUndefined(query.duration) ? (
<div
className="tw-flex tw-py-1 tw-justify-between"
data-testid="query-header">
<p>
Last run by{' '}
<Link
className="button-comp"
to={getUserPath(query.user?.name as string)}>
<button className="tw-font-medium tw-text-grey-body ">
{query.user?.displayName ?? query.user?.name}
</button>{' '}
</Link>
and took{' '}
<span className="tw-font-medium">{query.duration} seconds</span>
</p>
<button className="tw-pr-px">
{expanded ? (
<SVGIcons
alt="arrow-up"
className="tw-mr-4"
icon={Icons.ICON_UP}
width="16px"
/>
) : (
<SVGIcons
alt="arrow-down"
className="tw-mr-4"
icon={Icons.ICON_DOWN}
width="16px"
/>
)}
</button>
</div>
<button className="tw-pr-px">
{expanded ? (
<SVGIcons
alt="arrow-up"
className="tw-mr-4"
icon={Icons.ICON_UP}
width="16px"
/>
) : (
<SVGIcons
alt="arrow-down"
className="tw-mr-4"
icon={Icons.ICON_DOWN}
width="16px"
/>
)}
</button>
</div>
) : null}
</div>
<div className="tw-border tw-border-main tw-rounded-md tw-p-px">
<div

View File

@ -891,6 +891,10 @@ body .profiler-graph .recharts-active-dot circle {
height: auto !important;
}
.CodeMirror-wrap pre.CodeMirror-line {
padding-right: 40px;
}
.entity-feed-list {
grid-template-columns: 200px auto 200px;
}