Skip to content

Commit 4c1bd92

Browse files
authored
Merge pull request #2092 from bcgov/bugfix/ALCS-2448
2448: Fix public doc sorting
2 parents 06c0710 + faaa3bb commit 4c1bd92

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

portal-frontend/src/app/features/public/application/alc-review/submission-documents/submission-documents.component.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { PublicDocumentDto } from '../../../../../services/public/public.dto';
77
import { PublicService } from '../../../../../services/public/public.service';
88
import { openFileInline } from '../../../../../shared/utils/file';
99

10+
type PublicDocumentWithoutTypeDto = Omit<PublicDocumentDto, 'type'>;
11+
1012
@Component({
1113
selector: 'app-submission-documents[applicationSubmission]',
1214
templateUrl: './submission-documents.component.html',
@@ -21,13 +23,27 @@ export class PublicSubmissionDocumentsComponent implements OnInit, OnDestroy {
2123
@Input() applicationDocuments!: PublicDocumentDto[];
2224
@Input() applicationSubmission!: PublicApplicationSubmissionDto;
2325

24-
@ViewChild(MatSort) sort!: MatSort;
2526
dataSource: MatTableDataSource<PublicDocumentDto> = new MatTableDataSource<PublicDocumentDto>();
27+
@ViewChild(MatSort) sort!: MatSort;
2628

2729
constructor(private publicService: PublicService) {}
2830

2931
ngOnInit(): void {
30-
this.dataSource = new MatTableDataSource(this.applicationDocuments);
32+
this.dataSource.data = this.applicationDocuments;
33+
this.dataSource.sortingDataAccessor = (
34+
{ type, ...rest }: PublicDocumentDto,
35+
sortHeaderId: string,
36+
): string | number => {
37+
if (sortHeaderId === 'type') {
38+
return type?.label ?? '';
39+
}
40+
41+
return (rest as PublicDocumentWithoutTypeDto)[sortHeaderId as keyof PublicDocumentWithoutTypeDto] ?? '';
42+
};
43+
}
44+
45+
ngAfterViewInit() {
46+
this.dataSource.sort = this.sort;
3147
}
3248

3349
async openFile(file: PublicDocumentDto) {

0 commit comments

Comments
 (0)