Skip to content

Commit

Permalink
Merge pull request #364 from cisagov/343-ui-update-admin-tools-scan-h…
Browse files Browse the repository at this point in the history
…istory-table

343 UI Update Admin Tools Scan History table
  • Loading branch information
schmelz21 authored Jun 26, 2024
2 parents 14b9561 + 25e1c91 commit cae8335
Show file tree
Hide file tree
Showing 2 changed files with 400 additions and 164 deletions.
17 changes: 13 additions & 4 deletions backend/src/api/scan-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from './auth';
import ECSClient from '../tasks/ecs-client';

const PAGE_SIZE = parseInt(process.env.PAGE_SIZE ?? '') || 25;
const PAGE_SIZE = 15;

class ScanTaskFilters {
@IsString()
Expand Down Expand Up @@ -59,6 +59,11 @@ class ScanTaskSearch {
@IsOptional()
filters?: ScanTaskFilters;

@IsInt()
@IsOptional()
// If set to -1, returns all results.
pageSize?: number;

async filterResultQueryset(qs: SelectQueryBuilder<ScanTask>, event) {
if (this.filters?.name) {
qs.andWhere('scan.name ILIKE :name', {
Expand All @@ -84,12 +89,16 @@ class ScanTaskSearch {
}

async getResults(event) {
const pageSize = this.pageSize || PAGE_SIZE;

const qs = ScanTask.createQueryBuilder('scan_task')
.leftJoinAndSelect('scan_task.scan', 'scan')
.leftJoinAndSelect('scan_task.organizations', 'organization')
.orderBy(`scan_task.${this.sort}`, this.order)
.skip(PAGE_SIZE * (this.page - 1))
.take(PAGE_SIZE);
.orderBy(`scan_task.${this.sort}`, this.order);

if (pageSize !== -1) {
qs.skip(pageSize * (this.page - 1)).take(pageSize);
}

await this.filterResultQueryset(qs, event);
return qs.getManyAndCount();
Expand Down
Loading

0 comments on commit cae8335

Please sign in to comment.