-
Notifications
You must be signed in to change notification settings - Fork 147
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
Create TableHeaderBullets component #397
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
amundsen_application/static/js/components/TableDetail/TableHeaderBullets/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 { getDisplayNameByResource, getDatabaseDisplayName } from 'config/config-utils'; | ||
|
||
import { ResourceType } from 'interfaces/Resources'; | ||
|
||
export interface TableHeaderBulletsProps { | ||
cluster: string; | ||
database: string; | ||
} | ||
|
||
const TableHeaderBullets: React.SFC<TableHeaderBulletsProps> = ({ cluster, database }) => { | ||
return ( | ||
<ul className="header-bullets"> | ||
<li>{ getDisplayNameByResource(ResourceType.table)}</li> | ||
<li>{ getDatabaseDisplayName(database) }</li> | ||
<li>{ cluster }</li> | ||
</ul> | ||
); | ||
}; | ||
|
||
TableHeaderBullets.defaultProps = { | ||
cluster: '', | ||
database: '', | ||
}; | ||
|
||
export default TableHeaderBullets; |
61 changes: 61 additions & 0 deletions
61
...dsen_application/static/js/components/TableDetail/TableHeaderBullets/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,61 @@ | ||
import * as React from 'react'; | ||
|
||
import { mocked } from 'ts-jest/utils'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import TableHeaderBullets, { TableHeaderBulletsProps } from '../'; | ||
|
||
import { ResourceType } from 'interfaces/Resources'; | ||
|
||
const MOCK_RESOURCE_DISPLAY_NAME = 'Test'; | ||
const MOCK_DB_DISPLAY_NAME = 'AlsoTest'; | ||
|
||
jest.mock('config/config-utils', () => ({ | ||
getDisplayNameByResource: jest.fn(), | ||
getDatabaseDisplayName: jest.fn() | ||
})); | ||
import { getDatabaseDisplayName, getDisplayNameByResource } from 'config/config-utils'; | ||
|
||
describe('TableHeaderBullets', () => { | ||
const setup = (propOverrides?: Partial<TableHeaderBulletsProps>) => { | ||
const props: TableHeaderBulletsProps = { | ||
database: 'hive', | ||
cluster: 'main', | ||
...propOverrides | ||
}; | ||
const wrapper = shallow(<TableHeaderBullets {...props} />); | ||
return { props, wrapper }; | ||
}; | ||
|
||
describe('render', () => { | ||
let props: TableHeaderBulletsProps; | ||
let wrapper; | ||
let listElement; | ||
beforeAll(() => { | ||
mocked(getDatabaseDisplayName).mockImplementation(() => MOCK_DB_DISPLAY_NAME); | ||
mocked(getDisplayNameByResource).mockImplementation(() => MOCK_RESOURCE_DISPLAY_NAME); | ||
const setupResult = setup(); | ||
props = setupResult.props; | ||
wrapper = setupResult.wrapper; | ||
listElement = wrapper.find('ul'); | ||
}); | ||
|
||
it('renders a list with correct class', () => { | ||
expect(listElement.props().className).toEqual('header-bullets'); | ||
}); | ||
|
||
it('renders a list with resource display name', () => { | ||
expect(getDisplayNameByResource).toHaveBeenCalledWith(ResourceType.table); | ||
expect(listElement.find('li').at(0).text()).toEqual(MOCK_RESOURCE_DISPLAY_NAME); | ||
}); | ||
|
||
it('renders a list with database display name', () => { | ||
expect(getDatabaseDisplayName).toHaveBeenCalledWith(props.database); | ||
expect(listElement.find('li').at(1).text()).toEqual(MOCK_DB_DISPLAY_NAME); | ||
}); | ||
|
||
it('renders a list with cluster', () => { | ||
expect(listElement.find('li').at(2).text()).toEqual(props.cluster); | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought about overwriting the TableHeaderBullets -- If we wanted to add another field from the table metadata, we'd have to overwrite the component file and the template that uses the component. On the other hand, I can see how extracting specific fields and passing it to the component is cleaner and easier to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that. As our use cases for overwriting components internally expose themselves, I will lean towards whatever makes maintenance the least painful.