Skip to content

Commit bd012b6

Browse files
Merge branch 'fix/filtering-issues' into develop
2 parents b64ebb2 + 900774f commit bd012b6

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

app/(builder)/ycode/api/collections/[id]/items/filter/route.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ export async function POST(
497497
localeCode,
498498
collectionLayerClasses,
499499
collectionLayerTag,
500+
published: isPublished = true,
500501
} = body;
501502

502503
if (!layerTemplate || !Array.isArray(layerTemplate)) {
@@ -508,7 +509,7 @@ export async function POST(
508509

509510
const { matchingIds, total: filteredTotal } = await getFilteredItemIds(
510511
collectionId,
511-
true,
512+
isPublished,
512513
filterGroups,
513514
);
514515

@@ -525,7 +526,7 @@ export async function POST(
525526

526527
if (!sortBy || sortBy === 'none' || sortBy === 'manual') {
527528
// Let DB do ordering and pagination for cheap paths.
528-
const { items } = await getItemsByCollectionId(collectionId, true, {
529+
const { items } = await getItemsByCollectionId(collectionId, isPublished, {
529530
itemIds: matchingIds,
530531
limit: pageLimit,
531532
offset: pageOffset,
@@ -536,15 +537,15 @@ export async function POST(
536537
const randomizedIds = [...matchingIds].sort(() => Math.random() - 0.5);
537538
pageItemIds = randomizedIds.slice(pageOffset, pageOffset + pageLimit);
538539
if (pageItemIds.length > 0) {
539-
const { items } = await getItemsByCollectionId(collectionId, true, {
540+
const { items } = await getItemsByCollectionId(collectionId, isPublished, {
540541
itemIds: pageItemIds,
541542
});
542543
pageRawItems = reorderItemsById(items, pageItemIds);
543544
}
544545
} else {
545546
// For field-based sort, sort IDs using just the sort field values first,
546547
// then hydrate only the requested page window.
547-
const sortValueByItem = await getFieldValuesForItems(sortBy, true, matchingIds);
548+
const sortValueByItem = await getFieldValuesForItems(sortBy, isPublished, matchingIds);
548549
const sortedIds = [...matchingIds].sort((a, b) => {
549550
const aStr = String(sortValueByItem.get(a) || '');
550551
const bStr = String(sortValueByItem.get(b) || '');
@@ -559,7 +560,7 @@ export async function POST(
559560
});
560561
pageItemIds = sortedIds.slice(pageOffset, pageOffset + pageLimit);
561562
if (pageItemIds.length > 0) {
562-
const { items } = await getItemsByCollectionId(collectionId, true, {
563+
const { items } = await getItemsByCollectionId(collectionId, isPublished, {
563564
itemIds: pageItemIds,
564565
});
565566
pageRawItems = reorderItemsById(items, pageItemIds);
@@ -568,15 +569,15 @@ export async function POST(
568569

569570
const valuesByItem = await getValuesByItemIds(
570571
pageRawItems.map(i => i.id),
571-
true,
572+
isPublished,
572573
);
573574
const paginatedItems: CollectionItemWithValues[] = pageRawItems.map(item => ({
574575
...item,
575576
values: valuesByItem[item.id] || {},
576577
}));
577578
const hasMore = pageOffset + paginatedItems.length < filteredTotal;
578579

579-
const collectionFields = await getFieldsByCollectionId(collectionId, true, { excludeComputed: true });
580+
const collectionFields = await getFieldsByCollectionId(collectionId, isPublished, { excludeComputed: true });
580581
const slugField = collectionFields.find(f => f.key === 'slug');
581582
const collectionItemSlugs: Record<string, string> = {};
582583
if (slugField) {
@@ -595,7 +596,7 @@ export async function POST(
595596
let locale = null;
596597
let translations: Record<string, any> | undefined;
597598
if (localeCode) {
598-
const localeData = await loadTranslationsForLocale(localeCode, true);
599+
const localeData = await loadTranslationsForLocale(localeCode, isPublished);
599600
locale = localeData.locale;
600601
translations = localeData.translations;
601602
}
@@ -605,7 +606,7 @@ export async function POST(
605606
layerTemplate as Layer[],
606607
collectionId,
607608
collectionLayerId,
608-
true,
609+
isPublished,
609610
pages,
610611
folders,
611612
collectionItemSlugs,

components/FilterableCollection.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface FilterableCollectionProps {
1919
layerTemplate: Layer[];
2020
collectionLayerClasses?: string[];
2121
collectionLayerTag?: string;
22+
isPublished?: boolean;
2223
}
2324

2425
const FC_FILTERED_ATTR = 'data-fc-filtered';
@@ -37,6 +38,7 @@ export default function FilterableCollection({
3738
layerTemplate,
3839
collectionLayerClasses,
3940
collectionLayerTag,
41+
isPublished = true,
4042
}: FilterableCollectionProps) {
4143
const markerRef = useRef<HTMLSpanElement>(null);
4244
const ssrChildrenRef = useRef<Element[]>([]);
@@ -185,9 +187,10 @@ export default function FilterableCollection({
185187
if (inputValue && inputValue.includes(',')) {
186188
const checkedValues = inputValue.split(',').filter(Boolean);
187189
if (checkedValues.length > 0) {
190+
const arrayOperators = ['is_one_of', 'is_not_one_of', 'contains_all_of', 'contains_exactly'];
188191
activeInGroup.push({
189192
fieldId: condition.fieldId,
190-
operator: 'is_one_of',
193+
operator: arrayOperators.includes(condition.operator) ? condition.operator : 'is_one_of',
191194
value: JSON.stringify(checkedValues),
192195
fieldType: condition.fieldType,
193196
});
@@ -529,7 +532,7 @@ export default function FilterableCollection({
529532
sortOrder: effectiveSortOrder,
530533
limit,
531534
offset,
532-
published: true,
535+
published: isPublished,
533536
collectionLayerClasses,
534537
collectionLayerTag,
535538
}),
@@ -582,7 +585,7 @@ export default function FilterableCollection({
582585
abortRef.current = null;
583586
}
584587
});
585-
}, [collectionId, collectionLayerId, layerTemplate, effectiveSortBy, effectiveSortOrder, limit, paginationMode, updateEmptyStateElements, injectFilteredHTML, collectionLayerClasses, collectionLayerTag]);
588+
}, [collectionId, collectionLayerId, layerTemplate, effectiveSortBy, effectiveSortOrder, limit, paginationMode, updateEmptyStateElements, injectFilteredHTML, collectionLayerClasses, collectionLayerTag, isPublished]);
586589

587590
const fetchFilteredRef = useRef(fetchFiltered);
588591
useEffect(() => { fetchFilteredRef.current = fetchFiltered; }, [fetchFiltered]);

components/LayerRenderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ const LayerRenderer: React.FC<LayerRendererProps> = ({
246246
layerTemplate={layer._filterConfig!.layerTemplate}
247247
collectionLayerClasses={layer._filterConfig!.collectionLayerClasses}
248248
collectionLayerTag={layer._filterConfig!.collectionLayerTag}
249+
isPublished={layer._filterConfig!.isPublished}
249250
>
250251
{content}
251252
</FilterableCollection>
@@ -803,7 +804,7 @@ const LayerItem: React.FC<{
803804
if (!inputLayerId) return;
804805
const nameAttr = inputEl.getAttribute('name');
805806
if (nameAttr) nameMap[inputLayerId] = nameAttr;
806-
if (inputEl.type === 'checkbox') {
807+
if (inputEl.type === 'checkbox' || inputEl.type === 'radio') {
807808
const checked = (inputEl as HTMLInputElement).checked;
808809
const val = checked ? ((inputEl as HTMLInputElement).value || 'true') : '';
809810
inputValues[inputLayerId] = val;

lib/page-fetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,7 @@ export async function resolveCollectionLayers(
19801980
layerTemplate: layer.children || [],
19811981
collectionLayerClasses: Array.isArray(layer.classes) ? layer.classes : (layer.classes ? [layer.classes] : []),
19821982
collectionLayerTag: layer.name || 'div',
1983+
isPublished,
19831984
} : undefined,
19841985
};
19851986
} catch (error) {

types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ export interface Layer {
428428
layerTemplate: Layer[];
429429
collectionLayerClasses?: string[];
430430
collectionLayerTag?: string;
431+
isPublished?: boolean;
431432
};
432433
}
433434

0 commit comments

Comments
 (0)