Improve TableDelete and fix search request

This commit is contained in:
soupette 2018-06-07 15:08:11 +02:00
parent 935727dbb0
commit a90f60ddd0
10 changed files with 48 additions and 23 deletions

View File

@ -40,14 +40,14 @@ class Search extends React.Component {
this.triggerChange('');
}
triggerChange = (value) => {
this.props.change({
triggerChange = (value) => (
this.props.changeParams({
target: {
name: 'params.q',
value,
},
});
}
})
);
render() {
const { model } = this.props;
@ -78,13 +78,13 @@ class Search extends React.Component {
}
Search.defaultProps = {
change: () => {},
changeParams: () => {},
model: '',
value: '',
};
Search.propTypes = {
change: PropTypes.func,
changeParams: PropTypes.func,
model: PropTypes.string,
value: PropTypes.string,
};

View File

@ -23,6 +23,7 @@ class Table extends React.Component {
filters={this.props.filters}
colspan={this.props.headers.length + 1}
contentType={this.props.routeParams.slug}
search={this.props.search}
/>
) :
this.props.records.map((record, key) => (
@ -40,7 +41,7 @@ class Table extends React.Component {
/>
));
const entriesToDeleteNumber = this.props.entriesToDelete.length;
return (
<table className={`table ${styles.table}`}>
<TableHeader
@ -73,6 +74,7 @@ Table.contextTypes = {
Table.defaultProps = {
entriesToDelete: [],
handleDelete: () => {},
search: '',
};
Table.propTypes = {
@ -94,6 +96,7 @@ Table.propTypes = {
redirectUrl: PropTypes.string.isRequired,
route: PropTypes.object.isRequired,
routeParams: PropTypes.object.isRequired,
search: PropTypes.string,
sort: PropTypes.string.isRequired,
};

View File

@ -7,26 +7,40 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { upperFirst } from 'lodash';
import styles from './styles.scss';
function TableEmpty({ colspan, contentType, filters }) {
const id = filters.length > 0 ? 'withFilters' : 'withoutFilter';
function TableEmpty({ colspan, contentType, filters, search }) {
let id, values;
const model = upperFirst(contentType);
if (search !== '') {
id = 'withSearch',
values = { contentType: model, search };
} else {
id = filters.length > 0 ? 'withFilters' : 'withoutFilter';
values = { contentType: model || 'entry' };
}
return (
<tr className={styles.tableEmpty}>
<td colSpan={colspan + 1}>
<FormattedMessage id={`content-manager.components.TableEmpty.${id}`} values={{ contentType: contentType || 'entry' }} />
<FormattedMessage id={`content-manager.components.TableEmpty.${id}`} values={values} />
</td>
</tr>
);
}
TableEmpty.defaultProps = {
search: '',
};
TableEmpty.propTypes = {
colspan: PropTypes.number.isRequired,
contentType: PropTypes.string.isRequired,
filters: PropTypes.array.isRequired,
search: PropTypes.string,
};
export default TableEmpty;

View File

@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { createStructuredSelector } from 'reselect';
import { capitalize, get, isUndefined, map, omit, toInteger } from 'lodash';
import { capitalize, get, isUndefined, map, toInteger } from 'lodash';
import cn from 'classnames';
// App selectors
@ -165,7 +165,7 @@ export class ListPage extends React.Component {
listPage: { filters, params },
} = this.props;
return `?${generateSearchFromParams(omit(params, 'q'))}&source=${this.getSource()}${generateSearchFromFilters(filters)}`;
return `?${generateSearchFromParams(params)}&source=${this.getSource()}${generateSearchFromFilters(filters)}`;
}
/**
@ -340,7 +340,7 @@ export class ListPage extends React.Component {
}),
},
];
return (
<div>
<div className={cn('container-fluid', styles.containerFluid)}>
@ -417,6 +417,7 @@ export class ListPage extends React.Component {
redirectUrl={this.generateRedirectURI()}
route={this.props.match}
routeParams={this.props.match.params}
search={params.q}
sort={params._sort}
/>
<PopUpWarning

View File

@ -56,9 +56,12 @@ export function* dataGet(action) {
_limit,
_start,
_sort: sortValue,
q,
source,
});
if (q !== '') {
params.q = q;
}
const response = yield [
call(request, countURL, { method: 'GET', params }),

View File

@ -5,7 +5,7 @@
*/
const generateFiltersFromSearch = search => search
.split('&')
.filter(x => !x.includes('_limit') && !x.includes('_page') && !x.includes('_sort') && !x.includes('source'))
.filter(x => !x.includes('_limit') && !x.includes('_page') && !x.includes('_sort') && !x.includes('source') && !x.includes('q'))
.reduce((acc, curr) => {
const arr = curr.split('=');
const split = arr[0].split('_');
@ -40,10 +40,12 @@ const generateSearchFromFilters = filters => {
*/
const generateSearchFromParams = params =>
Object.keys(params).reduce((acc, curr, index) => {
if (index === 0) {
acc = `${curr}=${params[curr]}`;
} else {
acc = `${acc}&${curr}=${params[curr]}`;
if (params[curr] !== '') {
if (index === 0) {
acc = `${curr}=${params[curr]}`;
} else {
acc = `${acc}&${curr}=${params[curr]}`;
}
}
return acc;
}, '');

View File

@ -42,6 +42,7 @@
"components.TableEmpty.withFilters": "There is no {contentType} with the applied filters...",
"components.TableEmpty.withoutFilter": "There is no {contentType}...",
"components.TableEmpty.withSearch": "There is no {contentType} corresponding to the search ({search})...",
"EditRelations.title": "Relational data",

View File

@ -33,6 +33,7 @@
"components.TableEmpty.withFilters": "Aucun {contentType} n'a été trouvé avec ces filtres...",
"components.TableEmpty.withoutFilter": "Aucun {contentType} n'a été trouvé...",
"components.TableEmpty.withSearch": "Aucun {contentType} n'a été trouvé avec cette recherche ({search})...",
"components.FilterOptions.FILTER_TYPES.=": "est",
"components.FilterOptions.FILTER_TYPES._ne": "n'est pas",

View File

@ -46,11 +46,11 @@ module.exports = {
.count();
},
search: async function (params, populate) {
search: async function (params, populate) { // eslint-disable-line no-unused-vars
return [];
},
countSearch: async function (params = {}) {
countSearch: async function (params = {}) { // eslint-disable-line no-unused-vars
return 0;
},

View File

@ -18,11 +18,11 @@ module.exports = {
.count());
},
search: async function (params, populate) {
search: async function (params, populate) { // eslint-disable-line no-unused-vars
return [];
},
countSearch: async function (params = {}) {
countSearch: async function (params = {}) { // eslint-disable-line no-unused-vars
return 0;
},