-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b7aa476
commit 283d06f
Showing
85 changed files
with
4,347 additions
and
493 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,144 @@ | ||
/* | ||
* Copyright 2018, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const React = require('react'); | ||
const {Row, Col, Nav, NavItem, Glyphicon} = require('react-bootstrap'); | ||
const DockablePanel = require('../misc/panels/DockablePanel'); | ||
const Toolbar = require('../misc/toolbar/Toolbar'); | ||
const tooltip = require('../misc/enhancers/tooltip'); | ||
const NavItemT = tooltip(NavItem); | ||
const ResizableModal = require('../misc/ResizableModal'); | ||
const Portal = require('../misc/Portal'); | ||
const {head, isObject} = require('lodash'); | ||
const Message = require('../I18N/Message'); | ||
|
||
/** | ||
* Component for rendering TOC Settings as tabs inside a Dockable contanier | ||
* @memberof components.TOC | ||
* @name TOCItemsSettings | ||
* @class | ||
* @prop {boolean} dock switch between Dockable Panel and Resizable Modal, default true (DockPanel) | ||
* @prop {string} activeTab current active tab, should match the tab id | ||
* @prop {function} getTabs must return an array of object representing the tabs, eg (props) => [{ id: 'general', Component: MyGeneralComponent}] | ||
* @prop {string} className additional calss name | ||
*/ | ||
|
||
module.exports = props => { | ||
const { | ||
className = '', | ||
activeTab = 'general', | ||
currentLocale = 'en-US', | ||
width = 500, | ||
groups = [], | ||
element = {}, | ||
settings = {}, | ||
getTabs = () => [], | ||
onSave = () => {}, | ||
onClose = () => {}, | ||
onHideSettings = () => {}, | ||
onSetTab = () => {}, | ||
onUpdateParams = () => {}, | ||
onRetrieveLayerData = () => {}, | ||
onShowAlertModal = () => {}, | ||
realtimeUpdate = true, | ||
alertModal = false, | ||
dockStyle = {}, | ||
dock = true, | ||
showFullscreen, | ||
draggable, | ||
position = 'left' | ||
} = props; | ||
|
||
const tabs = getTabs(props); | ||
|
||
return ( | ||
<div> | ||
<DockablePanel | ||
open={settings.expanded} | ||
glyph="wrench" | ||
title={element.title && isObject(element.title) && (element.title[currentLocale] || element.title.default) || element.title || ''} | ||
className={className} | ||
onClose={onClose ? () => { onClose(); } : onHideSettings} | ||
size={width} | ||
style={dockStyle} | ||
showFullscreen={showFullscreen} | ||
dock={dock} | ||
draggable={draggable} | ||
position={position} | ||
header={[ | ||
<Row key="ms-toc-settings-toolbar" className="text-center"> | ||
<Col xs={12}> | ||
<Toolbar | ||
btnDefaultProps={{ bsStyle: 'primary', className: 'square-button-md' }} | ||
buttons={[{ | ||
glyph: 'floppy-disk', | ||
tooltipId: 'save', | ||
visible: !!onSave, | ||
onClick: onSave | ||
}, | ||
...(head(tabs.filter(tab => tab.id === activeTab && tab.toolbar).map(tab => tab.toolbar)) || [])]}/> | ||
</Col> | ||
</Row>, | ||
...(tabs.length > 1 ? [<Row key="ms-toc-settings-navbar" className="ms-row-tab"> | ||
<Col xs={12}> | ||
<Nav bsStyle="tabs" activeKey={activeTab} justified> | ||
{tabs.map(tab => | ||
<NavItemT | ||
key={'ms-tab-settings-' + tab.id} | ||
tooltip={<Message msgId={tab.tooltipId}/> } | ||
eventKey={tab.id} | ||
onClick={() => onSetTab(tab.id)}> | ||
<Glyphicon glyph={tab.glyph}/> | ||
</NavItemT> | ||
)} | ||
</Nav> | ||
</Col> | ||
</Row>] : []) | ||
]}> | ||
{tabs.filter(tab => tab.id && tab.id === activeTab).filter(tab => tab.Component).map(tab => ( | ||
<tab.Component | ||
{...props} | ||
key={'ms-tab-settings-body-' + tab.id} | ||
containerWidth={width} | ||
element={element} | ||
groups={groups} | ||
nodeType={settings.nodeType} | ||
settings={settings} | ||
retrieveLayerData={onRetrieveLayerData} | ||
onChange={(key, value) => onUpdateParams({[key]: value}, realtimeUpdate)}/> | ||
))} | ||
</DockablePanel> | ||
<Portal> | ||
<ResizableModal | ||
fade | ||
show={alertModal} | ||
title={<Message msgId="layerProperties.changedSettings"/>} | ||
size="xs" | ||
onClose={() => onShowAlertModal(false)} | ||
buttons={[ | ||
{ | ||
bsStyle: 'primary', | ||
text: <Message msgId="close"/>, | ||
onClick: () => onClose(true) | ||
}, | ||
{ | ||
bsStyle: 'primary', | ||
text: <Message msgId="save"/>, | ||
onClick: onSave | ||
} | ||
]}> | ||
<div className="ms-alert"> | ||
<div className="ms-alert-center"> | ||
<Message msgId="layerProperties.changedSettingsAlert"/> | ||
</div> | ||
</div> | ||
</ResizableModal> | ||
</Portal> | ||
</div> | ||
); | ||
}; |
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
77 changes: 77 additions & 0 deletions
77
web/client/components/TOC/__tests__/TOCItemsSettings-test.jsx
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,77 @@ | ||
/* | ||
* Copyright 2018, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const React = require('react'); | ||
const expect = require('expect'); | ||
const ReactDOM = require('react-dom'); | ||
const TOCItemsSettings = require('../TOCItemsSettings'); | ||
|
||
|
||
describe("test TOCItemsSettings", () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('test with tabs', () => { | ||
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => [ | ||
{ | ||
id: 'general', | ||
titleId: 'layerProperties.general', | ||
tooltipId: 'layerProperties.general', | ||
glyph: 'wrench', | ||
Component: () => <div id="test-general-body"></div> | ||
}, | ||
{ | ||
id: 'display', | ||
titleId: 'layerProperties.display', | ||
tooltipId: 'layerProperties.display', | ||
glyph: 'eye-open', | ||
Component: () => <div id="test-display-body"></div> | ||
} | ||
]}/>, document.getElementById("container")); | ||
const navBar = document.getElementsByClassName('nav-justified')[0]; | ||
expect(navBar.children.length).toBe(2); | ||
const testGeneralBody = document.getElementById('test-general-body'); | ||
expect(testGeneralBody).toExist(); | ||
const testDisplayBody = document.getElementById('test-display-body'); | ||
expect(testDisplayBody).toNotExist(); | ||
}); | ||
|
||
it('test without tabs', () => { | ||
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => []}/>, document.getElementById("container")); | ||
const navBar = document.getElementsByClassName('nav-justified')[0]; | ||
expect(navBar).toNotExist(); | ||
}); | ||
|
||
it('test with tabs length 1', () => { | ||
ReactDOM.render(<TOCItemsSettings activeTab="general" getTabs={() => [{ | ||
id: 'general', | ||
titleId: 'layerProperties.general', | ||
tooltipId: 'layerProperties.general', | ||
glyph: 'wrench', | ||
Component: () => <div id="test-general-body"></div> | ||
}]}/>, document.getElementById("container")); | ||
const navBar = document.getElementsByClassName('nav-justified')[0]; | ||
expect(navBar).toNotExist(); | ||
const testGeneralBody = document.getElementById('test-general-body'); | ||
expect(testGeneralBody).toExist(); | ||
}); | ||
|
||
it('test alert modal', () => { | ||
ReactDOM.render(<TOCItemsSettings alertModal/>, document.getElementById("container")); | ||
const alertModal = document.getElementsByClassName('ms-resizable-modal'); | ||
expect(alertModal.length).toBe(1); | ||
}); | ||
|
||
}); |
Oops, something went wrong.