@@ -48,7 +48,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
4848 @state ( ) private error : string | null = null ;
4949 @state ( ) private searchTimeout : ReturnType < typeof setTimeout > | null = null ;
5050 @state ( ) private totalObjects = 0 ;
51- @state ( ) private lastPage = - 1 ;
51+ @state ( ) private totalPages = 0 ;
5252
5353 private _provider : DrsProvider | null = null ;
5454
@@ -90,14 +90,25 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
9090 this . error = null ;
9191
9292 try {
93- const offset = ( this . currentPage - 1 ) * this . pageSize ;
94- const result = await this . _provider . getObjects ( this . pageSize , offset ) ;
93+ // API treats offset as page number, not actual offset
94+ const result = await this . _provider . getObjects (
95+ this . pageSize ,
96+ this . currentPage - 1
97+ ) ;
9598 this . objects = result . objects ;
9699
97- if ( this . objects . length === 0 ) {
98- this . lastPage = this . currentPage - 1 ;
100+ // Update total objects and pages from API response
101+ if ( result . pagination ?. total !== undefined ) {
102+ this . totalObjects = result . pagination . total ;
103+ this . totalPages = Math . ceil ( this . totalObjects / this . pageSize ) ;
104+ } else if ( this . objects . length === 0 ) {
105+ // Fallback: estimate based on current response
106+ this . totalPages = Math . max ( 0 , this . currentPage - 1 ) ;
99107 } else if ( this . objects . length < this . pageSize ) {
100- this . lastPage = this . currentPage ;
108+ this . totalPages = this . currentPage ;
109+ } else {
110+ // We don't know the total, so assume there are more pages
111+ this . totalPages = - 1 ; // -1 means unknown total
101112 }
102113
103114 // Update UI based on returned items
@@ -119,10 +130,6 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
119130 } catch ( err ) {
120131 this . error =
121132 err instanceof Error ? err . message : "Failed to load objects" ;
122- console . error ( {
123- error : this . error ,
124- breakPoint : "ECCClientGa4ghDrsObjects.loadData" ,
125- } ) ;
126133 } finally {
127134 this . loading = false ;
128135 }
@@ -139,7 +146,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
139146 // Set a new timeout for debouncing
140147 this . searchTimeout = setTimeout ( ( ) => {
141148 this . currentPage = 1 ; // Reset to first page on search
142- this . lastPage = - 1 ; // Reset lastPage when search changes
149+ this . totalPages = 0 ; // Reset total pages when search changes
143150 this . loadData ( ) ;
144151 } , 500 ) ; // 500ms debounce time
145152 }
@@ -216,7 +223,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
216223 </ ecc-utils-design-pagination-link >
217224 </ ecc-utils-design-pagination-item >
218225
219- ${ this . lastPage === - 1
226+ ${ this . totalPages === 0 || this . totalPages === - 1
220227 ? html `
221228 < ecc-utils-design-pagination-item >
222229 < ecc-utils-design-pagination-link
@@ -233,7 +240,7 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
233240 </ ecc-utils-design-pagination-item >
234241 `
235242 : "" }
236- ${ this . lastPage !== - 1 && this . currentPage < this . lastPage
243+ ${ this . totalPages > 0 && this . currentPage < this . totalPages
237244 ? html `
238245 < ecc-utils-design-pagination-item >
239246 < ecc-utils-design-pagination-link
@@ -247,32 +254,32 @@ export class ECCClientGa4ghDrsObjects extends LitElement {
247254 </ ecc-utils-design-pagination-item >
248255 `
249256 : "" }
250- ${ this . lastPage !== - 1 && this . currentPage < this . lastPage - 2
257+ ${ this . totalPages > 0 && this . currentPage < this . totalPages - 2
251258 ? html `
252259 < ecc-utils-design-pagination-item >
253260 < ecc-utils-design-pagination-ellipsis > </ ecc-utils-design-pagination-ellipsis >
254261 </ ecc-utils-design-pagination-item >
255262 `
256263 : "" }
257- ${ this . lastPage !== - 1 && this . currentPage < this . lastPage - 1
264+ ${ this . totalPages > 0 && this . currentPage < this . totalPages - 1
258265 ? html `
259266 < ecc-utils-design-pagination-item >
260267 < ecc-utils-design-pagination-link
261268 @ecc-button-clicked =${ ( e : CustomEvent ) => {
262269 if ( e . detail . variant === "link" ) {
263- this . goToPage ( this . lastPage ) ;
270+ this . goToPage ( this . totalPages ) ;
264271 }
265272 } }
266- > ${ this . lastPage } </ ecc-utils-design-pagination-link
273+ > ${ this . totalPages } </ ecc-utils-design-pagination-link
267274 >
268275 </ ecc-utils-design-pagination-item >
269276 `
270277 : "" }
271278
272279 < ecc-utils-design-pagination-item >
273280 < ecc-utils-design-pagination-next
274- ?disabled =${ this . lastPage !== - 1 &&
275- this . lastPage === this . currentPage }
281+ ?disabled =${ this . totalPages > 0 &&
282+ this . totalPages === this . currentPage }
276283 @ecc-button-clicked =${ ( e : CustomEvent ) => {
277284 if ( e . detail . variant === "next" ) {
278285 this . goToPage ( this . currentPage + 1 ) ;
0 commit comments