Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update editor to jump back to first page after a new search was triggered #3233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column name="Type" prop="SourceTypeOrReferenceId" [minWidth]="60"></ngx-datatable-column>
<ngx-datatable-column name="Group" prop="SourceGroup"></ngx-datatable-column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<keira-highlightjs-wrapper [code]="selectService.query" />
</form>

{{ selectService.pageOffset }}
Exitare marked this conversation as resolved.
Show resolved Hide resolved
@if (selectService.rows) {
<div>
<ngx-datatable
Expand All @@ -52,6 +53,8 @@
[rowHeight]="DTCFG.rowHeight"
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
(select)="selectService.onSelect($event)"
>
<ngx-datatable-column name="entry" prop="entry" [minWidth]="100">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column name="Entry" prop="entry" [minWidth]="100">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column name="MenuID" prop="MenuID" [minWidth]="80">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
2 changes: 2 additions & 0 deletions libs/features/item/src/select-item/select-item.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column [minWidth]="42" [maxWidth]="42" [sortable]="false">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
2 changes: 2 additions & 0 deletions libs/features/other-loots/src/select-loot.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column name="Entry" prop="Entry" [minWidth]="500">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column name="ID" prop="ID" [minWidth]="100">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
[limit]="DTCFG.limit"
[selectionType]="DTCFG.selectionType"
(select)="selectService.onSelect($event)"
[offset]="selectService.pageOffset"
(page)="onPage($event)"
>
<ngx-datatable-column [name]="SPELL_DBC_ID" [prop]="SPELL_DBC_ID" [minWidth]="150">
<ng-template let-row="row" ngx-datatable-cell-template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComplexKeyHandlerService } from '../../service/handlers/complex-key.handler.service';
import { TableRow, WIKI_BASE_URL } from '@keira/shared/constants';
import { DataTablePageEvent, TableRow, WIKI_BASE_URL } from '@keira/shared/constants';
import { DTCFG } from '@keira/shared/config';
import { ChangeDetectorRef, inject } from '@angular/core';
import { SearchService } from '../../service/select/search.service';
Expand All @@ -25,4 +25,8 @@ export abstract class SelectComplexKeyComponent<T extends TableRow> {
onSearch(): void {
this.selectService.onSearch(this.changeDetectorRef);
}

onPage(event: DataTablePageEvent): void {
this.selectService.pageOffset = event.offset;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */ // TODO: fix coverage
import { ChangeDetectorRef, inject } from '@angular/core';
import { TableRow } from '@keira/shared/constants';
import { DataTablePageEvent, TableRow } from '@keira/shared/constants';
import { SelectService } from '../../service/select/select.service';
import { MysqlQueryService } from '@keira/shared/db-layer';
import { HandlerService } from '../../service/handlers/handler.service';
Expand All @@ -21,4 +21,8 @@ export abstract class SelectComponent<T extends TableRow> {
onSearch(): void {
this.selectService.onSearch(this.changeDetectorRef);
}

onPage(event: DataTablePageEvent): void {
this.selectService.pageOffset = event.offset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ModelForm, ModelNestedForm, SubscriptionHandler } from '@keira/shared/u
export abstract class SearchService<T extends TableRow> extends SubscriptionHandler {
query: string;
rows: T[] | undefined;
pageOffset = 0; // Initialize to the first page
fields: FormGroup<ModelForm<T>> = new FormGroup({} as any);
queryForm = new FormGroup<ModelNestedForm<QueryForm<T>>>({
limit: new FormControl<number>(50) as any, // TODO: fix typing
Expand Down Expand Up @@ -43,6 +44,9 @@ export abstract class SearchService<T extends TableRow> extends SubscriptionHand
}

onSearch(changeDetectorRef: ChangeDetectorRef): void {
// Reset to the first page
this.pageOffset = 0;

this.subscriptions.push(
this.queryService.query<T>(this.query).subscribe((data) => {
this.rows = data as T[];
Expand Down
8 changes: 8 additions & 0 deletions libs/shared/constants/src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ export interface FieldDefinition {
name: string;
tooltip: string;
}

// Defines a type for the ngx datatable page event
export interface DataTablePageEvent {
count: number; // Total number of rows in the table
pageSize: number; // Number of rows per page (same as the 'limit' property)
limit: number; // Maximum rows displayed per page (also same as 'pageSize')
offset: number; // Current page index (0-based)
}