Fix view filters
This commit is contained in:
parent
3582b2bb89
commit
7a9a465bf4
@ -1005,17 +1005,15 @@ 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 file: CollectionFile | null = files.filter(f => f!.name === entry.slug)?.[0] ?? null;
|
|
||||||
|
|
||||||
if (file == null) {
|
|
||||||
throw new Error(`No file found for ${entry.slug} in ${collection.name}`);
|
|
||||||
}
|
|
||||||
return file.fields.map(f => f.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
const files = collection.files ?? [];
|
||||||
|
const file: CollectionFile | null = files.filter(f => f!.name === entry.slug)?.[0] ?? null;
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
throw new Error(`No file found for ${entry.slug} in ${collection.name}`);
|
||||||
|
}
|
||||||
|
return file.fields.map(f => f.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
filterEntries(collection: { entries: Entry[] }, filterRule: FilterRule) {
|
filterEntries(collection: { entries: Entry[] }, filterRule: FilterRule) {
|
||||||
|
@ -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],
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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) || [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user