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) { fieldsOrder(collection: Collection, entry: Entry) {
if ('fields' in collection) { if ('fields' in collection) {
return collection.fields?.map(f => f!.name) ?? []; return collection.fields?.map(f => f!.name) ?? [];
} else { }
const files = collection.files ?? []; const files = collection.files ?? [];
const file: CollectionFile | null = files.filter(f => f!.name === entry.slug)?.[0] ?? null; 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 file.fields.map(f => f.name);
} }
return [];
}
filterEntries(collection: { entries: Entry[] }, filterRule: FilterRule) { filterEntries(collection: { entries: Entry[] }, filterRule: FilterRule) {
return collection.entries.filter(entry => { return collection.entries.filter(entry => {
const fieldValue = entry.data?.[filterRule.field]; const fieldValue = entry.data?.[filterRule.field];

View File

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

View File

@ -71,7 +71,6 @@ 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);

View File

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