builds a centralized way to format fields for admin use
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
.table {
|
||||
margin-bottom: $baseline;
|
||||
overflow-x: scroll;
|
||||
overflow: auto;
|
||||
max-width: 100%;
|
||||
|
||||
thead {
|
||||
|
||||
@@ -11,6 +11,7 @@ import Pill from '../../../elements/Pill';
|
||||
import Button from '../../../elements/Button';
|
||||
import SortColumn from '../../../elements/SortColumn';
|
||||
import Table from '../../../elements/Table';
|
||||
import formatAdminFields from '../../../../utilities/formatAdminFields';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
@@ -165,8 +166,6 @@ const ListView = (props) => {
|
||||
collection,
|
||||
collection: {
|
||||
slug,
|
||||
fields,
|
||||
timestamps,
|
||||
labels: {
|
||||
plural,
|
||||
},
|
||||
@@ -174,11 +173,6 @@ const ListView = (props) => {
|
||||
} = props;
|
||||
const { setStepNav } = useStepNav();
|
||||
|
||||
let allFields = [...fields, { name: 'id', label: 'ID' }];
|
||||
|
||||
if (timestamps) {
|
||||
allFields = allFields.concat([{ name: 'createdAt', label: 'Created At' }, { name: 'updatedAt', label: 'Updated At' }]);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setStepNav([
|
||||
@@ -189,10 +183,11 @@ const ListView = (props) => {
|
||||
}, [setStepNav, plural]);
|
||||
|
||||
const List = customComponents?.[slug]?.views?.List || DefaultList;
|
||||
const formattedFields = formatAdminFields(collection);
|
||||
|
||||
return (
|
||||
<>
|
||||
<List collection={{ ...collection, fields: allFields }} />
|
||||
<List collection={{ ...collection, fields: formattedFields }} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
20
src/client/utilities/formatAdminFields.js
Normal file
20
src/client/utilities/formatAdminFields.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const formatAdminFields = (config) => {
|
||||
let formattedFields = config.fields.reduce((formatted, field) => {
|
||||
if (field.hidden === true || field?.hidden?.admin === true) {
|
||||
return formatted;
|
||||
}
|
||||
|
||||
return [
|
||||
...formatted,
|
||||
field,
|
||||
];
|
||||
}, [{ name: 'id', label: 'ID' }]);
|
||||
|
||||
if (config.timestamps) {
|
||||
formattedFields = formattedFields.concat([{ name: 'createdAt', label: 'Created At' }, { name: 'updatedAt', label: 'Updated At' }]);
|
||||
}
|
||||
|
||||
return formattedFields;
|
||||
};
|
||||
|
||||
export default formatAdminFields;
|
||||
Reference in New Issue
Block a user