mirror of
https://github.com/strapi/strapi.git
synced 2025-09-02 21:32:43 +00:00
Created DynamicTable component
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
parent
e318705ba0
commit
16d2b4dc6d
@ -0,0 +1,54 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { DynamicTable as Table, useStrapiApp } from '@strapi/helper-plugin';
|
||||||
|
import { INJECT_COLUMN_IN_TABLE } from '../../../exposedHooks';
|
||||||
|
|
||||||
|
const DynamicTable = ({ canDelete, contentTypeName, isLoading, layout, rows }) => {
|
||||||
|
const { runHookWaterfall } = useStrapiApp();
|
||||||
|
|
||||||
|
const tableHeaders = useMemo(() => {
|
||||||
|
const headers = runHookWaterfall(INJECT_COLUMN_IN_TABLE, {
|
||||||
|
displayedHeaders: layout.contentType.layouts.list,
|
||||||
|
layout,
|
||||||
|
});
|
||||||
|
|
||||||
|
return headers.displayedHeaders;
|
||||||
|
}, [runHookWaterfall, layout]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Table
|
||||||
|
contentType={contentTypeName}
|
||||||
|
isLoading={isLoading}
|
||||||
|
headers={tableHeaders}
|
||||||
|
// rows={data}
|
||||||
|
rows={rows}
|
||||||
|
withBulkActions
|
||||||
|
withMainAction={canDelete}
|
||||||
|
>
|
||||||
|
{/* TODO */}
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
DynamicTable.propTypes = {
|
||||||
|
canDelete: PropTypes.bool.isRequired,
|
||||||
|
contentTypeName: PropTypes.string.isRequired,
|
||||||
|
isLoading: PropTypes.bool.isRequired,
|
||||||
|
layout: PropTypes.exact({
|
||||||
|
components: PropTypes.object.isRequired,
|
||||||
|
contentType: PropTypes.shape({
|
||||||
|
attributes: PropTypes.object.isRequired,
|
||||||
|
metadatas: PropTypes.object.isRequired,
|
||||||
|
info: PropTypes.shape({ label: PropTypes.string.isRequired }).isRequired,
|
||||||
|
layouts: PropTypes.shape({
|
||||||
|
list: PropTypes.array.isRequired,
|
||||||
|
editRelations: PropTypes.array,
|
||||||
|
}).isRequired,
|
||||||
|
options: PropTypes.object.isRequired,
|
||||||
|
settings: PropTypes.object.isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
rows: PropTypes.array.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DynamicTable;
|
@ -1,4 +1,4 @@
|
|||||||
import React, { memo, useCallback, useEffect, useMemo, useRef } from 'react';
|
import React, { memo, useCallback, useEffect, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
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';
|
||||||
@ -12,7 +12,7 @@ import { useHistory, useLocation } from 'react-router-dom';
|
|||||||
import isEqual from 'react-fast-compare';
|
import isEqual from 'react-fast-compare';
|
||||||
import { stringify } from 'qs';
|
import { stringify } from 'qs';
|
||||||
import {
|
import {
|
||||||
DynamicTable,
|
// DynamicTable,
|
||||||
NoPermissions,
|
NoPermissions,
|
||||||
// CheckPermissions,
|
// CheckPermissions,
|
||||||
// PopUpWarning,
|
// PopUpWarning,
|
||||||
@ -20,7 +20,6 @@ import {
|
|||||||
useQueryParams,
|
useQueryParams,
|
||||||
useNotification,
|
useNotification,
|
||||||
useRBACProvider,
|
useRBACProvider,
|
||||||
useStrapiApp,
|
|
||||||
useTracking,
|
useTracking,
|
||||||
} from '@strapi/helper-plugin';
|
} from '@strapi/helper-plugin';
|
||||||
import { Main } from '@strapi/parts/Main';
|
import { Main } from '@strapi/parts/Main';
|
||||||
@ -31,7 +30,7 @@ import Add from '@strapi/icons/Add';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { axiosInstance } from '../../../core/utils';
|
import { axiosInstance } from '../../../core/utils';
|
||||||
// import { InjectionZone } from '../../../shared/components';
|
// import { InjectionZone } from '../../../shared/components';
|
||||||
import { INJECT_COLUMN_IN_TABLE } from '../../../exposedHooks';
|
import DynamicTable from '../../components/DynamicTable';
|
||||||
// import permissions from '../../../permissions';
|
// import permissions from '../../../permissions';
|
||||||
import {
|
import {
|
||||||
// formatFiltersFromQuery,
|
// formatFiltersFromQuery,
|
||||||
@ -92,7 +91,6 @@ function ListView({
|
|||||||
// toggleModalDelete,
|
// toggleModalDelete,
|
||||||
// toggleModalDeleteAll,
|
// toggleModalDeleteAll,
|
||||||
data,
|
data,
|
||||||
displayedHeaders,
|
|
||||||
getData,
|
getData,
|
||||||
getDataSucceeded,
|
getDataSucceeded,
|
||||||
isLoading,
|
isLoading,
|
||||||
@ -109,7 +107,7 @@ function ListView({
|
|||||||
// // settings: { bulkable: isBulkable, filterable: isFilterable, searchable: isSearchable },
|
// // settings: { bulkable: isBulkable, filterable: isFilterable, searchable: isSearchable },
|
||||||
// },
|
// },
|
||||||
// } = layout;
|
// } = layout;
|
||||||
console.log({ data });
|
|
||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const { trackUsage } = useTracking();
|
const { trackUsage } = useTracking();
|
||||||
const { refetchPermissions } = useRBACProvider();
|
const { refetchPermissions } = useRBACProvider();
|
||||||
@ -119,13 +117,13 @@ function ListView({
|
|||||||
|
|
||||||
useFocusWhenNavigate();
|
useFocusWhenNavigate();
|
||||||
|
|
||||||
const { runHookWaterfall } = useStrapiApp();
|
// const { runHookWaterfall } = useStrapiApp();
|
||||||
|
|
||||||
const tableHeaders = useMemo(() => {
|
// const tableHeaders = useMemo(() => {
|
||||||
const headers = runHookWaterfall(INJECT_COLUMN_IN_TABLE, { displayedHeaders, layout });
|
// const headers = runHookWaterfall(INJECT_COLUMN_IN_TABLE, { displayedHeaders, layout });
|
||||||
|
|
||||||
return headers.displayedHeaders;
|
// return headers.displayedHeaders;
|
||||||
}, [runHookWaterfall, displayedHeaders, layout]);
|
// }, [runHookWaterfall, displayedHeaders, layout]);
|
||||||
|
|
||||||
// const [{ query }, setQuery] = useQueryParams();
|
// const [{ query }, setQuery] = useQueryParams();
|
||||||
const [{ query }] = useQueryParams();
|
const [{ query }] = useQueryParams();
|
||||||
@ -139,6 +137,7 @@ function ListView({
|
|||||||
// const [idToDelete, setIdToDelete] = useState(null);
|
// const [idToDelete, setIdToDelete] = useState(null);
|
||||||
const contentType = layout.contentType;
|
const contentType = layout.contentType;
|
||||||
const hasDraftAndPublish = get(contentType, 'options.draftAndPublish', false);
|
const hasDraftAndPublish = get(contentType, 'options.draftAndPublish', false);
|
||||||
|
// TODO
|
||||||
// const allAllowedHeaders = useMemo(() => getAllAllowedHeaders(attributes), [attributes]);
|
// const allAllowedHeaders = useMemo(() => getAllAllowedHeaders(attributes), [attributes]);
|
||||||
|
|
||||||
// const filters = useMemo(() => {
|
// const filters = useMemo(() => {
|
||||||
@ -148,10 +147,6 @@ function ListView({
|
|||||||
// const sort = query.sort;
|
// const sort = query.sort;
|
||||||
// const _q = query._q || '';
|
// const _q = query._q || '';
|
||||||
|
|
||||||
// const firstSortableHeader = useMemo(() => getFirstSortableHeader(displayedHeaders), [
|
|
||||||
// displayedHeaders,
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// Using a ref to avoid requests being fired multiple times on slug on change
|
// Using a ref to avoid requests being fired multiple times on slug on change
|
||||||
// We need it because the hook as mulitple dependencies so it may run before the permissions have checked
|
// We need it because the hook as mulitple dependencies so it may run before the permissions have checked
|
||||||
const requestUrlRef = useRef('');
|
const requestUrlRef = useRef('');
|
||||||
@ -399,13 +394,12 @@ function ListView({
|
|||||||
<ContentLayout>
|
<ContentLayout>
|
||||||
{canRead ? (
|
{canRead ? (
|
||||||
<DynamicTable
|
<DynamicTable
|
||||||
contentType={headerLayoutTitle}
|
canDelete={canDelete}
|
||||||
|
contentTypeName={headerLayoutTitle}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
headers={tableHeaders}
|
// FIXME: remove the layout props drilling
|
||||||
// rows={data}
|
layout={layout}
|
||||||
rows={[]}
|
rows={data}
|
||||||
withBulkActions
|
|
||||||
withMainAction={canDelete}
|
|
||||||
>
|
>
|
||||||
{/* TODO */}
|
{/* TODO */}
|
||||||
</DynamicTable>
|
</DynamicTable>
|
||||||
@ -568,7 +562,6 @@ ListView.propTypes = {
|
|||||||
canDelete: PropTypes.bool.isRequired,
|
canDelete: PropTypes.bool.isRequired,
|
||||||
canRead: PropTypes.bool.isRequired,
|
canRead: PropTypes.bool.isRequired,
|
||||||
// canUpdate: PropTypes.bool.isRequired,
|
// canUpdate: PropTypes.bool.isRequired,
|
||||||
displayedHeaders: PropTypes.array.isRequired,
|
|
||||||
data: PropTypes.array.isRequired,
|
data: PropTypes.array.isRequired,
|
||||||
// didDeleteData: PropTypes.bool.isRequired,
|
// didDeleteData: PropTypes.bool.isRequired,
|
||||||
// entriesToDelete: PropTypes.array.isRequired,
|
// entriesToDelete: PropTypes.array.isRequired,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user