-
Notifications
You must be signed in to change notification settings - Fork 76
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
Faulty list view when back navigating #1243
Changes from all commits
5936d1c
391bd7b
fbc5bc1
7ec259d
67c2c85
e6f3b8e
511c4f5
fd7882d
63ddff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class TableSettings { | ||
public sortActiveId = ''; // The ID of the column the table is sorted by | ||
public sortDirection = ''; | ||
public pageSize = 20; | ||
public pageIndex = 0; | ||
} |
cheehongw marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { TableSettings } from '../models/table-settings.model'; | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
|
||
/** | ||
* Responsible for storing and retrieving the table settings for issue tables created | ||
* Map is required since there can be multiple tables within the same page | ||
*/ | ||
export class IssueTableSettingsService { | ||
private _tableSettingsMap: { [index: string]: TableSettings } = {}; | ||
|
||
public getTableSettings(tableName: string): TableSettings { | ||
return this._tableSettingsMap[tableName] || new TableSettings(); | ||
} | ||
|
||
public setTableSettings(tableName: string, tableSettings: TableSettings): void { | ||
this._tableSettingsMap[tableName] = tableSettings; | ||
} | ||
|
||
public clearTableSettings(): void { | ||
this._tableSettingsMap = {}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core'; | ||
import { MatPaginator } from '@angular/material/paginator'; | ||
import { MatPaginator, PageEvent } from '@angular/material/paginator'; | ||
import { MatSnackBar } from '@angular/material/snack-bar'; | ||
import { MatSort } from '@angular/material/sort'; | ||
import { MatSort, Sort } from '@angular/material/sort'; | ||
import { finalize } from 'rxjs/operators'; | ||
import { Issue, STATUS } from '../../core/models/issue.model'; | ||
import { TableSettings } from '../../core/models/table-settings.model'; | ||
import { DialogService } from '../../core/services/dialog.service'; | ||
import { ErrorHandlingService } from '../../core/services/error-handling.service'; | ||
import { GithubService } from '../../core/services/github.service'; | ||
import { IssueTableSettingsService } from '../../core/services/issue-table-settings.service'; | ||
import { IssueService } from '../../core/services/issue.service'; | ||
import { LabelService } from '../../core/services/label.service'; | ||
import { LoggingService } from '../../core/services/logging.service'; | ||
|
@@ -44,6 +46,8 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { | |
issues: IssuesDataTable; | ||
issuesPendingDeletion: { [id: number]: boolean }; | ||
|
||
public tableSettings: TableSettings; | ||
|
||
public readonly action_buttons = ACTION_BUTTONS; | ||
|
||
// Messages for the modal popup window upon deleting an issue | ||
|
@@ -57,6 +61,7 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { | |
public labelService: LabelService, | ||
private githubService: GithubService, | ||
public issueService: IssueService, | ||
public issueTableSettingsService: IssueTableSettingsService, | ||
private phaseService: PhaseService, | ||
private errorHandlingService: ErrorHandlingService, | ||
private logger: LoggingService, | ||
|
@@ -67,6 +72,7 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { | |
ngOnInit() { | ||
this.issues = new IssuesDataTable(this.issueService, this.sort, this.paginator, this.headers, this.filters); | ||
this.issuesPendingDeletion = {}; | ||
this.tableSettings = this.issueTableSettingsService.getTableSettings(this.table_name); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
|
@@ -75,6 +81,18 @@ export class IssueTablesComponent implements OnInit, AfterViewInit { | |
}); | ||
} | ||
|
||
sortChange(newSort: Sort) { | ||
this.tableSettings.sortActiveId = newSort.active; | ||
this.tableSettings.sortDirection = newSort.direction; | ||
this.issueTableSettingsService.setTableSettings(this.table_name, this.tableSettings); | ||
} | ||
|
||
pageChange(pageEvent: PageEvent) { | ||
this.tableSettings.pageSize = pageEvent.pageSize; | ||
this.tableSettings.pageIndex = pageEvent.pageIndex; | ||
this.issueTableSettingsService.setTableSettings(this.table_name, this.tableSettings); | ||
} | ||
|
||
Comment on lines
+84
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is the best practice to sync settings of a table component with the service. I would suggest the following:
@CATcher-org/2324s2 What do yall think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case wouldn't I still need these two functions to update the TableSettings in the service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't see the benefit for observables too. I think an observable implementation is beneficial if we have more than 1 table listening to the same set of settings but so far we are saving the settings for each table (or to be more precise |
||
isActionVisible(action: ACTION_BUTTONS): boolean { | ||
return this.actions.includes(action); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the member fields to have proper type annotation, so that the compiler can detect errors if the fields are not assigned the correct value. Also, the fields should have proper initial values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter prevents me from adding type annotations to member fields that are initialized. Error: no-inferrable-types.
The initial values used are also what I deem proper as initially the tables are not sorted at all, internally matsort is initialised with an empty string which is what I am emulating here.