-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(archive-viewer): Add breadcrumbs (#1119)
- Loading branch information
1 parent
b8c60e9
commit d09738f
Showing
8 changed files
with
200 additions
and
40 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
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,6 @@ | ||
.bp-ArchiveExplorer { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
height: 100%; | ||
} |
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,58 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Breadcrumb from 'box-ui-elements/es/components/breadcrumb'; | ||
import PlainButton from 'box-ui-elements/es/components/plain-button/PlainButton'; | ||
import { VIEWS } from './constants'; | ||
import './Breadcrumbs.scss'; | ||
|
||
class Breadcrumbs extends React.PureComponent { | ||
static propTypes = { | ||
fullPath: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
view: PropTypes.string.isRequired, | ||
}; | ||
|
||
/** | ||
* Split full path string to path items | ||
* | ||
* @param {string} fullPath - Full path for current folder | ||
* @return {Array<Object>} path items including name and path string | ||
*/ | ||
getPathItems = fullPath => { | ||
const pathNames = fullPath.split('/').slice(0, -1); | ||
// join path names from root to current index to get absolute path | ||
const getAbsolutePath = index => pathNames.slice(0, index + 1).join('/'); | ||
|
||
return pathNames.map((name, index) => ({ | ||
name, | ||
path: `${getAbsolutePath(index)}/`, | ||
})); | ||
}; | ||
|
||
/** | ||
* render breadcrumbs | ||
* | ||
* @return {jsx} Breadcrumbs | ||
*/ | ||
render() { | ||
const { fullPath, onClick, view } = this.props; | ||
|
||
return ( | ||
<div className="bp-Breadcrumbs"> | ||
<Breadcrumb> | ||
{view === VIEWS.VIEW_SEARCH ? ( | ||
<span>{__('search_results')}</span> | ||
) : ( | ||
this.getPathItems(fullPath).map(pathItem => ( | ||
<PlainButton key={pathItem.path} onClick={() => onClick(pathItem.path)} type="button"> | ||
{pathItem.name} | ||
</PlainButton> | ||
)) | ||
)} | ||
</Breadcrumb> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Breadcrumbs; |
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,11 @@ | ||
@import '~box-ui-elements/es/styles/variables'; | ||
|
||
.bp-Breadcrumbs { | ||
display: flex; | ||
flex: 0 0 50px; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 0 20px 0 25px; | ||
border-bottom: 1px solid $bdl-gray-10; | ||
box-shadow: 0 4px 6px -2px $transparent-black; | ||
} |
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
57 changes: 57 additions & 0 deletions
57
src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js
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,57 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import Breadcrumbs from '../Breadcrumbs'; | ||
import { VIEWS } from '../constants'; | ||
|
||
const sandbox = sinon.sandbox.create(); | ||
let fullPath; | ||
let onClick; | ||
let view; | ||
|
||
describe('lib/viewers/archive/Breadcrumbs', () => { | ||
beforeEach(() => { | ||
fullPath = 'test/subfolder/'; | ||
onClick = sandbox.stub(); | ||
view = VIEWS.VIEW_FOLDER; | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.verifyAndRestore(); | ||
}); | ||
|
||
describe('render()', () => { | ||
it('should render correct components', () => { | ||
const component = shallow(<Breadcrumbs fullPath={fullPath} onClick={onClick} view={view} />); | ||
|
||
expect(component.find('.bp-Breadcrumbs').length).to.equal(1); | ||
expect(component.find('InjectIntl(Breadcrumb)').length).to.equal(1); | ||
expect(component.find('PlainButton').length).to.equal(2); | ||
}); | ||
|
||
it('should render search result if view is search', () => { | ||
const component = shallow(<Breadcrumbs fullPath={fullPath} onClick={onClick} view={VIEWS.VIEW_SEARCH} />); | ||
|
||
expect(component.find('span').text()).to.equal(__('search_results')); | ||
}); | ||
}); | ||
|
||
describe('getPathItems()', () => { | ||
it('should return correct path items', () => { | ||
const component = shallow(<Breadcrumbs fullPath={fullPath} onClick={onClick} view={view} />); | ||
|
||
const pathItems = component.instance().getPathItems(fullPath); | ||
|
||
expect(pathItems).to.eql([ | ||
{ | ||
name: 'test', | ||
path: 'test/', | ||
}, | ||
{ | ||
name: 'subfolder', | ||
path: 'test/subfolder/', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
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