-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: List available badges on Home & Browse Pages #1535
Signed-off-by: Mariusz Górski <[email protected]>
- Loading branch information
Showing
32 changed files
with
720 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
frontend/amundsen_application/static/js/components/Badges/BadgeBrowseList/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright Contributors to the Amundsen project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export const AVAILABLE_BADGES_TITLE = 'Available Badges'; | ||
export const BROWSE_BADGES_TITLE = 'Browse Badges'; |
72 changes: 72 additions & 0 deletions
72
frontend/amundsen_application/static/js/components/Badges/BadgeBrowseList/index.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright Contributors to the Amundsen project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { BadgeStyle } from 'config/config-types'; | ||
import * as ConfigUtils from 'config/config-utils'; | ||
import { Badge } from 'interfaces/Badges'; | ||
|
||
import * as Analytics from 'utils/analytics'; | ||
|
||
import BadgeBrowseList, { BadgeBrowseListProps } from '.'; | ||
|
||
const badges: Badge[] = [ | ||
{ | ||
badge_name: 'beta', | ||
category: 'table_status', | ||
}, | ||
{ | ||
badge_name: 'Core Concepts', | ||
category: 'coco', | ||
}, | ||
]; | ||
|
||
const setup = (propOverrides?: Partial<BadgeBrowseListProps>) => { | ||
const props = { | ||
badges, | ||
...propOverrides, | ||
}; | ||
const wrapper = shallow<typeof BadgeBrowseList>( | ||
<BadgeBrowseList {...props} /> | ||
).dive(); | ||
return { props, wrapper }; | ||
}; | ||
|
||
const logClickSpy = jest.spyOn(Analytics, 'logClick'); | ||
logClickSpy.mockImplementation(() => null); | ||
|
||
describe('BadgeBrowseList', () => { | ||
const getBadgeConfigSpy = jest.spyOn(ConfigUtils, 'getBadgeConfig'); | ||
getBadgeConfigSpy.mockImplementation((badgeName: string) => ({ | ||
displayName: badgeName + ' test name', | ||
style: BadgeStyle.PRIMARY, | ||
})); | ||
|
||
describe('render', () => { | ||
describe('when BadgeBrowseList called with shortBadgesList={false}', () => { | ||
it('renders component with browse header', () => { | ||
const { wrapper } = setup({ shortBadgesList: false }); | ||
const expected = 1; | ||
const actualHeaders = wrapper.find('.header-title').length; | ||
const actualHrs = wrapper.find('.header-hr').length; | ||
|
||
expect(actualHeaders).toEqual(expected); | ||
expect(actualHrs).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('when BadgeBrowseList called with shortBadgesList={true}', () => { | ||
it('renders component without browse header', () => { | ||
const { wrapper } = setup({ shortBadgesList: true }); | ||
const expected = 0; | ||
const actualHeaders = wrapper.find('.header-title').length; | ||
const actualHrs = wrapper.find('.header-hr').length; | ||
|
||
expect(actualHeaders).toEqual(expected); | ||
expect(actualHrs).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
frontend/amundsen_application/static/js/components/Badges/BadgeBrowseList/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Contributors to the Amundsen project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as React from 'react'; | ||
import { Badge } from 'interfaces/Badges'; | ||
import BadgeList from 'features/BadgeList'; | ||
import './styles.scss'; | ||
import { | ||
AVAILABLE_BADGES_TITLE, | ||
BROWSE_BADGES_TITLE, | ||
} from 'components/Badges/BadgeBrowseList/constants'; | ||
import { isShowBadgesInHomeEnabled } from 'config/config-utils'; | ||
|
||
export interface BadgeBrowseListProps { | ||
badges: Badge[]; | ||
shortBadgesList?: boolean; | ||
} | ||
|
||
const BadgeBrowseListShort: React.FC<BadgeBrowseListProps> = ({ | ||
badges, | ||
}: BadgeBrowseListProps) => { | ||
const hasBadges = badges.length > 0; | ||
if (hasBadges && isShowBadgesInHomeEnabled()) { | ||
return ( | ||
<article className="badges-browse-section badges-browse-section-short"> | ||
<h2 className="available-badges-header-title"> | ||
{AVAILABLE_BADGES_TITLE} | ||
</h2> | ||
<BadgeList badges={badges} /> | ||
</article> | ||
); | ||
} | ||
// do not show component at all if there are no badges to be shown | ||
return null; | ||
}; | ||
|
||
const BadgeBrowseListLong: React.FC<BadgeBrowseListProps> = ({ | ||
badges, | ||
}: BadgeBrowseListProps) => ( | ||
<article className="badges-browse-section badges-browse-section-long"> | ||
<h1 className="header-title">{BROWSE_BADGES_TITLE}</h1> | ||
<hr className="header-hr" /> | ||
<label className="section-label"> | ||
<span className="section-title title-2">{AVAILABLE_BADGES_TITLE}</span> | ||
</label> | ||
<BadgeList badges={badges} /> | ||
</article> | ||
); | ||
|
||
const BadgeBrowseList: React.FC<BadgeBrowseListProps> = ({ | ||
badges, | ||
shortBadgesList, | ||
}: BadgeBrowseListProps) => { | ||
if (shortBadgesList) { | ||
return <BadgeBrowseListShort badges={badges} />; | ||
} | ||
|
||
return <BadgeBrowseListLong badges={badges} />; | ||
}; | ||
|
||
export default BadgeBrowseList; |
44 changes: 44 additions & 0 deletions
44
frontend/amundsen_application/static/js/components/Badges/BadgeBrowseList/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright Contributors to the Amundsen project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
@import 'variables'; | ||
@import 'typography'; | ||
|
||
.badges-browse-section { | ||
margin: 32px 0; | ||
|
||
.badge-list { | ||
display: block; | ||
font-weight: $font-weight-body-regular; | ||
margin-top: $spacer-3; | ||
margin-bottom: $spacer-2; | ||
} | ||
} | ||
|
||
.badges-browse-section-short { | ||
.available-badges-header-title { | ||
@extend %text-title-w1; | ||
|
||
margin-bottom: $spacer-1; | ||
} | ||
} | ||
|
||
|
||
.badges-browse-section-long { | ||
.header-hr { | ||
border: 2px solid $brand-color-4; | ||
} | ||
|
||
.header-title { | ||
@extend %text-title-w1; | ||
|
||
margin-bottom: $spacer-2; | ||
} | ||
|
||
.section-label { | ||
display: block; | ||
font-weight: $font-weight-body-regular; | ||
margin-top: $spacer-3; | ||
margin-bottom: $spacer-2; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.