mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Better way: just use options' fragmentName as mutationFragment
This commit is contained in:
parent
f9893aa615
commit
e3ba347f80
2 changed files with 20 additions and 17 deletions
|
@ -81,8 +81,6 @@ Datatable.propTypes = {
|
||||||
showEdit: PropTypes.bool,
|
showEdit: PropTypes.bool,
|
||||||
showNew: PropTypes.bool,
|
showNew: PropTypes.bool,
|
||||||
showSearch: PropTypes.bool,
|
showSearch: PropTypes.bool,
|
||||||
newFragmentName: PropTypes.string,
|
|
||||||
editFragmentName: PropTypes.string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Datatable.defaultProps = {
|
Datatable.defaultProps = {
|
||||||
|
@ -98,11 +96,16 @@ registerComponent('Datatable', Datatable, withCurrentUser);
|
||||||
DatatableAbove Component
|
DatatableAbove Component
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const DatatableAbove = ({ showSearch, showNew, canInsert, collection, value, updateQuery, newFragmentName }) =>
|
const DatatableAbove = (props) => {
|
||||||
|
const { showSearch, showNew, canInsert, value, updateQuery } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
<div className="datatable-above">
|
<div className="datatable-above">
|
||||||
{showSearch && <input className="datatable-search form-control" placeholder="Search…" type="text" name="datatableSearchQuery" value={value} onChange={updateQuery} />}
|
{showSearch && <input className="datatable-search form-control" placeholder="Search…" type="text" name="datatableSearchQuery" value={value} onChange={updateQuery} />}
|
||||||
{showNew && canInsert && <Components.NewButton newFragmentName={newFragmentName} collection={collection}/>}
|
{showNew && canInsert && <Components.NewButton {...props}/>}
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
registerComponent('DatatableAbove', DatatableAbove);
|
registerComponent('DatatableAbove', DatatableAbove);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -150,6 +153,7 @@ DatatableContents Component
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DatatableContents = (props) => {
|
const DatatableContents = (props) => {
|
||||||
|
|
||||||
const {collection, columns, results, loading, loadMore, count, totalCount, networkStatus, showEdit, currentUser, emptyState} = props;
|
const {collection, columns, results, loading, loadMore, count, totalCount, networkStatus, showEdit, currentUser, emptyState} = props;
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
@ -192,8 +196,9 @@ registerComponent('DatatableContents', DatatableContents);
|
||||||
DatatableRow Component
|
DatatableRow Component
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const DatatableRow = ({ collection, columns, document, showEdit, editFragmentName, currentUser }, { intl }) => {
|
const DatatableRow = (props, { intl }) => {
|
||||||
|
|
||||||
|
const { collection, columns, document, showEdit, editFragmentName, currentUser } = props;
|
||||||
const canEdit = collection && collection.options && collection.options.mutations && collection.options.mutations.edit && collection.options.mutations.edit.check(currentUser, document);
|
const canEdit = collection && collection.options && collection.options.mutations && collection.options.mutations.edit && collection.options.mutations.edit.check(currentUser, document);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -207,7 +212,7 @@ const DatatableRow = ({ collection, columns, document, showEdit, editFragmentNam
|
||||||
label={intl.formatMessage({id: 'datatable.edit'})}
|
label={intl.formatMessage({id: 'datatable.edit'})}
|
||||||
component={<Button bsStyle="primary"><FormattedMessage id="datatable.edit" /></Button>}
|
component={<Button bsStyle="primary"><FormattedMessage id="datatable.edit" /></Button>}
|
||||||
>
|
>
|
||||||
<Components.DatatableEditForm editFragmentName={editFragmentName} collection={collection} document={document} />
|
<Components.DatatableEditForm {...props} />
|
||||||
</Components.ModalTrigger>
|
</Components.ModalTrigger>
|
||||||
</td>
|
</td>
|
||||||
: null}
|
: null}
|
||||||
|
@ -225,7 +230,7 @@ DatatableRow.contextTypes = {
|
||||||
DatatableEditForm Component
|
DatatableEditForm Component
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const DatatableEditForm = ({ collection, document, closeModal, editFragmentName, ...properties }) =>
|
const DatatableEditForm = ({ collection, document, closeModal, options, ...properties }) =>
|
||||||
<Components.SmartForm
|
<Components.SmartForm
|
||||||
collection={collection}
|
collection={collection}
|
||||||
documentId={document._id}
|
documentId={document._id}
|
||||||
|
@ -236,8 +241,7 @@ const DatatableEditForm = ({ collection, document, closeModal, editFragmentName,
|
||||||
removeSuccessCallback={document => {
|
removeSuccessCallback={document => {
|
||||||
closeModal();
|
closeModal();
|
||||||
}}
|
}}
|
||||||
mutationFragmentName={editFragmentName}
|
mutationFragmentName={options.fragmentName}
|
||||||
{...properties}
|
|
||||||
/>
|
/>
|
||||||
registerComponent('DatatableEditForm', DatatableEditForm);
|
registerComponent('DatatableEditForm', DatatableEditForm);
|
||||||
|
|
||||||
|
@ -246,14 +250,13 @@ registerComponent('DatatableEditForm', DatatableEditForm);
|
||||||
DatatableNewForm Component
|
DatatableNewForm Component
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const DatatableNewForm = ({ collection, closeModal, newFragmentName, ...properties }) =>
|
const DatatableNewForm = ({ collection, closeModal, options, ...props }) =>
|
||||||
<Components.SmartForm
|
<Components.SmartForm
|
||||||
collection={collection}
|
collection={collection}
|
||||||
successCallback={document => {
|
successCallback={document => {
|
||||||
closeModal();
|
closeModal();
|
||||||
}}
|
}}
|
||||||
mutationFragmentName={newFragmentName}
|
mutationFragmentName={options.fragmentName}
|
||||||
{...properties}
|
|
||||||
/>
|
/>
|
||||||
registerComponent('DatatableNewForm', DatatableNewForm);
|
registerComponent('DatatableNewForm', DatatableNewForm);
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ import React from 'react';
|
||||||
import Button from 'react-bootstrap/lib/Button';
|
import Button from 'react-bootstrap/lib/Button';
|
||||||
import { FormattedMessage, intlShape } from 'meteor/vulcan:i18n';
|
import { FormattedMessage, intlShape } from 'meteor/vulcan:i18n';
|
||||||
|
|
||||||
const NewButton = ({ collection, bsStyle = 'primary', ...properties }, {intl}) =>
|
const NewButton = ({ collection, bsStyle = 'primary', ...props }, {intl}) =>
|
||||||
<Components.ModalTrigger
|
<Components.ModalTrigger
|
||||||
label={intl.formatMessage({id: 'datatable.new'})}
|
label={intl.formatMessage({id: 'datatable.new'})}
|
||||||
component={<Button bsStyle={bsStyle}><FormattedMessage id="datatable.new" /></Button>}
|
component={<Button bsStyle={bsStyle}><FormattedMessage id="datatable.new" /></Button>}
|
||||||
>
|
>
|
||||||
<Components.DatatableNewForm collection={collection} {...properties} />
|
<Components.DatatableNewForm collection={collection} {...props} />
|
||||||
</Components.ModalTrigger>
|
</Components.ModalTrigger>
|
||||||
|
|
||||||
NewButton.contextTypes = {
|
NewButton.contextTypes = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue