Skip to content

fix: Fix hideNonClickableBadges configuration #1974

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
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 @@ -9,7 +9,10 @@ import {
AVAILABLE_BADGES_TITLE,
BROWSE_BADGES_TITLE,
} from 'components/Badges/BadgeBrowseList/constants';
import { isShowBadgesInHomeEnabled } from 'config/config-utils';
import {
hideNonClickableBadges,
isShowBadgesInHomeEnabled,
} from 'config/config-utils';

export interface BadgeBrowseListProps {
badges: Badge[];
Expand All @@ -26,7 +29,10 @@ const BadgeBrowseListShort: React.FC<BadgeBrowseListProps> = ({
<h2 className="available-badges-header-title">
{AVAILABLE_BADGES_TITLE}
</h2>
<BadgeList badges={badges} />
<BadgeList
badges={badges}
hideNonClickableBadges={hideNonClickableBadges()}
/>
</article>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const setup = (propOverrides?: Partial<BadgeListProps>) => {
const props = {
badges,
onBadgeClick: () => {},
hideNonClickableBadges: false,
...propOverrides,
};
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down Expand Up @@ -113,6 +114,17 @@ describe('BadgeList', () => {

expect(actual).toEqual(expected);
});

it('renders null when hideNonClickableBadges is true', () => {
const { wrapper } = setup({
badges: columnBadges,
hideNonClickableBadges: true,
});
const expected = 2;
const actual = wrapper.find('null').length;

expect(actual).toEqual(expected);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as React from 'react';

import { getBadgeConfig, hideNonClickableBadges } from 'config/config-utils';
import { getBadgeConfig } from 'config/config-utils';
import { BadgeStyle, BadgeStyleConfig } from 'config/config-types';

import { convertText, CaseType } from 'utils/textUtils';
Expand All @@ -18,6 +18,7 @@ const COLUMN_BADGE_CATEGORY = 'column';
export interface BadgeListProps {
badges: Badge[];
onBadgeClick: (badgeText: string) => void;
hideNonClickableBadges?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to test if this works with a new test

}

export interface ActionableBadgeProps {
Expand Down Expand Up @@ -58,7 +59,7 @@ export default class BadgeList extends React.Component<BadgeListProps> {
};

render() {
const { badges } = this.props;
const { badges, hideNonClickableBadges } = this.props;
const alphabetizedBadges = badges.sort((a, b) => {
const aName = (a.badge_name ? a.badge_name : a.tag_name) || '';
const bName = (b.badge_name ? b.badge_name : b.tag_name) || '';
Expand All @@ -85,7 +86,7 @@ export default class BadgeList extends React.Component<BadgeListProps> {
if (
badge.badge_name &&
badge.category === COLUMN_BADGE_CATEGORY &&
!hideNonClickableBadges()
!hideNonClickableBadges
) {
return (
<StaticBadge
Expand Down