Skip to content

Commit

Permalink
DownloadCount - show number of downloads, use for legacy roles
Browse files Browse the repository at this point in the history
  • Loading branch information
himdel committed Aug 2, 2023
1 parent 5fb23e0 commit ab12c39
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/api/response-types/legacy-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class LegacyRoleListType {
commit: string;
name: string;
description: string;
download_count: number;
summary_fields: {
dependencies: string[];
namespace: {
Expand Down Expand Up @@ -77,6 +78,7 @@ export class LegacyRoleDetailType {
commit: string;
name: string;
description: string;
download_count: number;
summary_fields: {
dependencies: string[];
namespace: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export { WizardModal } from './patternfly-wrappers/wizard-modal';
export { PreviewRoles } from './rbac/preview-roles';
export { SelectRoles } from './rbac/select-roles';
export { SelectGroup } from './rbac/select-group';

export { DownloadCount } from './shared/download-count';
export { LegacyRoleListItem } from './legacy-role-list/legacy-role-item';
export { LegacyNamespaceListItem } from './legacy-namespace-list/legacy-namespace-item';
export { WisdomModal } from './wisdom-modal/wisdom-modal';
Expand Down
5 changes: 4 additions & 1 deletion src/components/legacy-role-list/legacy-role-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import React from 'react';
import { Link } from 'react-router-dom';
import { LegacyRoleDetailType } from 'src/api/response-types/legacy-role';
import { DateComponent, Logo, Tag } from 'src/components';
import { DateComponent, DownloadCount, Logo, Tag } from 'src/components';
import { Paths, formatPath } from 'src/paths';
import { chipGroupProps } from 'src/utilities';
import './legacy-role-item.scss';
Expand Down Expand Up @@ -105,6 +105,9 @@ export class LegacyRoleListItem extends React.Component<LegacyRoleProps> {
</Trans>
</div>
<div className='hub-entry'>{release_name}</div>
<div className='hub-entry'>
<DownloadCount item={role} />
</div>
</DataListCell>,
);

Expand Down
24 changes: 24 additions & 0 deletions src/components/shared/download-count.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Trans } from '@lingui/macro';
import { DownloadIcon } from '@patternfly/react-icons';
import React from 'react';
import { language } from 'src/l10n';

interface IProps {
item?: { download_count?: number };
}

export const DownloadCount = ({ item }) => {
if (!item?.download_count) {
return null;
}

const downloadCount = new Intl.NumberFormat(language).format(
item.download_count,
);

return (
<>
<DownloadIcon /> <Trans>{downloadCount} Downloads</Trans>
</>
);
};
4 changes: 4 additions & 0 deletions src/containers/legacy-roles/legacy-role.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Breadcrumbs,
ClipboardCopy,
DateComponent,
DownloadCount,
LoadingPageWithHeader,
Logo,
Main,
Expand Down Expand Up @@ -315,6 +316,9 @@ class LegacyRole extends React.Component<RouteProps, IProps> {
Github Repository <ExternalLinkAltIcon />
</a>
</div>
<div className='hub-entry'>
<DownloadCount item={role} />
</div>
</DataListCell>,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/l10n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const overrideLanguage =
window.localStorage.override_l10n &&
availableLanguages.includes(window.localStorage.override_l10n) &&
window.localStorage.override_l10n;
const language = overrideLanguage || userLanguage || 'en';
export const language = overrideLanguage || userLanguage || 'en';
const pseudolocalization = window.localStorage.test_l10n === 'true';

if (overrideLanguage) {
Expand Down

0 comments on commit ab12c39

Please sign in to comment.