fix(filters) : repair broken filters on catalog and document pages

- modelTypes.ts: use API Platform OrderFilter format (order[field]=dir) and proper page param
- product-catalog: load all products (itemsPerPage: 200) instead of default 30
- documents: load all documents (itemsPerPage: 200) instead of default 30
- useDocuments: support itemsPerPage option in loadDocuments/loadFromEndpoint
- pieces-catalog + component-catalog: add force:true to bypass stale cache on sort/filter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-02-11 15:32:54 +01:00
parent 8fecf67a7f
commit 185af65519
6 changed files with 33 additions and 44 deletions

View File

@@ -49,11 +49,12 @@ export function useDocuments() {
const loadFromEndpoint = async ( const loadFromEndpoint = async (
endpoint: string, endpoint: string,
{ updateStore = false }: { updateStore?: boolean } = {}, { updateStore = false, itemsPerPage }: { updateStore?: boolean; itemsPerPage?: number } = {},
): Promise<DocumentResult> => { ): Promise<DocumentResult> => {
loading.value = true loading.value = true
try { try {
const result = await get(endpoint) const url = itemsPerPage ? `${endpoint}${endpoint.includes('?') ? '&' : '?'}itemsPerPage=${itemsPerPage}` : endpoint
const result = await get(url)
if (result.success) { if (result.success) {
const data = extractCollection(result.data) const data = extractCollection(result.data)
if (updateStore) { if (updateStore) {
@@ -76,9 +77,9 @@ export function useDocuments() {
} }
const loadDocuments = async ( const loadDocuments = async (
options: { updateStore?: boolean } = {}, options: { updateStore?: boolean; itemsPerPage?: number } = {},
): Promise<DocumentResult> => { ): Promise<DocumentResult> => {
return loadFromEndpoint('/documents', { updateStore: options.updateStore ?? true }) return loadFromEndpoint('/documents', { updateStore: options.updateStore ?? true, itemsPerPage: options.itemsPerPage })
} }
const loadDocumentsBySite = async ( const loadDocumentsBySite = async (

View File

@@ -234,7 +234,8 @@ const fetchComposants = async () => {
page: currentPage.value, page: currentPage.value,
itemsPerPage: itemsPerPage.value, itemsPerPage: itemsPerPage.value,
orderBy: sortField.value, orderBy: sortField.value,
orderDir: sortDirection.value orderDir: sortDirection.value,
force: true
}) })
} }

View File

@@ -146,7 +146,7 @@ const previewDocument = ref(null)
const previewVisible = ref(false) const previewVisible = ref(false)
onMounted(() => { onMounted(() => {
loadDocuments() loadDocuments({ itemsPerPage: 200 })
}) })
const filteredDocuments = computed(() => { const filteredDocuments = computed(() => {

View File

@@ -256,7 +256,8 @@ const fetchPieces = async () => {
page: currentPage.value, page: currentPage.value,
itemsPerPage: itemsPerPage.value, itemsPerPage: itemsPerPage.value,
orderBy: sortField.value, orderBy: sortField.value,
orderDir: sortDirection.value orderDir: sortDirection.value,
force: true
}) })
} }

View File

@@ -388,7 +388,7 @@ const resolvePreviewAlt = (product: Record<string, any>) => {
} }
const reload = async () => { const reload = async () => {
await loadProducts({ force: true }) await loadProducts({ itemsPerPage: 200, force: true })
} }
const { confirm } = useConfirm() const { confirm } = useConfirm()
@@ -409,7 +409,7 @@ const confirmDelete = async (product: Record<string, any>) => {
onMounted(async () => { onMounted(async () => {
await Promise.all([ await Promise.all([
loadProducts(), loadProducts({ itemsPerPage: 200, force: true }),
loadProductTypes() loadProductTypes()
]) ])
}) })

View File

@@ -132,28 +132,19 @@ export async function listModelTypes(params: ModelTypeListParams = {}, opts: { s
if (params.category) { if (params.category) {
query.category = params.category; query.category = params.category;
} }
if (params.sort) {
query.sort = params.sort;
}
if (params.dir) {
query.dir = params.dir;
}
const hasCategoryFilter = Boolean(params.category);
const effectiveLimit = typeof params.limit === 'number' ? params.limit : undefined;
const effectiveOffset = typeof params.offset === 'number' ? params.offset : 0;
if (hasCategoryFilter) { // Sort: API Platform OrderFilter uses order[field]=direction
// Fetch enough items to allow client-side category filtering + pagination. const sortField = params.sort || 'name';
query.itemsPerPage = Math.max(effectiveLimit ?? 200, 200); const sortDir = params.dir || 'asc';
query.offset = 0; query[`order[${sortField}]`] = sortDir;
} else {
if (typeof params.limit === 'number') { // Pagination: API Platform uses page + itemsPerPage
query.itemsPerPage = params.limit; const effectiveLimit = typeof params.limit === 'number' ? params.limit : 20;
} const effectiveOffset = typeof params.offset === 'number' ? params.offset : 0;
if (typeof params.offset === 'number') { const page = Math.floor(effectiveOffset / effectiveLimit) + 1;
query.offset = params.offset;
} query.itemsPerPage = effectiveLimit;
} query.page = page;
const payload = await requestFetch<Record<string, any>>(ENDPOINT, createOptions({ const payload = await requestFetch<Record<string, any>>(ENDPOINT, createOptions({
method: 'GET', method: 'GET',
@@ -168,25 +159,20 @@ export async function listModelTypes(params: ModelTypeListParams = {}, opts: { s
: Array.isArray(payload?.items) : Array.isArray(payload?.items)
? payload.items ? payload.items
: []; : [];
const filteredItems = params.category
? rawItems.filter((item: any) => item?.category === params.category) const total = typeof payload?.totalItems === 'number'
: rawItems; ? payload.totalItems
const total = params.category : typeof payload?.['hydra:totalItems'] === 'number'
? filteredItems.length ? payload['hydra:totalItems']
: typeof payload?.totalItems === 'number' : rawItems.length;
? payload.totalItems
: Array.isArray(payload?.items) const items = rawItems.map(normalizeModelType);
? payload.items.length
: rawItems.length;
const items = (params.category && typeof effectiveLimit === 'number'
? filteredItems.slice(effectiveOffset, effectiveOffset + effectiveLimit)
: filteredItems).map(normalizeModelType);
return { return {
items, items,
total, total,
offset: effectiveOffset, offset: effectiveOffset,
limit: typeof effectiveLimit === 'number' ? effectiveLimit : items.length, limit: effectiveLimit,
} satisfies ModelTypeListResponse; } satisfies ModelTypeListResponse;
} }