mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 14:51:29 +00:00
Improve TableDelete and fix search request
This commit is contained in:
parent
935727dbb0
commit
a90f60ddd0
@ -40,14 +40,14 @@ class Search extends React.Component {
|
|||||||
this.triggerChange('');
|
this.triggerChange('');
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerChange = (value) => {
|
triggerChange = (value) => (
|
||||||
this.props.change({
|
this.props.changeParams({
|
||||||
target: {
|
target: {
|
||||||
name: 'params.q',
|
name: 'params.q',
|
||||||
value,
|
value,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
}
|
);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { model } = this.props;
|
const { model } = this.props;
|
||||||
@ -78,13 +78,13 @@ class Search extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Search.defaultProps = {
|
Search.defaultProps = {
|
||||||
change: () => {},
|
changeParams: () => {},
|
||||||
model: '',
|
model: '',
|
||||||
value: '',
|
value: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
Search.propTypes = {
|
Search.propTypes = {
|
||||||
change: PropTypes.func,
|
changeParams: PropTypes.func,
|
||||||
model: PropTypes.string,
|
model: PropTypes.string,
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -23,6 +23,7 @@ class Table extends React.Component {
|
|||||||
filters={this.props.filters}
|
filters={this.props.filters}
|
||||||
colspan={this.props.headers.length + 1}
|
colspan={this.props.headers.length + 1}
|
||||||
contentType={this.props.routeParams.slug}
|
contentType={this.props.routeParams.slug}
|
||||||
|
search={this.props.search}
|
||||||
/>
|
/>
|
||||||
) :
|
) :
|
||||||
this.props.records.map((record, key) => (
|
this.props.records.map((record, key) => (
|
||||||
@ -73,6 +74,7 @@ Table.contextTypes = {
|
|||||||
Table.defaultProps = {
|
Table.defaultProps = {
|
||||||
entriesToDelete: [],
|
entriesToDelete: [],
|
||||||
handleDelete: () => {},
|
handleDelete: () => {},
|
||||||
|
search: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
Table.propTypes = {
|
Table.propTypes = {
|
||||||
@ -94,6 +96,7 @@ Table.propTypes = {
|
|||||||
redirectUrl: PropTypes.string.isRequired,
|
redirectUrl: PropTypes.string.isRequired,
|
||||||
route: PropTypes.object.isRequired,
|
route: PropTypes.object.isRequired,
|
||||||
routeParams: PropTypes.object.isRequired,
|
routeParams: PropTypes.object.isRequired,
|
||||||
|
search: PropTypes.string,
|
||||||
sort: PropTypes.string.isRequired,
|
sort: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -7,26 +7,40 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { upperFirst } from 'lodash';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
function TableEmpty({ colspan, contentType, filters }) {
|
function TableEmpty({ colspan, contentType, filters, search }) {
|
||||||
const id = filters.length > 0 ? 'withFilters' : 'withoutFilter';
|
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 (
|
return (
|
||||||
<tr className={styles.tableEmpty}>
|
<tr className={styles.tableEmpty}>
|
||||||
<td colSpan={colspan + 1}>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TableEmpty.defaultProps = {
|
||||||
|
search: '',
|
||||||
|
};
|
||||||
|
|
||||||
TableEmpty.propTypes = {
|
TableEmpty.propTypes = {
|
||||||
colspan: PropTypes.number.isRequired,
|
colspan: PropTypes.number.isRequired,
|
||||||
contentType: PropTypes.string.isRequired,
|
contentType: PropTypes.string.isRequired,
|
||||||
filters: PropTypes.array.isRequired,
|
filters: PropTypes.array.isRequired,
|
||||||
|
search: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TableEmpty;
|
export default TableEmpty;
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators, compose } from 'redux';
|
import { bindActionCreators, compose } from 'redux';
|
||||||
import { createStructuredSelector } from 'reselect';
|
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';
|
import cn from 'classnames';
|
||||||
|
|
||||||
// App selectors
|
// App selectors
|
||||||
@ -165,7 +165,7 @@ export class ListPage extends React.Component {
|
|||||||
listPage: { filters, params },
|
listPage: { filters, params },
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return `?${generateSearchFromParams(omit(params, 'q'))}&source=${this.getSource()}${generateSearchFromFilters(filters)}`;
|
return `?${generateSearchFromParams(params)}&source=${this.getSource()}${generateSearchFromFilters(filters)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -417,6 +417,7 @@ export class ListPage extends React.Component {
|
|||||||
redirectUrl={this.generateRedirectURI()}
|
redirectUrl={this.generateRedirectURI()}
|
||||||
route={this.props.match}
|
route={this.props.match}
|
||||||
routeParams={this.props.match.params}
|
routeParams={this.props.match.params}
|
||||||
|
search={params.q}
|
||||||
sort={params._sort}
|
sort={params._sort}
|
||||||
/>
|
/>
|
||||||
<PopUpWarning
|
<PopUpWarning
|
||||||
|
|||||||
@ -56,10 +56,13 @@ export function* dataGet(action) {
|
|||||||
_limit,
|
_limit,
|
||||||
_start,
|
_start,
|
||||||
_sort: sortValue,
|
_sort: sortValue,
|
||||||
q,
|
|
||||||
source,
|
source,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (q !== '') {
|
||||||
|
params.q = q;
|
||||||
|
}
|
||||||
|
|
||||||
const response = yield [
|
const response = yield [
|
||||||
call(request, countURL, { method: 'GET', params }),
|
call(request, countURL, { method: 'GET', params }),
|
||||||
call(request, recordsURL, { method: 'GET', params }),
|
call(request, recordsURL, { method: 'GET', params }),
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
const generateFiltersFromSearch = search => search
|
const generateFiltersFromSearch = search => search
|
||||||
.split('&')
|
.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) => {
|
.reduce((acc, curr) => {
|
||||||
const arr = curr.split('=');
|
const arr = curr.split('=');
|
||||||
const split = arr[0].split('_');
|
const split = arr[0].split('_');
|
||||||
@ -40,11 +40,13 @@ const generateSearchFromFilters = filters => {
|
|||||||
*/
|
*/
|
||||||
const generateSearchFromParams = params =>
|
const generateSearchFromParams = params =>
|
||||||
Object.keys(params).reduce((acc, curr, index) => {
|
Object.keys(params).reduce((acc, curr, index) => {
|
||||||
|
if (params[curr] !== '') {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
acc = `${curr}=${params[curr]}`;
|
acc = `${curr}=${params[curr]}`;
|
||||||
} else {
|
} else {
|
||||||
acc = `${acc}&${curr}=${params[curr]}`;
|
acc = `${acc}&${curr}=${params[curr]}`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
"components.TableEmpty.withFilters": "There is no {contentType} with the applied filters...",
|
"components.TableEmpty.withFilters": "There is no {contentType} with the applied filters...",
|
||||||
"components.TableEmpty.withoutFilter": "There is no {contentType}...",
|
"components.TableEmpty.withoutFilter": "There is no {contentType}...",
|
||||||
|
"components.TableEmpty.withSearch": "There is no {contentType} corresponding to the search ({search})...",
|
||||||
|
|
||||||
"EditRelations.title": "Relational data",
|
"EditRelations.title": "Relational data",
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
"components.TableEmpty.withFilters": "Aucun {contentType} n'a été trouvé avec ces filtres...",
|
"components.TableEmpty.withFilters": "Aucun {contentType} n'a été trouvé avec ces filtres...",
|
||||||
"components.TableEmpty.withoutFilter": "Aucun {contentType} n'a été trouvé...",
|
"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.=": "est",
|
||||||
"components.FilterOptions.FILTER_TYPES._ne": "n'est pas",
|
"components.FilterOptions.FILTER_TYPES._ne": "n'est pas",
|
||||||
|
|||||||
@ -46,11 +46,11 @@ module.exports = {
|
|||||||
.count();
|
.count();
|
||||||
},
|
},
|
||||||
|
|
||||||
search: async function (params, populate) {
|
search: async function (params, populate) { // eslint-disable-line no-unused-vars
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
countSearch: async function (params = {}) {
|
countSearch: async function (params = {}) { // eslint-disable-line no-unused-vars
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,11 @@ module.exports = {
|
|||||||
.count());
|
.count());
|
||||||
},
|
},
|
||||||
|
|
||||||
search: async function (params, populate) {
|
search: async function (params, populate) { // eslint-disable-line no-unused-vars
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
countSearch: async function (params = {}) {
|
countSearch: async function (params = {}) { // eslint-disable-line no-unused-vars
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user