fix: group by

This commit is contained in:
Daniel Lautzenheiser 2023-04-10 16:00:31 -04:00
parent 602bb30730
commit 3582b2bb89

View File

@ -6,10 +6,11 @@ import { loadEntries, traverseCollectionCursor } from '@staticcms/core/actions/e
import useEntries from '@staticcms/core/lib/hooks/useEntries'; import useEntries from '@staticcms/core/lib/hooks/useEntries';
import useGroups from '@staticcms/core/lib/hooks/useGroups'; import useGroups from '@staticcms/core/lib/hooks/useGroups';
import { Cursor } from '@staticcms/core/lib/util'; import { Cursor } from '@staticcms/core/lib/util';
import classNames from '@staticcms/core/lib/util/classNames.util';
import { selectCollectionEntriesCursor } from '@staticcms/core/reducers/selectors/cursors'; import { selectCollectionEntriesCursor } from '@staticcms/core/reducers/selectors/cursors';
import { selectEntriesLoaded, selectIsFetching } from '@staticcms/core/reducers/selectors/entries'; import { selectEntriesLoaded, selectIsFetching } from '@staticcms/core/reducers/selectors/entries';
import Entries from './Entries';
import { useAppDispatch } from '@staticcms/core/store/hooks'; import { useAppDispatch } from '@staticcms/core/store/hooks';
import Entries from './Entries';
import type { ViewStyle } from '@staticcms/core/constants/views'; import type { ViewStyle } from '@staticcms/core/constants/views';
import type { Collection, Entry, GroupOfEntries, TranslatedProps } from '@staticcms/core/interface'; import type { Collection, Entry, GroupOfEntries, TranslatedProps } from '@staticcms/core/interface';
@ -70,6 +71,7 @@ const EntriesCollection = ({
const [prevCollection, setPrevCollection] = useState(collection); const [prevCollection, setPrevCollection] = useState(collection);
const groups = useGroups(collection.name); const groups = useGroups(collection.name);
console.log('[GROUPS] groups', groups);
const entries = useEntries(collection); const entries = useEntries(collection);
@ -104,26 +106,39 @@ const EntriesCollection = ({
); );
if (groups && groups.length > 0) { if (groups && groups.length > 0) {
<> return (
{groups.map(group => { <>
const title = getGroupTitle(group, t); {groups.map((group, index) => {
return ( const title = getGroupTitle(group, t);
<div key={group.id} id={group.id}> return (
<h2>{title}</h2> <div key={group.id} id={group.id}>
<Entries <h2
collection={collection} className={classNames(
entries={getGroupEntries(filteredEntries, group.paths)} `
isFetching={isFetching} px-2
collectionName={collection.label} pt-4
viewStyle={viewStyle} pb-2
cursor={cursor} `,
handleCursorActions={handleCursorActions} index === 0 && 'pt-0',
page={page} )}
/> >
</div> {title}
); </h2>
})} <Entries
</>; collection={collection}
entries={getGroupEntries(filteredEntries, group.paths)}
isFetching={isFetching}
collectionName={collection.label}
viewStyle={viewStyle}
cursor={cursor}
handleCursorActions={handleCursorActions}
page={page}
/>
</div>
);
})}
</>
);
} }
return ( return (