mirror of
https://github.com/strapi/strapi.git
synced 2025-11-14 09:07:59 +00:00
Created filterpicker
This commit is contained in:
parent
ba6631d1e3
commit
ea32c05976
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, { memo } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { isEmpty, isFunction, isObject } from 'lodash';
|
import { isEmpty, isFunction, isObject } from 'lodash';
|
||||||
@ -13,7 +13,14 @@ import LoadingBar from '../LoadingBar';
|
|||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
function PluginHeaderTitle({ description, title, titleId, withDescriptionAnim, icon, onClickIcon }) {
|
function PluginHeaderTitle({
|
||||||
|
description,
|
||||||
|
title,
|
||||||
|
titleId,
|
||||||
|
withDescriptionAnim,
|
||||||
|
icon,
|
||||||
|
onClickIcon,
|
||||||
|
}) {
|
||||||
const contentTitle = formatData(title);
|
const contentTitle = formatData(title);
|
||||||
const contentDescription = formatData(description);
|
const contentDescription = formatData(description);
|
||||||
|
|
||||||
@ -24,22 +31,34 @@ function PluginHeaderTitle({ description, title, titleId, withDescriptionAnim, i
|
|||||||
{contentTitle}
|
{contentTitle}
|
||||||
</h1>
|
</h1>
|
||||||
{icon && (
|
{icon && (
|
||||||
<i className={`${icon} ${styles.icon}`} id="editCTName" onClick={onClickIcon} role="button" />
|
<i
|
||||||
|
className={`${icon} ${styles.icon}`}
|
||||||
|
id="editCTName"
|
||||||
|
onClick={onClickIcon}
|
||||||
|
role="button"
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{withDescriptionAnim ? (
|
{withDescriptionAnim ? (
|
||||||
<LoadingBar />
|
<LoadingBar />
|
||||||
) : (
|
) : (
|
||||||
<p className={styles.pluginHeaderTitleDescription}>{contentDescription} </p>
|
<p className={styles.pluginHeaderTitleDescription}>
|
||||||
|
{contentDescription}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatData = data => {
|
const formatData = data => {
|
||||||
|
if (isObject(data) && !isEmpty(data.id)) {
|
||||||
if (isObject(data)) {
|
return (
|
||||||
return isEmpty(data.id) ? null : <FormattedMessage id={data.id} defaultMessage={data.id} values={data.values} />;
|
<FormattedMessage
|
||||||
|
id={data.id}
|
||||||
|
defaultMessage={data.id}
|
||||||
|
values={data.values}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFunction(data)) {
|
if (isFunction(data)) {
|
||||||
@ -81,4 +100,4 @@ PluginHeaderTitle.propTypes = {
|
|||||||
withDescriptionAnim: PropTypes.bool,
|
withDescriptionAnim: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PluginHeaderTitle;
|
export default memo(PluginHeaderTitle);
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
import React, { memo } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { capitalize } from 'lodash';
|
||||||
|
import { Collapse } from 'reactstrap';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { PluginHeader } from 'strapi-helper-plugin';
|
||||||
|
|
||||||
|
import Container from '../Container';
|
||||||
|
import pluginId from '../../pluginId';
|
||||||
|
|
||||||
|
function FilterPicker({ actions, isOpen, name }) {
|
||||||
|
const renderTitle = () => (
|
||||||
|
<FormattedMessage
|
||||||
|
id={`${pluginId}.components.FiltersPickWrapper.PluginHeader.title.filter`}
|
||||||
|
>
|
||||||
|
{message => (
|
||||||
|
<span>
|
||||||
|
{capitalize(name)} -
|
||||||
|
<span>{message}</span>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</FormattedMessage>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<Collapse isOpen={isOpen}>
|
||||||
|
<Container style={{ backgroundColor: 'white' }}>
|
||||||
|
<PluginHeader
|
||||||
|
actions={actions}
|
||||||
|
title={renderTitle}
|
||||||
|
description={{
|
||||||
|
id: `${pluginId}.components.FiltersPickWrapper.PluginHeader.description`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
|
</Collapse>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterPicker.defaultProps = {
|
||||||
|
actions: [],
|
||||||
|
isOpen: false,
|
||||||
|
name: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
FilterPicker.propTypes = {
|
||||||
|
actions: PropTypes.array,
|
||||||
|
isOpen: PropTypes.bool,
|
||||||
|
name: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(FilterPicker);
|
||||||
@ -18,6 +18,7 @@ import pluginId from '../../pluginId';
|
|||||||
import FilterLogo from '../../assets/images/icon_filter.png';
|
import FilterLogo from '../../assets/images/icon_filter.png';
|
||||||
|
|
||||||
import Container from '../../components/Container';
|
import Container from '../../components/Container';
|
||||||
|
import FilterPicker from '../../components/FilterPicker';
|
||||||
import InputCheckbox from '../../components/InputCheckbox';
|
import InputCheckbox from '../../components/InputCheckbox';
|
||||||
import Search from '../../components/Search';
|
import Search from '../../components/Search';
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ function ListView({
|
|||||||
strapi.useInjectReducer({ key: 'listView', reducer, pluginId });
|
strapi.useInjectReducer({ key: 'listView', reducer, pluginId });
|
||||||
strapi.useInjectSaga({ key: 'listView', saga, pluginId });
|
strapi.useInjectSaga({ key: 'listView', saga, pluginId });
|
||||||
const [isLabelPickerOpen, setLabelPickerState] = useState(false);
|
const [isLabelPickerOpen, setLabelPickerState] = useState(false);
|
||||||
|
const [isFilterPickerOpen, setFilterPickerState] = useState(false);
|
||||||
const getLayoutSettingRef = useRef();
|
const getLayoutSettingRef = useRef();
|
||||||
getLayoutSettingRef.current = settingName =>
|
getLayoutSettingRef.current = settingName =>
|
||||||
get(layouts, [slug, 'settings', settingName], '');
|
get(layouts, [slug, 'settings', settingName], '');
|
||||||
@ -74,6 +76,8 @@ function ListView({
|
|||||||
|
|
||||||
const toggleLabelPickerState = () =>
|
const toggleLabelPickerState = () =>
|
||||||
setLabelPickerState(prevState => !prevState);
|
setLabelPickerState(prevState => !prevState);
|
||||||
|
const toggleFilterPickerState = () =>
|
||||||
|
setFilterPickerState(prevState => !prevState);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getData(slug, generateSearchParams());
|
getData(slug, generateSearchParams());
|
||||||
@ -127,10 +131,37 @@ function ListView({
|
|||||||
target: { name: `${slug}.${name}`, value: !value },
|
target: { name: `${slug}.${name}`, value: !value },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const filterPickerActions = [
|
||||||
|
{
|
||||||
|
label: `${pluginId}.components.FiltersPickWrapper.PluginHeader.actions.clearAll`,
|
||||||
|
kind: 'secondary',
|
||||||
|
onClick: () => {
|
||||||
|
toggleFilterPickerState();
|
||||||
|
// this.props.close();
|
||||||
|
// this.props.removeAllFilters();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${pluginId}.components.FiltersPickWrapper.PluginHeader.actions.apply`,
|
||||||
|
kind: 'primary',
|
||||||
|
type: 'submit',
|
||||||
|
onClick: () => {
|
||||||
|
emitEvent('didFilterEntries');
|
||||||
|
toggleFilterPickerState();
|
||||||
|
// this.props.onSubmit(e);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<FilterPicker
|
||||||
|
actions={filterPickerActions}
|
||||||
|
isOpen={isFilterPickerOpen}
|
||||||
|
name={slug}
|
||||||
|
/>
|
||||||
<Container>
|
<Container>
|
||||||
|
{!isFilterPickerOpen && (
|
||||||
<PluginHeader
|
<PluginHeader
|
||||||
actions={pluginHeaderActions}
|
actions={pluginHeaderActions}
|
||||||
description={{
|
description={{
|
||||||
@ -147,6 +178,25 @@ function ListView({
|
|||||||
}}
|
}}
|
||||||
withDescriptionAnim={isLoading}
|
withDescriptionAnim={isLoading}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{/* <StyledCollapse isOpen={!isFilterPickerOpen}>
|
||||||
|
<PluginHeader
|
||||||
|
actions={pluginHeaderActions}
|
||||||
|
description={{
|
||||||
|
id:
|
||||||
|
count > 1
|
||||||
|
? `${pluginId}.containers.List.pluginHeaderDescription`
|
||||||
|
: `${pluginId}.containers.List.pluginHeaderDescription.singular`,
|
||||||
|
values: {
|
||||||
|
label: count,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
title={{
|
||||||
|
id: slug || 'Content Manager',
|
||||||
|
}}
|
||||||
|
withDescriptionAnim={isLoading}
|
||||||
|
/>
|
||||||
|
</StyledCollapse> */}
|
||||||
{getLayoutSettingRef.current('searchable') && (
|
{getLayoutSettingRef.current('searchable') && (
|
||||||
<Search
|
<Search
|
||||||
changeParams={handleChangeParams}
|
changeParams={handleChangeParams}
|
||||||
@ -158,7 +208,7 @@ function ListView({
|
|||||||
<Wrapper>
|
<Wrapper>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-10">
|
<div className="col-10">
|
||||||
<AddFilterCta type="button">
|
<AddFilterCta type="button" onClick={toggleFilterPickerState}>
|
||||||
<Img src={FilterLogo} alt="filter_logo" />
|
<Img src={FilterLogo} alt="filter_logo" />
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id={`${pluginId}.components.AddFilterCTA.add`}
|
id={`${pluginId}.components.AddFilterCTA.add`}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user