Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
10,389 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@silverstripe/eslint-config/.eslintrc'); |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
host-map.php | ||
node_modules | ||
client/dist/*/*.map |
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 @@ | ||
10 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/* global window */ | ||
import registerComponents from 'boot/registerComponents'; | ||
|
||
window.document.addEventListener('DOMContentLoaded', () => { | ||
registerComponents(); | ||
}); |
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,9 @@ | ||
import Injector from 'lib/Injector'; | ||
import SubsiteChangeAlert from 'components/SubsiteChangeAlert/SubsiteChangeAlert'; | ||
|
||
export default () => { | ||
Injector.component.registerMany({ | ||
// List your React components here so Injector is aware of them | ||
SubsiteChangeAlert | ||
}); | ||
}; |
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 @@ | ||
// Include any legacy Entwine wrappers | ||
|
||
// Include boot entrypoint | ||
require('legacy/entwine/LeftAndMain_Subsites.js'); | ||
require('legacy/entwine/SubsitesTreeDropdownField.js'); | ||
require('boot'); |
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,9 @@ | ||
// Import core variables from silverstripe/admin | ||
// @import "variables"; | ||
|
||
// Import all of your SCSS stylesheets using relative paths from "components" | ||
// e.g. @import '../components/MyComponent/MyComponent.scss'; | ||
|
||
// Import any legacy SCSS stylesheets | ||
// e.g. @import '../styles/MyComponent-ModelAdmin-legacy.scss | ||
@import "../styles/LeftAndMain_Subsites"; |
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,3 @@ | ||
# React components | ||
|
||
Put any React components in here. |
59 changes: 59 additions & 0 deletions
59
client/src/components/SubsiteChangeAlert/SubsiteChangeAlert.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,59 @@ | ||
/* global window */ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; | ||
import i18n from 'i18n'; | ||
import createEvent from 'legacy/createEvent'; | ||
|
||
class SubsiteChangeAlert extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleRevert = this.handleRevert.bind(this); | ||
} | ||
|
||
handleRevert() { | ||
const { myTabSubsiteID, myTabSubsiteName, revertCallback } = this.props; | ||
revertCallback(myTabSubsiteID, myTabSubsiteName); | ||
} | ||
|
||
getMessage() { | ||
const { otherTabSubsiteName, myTabSubsiteName } = this.props; | ||
|
||
return i18n.inject( | ||
i18n._t( | ||
'SubsiteChangeAlert.SUBSITE_CHANGED', | ||
`Your current subsite has changed to {otherTabSubsiteName}, continuing to edit this content will cause problems. | ||
To continue editing {myTabSubsiteName}, please change the active subsite back.` | ||
), | ||
{ | ||
otherTabSubsiteName, | ||
myTabSubsiteName | ||
} | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Modal isOpen={true} backdrop="static"> | ||
<ModalHeader> | ||
{i18n._t('SubsiteChangeAlert.SUBSITE_CHANGED_TITLE', 'Subsite changed')} | ||
</ModalHeader> | ||
<ModalBody>{this.getMessage()}</ModalBody> | ||
<ModalFooter> | ||
<Button color="danger" onClick={this.handleRevert}> | ||
{i18n._t(SubsiteChangeAlert.REVERT, 'Change back')} | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
SubsiteChangeAlert.propTypes = { | ||
otherTabSubsiteName: PropTypes.string, | ||
myTabSubsiteID: PropTypes.string, | ||
myTabSubsiteName: PropTypes.string, | ||
revertCallback: PropTypes.func, | ||
} | ||
|
||
export default SubsiteChangeAlert; |
44 changes: 44 additions & 0 deletions
44
client/src/components/SubsiteChangeAlert/tests/SubsiteChangeAlert-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,44 @@ | ||
/* global jest, describe, it, expect */ | ||
import React from 'react'; | ||
import SubsiteChangeAlert from '../SubsiteChangeAlert'; | ||
import { configure, shallow } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
configure({ adapter: new Adapter() }); | ||
|
||
describe('SubsiteChangeAlert', () => { | ||
describe('handleRevert', () => { | ||
it('delegates to the callback with relveant properties', () => { | ||
const callbackFn = jest.fn(); | ||
const alert = shallow( | ||
<SubsiteChangeAlert | ||
myTabSubsiteID="1" | ||
myTabSubsiteName="one" | ||
revertCallback={callbackFn} | ||
/> | ||
); | ||
alert.instance().handleRevert(); | ||
expect(callbackFn.mock.calls).toEqual([['1', 'one']]); | ||
}); | ||
}); | ||
describe('getMessage', () => { | ||
it('should show the old subsite name correctly', () => { | ||
const alert = shallow( | ||
<SubsiteChangeAlert | ||
myTabSubsiteName="oldSite" | ||
otherTabSubsiteName="newSite" | ||
/> | ||
); | ||
expect(alert.instance().getMessage()).toContain('continue editing oldSite'); | ||
}); | ||
it('should show the new active subsite name', () => { | ||
const alert = shallow( | ||
<SubsiteChangeAlert | ||
myTabSubsiteName="oldSite" | ||
otherTabSubsiteName="newSite" | ||
/> | ||
); | ||
expect(alert.instance().getMessage()).toContain('changed to newSite'); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
/* global window */ | ||
// Polyfill IE11 | ||
function createEvent(type, extraData) { | ||
const { document, Event } = window; | ||
let event; | ||
if (typeof Event === 'object') { | ||
event = document.createEvent('Event', true, true); | ||
event.initEvent(type); | ||
} else { | ||
event = new Event(type); | ||
} | ||
if (extraData) { | ||
Object.keys(extraData).forEach((key) => { | ||
event[key] = extraData[key]; | ||
}); | ||
} | ||
return event; | ||
} | ||
|
||
export default createEvent; |
Oops, something went wrong.