fix/filtros-catalogos

This commit is contained in:
2026-04-27 08:08:54 -06:00
parent a23eecfc3b
commit df6ffe422a
5 changed files with 44 additions and 17 deletions

View File

@@ -27,6 +27,14 @@ class ConceptService:
Concept.company_id == company_id
)
if filters:
if filters.get("code"):
query = query.filter(Concept.code.ilike(f"%{filters['code']}%"))
if filters.get("description"):
query = query.filter(
Concept.description.ilike(f"%{filters['description']}%")
)
total = query.count()
items = query.offset(skip).limit(limit).all()

View File

@@ -22,8 +22,12 @@ class IdentifierService:
)
if filters:
# Add filters here if needed
pass
if filters.get("code"):
query = query.filter(Identifier.code.ilike(f"%{filters['code']}%"))
if filters.get("description"):
query = query.filter(
Identifier.description.ilike(f"%{filters['description']}%")
)
total = query.count()
items = query.offset(skip).limit(limit).all()

View File

@@ -27,8 +27,12 @@ class LegendService:
)
if filters:
# Add filters here if needed
pass
if filters.get("code"):
query = query.filter(Legend.code.ilike(f"%{filters['code']}%"))
if filters.get("description"):
query = query.filter(
Legend.description.ilike(f"%{filters['description']}%")
)
total = query.count()
items = query.offset(skip).limit(limit).all()

View File

@@ -40,8 +40,10 @@
// Filters
let sealFilter = $state('');
let timeout: ReturnType<typeof setTimeout>;
let hasMore = $derived(allItems.length >= currentPage * pageSize);
const columns = createColumns();
onMount(() => {
// Sync access_token from cookies to localStorage
@@ -129,7 +131,10 @@
}
function handleSearch() {
loadInitialData();
clearTimeout(timeout);
timeout = setTimeout(() => {
loadInitialData();
}, 500);
}
function handleSuccess() {
@@ -162,7 +167,6 @@
return;
}
loading = true;
error = null;
try {
@@ -173,8 +177,6 @@
} catch (err) {
error = 'Error al eliminar el sello';
console.error('Error deleting seal:', err);
} finally {
loading = false;
}
}
@@ -218,7 +220,6 @@
placeholder="Filtrar por sello"
bind:value={sealFilter}
oninput={handleSearch}
disabled={loading}
class="h-9 w-44 bg-card lg:w-64"
/>
</div>
@@ -228,7 +229,7 @@
<div class="flex h-full min-h-0 rounded-md border bg-background overflow-hidden flex-col">
<InfiniteDataTable
data={allItems}
columns={createColumns()}
{columns}
{loading}
{hasMore}
{loadMore}

View File

@@ -45,6 +45,12 @@
let loading = $state(false);
let hasMore = $derived(allItems.length < totalItems);
let selectedIds = $state<(string | number)[]>([]);
const columns = createColumns();
const getCompanyId = () =>
companyStore.activeCompany?.id ??
allItems[0]?.company_id ??
data.conversions?.items?.[0]?.company_id ??
null;
const selectedItem = $derived(
selectedIds.length === 1
? allItems.find((item) => String(item.id) === String(selectedIds[0])) ?? null
@@ -64,7 +70,8 @@
if (!browser) return;
clearTimeout(timeout);
timeout = setTimeout(async () => {
if (!companyStore.activeCompany) return;
const companyId = getCompanyId();
if (!companyId) return;
loading = true;
error = null;
try {
@@ -75,7 +82,7 @@
const response = await getUnitConversions(
1,
pageSize,
companyStore.activeCompany.id,
companyId,
filters
);
if (response?.items) {
@@ -102,7 +109,9 @@
}
async function loadMore() {
if (loading || !hasMore || !companyStore.activeCompany) return;
if (loading || !hasMore) return;
const companyId = getCompanyId();
if (!companyId) return;
loading = true;
error = null;
try {
@@ -113,7 +122,7 @@
const response = await getUnitConversions(
currentPage + 1,
pageSize,
companyStore.activeCompany.id,
companyId,
filters
);
if (response?.items) {
@@ -130,7 +139,8 @@
}
async function reloadData() {
if (!companyStore.activeCompany) return;
const companyId = getCompanyId();
if (!companyId) return;
loading = true;
error = null;
try {
@@ -141,7 +151,7 @@
const response = await getUnitConversions(
1,
pageSize,
companyStore.activeCompany.id,
companyId,
filters
);
if (response?.items) {
@@ -236,7 +246,7 @@
<div class="rounded-md border bg-background overflow-hidden">
<InfiniteDataTable
data={allItems}
columns={createColumns()}
{columns}
{loading}
{hasMore}
{loadMore}