mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
Add actions to filterpicker
This commit is contained in:
parent
e9ce813474
commit
7260bbe309
@ -2,6 +2,7 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
const Div = styled.div`
|
const Div = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
|
margin-bottom: 6px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default Div;
|
export default Div;
|
||||||
|
@ -37,7 +37,7 @@ const getInputType = (attrType) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultInputStyle = { height: '30px', width: '200px', marginRight: '10px' };
|
const defaultInputStyle = { height: '30px', width: '200px', marginRight: '10px', paddingTop: '9px' };
|
||||||
|
|
||||||
function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, schema, showAddButton }) {
|
function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, schema, showAddButton }) {
|
||||||
const selectStyle = { minHeight: '30px', minWidth: '170px', maxWidth: '200px' };
|
const selectStyle = { minHeight: '30px', minWidth: '170px', maxWidth: '200px' };
|
||||||
|
@ -38,6 +38,28 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateActions = () => ([
|
||||||
|
{
|
||||||
|
label: 'content-manager.components.FiltersPickWrapper.PluginHeader.actions.clearAll',
|
||||||
|
kind: 'secondary',
|
||||||
|
onClick: () => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
this.props.close();
|
||||||
|
setTimeout(() => {
|
||||||
|
this.props.removeAllFilters();
|
||||||
|
resolve();
|
||||||
|
}, 600);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'content-manager.components.FiltersPickWrapper.PluginHeader.actions.apply',
|
||||||
|
kind: 'primary',
|
||||||
|
type: 'submit',
|
||||||
|
onClick: this.props.onSubmit,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
handleChange = ({ target }) => {
|
handleChange = ({ target }) => {
|
||||||
const split = target.name.split('.');
|
const split = target.name.split('.');
|
||||||
this.props.onChange(split[0], split[1], target.value);
|
this.props.onChange(split[0], split[1], target.value);
|
||||||
@ -57,6 +79,7 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.props.removeFilter(index);
|
this.props.removeFilter(index);
|
||||||
|
this.props.onSubmit();
|
||||||
resolve();
|
resolve();
|
||||||
}, 600);
|
}, 600);
|
||||||
});
|
});
|
||||||
@ -85,54 +108,56 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { actions, appliedFilters, schema, show } = this.props;
|
const { appliedFilters, schema, show } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SlideDown on={show}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<Div>
|
<SlideDown on={show}>
|
||||||
<div>
|
<Div>
|
||||||
<PluginHeader
|
<div>
|
||||||
actions={actions}
|
<PluginHeader
|
||||||
description={{
|
actions={this.generateActions()}
|
||||||
id: 'content-manager.components.FiltersPickWrapper.PluginHeader.description',
|
description={{
|
||||||
}}
|
id: 'content-manager.components.FiltersPickWrapper.PluginHeader.description',
|
||||||
title={this.renderTitle()}
|
}}
|
||||||
/>
|
title={this.renderTitle()}
|
||||||
<div style={{ marginTop: '-10px' }}>
|
/>
|
||||||
{appliedFilters.map((filter, key) => (
|
<div style={{ marginTop: '-13px' }}>
|
||||||
<FilterOptions
|
{appliedFilters.map((filter, key) => (
|
||||||
key={key}
|
<FilterOptions
|
||||||
filter={filter}
|
key={key}
|
||||||
index={key}
|
filter={filter}
|
||||||
onChange={this.handleChange}
|
index={key}
|
||||||
onClickAdd={this.handleClickAdd}
|
onChange={this.handleChange}
|
||||||
onClickRemove={this.handleClickRemove}
|
onClickAdd={this.handleClickAdd}
|
||||||
schema={schema}
|
onClickRemove={this.handleClickRemove}
|
||||||
showAddButton={this.shouldDisplayAddButton(key)}
|
schema={schema}
|
||||||
/>
|
showAddButton={this.shouldDisplayAddButton(key)}
|
||||||
))}
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Div>
|
||||||
</Div>
|
</SlideDown>
|
||||||
</SlideDown>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FiltersPickWrapper.defaultProps = {
|
FiltersPickWrapper.defaultProps = {
|
||||||
actions: [],
|
|
||||||
appliedFilters: [],
|
appliedFilters: [],
|
||||||
modelName: '',
|
modelName: '',
|
||||||
schema: {},
|
schema: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
FiltersPickWrapper.propTypes = {
|
FiltersPickWrapper.propTypes = {
|
||||||
actions: PropTypes.array,
|
|
||||||
addFilter: PropTypes.func.isRequired,
|
addFilter: PropTypes.func.isRequired,
|
||||||
appliedFilters: PropTypes.array,
|
appliedFilters: PropTypes.array,
|
||||||
close: PropTypes.func.isRequired,
|
close: PropTypes.func.isRequired,
|
||||||
modelName: PropTypes.string,
|
modelName: PropTypes.string,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
|
onSubmit: PropTypes.func.isRequired,
|
||||||
|
removeAllFilters: PropTypes.func.isRequired,
|
||||||
removeFilter: PropTypes.func.isRequired,
|
removeFilter: PropTypes.func.isRequired,
|
||||||
schema: PropTypes.object,
|
schema: PropTypes.object,
|
||||||
show: PropTypes.bool.isRequired,
|
show: PropTypes.bool.isRequired,
|
||||||
|
@ -13,8 +13,10 @@ import {
|
|||||||
GET_DATA_SUCCEEDED,
|
GET_DATA_SUCCEEDED,
|
||||||
ON_CHANGE,
|
ON_CHANGE,
|
||||||
ON_TOGGLE_FILTERS,
|
ON_TOGGLE_FILTERS,
|
||||||
|
REMOVE_ALL_FILTERS,
|
||||||
REMOVE_FILTER,
|
REMOVE_FILTER,
|
||||||
SET_PARAMS,
|
SET_PARAMS,
|
||||||
|
SUBMIT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
export function addFilter(filter) {
|
export function addFilter(filter) {
|
||||||
@ -78,6 +80,12 @@ export function onToggleFilters() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function removeAllFilters() {
|
||||||
|
return {
|
||||||
|
type: REMOVE_ALL_FILTERS,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function removeFilter(index) {
|
export function removeFilter(index) {
|
||||||
return {
|
return {
|
||||||
type: REMOVE_FILTER,
|
type: REMOVE_FILTER,
|
||||||
@ -91,3 +99,9 @@ export function setParams(params) {
|
|||||||
params,
|
params,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function submit() {
|
||||||
|
return {
|
||||||
|
type: SUBMIT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -13,5 +13,7 @@ export const GET_DATA = 'ContentManager/ListPage/GET_DATA';
|
|||||||
export const GET_DATA_SUCCEEDED = 'ContentManager/ListPage/GET_DATA_SUCCEEDED';
|
export const GET_DATA_SUCCEEDED = 'ContentManager/ListPage/GET_DATA_SUCCEEDED';
|
||||||
export const ON_CHANGE = 'ContentManager/ListPage/ON_CHANGE';
|
export const ON_CHANGE = 'ContentManager/ListPage/ON_CHANGE';
|
||||||
export const ON_TOGGLE_FILTERS = 'ContentManager/ListPage/ON_TOGGLE_FILTERS';
|
export const ON_TOGGLE_FILTERS = 'ContentManager/ListPage/ON_TOGGLE_FILTERS';
|
||||||
|
export const REMOVE_ALL_FILTERS = 'ContentManager/ListPage/REMOVE_ALL_FILTERS';
|
||||||
export const REMOVE_FILTER = 'ContentManager/ListPage/REMOVE_FILTER';
|
export const REMOVE_FILTER = 'ContentManager/ListPage/REMOVE_FILTER';
|
||||||
export const SET_PARAMS = 'ContentManager/ListPage/SET_PARAMS';
|
export const SET_PARAMS = 'ContentManager/ListPage/SET_PARAMS';
|
||||||
|
export const SUBMIT = 'ContentManager/ListPage/SUBMIT';
|
||||||
|
@ -41,8 +41,10 @@ import {
|
|||||||
getData,
|
getData,
|
||||||
onChange,
|
onChange,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
setParams,
|
setParams,
|
||||||
|
submit,
|
||||||
} from './actions';
|
} from './actions';
|
||||||
|
|
||||||
import reducer from './reducer';
|
import reducer from './reducer';
|
||||||
@ -248,6 +250,16 @@ export class ListPage extends React.Component {
|
|||||||
this.setState({ showWarning: false });
|
this.setState({ showWarning: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleSubmit = e => {
|
||||||
|
try {
|
||||||
|
e.preventDefault();
|
||||||
|
} catch(err) {
|
||||||
|
// Silent
|
||||||
|
} finally {
|
||||||
|
this.props.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toggleModalWarning = e => {
|
toggleModalWarning = e => {
|
||||||
if (!isUndefined(e)) {
|
if (!isUndefined(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -267,6 +279,7 @@ export class ListPage extends React.Component {
|
|||||||
listPage: { appliedFilters, params, showFilter },
|
listPage: { appliedFilters, params, showFilter },
|
||||||
onChange,
|
onChange,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const pluginHeaderActions = [
|
const pluginHeaderActions = [
|
||||||
@ -294,6 +307,8 @@ export class ListPage extends React.Component {
|
|||||||
close={onToggleFilters}
|
close={onToggleFilters}
|
||||||
modelName={this.getCurrentModelName()}
|
modelName={this.getCurrentModelName()}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
onSubmit={this.handleSubmit}
|
||||||
|
removeAllFilters={removeAllFilters}
|
||||||
removeFilter={removeFilter}
|
removeFilter={removeFilter}
|
||||||
schema={this.getCurrentSchema()}
|
schema={this.getCurrentSchema()}
|
||||||
show={showFilter}
|
show={showFilter}
|
||||||
@ -377,9 +392,11 @@ ListPage.propTypes = {
|
|||||||
models: PropTypes.object.isRequired,
|
models: PropTypes.object.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onToggleFilters: PropTypes.func.isRequired,
|
onToggleFilters: PropTypes.func.isRequired,
|
||||||
|
removeAllFilters: PropTypes.func.isRequired,
|
||||||
removeFilter: PropTypes.func.isRequired,
|
removeFilter: PropTypes.func.isRequired,
|
||||||
schema: PropTypes.object.isRequired,
|
schema: PropTypes.object.isRequired,
|
||||||
setParams: PropTypes.func.isRequired,
|
setParams: PropTypes.func.isRequired,
|
||||||
|
submit: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
@ -391,8 +408,10 @@ function mapDispatchToProps(dispatch) {
|
|||||||
getData,
|
getData,
|
||||||
onChange,
|
onChange,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
setParams,
|
setParams,
|
||||||
|
submit,
|
||||||
},
|
},
|
||||||
dispatch,
|
dispatch,
|
||||||
);
|
);
|
||||||
|
@ -14,13 +14,16 @@ import {
|
|||||||
GET_DATA_SUCCEEDED,
|
GET_DATA_SUCCEEDED,
|
||||||
ON_CHANGE,
|
ON_CHANGE,
|
||||||
ON_TOGGLE_FILTERS,
|
ON_TOGGLE_FILTERS,
|
||||||
|
REMOVE_ALL_FILTERS,
|
||||||
REMOVE_FILTER,
|
REMOVE_FILTER,
|
||||||
SET_PARAMS,
|
SET_PARAMS,
|
||||||
|
SUBMIT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
const initialState = fromJS({
|
const initialState = fromJS({
|
||||||
count: 0,
|
|
||||||
appliedFilters: List([]),
|
appliedFilters: List([]),
|
||||||
|
count: 0,
|
||||||
|
filters: List([]),
|
||||||
params: Map({
|
params: Map({
|
||||||
_limit: 10,
|
_limit: 10,
|
||||||
_page: 1,
|
_page: 1,
|
||||||
@ -56,10 +59,18 @@ function listPageReducer(state = initialState, action) {
|
|||||||
return state.updateIn(['appliedFilters', action.index, action.key], () => action.value);
|
return state.updateIn(['appliedFilters', action.index, action.key], () => action.value);
|
||||||
case ON_TOGGLE_FILTERS:
|
case ON_TOGGLE_FILTERS:
|
||||||
return state.update('showFilter', v => !v);
|
return state.update('showFilter', v => !v);
|
||||||
|
case REMOVE_ALL_FILTERS:
|
||||||
|
return state
|
||||||
|
.update('appliedFilters', () => List([]))
|
||||||
|
.update('filters', () => List([]));
|
||||||
case REMOVE_FILTER:
|
case REMOVE_FILTER:
|
||||||
return state.update('appliedFilters', list => list.splice(action.index, 1));
|
return state.update('appliedFilters', list => list.splice(action.index, 1));
|
||||||
case SET_PARAMS:
|
case SET_PARAMS:
|
||||||
return state.update('params', () => Map(action.params));
|
return state.update('params', () => Map(action.params));
|
||||||
|
case SUBMIT:
|
||||||
|
return state
|
||||||
|
.update('filters', () => state.get('appliedFilters'))
|
||||||
|
.update('showFilter', () => false);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
"components.AddFilterCTA.add": "Add filter",
|
"components.AddFilterCTA.add": "Add filter",
|
||||||
"components.FilterOptions.button.apply": "Apply",
|
"components.FilterOptions.button.apply": "Apply",
|
||||||
|
"components.FiltersPickWrapper.PluginHeader.actions.apply": "Apply",
|
||||||
|
"components.FiltersPickWrapper.PluginHeader.actions.clearAll": "Clear all",
|
||||||
"components.FiltersPickWrapper.PluginHeader.description": "Set the conditions to apply to filter the entries",
|
"components.FiltersPickWrapper.PluginHeader.description": "Set the conditions to apply to filter the entries",
|
||||||
"components.FiltersPickWrapper.PluginHeader.title.filter": "Filters",
|
"components.FiltersPickWrapper.PluginHeader.title.filter": "Filters",
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
"components.AddFilterCTA.add": "Ajouter un filtre",
|
"components.AddFilterCTA.add": "Ajouter un filtre",
|
||||||
"components.FilterOptions.button.apply": "Appliquer",
|
"components.FilterOptions.button.apply": "Appliquer",
|
||||||
|
"components.FiltersPickWrapper.PluginHeader.actions.apply": "Appliquer",
|
||||||
|
"components.FiltersPickWrapper.PluginHeader.actions.clearAll": "Tout supprimer",
|
||||||
"components.FiltersPickWrapper.PluginHeader.description": "Définissez les conditions des filtres à appliquer",
|
"components.FiltersPickWrapper.PluginHeader.description": "Définissez les conditions des filtres à appliquer",
|
||||||
"components.FiltersPickWrapper.PluginHeader.title.filter": "Filtres",
|
"components.FiltersPickWrapper.PluginHeader.title.filter": "Filtres",
|
||||||
|
|
||||||
|
@ -8,5 +8,12 @@
|
|||||||
"appearance": ""
|
"appearance": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"fevzilyaguk": {
|
||||||
|
"attributes": {
|
||||||
|
"razeiugeryeizla": {
|
||||||
|
"appearance": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user