Fix view filters

This commit is contained in:
Daniel Lautzenheiser 2023-04-10 16:25:46 -04:00
parent 3582b2bb89
commit 7a9a465bf4
4 changed files with 12 additions and 14 deletions

View File

@ -1005,7 +1005,8 @@ export class Backend<EF extends BaseField = UnknownField, BC extends BackendClas
fieldsOrder(collection: Collection, entry: Entry) {
if ('fields' in collection) {
return collection.fields?.map(f => f!.name) ?? [];
} else {
}
const files = collection.files ?? [];
const file: CollectionFile | null = files.filter(f => f!.name === entry.slug)?.[0] ?? null;
@ -1015,9 +1016,6 @@ export class Backend<EF extends BaseField = UnknownField, BC extends BackendClas
return file.fields.map(f => f.name);
}
return [];
}
filterEntries(collection: { entries: Entry[] }, filterRule: FilterRule) {
return collection.entries.filter(entry => {
const fieldValue = entry.data?.[filterRule.field];

View File

@ -25,6 +25,7 @@ const FilterControl = ({
const handleFilterClick = useCallback(
(viewFilter: ViewFilter) => (event: MouseEvent | ChangeEvent) => {
event.stopPropagation();
event.preventDefault();
onFilterClick(viewFilter);
},
[onFilterClick],

View File

@ -71,7 +71,6 @@ const EntriesCollection = ({
const [prevCollection, setPrevCollection] = useState(collection);
const groups = useGroups(collection.name);
console.log('[GROUPS] groups', groups);
const entries = useEntries(collection);

View File

@ -1,14 +1,14 @@
import { useMemo } from 'react';
import { selectEntriesSortField } from '@staticcms/core/reducers/selectors/entries';
import { selectEntriesFilter } from '@staticcms/core/reducers/selectors/entries';
import { useAppSelector } from '@staticcms/core/store/hooks';
export default function useFilters(collectionName: string) {
const entriesSortFieldSelector = useMemo(
() => selectEntriesSortField(collectionName),
const entriesFilterFieldSelector = useMemo(
() => selectEntriesFilter(collectionName),
[collectionName],
);
const filters = useAppSelector(entriesSortFieldSelector);
const filters = useAppSelector(entriesFilterFieldSelector);
return useMemo(() => {
return Object.values(filters ?? {}).filter(v => v?.active === true) || [];