-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added badge support for tables - Added BadgeConfig to customize display names/styles of defined badges
- Loading branch information
Daniel
authored
Dec 12, 2019
1 parent
e7b3b6a
commit c1b50cb
Showing
15 changed files
with
182 additions
and
6 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
27 changes: 27 additions & 0 deletions
27
frontend/amundsen_application/static/js/components/common/BadgeList/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,27 @@ | ||
import * as React from 'react'; | ||
|
||
import Flag from 'components/common/Flag'; | ||
import { getBadgeConfig } from 'config/config-utils'; | ||
import { Badge } from 'interfaces/Tags'; | ||
|
||
export interface BadgeListProps { | ||
badges: Badge[]; | ||
} | ||
|
||
const BadgeList: React.SFC<BadgeListProps> = ({ badges }) => { | ||
return ( | ||
<span className="badge-list"> | ||
{ | ||
badges.map((badge, index) => { | ||
const badgeConfig = getBadgeConfig(badge.tag_name); | ||
|
||
return <Flag text={ badgeConfig.displayName } | ||
labelStyle={ badgeConfig.style } | ||
key={`badge-${index}`}/>; | ||
}) | ||
} | ||
</span> | ||
); | ||
}; | ||
|
||
export default BadgeList; |
52 changes: 52 additions & 0 deletions
52
frontend/amundsen_application/static/js/components/common/BadgeList/tests/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,52 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import BadgeList from '../' | ||
import Flag from 'components/common/Flag'; | ||
import { BadgeStyle } from 'config/config-types'; | ||
import * as ConfigUtils from 'config/config-utils'; | ||
import { Badge, TagType } from 'interfaces/Tags'; | ||
|
||
describe('BadgeList', () => { | ||
const getBadgeConfigSpy = jest.spyOn(ConfigUtils, 'getBadgeConfig'); | ||
getBadgeConfigSpy.mockImplementation((badgeName: string) => { | ||
return { | ||
displayName: badgeName + " test name", | ||
style: BadgeStyle.PRIMARY, | ||
}; | ||
}); | ||
|
||
describe('BadgeList function component', () => { | ||
const badges: Badge[] = [ | ||
{ | ||
tag_name: 'test_1', | ||
tag_type: TagType.BADGE, | ||
}, | ||
{ | ||
tag_name: 'test_3', | ||
tag_type: TagType.BADGE, | ||
}, | ||
]; | ||
|
||
const badgeList = shallow(<BadgeList badges={ badges } />); | ||
|
||
it('renders a badge-list element', () => { | ||
const container = badgeList.find('.badge-list') | ||
expect(container.exists()).toBe(true); | ||
}); | ||
|
||
it('renders a <Flag> for each badge in the input', () => { | ||
expect(badgeList.find(Flag).length).toEqual(badges.length); | ||
}); | ||
|
||
it('passes the correct props to the flag', () => { | ||
badges.forEach((badge, index) => { | ||
const flag = badgeList.childAt(index); | ||
const flagProps = flag.props(); | ||
const badgeConfig = ConfigUtils.getBadgeConfig(badge.tag_name); | ||
expect(flagProps.text).toEqual(badgeConfig.displayName); | ||
expect(flagProps.labelStyle).toEqual(badgeConfig.style); | ||
}); | ||
}); | ||
}); | ||
}); |
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
1 change: 1 addition & 0 deletions
1
frontend/amundsen_application/static/js/config/config-default.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
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
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
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
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
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