2020-06-19 10:54:31 +02:00
|
|
|
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
2019-07-08 17:01:12 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators, compose } from 'redux';
|
2020-11-04 18:37:19 +01:00
|
|
|
import { get, isEmpty } from 'lodash';
|
2020-08-31 14:14:22 +02:00
|
|
|
import { FormattedMessage, useIntl } from 'react-intl';
|
2020-11-04 11:15:11 +01:00
|
|
|
import { useHistory, useLocation } from 'react-router-dom';
|
2019-11-07 10:48:02 +01:00
|
|
|
import { Header } from '@buffetjs/custom';
|
|
|
|
import {
|
|
|
|
PopUpWarning,
|
2020-02-20 22:49:51 +01:00
|
|
|
generateFiltersFromSearch,
|
2020-02-10 16:33:29 +01:00
|
|
|
request,
|
2020-06-11 09:38:34 +02:00
|
|
|
CheckPermissions,
|
2020-11-03 17:07:56 +01:00
|
|
|
useGlobalContext,
|
2020-06-19 17:30:50 +02:00
|
|
|
useUserPermissions,
|
2020-06-22 12:59:17 +02:00
|
|
|
useQuery,
|
2019-11-07 10:48:02 +01:00
|
|
|
} from 'strapi-helper-plugin';
|
2019-07-08 17:01:12 +02:00
|
|
|
import pluginId from '../../pluginId';
|
2020-06-10 15:52:10 +02:00
|
|
|
import pluginPermissions from '../../permissions';
|
2020-11-04 18:37:19 +01:00
|
|
|
import { generatePermissionsObject, getRequestUrl, getTrad } from '../../utils';
|
2020-06-22 17:20:09 +02:00
|
|
|
|
2019-10-15 11:17:26 +02:00
|
|
|
import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown';
|
2019-07-08 20:27:38 +02:00
|
|
|
import Container from '../../components/Container';
|
2019-07-09 16:56:40 +02:00
|
|
|
import CustomTable from '../../components/CustomTable';
|
2020-11-03 17:07:56 +01:00
|
|
|
|
|
|
|
// import FilterPicker from '../../components/FilterPicker';
|
2019-07-08 20:27:38 +02:00
|
|
|
import Search from '../../components/Search';
|
2019-10-31 11:57:40 +01:00
|
|
|
import ListViewProvider from '../ListViewProvider';
|
2019-12-13 15:37:34 +01:00
|
|
|
import { AddFilterCta, FilterIcon, Wrapper } from './components';
|
2019-07-10 12:20:25 +02:00
|
|
|
import Filter from './Filter';
|
2019-07-10 08:43:40 +02:00
|
|
|
import Footer from './Footer';
|
2019-07-09 19:38:39 +02:00
|
|
|
import {
|
2020-06-22 12:59:17 +02:00
|
|
|
getData,
|
2020-02-10 16:33:29 +01:00
|
|
|
getDataSucceeded,
|
2019-07-09 19:38:39 +02:00
|
|
|
onChangeBulk,
|
|
|
|
onChangeBulkSelectall,
|
2020-07-07 17:03:16 +02:00
|
|
|
onDeleteDataError,
|
2020-02-10 16:33:29 +01:00
|
|
|
onDeleteDataSucceeded,
|
|
|
|
onDeleteSeveralDataSucceeded,
|
2019-07-09 19:38:39 +02:00
|
|
|
resetProps,
|
2020-06-22 13:53:29 +02:00
|
|
|
setModalLoadingState,
|
2019-07-10 09:12:48 +02:00
|
|
|
toggleModalDelete,
|
2019-07-09 19:38:39 +02:00
|
|
|
toggleModalDeleteAll,
|
2020-11-04 18:37:19 +01:00
|
|
|
//
|
|
|
|
setLayout,
|
|
|
|
onChangeListHeaders,
|
|
|
|
onResetListHeaders,
|
2019-07-09 19:38:39 +02:00
|
|
|
} from './actions';
|
2019-07-08 17:01:12 +02:00
|
|
|
import makeSelectListView from './selectors';
|
2020-06-19 17:30:50 +02:00
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
import { getAllAllowedHeaders, getFirstSortableHeader } from './utils';
|
|
|
|
|
2020-01-21 16:03:31 +01:00
|
|
|
/* eslint-disable react/no-array-index-key */
|
|
|
|
|
2020-11-03 17:07:56 +01:00
|
|
|
const FilterPicker = () => <div>FILTER</div>;
|
|
|
|
|
2019-07-08 17:01:12 +02:00
|
|
|
function ListView({
|
2019-07-08 20:27:38 +02:00
|
|
|
count,
|
2019-07-09 16:56:40 +02:00
|
|
|
data,
|
2020-06-22 12:59:17 +02:00
|
|
|
didDeleteData,
|
2020-11-04 18:37:19 +01:00
|
|
|
|
2019-07-09 19:38:39 +02:00
|
|
|
entriesToDelete,
|
2020-05-05 02:05:35 +02:00
|
|
|
isLoading,
|
2020-11-04 11:15:11 +01:00
|
|
|
// location: { pathname },
|
2020-06-22 12:59:17 +02:00
|
|
|
getData,
|
2020-02-10 16:33:29 +01:00
|
|
|
getDataSucceeded,
|
2020-11-04 18:37:19 +01:00
|
|
|
|
2019-07-09 19:38:39 +02:00
|
|
|
onChangeBulk,
|
|
|
|
onChangeBulkSelectall,
|
2020-07-07 17:03:16 +02:00
|
|
|
onDeleteDataError,
|
2020-02-10 16:33:29 +01:00
|
|
|
onDeleteDataSucceeded,
|
|
|
|
onDeleteSeveralDataSucceeded,
|
2020-11-04 18:37:19 +01:00
|
|
|
|
2019-07-08 20:27:38 +02:00
|
|
|
resetProps,
|
2020-06-22 13:53:29 +02:00
|
|
|
setModalLoadingState,
|
2019-07-10 09:12:48 +02:00
|
|
|
showWarningDelete,
|
2020-06-22 13:53:29 +02:00
|
|
|
showModalConfirmButtonLoading,
|
|
|
|
showWarningDeleteAll,
|
2019-10-24 17:08:52 +02:00
|
|
|
slug,
|
2019-07-10 09:12:48 +02:00
|
|
|
toggleModalDelete,
|
2019-07-09 19:38:39 +02:00
|
|
|
toggleModalDeleteAll,
|
2020-11-04 11:15:11 +01:00
|
|
|
|
|
|
|
// NEW
|
2020-11-04 18:37:19 +01:00
|
|
|
// allAllowedHeaders,
|
|
|
|
displayedHeaders,
|
2020-11-04 11:15:11 +01:00
|
|
|
layout,
|
2020-11-04 18:37:19 +01:00
|
|
|
onChangeListHeaders,
|
|
|
|
onResetListHeaders,
|
|
|
|
setLayout,
|
2019-07-08 17:01:12 +02:00
|
|
|
}) {
|
2020-11-03 17:07:56 +01:00
|
|
|
const { emitEvent } = useGlobalContext();
|
2020-06-19 17:30:50 +02:00
|
|
|
const viewPermissions = useMemo(() => generatePermissionsObject(slug), [slug]);
|
|
|
|
const {
|
|
|
|
isLoading: isLoadingForPermissions,
|
|
|
|
allowedActions: { canCreate, canRead, canUpdate, canDelete },
|
|
|
|
} = useUserPermissions(viewPermissions);
|
2020-06-22 12:59:17 +02:00
|
|
|
const query = useQuery();
|
2020-11-04 11:15:11 +01:00
|
|
|
const { pathname, search } = useLocation();
|
|
|
|
const { push } = useHistory;
|
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const isFirstRender = useRef(true);
|
2020-08-31 14:14:22 +02:00
|
|
|
const { formatMessage } = useIntl();
|
2020-11-04 18:37:19 +01:00
|
|
|
|
2019-07-09 12:31:18 +02:00
|
|
|
const [isFilterPickerOpen, setFilterPickerState] = useState(false);
|
2019-07-10 09:12:48 +02:00
|
|
|
const [idToDelete, setIdToDelete] = useState(null);
|
2020-11-04 11:15:11 +01:00
|
|
|
|
|
|
|
const contentType = layout.contentType;
|
|
|
|
const {
|
2020-11-04 18:37:19 +01:00
|
|
|
contentType: {
|
|
|
|
attributes,
|
|
|
|
settings: {
|
|
|
|
defaultSortBy,
|
|
|
|
defaultSortOrder,
|
|
|
|
bulkable: isBulkable,
|
|
|
|
filterable: isFilterable,
|
|
|
|
searchable: isSearchable,
|
|
|
|
pageSize,
|
|
|
|
// mainField,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} = layout;
|
|
|
|
|
2020-11-04 11:15:11 +01:00
|
|
|
const hasDraftAndPublish = contentType.options.draftAndPublish;
|
|
|
|
const defaultSort = `${defaultSortBy}:${defaultSortOrder}`;
|
2020-11-04 18:37:19 +01:00
|
|
|
const allAllowedHeaders = getAllAllowedHeaders(attributes);
|
2020-06-22 12:59:17 +02:00
|
|
|
|
|
|
|
const filters = useMemo(() => {
|
|
|
|
const currentSearch = new URLSearchParams(search);
|
|
|
|
|
|
|
|
// Delete all params that are not related to the filters
|
|
|
|
const paramsToDelete = ['_limit', '_page', '_sort', '_q'];
|
|
|
|
|
|
|
|
for (let i = 0; i < paramsToDelete.length; i++) {
|
|
|
|
currentSearch.delete(paramsToDelete[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return generateFiltersFromSearch(currentSearch.toString());
|
|
|
|
}, [search]);
|
2020-11-04 11:15:11 +01:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
const _limit = pageSize;
|
|
|
|
// const _limit = useMemo(() => {
|
|
|
|
// return parseInt(query.get('_limit') || pageSize, 10);
|
|
|
|
// }, [pageSize, query]);
|
|
|
|
// TODO
|
|
|
|
const _q = query.get('_q') || '';
|
|
|
|
// TODO
|
|
|
|
const _page = parseInt(query.get('_page') || 1, 10);
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
const _sort = query.get('_sort') || defaultSort;
|
2020-11-04 18:37:19 +01:00
|
|
|
const label = contentType.info.label;
|
2020-11-04 11:15:11 +01:00
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const _start = useMemo(() => {
|
|
|
|
return (_page - 1) * parseInt(_limit, 10);
|
|
|
|
}, [_limit, _page]);
|
2020-11-04 11:15:11 +01:00
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const searchToSendForRequest = useMemo(() => {
|
|
|
|
const currentSearch = new URLSearchParams(search);
|
|
|
|
|
|
|
|
currentSearch.set('_limit', _limit);
|
|
|
|
currentSearch.set('_sort', _sort);
|
|
|
|
currentSearch.set('_start', _start);
|
|
|
|
currentSearch.delete('_page');
|
|
|
|
|
|
|
|
return currentSearch.toString();
|
|
|
|
}, [_limit, _sort, _start, search]);
|
|
|
|
|
|
|
|
const getDataActionRef = useRef(getData);
|
|
|
|
const getDataSucceededRef = useRef(getDataSucceeded);
|
|
|
|
|
|
|
|
const shouldSendRequest = useMemo(() => {
|
|
|
|
return !isLoadingForPermissions && canRead;
|
|
|
|
}, [canRead, isLoadingForPermissions]);
|
|
|
|
|
|
|
|
const fetchData = async (search = searchToSendForRequest) => {
|
2020-02-10 16:33:29 +01:00
|
|
|
try {
|
2020-11-04 18:37:19 +01:00
|
|
|
// getDataActionRef.current();
|
|
|
|
// const [{ count }, data] = await Promise.all([
|
|
|
|
// request(getRequestUrl(`explorer/${slug}/count?${search}`), {
|
|
|
|
// method: 'GET',
|
|
|
|
// }),
|
|
|
|
// request(getRequestUrl(`explorer/${slug}?${search}`), {
|
|
|
|
// method: 'GET',
|
|
|
|
// }),
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// const c = await request(getRequestUrl(`collection-types/${slug}?${search}`));
|
|
|
|
// console.log({ c });
|
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
id: 16,
|
|
|
|
postal_coder: 'kkkk',
|
|
|
|
city: 'kljkojihv',
|
|
|
|
created_by: {
|
|
|
|
id: 1,
|
|
|
|
firstname: 'cyril',
|
|
|
|
lastname: 'lopez',
|
|
|
|
username: null,
|
|
|
|
email: 'cyril@strapi.io',
|
|
|
|
resetPasswordToken: null,
|
|
|
|
registrationToken: null,
|
|
|
|
isActive: true,
|
|
|
|
blocked: null,
|
|
|
|
},
|
|
|
|
updated_by: {
|
|
|
|
id: 1,
|
|
|
|
firstname: 'cyril',
|
|
|
|
lastname: 'lopez',
|
|
|
|
username: null,
|
|
|
|
email: 'cyril@strapi.io',
|
|
|
|
resetPasswordToken: null,
|
|
|
|
registrationToken: null,
|
|
|
|
isActive: true,
|
|
|
|
blocked: null,
|
|
|
|
},
|
|
|
|
created_at: '2020-10-28T09:03:20.905Z',
|
|
|
|
updated_at: '2020-10-28T13:51:35.381Z',
|
|
|
|
published_at: '2020-10-28T13:51:35.351Z',
|
|
|
|
cover: null,
|
|
|
|
images: [],
|
|
|
|
categories: [],
|
|
|
|
likes: [],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
getDataSucceededRef.current(1, data);
|
2020-02-10 16:33:29 +01:00
|
|
|
} catch (err) {
|
|
|
|
strapi.notification.error(`${pluginId}.error.model.fetch`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
useEffect(() => {
|
|
|
|
// TODO
|
|
|
|
console.log('up');
|
|
|
|
setLayout(layout);
|
|
|
|
}, [layout, setLayout]);
|
2019-07-08 20:27:38 +02:00
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
const firstSortableHeader = useMemo(() => getFirstSortableHeader(displayedHeaders), [
|
|
|
|
displayedHeaders,
|
|
|
|
]);
|
2020-06-22 12:59:17 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
isFirstRender.current = true;
|
|
|
|
};
|
|
|
|
}, [slug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isFirstRender.current) {
|
|
|
|
fetchData(searchToSendForRequest);
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [searchToSendForRequest]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
resetProps();
|
|
|
|
setFilterPickerState(false);
|
|
|
|
};
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [slug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (shouldSendRequest) {
|
|
|
|
fetchData();
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
isFirstRender.current = false;
|
|
|
|
};
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [shouldSendRequest]);
|
2020-02-10 16:33:29 +01:00
|
|
|
|
|
|
|
const handleConfirmDeleteData = useCallback(async () => {
|
|
|
|
try {
|
2020-10-02 18:20:53 +02:00
|
|
|
let trackerProperty = {};
|
2020-10-01 17:12:51 +02:00
|
|
|
|
|
|
|
if (hasDraftAndPublish) {
|
|
|
|
const dataToDelete = data.find(obj => obj.id.toString() === idToDelete.toString());
|
|
|
|
const isDraftEntry = isEmpty(dataToDelete.published_at);
|
|
|
|
const status = isDraftEntry ? 'draft' : 'published';
|
|
|
|
|
2020-10-02 18:20:53 +02:00
|
|
|
trackerProperty = { status };
|
2020-10-01 17:12:51 +02:00
|
|
|
}
|
|
|
|
|
2020-10-02 18:20:53 +02:00
|
|
|
emitEvent('willDeleteEntry', trackerProperty);
|
2020-06-22 13:53:29 +02:00
|
|
|
setModalLoadingState();
|
2020-02-10 16:33:29 +01:00
|
|
|
|
|
|
|
await request(getRequestUrl(`explorer/${slug}/${idToDelete}`), {
|
|
|
|
method: 'DELETE',
|
|
|
|
});
|
|
|
|
|
|
|
|
strapi.notification.success(`${pluginId}.success.record.delete`);
|
|
|
|
|
|
|
|
// Close the modal and refetch data
|
|
|
|
onDeleteDataSucceeded();
|
2020-10-02 18:20:53 +02:00
|
|
|
emitEvent('didDeleteEntry', trackerProperty);
|
2020-02-10 16:33:29 +01:00
|
|
|
} catch (err) {
|
2020-07-07 17:03:16 +02:00
|
|
|
const errorMessage = get(
|
|
|
|
err,
|
|
|
|
'response.payload.message',
|
|
|
|
formatMessage({ id: `${pluginId}.error.record.delete` })
|
|
|
|
);
|
|
|
|
|
|
|
|
strapi.notification.error(errorMessage);
|
|
|
|
// Close the modal
|
|
|
|
onDeleteDataError();
|
2020-02-10 16:33:29 +01:00
|
|
|
}
|
2020-07-07 17:03:16 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-10-01 17:12:51 +02:00
|
|
|
}, [setModalLoadingState, slug, idToDelete, onDeleteDataSucceeded, hasDraftAndPublish, data]);
|
2020-02-10 16:33:29 +01:00
|
|
|
|
|
|
|
const handleConfirmDeleteAllData = useCallback(async () => {
|
|
|
|
const params = Object.assign(entriesToDelete);
|
|
|
|
|
|
|
|
try {
|
2020-06-22 13:53:29 +02:00
|
|
|
setModalLoadingState();
|
|
|
|
|
2020-02-10 16:33:29 +01:00
|
|
|
await request(getRequestUrl(`explorer/deleteAll/${slug}`), {
|
|
|
|
method: 'DELETE',
|
|
|
|
params,
|
|
|
|
});
|
|
|
|
|
|
|
|
onDeleteSeveralDataSucceeded();
|
|
|
|
} catch (err) {
|
|
|
|
strapi.notification.error(`${pluginId}.error.record.delete`);
|
|
|
|
}
|
2020-06-22 13:53:29 +02:00
|
|
|
}, [entriesToDelete, onDeleteSeveralDataSucceeded, slug, setModalLoadingState]);
|
2020-02-10 16:33:29 +01:00
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
const handleChangeListLabels = useCallback(
|
|
|
|
({ name, value }) => {
|
|
|
|
// const currentSort = _sort;
|
|
|
|
// // Display a notification if trying to remove the last displayed field
|
|
|
|
if (value && displayedHeaders.length === 1) {
|
|
|
|
strapi.notification.error('content-manager.notification.error.displayedFields');
|
2019-07-09 16:56:40 +02:00
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-11-26 10:39:26 +01:00
|
|
|
|
2020-11-04 18:37:19 +01:00
|
|
|
// TODO
|
|
|
|
// // Update the sort when removing the displayed one
|
|
|
|
// if (currentSort.split(':')[0] === name && value) {
|
|
|
|
// emitEvent('didChangeDisplayedFields');
|
|
|
|
// handleChangeSearch({
|
|
|
|
// target: {
|
|
|
|
// name: '_sort',
|
|
|
|
// value: `${firstSortableHeader}:ASC`,
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
onChangeListHeaders({ name, value });
|
|
|
|
},
|
|
|
|
[displayedHeaders, onChangeListHeaders]
|
|
|
|
);
|
2019-07-09 18:11:09 +02:00
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const handleChangeFilters = ({ target: { value } }) => {
|
|
|
|
const newSearch = new URLSearchParams();
|
|
|
|
|
|
|
|
// Set the default params
|
|
|
|
newSearch.set('_limit', _limit);
|
|
|
|
newSearch.set('_sort', _sort);
|
|
|
|
newSearch.set('_page', 1);
|
|
|
|
|
|
|
|
value.forEach(({ filter, name, value: filterValue }) => {
|
|
|
|
const filterType = filter === '=' ? '' : filter;
|
|
|
|
const filterName = `${name}${filterType}`;
|
|
|
|
|
|
|
|
newSearch.append(filterName, filterValue);
|
|
|
|
});
|
2019-07-09 18:11:09 +02:00
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
push({ search: newSearch.toString() });
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleChangeSearch = async ({ target: { name, value } }) => {
|
|
|
|
const currentSearch = new URLSearchParams(searchToSendForRequest);
|
|
|
|
|
|
|
|
// Pagination
|
|
|
|
currentSearch.delete('_start');
|
|
|
|
|
|
|
|
if (value === '') {
|
|
|
|
currentSearch.delete(name);
|
|
|
|
} else {
|
|
|
|
currentSearch.set(name, value);
|
2019-07-10 08:43:40 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const searchToString = currentSearch.toString();
|
|
|
|
|
|
|
|
push({ search: searchToString });
|
2019-07-09 18:11:09 +02:00
|
|
|
};
|
2020-06-19 10:54:31 +02:00
|
|
|
|
2019-07-10 09:12:48 +02:00
|
|
|
const handleClickDelete = id => {
|
|
|
|
setIdToDelete(id);
|
|
|
|
toggleModalDelete();
|
|
|
|
};
|
2020-06-19 10:54:31 +02:00
|
|
|
|
2020-06-22 12:59:17 +02:00
|
|
|
const handleModalClose = () => {
|
|
|
|
if (didDeleteData) {
|
|
|
|
fetchData();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-10 17:31:49 +02:00
|
|
|
const handleSubmit = (filters = []) => {
|
2019-07-09 18:11:09 +02:00
|
|
|
emitEvent('didFilterEntries');
|
|
|
|
toggleFilterPickerState();
|
2020-06-22 12:59:17 +02:00
|
|
|
handleChangeFilters({ target: { name: 'filters', value: filters } });
|
|
|
|
};
|
|
|
|
|
|
|
|
const toggleFilterPickerState = () => {
|
|
|
|
if (!isFilterPickerOpen) {
|
|
|
|
emitEvent('willFilterEntries');
|
|
|
|
}
|
|
|
|
|
|
|
|
setFilterPickerState(prevState => !prevState);
|
|
|
|
};
|
|
|
|
|
2019-07-09 12:31:18 +02:00
|
|
|
const filterPickerActions = [
|
|
|
|
{
|
|
|
|
label: `${pluginId}.components.FiltersPickWrapper.PluginHeader.actions.clearAll`,
|
|
|
|
kind: 'secondary',
|
|
|
|
onClick: () => {
|
|
|
|
toggleFilterPickerState();
|
2020-06-22 12:59:17 +02:00
|
|
|
// Delete all filters
|
|
|
|
handleChangeFilters({ target: { name: 'filters', value: [] } });
|
2019-07-09 12:31:18 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: `${pluginId}.components.FiltersPickWrapper.PluginHeader.actions.apply`,
|
|
|
|
kind: 'primary',
|
|
|
|
type: 'submit',
|
|
|
|
},
|
|
|
|
];
|
2019-11-06 12:06:17 +01:00
|
|
|
|
2020-06-19 10:54:31 +02:00
|
|
|
const headerAction = useMemo(
|
2020-06-19 17:30:50 +02:00
|
|
|
() => {
|
|
|
|
if (!canCreate) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: formatMessage(
|
|
|
|
{
|
|
|
|
id: 'content-manager.containers.List.addAnEntry',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
entity: label || 'Content Manager',
|
|
|
|
}
|
|
|
|
),
|
|
|
|
onClick: () => {
|
2020-10-02 18:20:53 +02:00
|
|
|
const trackerProperty = hasDraftAndPublish ? { status: 'draft' } : {};
|
2020-10-01 17:12:51 +02:00
|
|
|
|
2020-10-02 18:20:53 +02:00
|
|
|
emitEvent('willCreateEntry', trackerProperty);
|
2020-06-19 17:30:50 +02:00
|
|
|
push({
|
|
|
|
pathname: `${pathname}/create`,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
color: 'primary',
|
|
|
|
type: 'button',
|
|
|
|
icon: true,
|
|
|
|
style: {
|
|
|
|
paddingLeft: 15,
|
|
|
|
paddingRight: 15,
|
|
|
|
fontWeight: 600,
|
2020-06-19 10:54:31 +02:00
|
|
|
},
|
2019-11-07 10:48:02 +01:00
|
|
|
},
|
2020-06-19 17:30:50 +02:00
|
|
|
];
|
|
|
|
},
|
2020-06-19 10:54:31 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-10-01 17:12:51 +02:00
|
|
|
[label, pathname, search, canCreate, formatMessage, hasDraftAndPublish]
|
2020-06-19 10:54:31 +02:00
|
|
|
);
|
2019-07-09 16:56:40 +02:00
|
|
|
|
2020-06-19 10:54:31 +02:00
|
|
|
const headerProps = useMemo(() => {
|
2020-06-19 17:30:50 +02:00
|
|
|
/* eslint-disable indent */
|
2020-06-19 10:54:31 +02:00
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
label: label || 'Content Manager',
|
2019-11-07 10:48:02 +01:00
|
|
|
},
|
2020-06-19 17:30:50 +02:00
|
|
|
content: canRead
|
|
|
|
? formatMessage(
|
|
|
|
{
|
|
|
|
id:
|
|
|
|
count > 1
|
|
|
|
? `${pluginId}.containers.List.pluginHeaderDescription`
|
|
|
|
: `${pluginId}.containers.List.pluginHeaderDescription.singular`,
|
|
|
|
},
|
|
|
|
{ label: count }
|
|
|
|
)
|
|
|
|
: null,
|
2020-06-19 10:54:31 +02:00
|
|
|
actions: headerAction,
|
|
|
|
};
|
2020-06-19 17:30:50 +02:00
|
|
|
/* eslint-enable indent */
|
2020-07-08 17:29:35 +02:00
|
|
|
}, [count, headerAction, label, canRead, formatMessage]);
|
2019-11-06 12:06:17 +01:00
|
|
|
|
2019-07-08 17:01:12 +02:00
|
|
|
return (
|
2019-07-08 20:27:38 +02:00
|
|
|
<>
|
2019-07-09 18:11:09 +02:00
|
|
|
<ListViewProvider
|
2019-07-09 19:38:39 +02:00
|
|
|
data={data}
|
2019-07-10 08:43:40 +02:00
|
|
|
count={count}
|
2019-07-09 19:38:39 +02:00
|
|
|
entriesToDelete={entriesToDelete}
|
2019-07-10 11:12:30 +02:00
|
|
|
emitEvent={emitEvent}
|
2020-06-19 10:54:31 +02:00
|
|
|
label={label}
|
2019-07-09 19:38:39 +02:00
|
|
|
onChangeBulk={onChangeBulk}
|
|
|
|
onChangeBulkSelectall={onChangeBulkSelectall}
|
2020-06-22 12:59:17 +02:00
|
|
|
onChangeSearch={handleChangeSearch}
|
2019-07-10 09:12:48 +02:00
|
|
|
onClickDelete={handleClickDelete}
|
2020-11-04 18:37:19 +01:00
|
|
|
// schema={listSchema}
|
|
|
|
schema={{}}
|
2019-07-09 18:11:09 +02:00
|
|
|
slug={slug}
|
2019-07-09 19:38:39 +02:00
|
|
|
toggleModalDeleteAll={toggleModalDeleteAll}
|
2020-06-22 12:59:17 +02:00
|
|
|
_limit={_limit}
|
|
|
|
_page={_page}
|
|
|
|
filters={filters}
|
|
|
|
_q={_q}
|
|
|
|
_sort={_sort}
|
2020-11-04 18:37:19 +01:00
|
|
|
// to keep
|
|
|
|
firstSortableHeader={firstSortableHeader}
|
2019-07-09 18:11:09 +02:00
|
|
|
>
|
|
|
|
<FilterPicker
|
|
|
|
actions={filterPickerActions}
|
|
|
|
isOpen={isFilterPickerOpen}
|
2020-06-19 10:54:31 +02:00
|
|
|
name={label}
|
2019-07-10 17:31:49 +02:00
|
|
|
toggleFilterPickerState={toggleFilterPickerState}
|
2019-07-09 18:11:09 +02:00
|
|
|
onSubmit={handleSubmit}
|
|
|
|
/>
|
|
|
|
<Container className="container-fluid">
|
2020-06-19 17:30:50 +02:00
|
|
|
{!isFilterPickerOpen && <Header {...headerProps} isLoading={isLoading && canRead} />}
|
2020-06-22 12:59:17 +02:00
|
|
|
{isSearchable && canRead && (
|
|
|
|
<Search changeParams={handleChangeSearch} initValue={_q} model={label} value={_q} />
|
2019-07-09 18:11:09 +02:00
|
|
|
)}
|
2020-06-19 17:30:50 +02:00
|
|
|
{canRead && (
|
|
|
|
<Wrapper>
|
|
|
|
<div className="row" style={{ marginBottom: '5px' }}>
|
|
|
|
<div className="col-10">
|
|
|
|
<div className="row" style={{ marginLeft: 0, marginRight: 0 }}>
|
2020-06-22 12:59:17 +02:00
|
|
|
{isFilterable && (
|
2020-06-19 17:30:50 +02:00
|
|
|
<>
|
|
|
|
<AddFilterCta type="button" onClick={toggleFilterPickerState}>
|
|
|
|
<FilterIcon />
|
|
|
|
<FormattedMessage id="app.utils.filters" />
|
|
|
|
</AddFilterCta>
|
2020-06-22 12:59:17 +02:00
|
|
|
{filters.map((filter, key) => (
|
2020-06-19 17:30:50 +02:00
|
|
|
<Filter
|
|
|
|
{...filter}
|
2020-06-22 12:59:17 +02:00
|
|
|
changeParams={handleChangeFilters}
|
|
|
|
filters={filters}
|
2020-06-19 17:30:50 +02:00
|
|
|
index={key}
|
2020-11-04 18:37:19 +01:00
|
|
|
schema={{}}
|
2020-06-19 17:30:50 +02:00
|
|
|
key={key}
|
|
|
|
toggleFilterPickerState={toggleFilterPickerState}
|
|
|
|
isFilterPickerOpen={isFilterPickerOpen}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-2">
|
|
|
|
<CheckPermissions permissions={pluginPermissions.collectionTypesConfigurations}>
|
|
|
|
<DisplayedFieldsDropdown
|
2020-11-04 18:37:19 +01:00
|
|
|
displayedHeaders={displayedHeaders}
|
|
|
|
items={allAllowedHeaders}
|
|
|
|
// items={allAllowedHeaders}
|
2020-06-19 17:30:50 +02:00
|
|
|
onChange={handleChangeListLabels}
|
2020-11-04 18:37:19 +01:00
|
|
|
onClickReset={onResetListHeaders}
|
2020-06-19 17:30:50 +02:00
|
|
|
slug={slug}
|
|
|
|
/>
|
|
|
|
</CheckPermissions>
|
2019-07-10 12:20:25 +02:00
|
|
|
</div>
|
2019-07-09 18:11:09 +02:00
|
|
|
</div>
|
2020-06-19 17:30:50 +02:00
|
|
|
<div className="row" style={{ paddingTop: '12px' }}>
|
|
|
|
<div className="col-12">
|
|
|
|
<CustomTable
|
|
|
|
data={data}
|
|
|
|
canDelete={canDelete}
|
|
|
|
canUpdate={canUpdate}
|
2020-11-04 18:37:19 +01:00
|
|
|
displayedHeaders={displayedHeaders}
|
|
|
|
hasDraftAndPublish={hasDraftAndPublish}
|
2020-06-22 12:59:17 +02:00
|
|
|
isBulkable={isBulkable}
|
|
|
|
onChangeParams={handleChangeSearch}
|
2020-06-19 17:30:50 +02:00
|
|
|
showLoader={isLoading}
|
2020-06-10 15:52:10 +02:00
|
|
|
/>
|
2020-06-19 17:30:50 +02:00
|
|
|
<Footer />
|
|
|
|
</div>
|
2019-07-09 18:11:09 +02:00
|
|
|
</div>
|
2020-06-19 17:30:50 +02:00
|
|
|
</Wrapper>
|
|
|
|
)}
|
2019-07-09 18:11:09 +02:00
|
|
|
</Container>
|
2019-07-10 09:12:48 +02:00
|
|
|
<PopUpWarning
|
|
|
|
isOpen={showWarningDelete}
|
|
|
|
toggleModal={toggleModalDelete}
|
|
|
|
content={{
|
2020-09-03 15:38:33 +02:00
|
|
|
message: getTrad('popUpWarning.bodyMessage.contentType.delete'),
|
2019-07-10 09:12:48 +02:00
|
|
|
}}
|
2020-02-10 16:33:29 +01:00
|
|
|
onConfirm={handleConfirmDeleteData}
|
2019-07-10 09:12:48 +02:00
|
|
|
popUpWarningType="danger"
|
2020-06-22 12:59:17 +02:00
|
|
|
onClosed={handleModalClose}
|
2020-06-22 13:53:29 +02:00
|
|
|
isConfirmButtonLoading={showModalConfirmButtonLoading}
|
2019-07-10 09:12:48 +02:00
|
|
|
/>
|
2019-07-09 19:38:39 +02:00
|
|
|
<PopUpWarning
|
|
|
|
isOpen={showWarningDeleteAll}
|
|
|
|
toggleModal={toggleModalDeleteAll}
|
|
|
|
content={{
|
2020-09-03 15:38:33 +02:00
|
|
|
message: getTrad(
|
|
|
|
`popUpWarning.bodyMessage.contentType.delete${
|
|
|
|
entriesToDelete.length > 1 ? '.all' : ''
|
|
|
|
}`
|
|
|
|
),
|
2019-07-09 19:38:39 +02:00
|
|
|
}}
|
|
|
|
popUpWarningType="danger"
|
2020-02-10 16:33:29 +01:00
|
|
|
onConfirm={handleConfirmDeleteAllData}
|
2020-06-22 12:59:17 +02:00
|
|
|
onClosed={handleModalClose}
|
2020-06-22 13:53:29 +02:00
|
|
|
isConfirmButtonLoading={showModalConfirmButtonLoading}
|
2019-07-09 19:38:39 +02:00
|
|
|
/>
|
2019-07-09 18:11:09 +02:00
|
|
|
</ListViewProvider>
|
2019-07-08 20:27:38 +02:00
|
|
|
</>
|
2019-07-08 17:01:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
ListView.defaultProps = {
|
2020-11-04 11:15:11 +01:00
|
|
|
// layouts: {},
|
2019-07-08 17:01:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ListView.propTypes = {
|
2020-11-04 18:37:19 +01:00
|
|
|
// allAllowedHeaders: PropTypes.array.isRequired,
|
|
|
|
displayedHeaders: PropTypes.array.isRequired,
|
2020-11-04 11:15:11 +01:00
|
|
|
layout: PropTypes.exact({
|
|
|
|
components: PropTypes.object.isRequired,
|
|
|
|
contentType: PropTypes.shape({
|
2020-11-04 18:37:19 +01:00
|
|
|
attributes: PropTypes.object.isRequired,
|
|
|
|
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
|
|
|
layouts: PropTypes.shape({
|
|
|
|
list: PropTypes.array.isRequired,
|
|
|
|
}).isRequired,
|
2020-11-04 11:15:11 +01:00
|
|
|
options: PropTypes.object.isRequired,
|
|
|
|
settings: PropTypes.object.isRequired,
|
|
|
|
}).isRequired,
|
2020-01-21 16:03:31 +01:00
|
|
|
}).isRequired,
|
2020-11-04 11:15:11 +01:00
|
|
|
// count: PropTypes.number.isRequired,
|
|
|
|
// data: PropTypes.array.isRequired,
|
|
|
|
// didDeleteData: PropTypes.bool.isRequired,
|
|
|
|
// // emitEvent: PropTypes.func.isRequired,
|
|
|
|
// entriesToDelete: PropTypes.array.isRequired,
|
|
|
|
// isLoading: PropTypes.bool.isRequired,
|
|
|
|
// layouts: PropTypes.object,
|
|
|
|
// location: PropTypes.shape({
|
|
|
|
// pathname: PropTypes.string.isRequired,
|
|
|
|
// search: PropTypes.string.isRequired,
|
|
|
|
// }).isRequired,
|
|
|
|
// // models: PropTypes.array.isRequired,
|
|
|
|
// getData: PropTypes.func.isRequired,
|
|
|
|
// getDataSucceeded: PropTypes.func.isRequired,
|
|
|
|
// history: PropTypes.shape({
|
|
|
|
// push: PropTypes.func.isRequired,
|
|
|
|
// }).isRequired,
|
|
|
|
// onChangeBulk: PropTypes.func.isRequired,
|
|
|
|
// onChangeBulkSelectall: PropTypes.func.isRequired,
|
2020-11-04 18:37:19 +01:00
|
|
|
onChangeListHeaders: PropTypes.func.isRequired,
|
2020-11-04 11:15:11 +01:00
|
|
|
// onDeleteDataError: PropTypes.func.isRequired,
|
|
|
|
// onDeleteDataSucceeded: PropTypes.func.isRequired,
|
|
|
|
// onDeleteSeveralDataSucceeded: PropTypes.func.isRequired,
|
2020-11-04 18:37:19 +01:00
|
|
|
onResetListHeaders: PropTypes.func.isRequired,
|
2020-11-04 11:15:11 +01:00
|
|
|
// resetProps: PropTypes.func.isRequired,
|
|
|
|
// setModalLoadingState: PropTypes.func.isRequired,
|
|
|
|
// showModalConfirmButtonLoading: PropTypes.bool.isRequired,
|
|
|
|
// showWarningDelete: PropTypes.bool.isRequired,
|
|
|
|
// showWarningDeleteAll: PropTypes.bool.isRequired,
|
|
|
|
// slug: PropTypes.string.isRequired,
|
|
|
|
// toggleModalDelete: PropTypes.func.isRequired,
|
|
|
|
// toggleModalDeleteAll: PropTypes.func.isRequired,
|
2020-11-04 18:37:19 +01:00
|
|
|
setLayout: PropTypes.func.isRequired,
|
2019-07-08 17:01:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = makeSelectListView();
|
|
|
|
|
|
|
|
export function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(
|
|
|
|
{
|
2020-06-22 12:59:17 +02:00
|
|
|
getData,
|
2020-02-10 16:33:29 +01:00
|
|
|
getDataSucceeded,
|
2019-07-09 19:38:39 +02:00
|
|
|
onChangeBulk,
|
|
|
|
onChangeBulkSelectall,
|
2020-11-04 18:37:19 +01:00
|
|
|
onChangeListHeaders,
|
2020-07-07 17:03:16 +02:00
|
|
|
onDeleteDataError,
|
2020-02-10 16:33:29 +01:00
|
|
|
onDeleteDataSucceeded,
|
|
|
|
onDeleteSeveralDataSucceeded,
|
2020-11-04 18:37:19 +01:00
|
|
|
onResetListHeaders,
|
2019-07-08 20:27:38 +02:00
|
|
|
resetProps,
|
2020-06-22 13:53:29 +02:00
|
|
|
setModalLoadingState,
|
2019-07-10 09:12:48 +02:00
|
|
|
toggleModalDelete,
|
2019-07-09 19:38:39 +02:00
|
|
|
toggleModalDeleteAll,
|
2020-11-04 18:37:19 +01:00
|
|
|
setLayout,
|
2019-07-08 17:01:12 +02:00
|
|
|
},
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
}
|
2020-02-13 11:17:32 +01:00
|
|
|
const withConnect = connect(mapStateToProps, mapDispatchToProps);
|
2019-07-08 17:01:12 +02:00
|
|
|
|
2020-02-13 11:17:32 +01:00
|
|
|
export default compose(withConnect, memo)(ListView);
|