Skip to content

ref(ts): Convert <QueryCount> to typescript #16356

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

Merged
merged 1 commit into from
Jan 13, 2020
Merged
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
Expand Up @@ -2,14 +2,31 @@ import PropTypes from 'prop-types';
import React from 'react';
import classNames from 'classnames';

import {defined} from 'app/utils';

type Props = {
count?: number;
max?: number;
hideIfEmpty?: boolean;
inline?: boolean;
className?: string;
};

/**
* Displays a number count. If `max` is specified, then give representation
* of count, i.e. "1000+"
*
* Render nothing by default if `count` is falsy.
*/
function QueryCount({className, count, max, hideIfEmpty, inline}) {
const countOrMax = typeof max !== 'undefined' && count >= max ? `${max}+` : count;

const QueryCount: React.FC<Props> = ({
className,
count,
max,
hideIfEmpty = true,
inline = true,
}) => {
const countOrMax = defined(count) && defined(max) && count >= max ? `${max}+` : count;
const cx = classNames('query-count', className, {
inline,
});
Expand All @@ -25,17 +42,13 @@ function QueryCount({className, count, max, hideIfEmpty, inline}) {
<span>)</span>
</div>
);
}
};
QueryCount.propTypes = {
className: PropTypes.string,
count: PropTypes.number,
max: PropTypes.number,
hideIfEmpty: PropTypes.bool,
inline: PropTypes.bool,
};
QueryCount.defaultProps = {
hideIfEmpty: true,
inline: true,
};

export default QueryCount;
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ exports[`Issues Similar View renders with mocked data 1`] = `
</span>
<QueryCount
count={4}
hideIfEmpty={true}
inline={true}
>
<div
className="query-count inline"
Expand Down