This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from codaco/feature/sortable-panels
Sortable panels
- Loading branch information
Showing
50 changed files
with
1,093 additions
and
667 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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/renderer/components/ProtocolPanel.js → ...rer/components/workspace/ProtocolPanel.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
4 changes: 2 additions & 2 deletions
4
src/renderer/components/ServerPanel.js → ...derer/components/workspace/ServerPanel.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
4 changes: 2 additions & 2 deletions
4
...enderer/components/SessionHistoryPanel.js → ...mponents/workspace/SessionHistoryPanel.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
4 changes: 2 additions & 2 deletions
4
src/renderer/components/SessionPanel.js → ...erer/components/workspace/SessionPanel.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
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,23 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { SortableElement, SortableHandle } from 'react-sortable-hoc'; | ||
|
||
const DragHandle = SortableHandle(() => <div className="sortable__handle" />); | ||
|
||
class Panel extends PureComponent { | ||
render() { | ||
const { children } = this.props; | ||
return ( | ||
<div className="sortable"> | ||
{ children } | ||
<DragHandle /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Panel.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default SortableElement(Panel); |
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,42 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { SortableContainer } from 'react-sortable-hoc'; | ||
|
||
import SortablePanel from './SortablePanel'; | ||
|
||
/** | ||
* Render a collection of sortable workspace panels. | ||
* Note: SortableContainer must render a containing DOM element (<div>) around the | ||
* SortableElement collection. | ||
*/ | ||
class Panels extends PureComponent { | ||
render() { | ||
const { className, panels } = this.props; | ||
return ( | ||
<div className={className}> | ||
{ | ||
panels.map((panel, index) => ( | ||
<SortablePanel | ||
key={`${panel.key}-panel`} | ||
index={index} | ||
disabled={panel.props.disabled || false} | ||
> | ||
{ panel } | ||
</SortablePanel> | ||
)) | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Panels.defaultProps = { | ||
className: '', | ||
}; | ||
|
||
Panels.propTypes = { | ||
className: PropTypes.string, | ||
panels: PropTypes.arrayOf(PropTypes.node).isRequired, | ||
}; | ||
|
||
export default SortableContainer(Panels, { withRef: true }); |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...omponents/__tests__/ProtocolPanel-test.js → ...workspace/__tests__/ProtocolPanel-test.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
src/renderer/components/workspace/__tests__/SortablePanel-test.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,24 @@ | ||
/* eslint-env jest */ | ||
import React from 'react'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
import SortablePanel from '../SortablePanel'; | ||
|
||
jest.mock('react-sortable-hoc', () => ({ | ||
SortableElement: jest.fn(component => component), | ||
SortableHandle: jest.fn(component => component), | ||
})); | ||
|
||
describe('SortablePanel', () => { | ||
it('renders provided children', () => { | ||
const children = <div>mock</div>; | ||
const sortable = shallow(<SortablePanel index={0}>{children}</SortablePanel>); | ||
expect(sortable.contains(children)).toBe(true); | ||
}); | ||
|
||
it('renders a drag handle', () => { | ||
const children = <div>mock</div>; | ||
const sortable = mount(<SortablePanel index={0}>{children}</SortablePanel>); | ||
expect(sortable.find('.sortable__handle')).toHaveLength(1); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/renderer/components/workspace/__tests__/SortablePanels-test.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,26 @@ | ||
/* eslint-env jest */ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import SortablePanels from '../SortablePanels'; | ||
|
||
jest.mock('react-sortable-hoc', () => ({ | ||
SortableContainer: jest.fn(component => component), | ||
SortableElement: jest.fn(component => component), | ||
SortableHandle: jest.fn(component => component), | ||
})); | ||
|
||
describe('SortablePanel', () => { | ||
it('renders children mapped from a "panels" prop', () => { | ||
const panels = [<div>mock</div>]; | ||
const subject = shallow(<SortablePanels panels={panels} />); | ||
expect(subject.contains(panels[0])).toBe(true); | ||
}); | ||
|
||
it('defines an index for sorting', () => { | ||
const panels = [<div>mock</div>, <div>mock</div>]; | ||
const subject = shallow(<SortablePanels panels={panels} />).find('Panel'); | ||
expect(subject.get(0).props.index).toBe(0); | ||
expect(subject.get(1).props.index).toBe(1); | ||
}); | ||
}); |
Oops, something went wrong.