Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: properly handle default group and filter
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Feb 8, 2024
1 parent ccd242c commit 9fca472
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
9 changes: 2 additions & 7 deletions packages/core/src/actions/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,8 @@ export function groupByField(collection: CollectionWithDefaults, group: ViewGrou
return async (dispatch: ThunkDispatch<RootState, {}, AnyAction>, getState: () => RootState) => {
const state = getState();
const isFetching = selectIsFetching(state, collection.name);
dispatch({
type: GROUP_ENTRIES_REQUEST,
payload: {
collection: collection.name,
group,
},
});
dispatch(groupEntriesRequest(collection, group));

Check warning on line 341 in packages/core/src/actions/entries.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/actions/entries.ts#L341

Added line #L341 was not covered by tests

if (isFetching) {
return;
}
Expand Down
44 changes: 25 additions & 19 deletions packages/core/src/components/collections/CollectionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,37 @@ const CollectionView: FC<CollectionViewProps> = ({
const sortGroupFilterEntries = () => {
setTimeout(async () => {
if (defaultSort && defaultSort.field) {
await onSortClick(defaultSort.field, defaultSort.direction ?? SORT_DIRECTION_ASCENDING);
const isDefaultSortActive = Boolean(
Object.values(sort).find(s => s.key === defaultSort.field),
);
if (!isDefaultSortActive) {
await onSortClick(defaultSort.field, defaultSort.direction ?? SORT_DIRECTION_ASCENDING);
}
}

if (defaultViewGroupName) {
const defaultViewGroup = viewGroups?.groups.find(g => g.name === defaultViewGroupName);
if (defaultViewGroup) {
await onGroupClick(defaultViewGroup);
const isDefaultGroupActive = Boolean(
Object.values(group).find(g => g.name === defaultViewGroupName && g.active),
);
if (!isDefaultGroupActive) {
const defaultViewGroup = viewGroups?.groups.find(g => g.name === defaultViewGroupName);
if (defaultViewGroup) {
await onGroupClick(defaultViewGroup);
}
}
}

if (defaultViewFilterName) {
const defaultViewFilter = viewFilters?.filters.find(
f => f.name === defaultViewFilterName,
const isDefaultFilterActive = Boolean(
Object.values(filter).find(f => f.name === defaultViewFilterName && f.active),
);
if (defaultViewFilter) {
await onFilterClick(defaultViewFilter);
if (!isDefaultFilterActive) {
const defaultViewFilter = viewFilters?.filters.find(
f => f.name === defaultViewFilterName,
);
if (defaultViewFilter) {
await onFilterClick(defaultViewFilter);
}
}
}

Expand All @@ -219,17 +234,8 @@ const CollectionView: FC<CollectionViewProps> = ({
return () => {
alive = false;
};
}, [
collection,
onFilterClick,
onGroupClick,
onSortClick,
prevCollection,
readyToLoad,
sort,
viewFilters?.filters,
viewGroups?.groups,
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [collection, onFilterClick, onGroupClick, onSortClick, prevCollection, readyToLoad]);

const collectionDescription = collection?.description;

Expand Down

0 comments on commit 9fca472

Please sign in to comment.