mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 07:10:11 +00:00
Open FilterPickWrapper when clicking on a filter with correct input autofocus
This commit is contained in:
parent
2ece502650
commit
20d896c92a
@ -60,7 +60,7 @@ function InputDate(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputDate.defaultProps = {
|
InputDate.defaultProps = {
|
||||||
autoFocus: true,
|
autoFocus: false,
|
||||||
className: '',
|
className: '',
|
||||||
deactivateErrorHighlight: false,
|
deactivateErrorHighlight: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|||||||
@ -6,11 +6,8 @@
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
const Flex = styled.div`
|
const Flex = styled.div`
|
||||||
${'' /* display: flex; */}
|
|
||||||
height: 30px;
|
height: 30px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
${'' /* max-width: 250px; */}
|
|
||||||
${'' /* min-width: 200px; */}
|
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
@ -20,12 +17,12 @@ const Flex = styled.div`
|
|||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
color: #007EFF;
|
color: #007EFF;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
> div:first-child {
|
|
||||||
flex: 2;
|
|
||||||
}
|
|
||||||
> span:nth-child(2) {
|
> span:nth-child(2) {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
> span:nth-child(3) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
-webkit-font-smoothing-antialiased;
|
-webkit-font-smoothing-antialiased;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import Remove from './Remove';
|
|||||||
import Separator from './Separator';
|
import Separator from './Separator';
|
||||||
|
|
||||||
|
|
||||||
function Filter({ filter, index, onClick, schema }) {
|
function Filter({ filter, index, onClick, onClickOpen, schema }) {
|
||||||
let value = filter.value;
|
let value = filter.value;
|
||||||
|
|
||||||
if (schema[filter.attr].type === 'date') {
|
if (schema[filter.attr].type === 'date') {
|
||||||
@ -29,7 +29,13 @@ function Filter({ filter, index, onClick, schema }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex>
|
<Flex
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
onClickOpen(index);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<span>{upperFirst(filter.attr)} </span>
|
<span>{upperFirst(filter.attr)} </span>
|
||||||
<FormattedMessage id={`content-manager.components.FilterOptions.FILTER_TYPES.${filter.filter}`} />
|
<FormattedMessage id={`content-manager.components.FilterOptions.FILTER_TYPES.${filter.filter}`} />
|
||||||
<span> {toString(value)}</span>
|
<span> {toString(value)}</span>
|
||||||
@ -43,6 +49,10 @@ Filter.defaultProps = {
|
|||||||
filter: {},
|
filter: {},
|
||||||
index: 0,
|
index: 0,
|
||||||
onClick: () => {},
|
onClick: () => {},
|
||||||
|
onClickOpen: (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
},
|
||||||
schema: {},
|
schema: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,6 +60,7 @@ Filter.propTypes = {
|
|||||||
filter: PropTypes.object,
|
filter: PropTypes.object,
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
|
onClickOpen: PropTypes.func,
|
||||||
schema: PropTypes.object,
|
schema: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,21 @@ const getInputType = (attrType) => {
|
|||||||
|
|
||||||
|
|
||||||
class InputWithAutofocus extends React.Component {
|
class InputWithAutofocus extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
if (this.props.filterToFocus === this.props.index) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.inputEl.hasOwnProperty('openCalendar')) {
|
||||||
|
this.inputEl.openCalendar();
|
||||||
|
} else {
|
||||||
|
this.inputEl.focus();
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { filter, inputStyle, name, onChange, schema } = this.props;
|
const { filter, inputStyle, name, onChange, schema } = this.props;
|
||||||
const Input = getInputType(get(schema, [filter.attr, 'type'], 'string'));
|
const Input = getInputType(get(schema, [filter.attr, 'type'], 'string'));
|
||||||
@ -50,6 +65,11 @@ class InputWithAutofocus extends React.Component {
|
|||||||
|
|
||||||
InputWithAutofocus.propTypes = {
|
InputWithAutofocus.propTypes = {
|
||||||
filter: PropTypes.object.isRequired,
|
filter: PropTypes.object.isRequired,
|
||||||
|
filterToFocus: PropTypes.oneOfType([
|
||||||
|
PropTypes.object,
|
||||||
|
PropTypes.number,
|
||||||
|
]).isRequired,
|
||||||
|
index: PropTypes.number.isRequired,
|
||||||
inputStyle: PropTypes.object.isRequired,
|
inputStyle: PropTypes.object.isRequired,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import FILTER_TYPES from './filterTypes';
|
|||||||
const defaultInputStyle = { width: '210px', marginRight: '10px', paddingTop: '4px' };
|
const defaultInputStyle = { width: '210px', marginRight: '10px', paddingTop: '4px' };
|
||||||
const midSelectStyle = { minWidth: '130px', maxWidth: '200px', marginLeft: '10px', marginRight: '10px' };
|
const midSelectStyle = { minWidth: '130px', maxWidth: '200px', marginLeft: '10px', marginRight: '10px' };
|
||||||
|
|
||||||
function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, schema, showAddButton }) {
|
function FilterOptions({ filter, filterToFocus, index, onChange, onClickAdd, onClickRemove, schema, show, showAddButton }) {
|
||||||
const selectStyle = { minWidth: '170px', maxWidth: '200px' };
|
const selectStyle = { minWidth: '170px', maxWidth: '200px' };
|
||||||
const attrType = get(schema, [filter.attr, 'type'], 'string');
|
const attrType = get(schema, [filter.attr, 'type'], 'string');
|
||||||
const inputStyle = attrType === 'boolean' ?
|
const inputStyle = attrType === 'boolean' ?
|
||||||
@ -49,8 +49,11 @@ function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, sch
|
|||||||
style={midSelectStyle}
|
style={midSelectStyle}
|
||||||
/>
|
/>
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
|
{show && (
|
||||||
<InputWithAutofocus
|
<InputWithAutofocus
|
||||||
filter={filter}
|
filter={filter}
|
||||||
|
filterToFocus={filterToFocus}
|
||||||
|
index={index}
|
||||||
inputStyle={inputStyle}
|
inputStyle={inputStyle}
|
||||||
name={`${index}.value`}
|
name={`${index}.value`}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
@ -58,6 +61,7 @@ function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, sch
|
|||||||
style={inputStyle}
|
style={inputStyle}
|
||||||
value={get(filter, 'value')}
|
value={get(filter, 'value')}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
{showAddButton && (
|
{showAddButton && (
|
||||||
<Add
|
<Add
|
||||||
@ -72,21 +76,28 @@ function FilterOptions({ filter, index, onChange, onClickAdd, onClickRemove, sch
|
|||||||
|
|
||||||
FilterOptions.defaultProps = {
|
FilterOptions.defaultProps = {
|
||||||
filter: {},
|
filter: {},
|
||||||
|
filterToFocus: null,
|
||||||
index: 0,
|
index: 0,
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
onClickAdd: () => {},
|
onClickAdd: () => {},
|
||||||
onClickRemove: () => {},
|
onClickRemove: () => {},
|
||||||
schema: {},
|
schema: {},
|
||||||
|
show: false,
|
||||||
showAddButton: false,
|
showAddButton: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
FilterOptions.propTypes = {
|
FilterOptions.propTypes = {
|
||||||
filter: PropTypes.object,
|
filter: PropTypes.object,
|
||||||
|
filterToFocus: PropTypes.oneOfType([
|
||||||
|
PropTypes.object,
|
||||||
|
PropTypes.number,
|
||||||
|
]),
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
onClickAdd: PropTypes.func,
|
onClickAdd: PropTypes.func,
|
||||||
onClickRemove: PropTypes.func,
|
onClickRemove: PropTypes.func,
|
||||||
schema: PropTypes.object,
|
schema: PropTypes.object,
|
||||||
|
show: PropTypes.bool,
|
||||||
showAddButton: PropTypes.bool,
|
showAddButton: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -112,7 +112,7 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { appliedFilters, schema, show } = this.props;
|
const { appliedFilters, filterToFocus, schema, show } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
@ -131,11 +131,13 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
<FilterOptions
|
<FilterOptions
|
||||||
key={key}
|
key={key}
|
||||||
filter={filter}
|
filter={filter}
|
||||||
|
filterToFocus={filterToFocus}
|
||||||
index={key}
|
index={key}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
onClickAdd={this.handleClickAdd}
|
onClickAdd={this.handleClickAdd}
|
||||||
onClickRemove={this.handleClickRemove}
|
onClickRemove={this.handleClickRemove}
|
||||||
schema={schema}
|
schema={schema}
|
||||||
|
show={show}
|
||||||
showAddButton={this.shouldDisplayAddButton(key)}
|
showAddButton={this.shouldDisplayAddButton(key)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@ -156,6 +158,7 @@ class FiltersPickWrapper extends React.PureComponent {
|
|||||||
|
|
||||||
FiltersPickWrapper.defaultProps = {
|
FiltersPickWrapper.defaultProps = {
|
||||||
appliedFilters: [],
|
appliedFilters: [],
|
||||||
|
filterToFocus: null,
|
||||||
modelName: '',
|
modelName: '',
|
||||||
schema: {},
|
schema: {},
|
||||||
};
|
};
|
||||||
@ -164,6 +167,10 @@ FiltersPickWrapper.propTypes = {
|
|||||||
addFilter: PropTypes.func.isRequired,
|
addFilter: PropTypes.func.isRequired,
|
||||||
appliedFilters: PropTypes.array,
|
appliedFilters: PropTypes.array,
|
||||||
close: PropTypes.func.isRequired,
|
close: PropTypes.func.isRequired,
|
||||||
|
filterToFocus: PropTypes.oneOfType([
|
||||||
|
PropTypes.object,
|
||||||
|
PropTypes.number,
|
||||||
|
]),
|
||||||
modelName: PropTypes.string,
|
modelName: PropTypes.string,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import {
|
|||||||
ON_CHANGE,
|
ON_CHANGE,
|
||||||
ON_CLICK_REMOVE,
|
ON_CLICK_REMOVE,
|
||||||
ON_TOGGLE_FILTERS,
|
ON_TOGGLE_FILTERS,
|
||||||
|
OPEN_FILTERS_WITH_SELECTION,
|
||||||
REMOVE_ALL_FILTERS,
|
REMOVE_ALL_FILTERS,
|
||||||
REMOVE_FILTER,
|
REMOVE_FILTER,
|
||||||
SET_PARAMS,
|
SET_PARAMS,
|
||||||
@ -82,6 +83,13 @@ export function onClickRemove(index) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function openFiltersWithSelections(index) {
|
||||||
|
return {
|
||||||
|
type: OPEN_FILTERS_WITH_SELECTION,
|
||||||
|
index,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function onToggleFilters() {
|
export function onToggleFilters() {
|
||||||
return {
|
return {
|
||||||
type: ON_TOGGLE_FILTERS,
|
type: ON_TOGGLE_FILTERS,
|
||||||
|
|||||||
@ -14,6 +14,7 @@ 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_CLICK_REMOVE = 'ContentManager/ListPage/ON_CLICK_REMOVE';
|
export const ON_CLICK_REMOVE = 'ContentManager/ListPage/ON_CLICK_REMOVE';
|
||||||
export const ON_TOGGLE_FILTERS = 'ContentManager/ListPage/ON_TOGGLE_FILTERS';
|
export const ON_TOGGLE_FILTERS = 'ContentManager/ListPage/ON_TOGGLE_FILTERS';
|
||||||
|
export const OPEN_FILTERS_WITH_SELECTION = 'ContentManager/ListPage/OPEN_FILTERS_WITH_SELECTION';
|
||||||
export const REMOVE_ALL_FILTERS = 'ContentManager/ListPage/REMOVE_ALL_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';
|
||||||
|
|||||||
@ -43,6 +43,7 @@ import {
|
|||||||
onChange,
|
onChange,
|
||||||
onClickRemove,
|
onClickRemove,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
openFiltersWithSelections,
|
||||||
removeAllFilters,
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
setParams,
|
setParams,
|
||||||
@ -296,10 +297,11 @@ export class ListPage extends React.Component {
|
|||||||
const {
|
const {
|
||||||
addFilter,
|
addFilter,
|
||||||
listPage,
|
listPage,
|
||||||
listPage: { appliedFilters, filters, params, showFilter },
|
listPage: { appliedFilters, filters, filterToFocus, params, showFilter },
|
||||||
onChange,
|
onChange,
|
||||||
onClickRemove,
|
onClickRemove,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
openFiltersWithSelections,
|
||||||
removeAllFilters,
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
@ -324,6 +326,7 @@ export class ListPage extends React.Component {
|
|||||||
addFilter={addFilter}
|
addFilter={addFilter}
|
||||||
appliedFilters={appliedFilters}
|
appliedFilters={appliedFilters}
|
||||||
close={onToggleFilters}
|
close={onToggleFilters}
|
||||||
|
filterToFocus={filterToFocus}
|
||||||
modelName={this.getCurrentModelName()}
|
modelName={this.getCurrentModelName()}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onSubmit={this.handleSubmit}
|
onSubmit={this.handleSubmit}
|
||||||
@ -364,6 +367,7 @@ export class ListPage extends React.Component {
|
|||||||
filter={filter}
|
filter={filter}
|
||||||
index={key}
|
index={key}
|
||||||
onClick={onClickRemove}
|
onClick={onClickRemove}
|
||||||
|
onClickOpen={openFiltersWithSelections}
|
||||||
schema={this.getCurrentSchema()}
|
schema={this.getCurrentSchema()}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@ -425,6 +429,7 @@ ListPage.propTypes = {
|
|||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onClickRemove: PropTypes.func.isRequired,
|
onClickRemove: PropTypes.func.isRequired,
|
||||||
onToggleFilters: PropTypes.func.isRequired,
|
onToggleFilters: PropTypes.func.isRequired,
|
||||||
|
openFiltersWithSelections: PropTypes.func.isRequired,
|
||||||
removeAllFilters: PropTypes.func.isRequired,
|
removeAllFilters: PropTypes.func.isRequired,
|
||||||
removeFilter: PropTypes.func.isRequired,
|
removeFilter: PropTypes.func.isRequired,
|
||||||
schema: PropTypes.object.isRequired,
|
schema: PropTypes.object.isRequired,
|
||||||
@ -442,6 +447,7 @@ function mapDispatchToProps(dispatch) {
|
|||||||
onChange,
|
onChange,
|
||||||
onClickRemove,
|
onClickRemove,
|
||||||
onToggleFilters,
|
onToggleFilters,
|
||||||
|
openFiltersWithSelections,
|
||||||
removeAllFilters,
|
removeAllFilters,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
setParams,
|
setParams,
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
ON_CHANGE,
|
ON_CHANGE,
|
||||||
ON_CLICK_REMOVE,
|
ON_CLICK_REMOVE,
|
||||||
ON_TOGGLE_FILTERS,
|
ON_TOGGLE_FILTERS,
|
||||||
|
OPEN_FILTERS_WITH_SELECTION,
|
||||||
REMOVE_ALL_FILTERS,
|
REMOVE_ALL_FILTERS,
|
||||||
REMOVE_FILTER,
|
REMOVE_FILTER,
|
||||||
SET_PARAMS,
|
SET_PARAMS,
|
||||||
@ -25,6 +26,8 @@ const initialState = fromJS({
|
|||||||
appliedFilters: List([]),
|
appliedFilters: List([]),
|
||||||
count: 0,
|
count: 0,
|
||||||
filters: List([]),
|
filters: List([]),
|
||||||
|
filtersUpdated: false,
|
||||||
|
filterToFocus: null,
|
||||||
params: Map({
|
params: Map({
|
||||||
_limit: 10,
|
_limit: 10,
|
||||||
_page: 1,
|
_page: 1,
|
||||||
@ -32,7 +35,6 @@ const initialState = fromJS({
|
|||||||
}),
|
}),
|
||||||
records: List([]),
|
records: List([]),
|
||||||
showFilter: false,
|
showFilter: false,
|
||||||
filtersUpdated: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function listPageReducer(state = initialState, action) {
|
function listPageReducer(state = initialState, action) {
|
||||||
@ -65,7 +67,13 @@ function listPageReducer(state = initialState, action) {
|
|||||||
.update('filters', list => list.splice(action.index, 1))
|
.update('filters', list => list.splice(action.index, 1))
|
||||||
.update('filtersUpdated', v => v = !v);
|
.update('filtersUpdated', v => v = !v);
|
||||||
case ON_TOGGLE_FILTERS:
|
case ON_TOGGLE_FILTERS:
|
||||||
return state.update('showFilter', v => !v);
|
return state
|
||||||
|
.update('filterToFocus', () => null)
|
||||||
|
.update('showFilter', v => !v);
|
||||||
|
case OPEN_FILTERS_WITH_SELECTION:
|
||||||
|
return state
|
||||||
|
.update('showFilter', () => true)
|
||||||
|
.update('filterToFocus', () => action.index);
|
||||||
case REMOVE_ALL_FILTERS:
|
case REMOVE_ALL_FILTERS:
|
||||||
return state
|
return state
|
||||||
.update('appliedFilters', () => List([]))
|
.update('appliedFilters', () => List([]))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user