fix/filtros-catalogos
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user