-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
1 parent
545f687
commit 0dee3b1
Showing
6 changed files
with
239 additions
and
1 deletion.
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
147 changes: 147 additions & 0 deletions
147
src/components/manage/Contents/ContentsPropertiesModal.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,147 @@ | ||
/** | ||
* Contents properties modal. | ||
* @module components/manage/Contents/ContentsPropertiesModal | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import { isEmpty, map } from 'lodash'; | ||
|
||
import { editContent } from '../../../actions'; | ||
import { ModalForm } from '../../../components'; | ||
|
||
/** | ||
* ContentsPropertiesModal class. | ||
* @class ContentsPropertiesModal | ||
* @extends Component | ||
*/ | ||
@connect( | ||
state => ({ | ||
request: state.content.edit, | ||
}), | ||
dispatch => bindActionCreators({ editContent }, dispatch), | ||
) | ||
export default class ContentsPropertiesModal extends Component { | ||
/** | ||
* Property types. | ||
* @property {Object} propTypes Property types. | ||
* @static | ||
*/ | ||
static propTypes = { | ||
editContent: PropTypes.func.isRequired, | ||
items: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
request: PropTypes.shape({ | ||
loading: PropTypes.bool, | ||
loaded: PropTypes.bool, | ||
}).isRequired, | ||
open: PropTypes.bool.isRequired, | ||
onOk: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
}; | ||
|
||
/** | ||
* Constructor | ||
* @method constructor | ||
* @param {Object} props Component properties | ||
* @constructs ContentsUploadModal | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
this.onSubmit = this.onSubmit.bind(this); | ||
} | ||
|
||
/** | ||
* Component will receive props | ||
* @method componentWillReceiveProps | ||
* @param {Object} nextProps Next properties | ||
* @returns {undefined} | ||
*/ | ||
componentWillReceiveProps(nextProps) { | ||
if (this.props.request.loading && nextProps.request.loaded) { | ||
this.props.onOk(); | ||
} | ||
} | ||
|
||
/** | ||
* Submit handler | ||
* @method onSubmit | ||
* @param {Object} data Form data | ||
* @returns {undefined} | ||
*/ | ||
onSubmit(data) { | ||
if (isEmpty(data)) { | ||
this.props.onOk(); | ||
} else { | ||
this.props.editContent( | ||
this.props.items, | ||
map(this.props.items, () => data), | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Render method. | ||
* @method render | ||
* @returns {string} Markup for the component. | ||
*/ | ||
render() { | ||
return ( | ||
this.props.open && | ||
<ModalForm | ||
open={this.props.open} | ||
onSubmit={this.onSubmit} | ||
onCancel={this.props.onCancel} | ||
title="Properties" | ||
schema={{ | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: [ | ||
'effective', | ||
'expires', | ||
'rights', | ||
'creators', | ||
'exclude_from_nav', | ||
], | ||
}, | ||
], | ||
properties: { | ||
effective: { | ||
description: 'If this date is in the future, the content will not show up in listings and searches until this date.', | ||
title: 'Publishing Date', | ||
type: 'string', | ||
widget: 'datetime', | ||
}, | ||
expires: { | ||
description: 'When this date is reached, the content will nolonger be visible in listings and searches.', | ||
title: 'Expiration Date', | ||
type: 'string', | ||
widget: 'datetime', | ||
}, | ||
rights: { | ||
description: 'Copyright statement or other rights information on this item.', | ||
title: 'Rights', | ||
type: 'string', | ||
widget: 'textarea', | ||
}, | ||
creators: { | ||
description: 'Persons responsible for creating the content of this item. Please enter a list of user names, one per line. The principal creator should come first.', | ||
title: 'Creators', | ||
type: 'array', | ||
}, | ||
exclude_from_nav: { | ||
default: false, | ||
description: 'If selected, this item will not appear in the navigation tree', | ||
title: 'Exclude from navigation', | ||
type: 'boolean', | ||
}, | ||
}, | ||
required: [], | ||
}} | ||
/> | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/components/manage/Contents/ContentsPropertiesModal.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,35 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import configureStore from 'redux-mock-store'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import ContentsPropertiesModal from './ContentsPropertiesModal'; | ||
|
||
const mockStore = configureStore(); | ||
|
||
jest.mock('../Form/ModalForm', () => jest.fn(() => <div id="modalform" />)); | ||
|
||
describe('ContentsPropertiesModal', () => { | ||
it('renders a contents properties modal component', () => { | ||
const store = mockStore({ | ||
content: { | ||
edit: { | ||
loading: false, | ||
loaded: true, | ||
}, | ||
}, | ||
}); | ||
const component = renderer.create( | ||
<Provider store={store}> | ||
<ContentsPropertiesModal | ||
open | ||
onOk={() => {}} | ||
onCancel={() => {}} | ||
items={['/blog']} | ||
/> | ||
</Provider>, | ||
); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/components/manage/Contents/__snapshots__/ContentsPropertiesModal.test.jsx.snap
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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ContentsPropertiesModal renders a contents properties modal component 1`] = ` | ||
<div | ||
id="modalform" | ||
/> | ||
`; |