-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TPv2 Add Download Options Dialog to Generic Table (#7472)
* Add download options dialog to generic table * Better coverage * Fix lint * Fix rebase
- Loading branch information
1 parent
b32cd0e
commit 692e86a
Showing
7 changed files
with
288 additions
and
21 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...rtal/src/app/shared/generic-table/download-options/download-options-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<h2 mat-dialog-title>Export Options</h2> | ||
<form method="dialog" ngNativeValidate (ngSubmit)="onSubmit()"> | ||
<div class="content" mat-dialog-content> | ||
<mat-form-field appearance="fill"> | ||
<mat-label>File Name (no extension)</mat-label> | ||
<input name="fileName" matInput type="text" [(ngModel)]="fileName" required /> | ||
</mat-form-field> | ||
<mat-form-field appearance="fill"> | ||
<mat-label>Delimiter</mat-label> | ||
<input name="delimiter" matInput type="text" [(ngModel)]="seperator" required /> | ||
</mat-form-field> | ||
<mat-checkbox name="includeHeaders" [(ngModel)]="includeHeaders">Include Headers</mat-checkbox> | ||
<mat-checkbox name="includeHidden" *ngIf="this.visibleColumns.length !== this.columns.length" [(ngModel)]="includeHidden">Include Hidden Columns ({{this.visibleColumns.length}}/{{this.columns.length}} visible)</mat-checkbox> | ||
<mat-checkbox name="includeFiltered" *ngIf="visibleRows !== allRows" [(ngModel)]="includeFiltered">Include Filtered Rows ({{visibleRows}}/{{allRows}} visible)</mat-checkbox> | ||
<mat-checkbox name="onlySelected" *ngIf="selectedRows" [(ngModel)]="onlySelected">Only Selected Rows ({{selectedRows}}/{{allRows}} selected)</mat-checkbox> | ||
</div> | ||
<div mat-dialog-actions> | ||
<button mat-button type="submit">Confirm</button> | ||
<button mat-button type="button" [mat-dialog-close]="undefined">Cancel</button> | ||
</div> | ||
</form> |
18 changes: 18 additions & 0 deletions
18
...rtal/src/app/shared/generic-table/download-options/download-options-dialog.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
div.content { | ||
display: grid; | ||
} |
86 changes: 86 additions & 0 deletions
86
...l/src/app/shared/generic-table/download-options/download-options-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { HarnessLoader } from "@angular/cdk/testing"; | ||
import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed"; | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { MatCheckboxHarness } from "@angular/material/checkbox/testing"; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; | ||
import { NoopAnimationsModule } from "@angular/platform-browser/animations"; | ||
|
||
import { AppUIModule } from "src/app/app.ui.module"; | ||
import { | ||
DownloadOptionsDialogComponent, | ||
DownloadOptionsDialogData | ||
} from "src/app/shared/generic-table/download-options/download-options-dialog.component"; | ||
|
||
let loader: HarnessLoader; | ||
describe("DownloadOptionsComponent", () => { | ||
let component: DownloadOptionsDialogComponent; | ||
let fixture: ComponentFixture<DownloadOptionsDialogComponent>; | ||
const data: DownloadOptionsDialogData = { | ||
allRows: 5, | ||
columns: [{ | ||
hide: true | ||
}, { | ||
hide: false | ||
}], | ||
name: "test", | ||
selectedRows: undefined, | ||
visibleRows: 5 | ||
}; | ||
const spyRef = jasmine.createSpyObj("MatDialogRef", ["close"]); | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ DownloadOptionsDialogComponent ], | ||
imports: [ | ||
AppUIModule, | ||
NoopAnimationsModule | ||
], | ||
providers: [ | ||
{provide: MatDialogRef, useValue: spyRef}, | ||
{provide: MAT_DIALOG_DATA, useValue: data} | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DownloadOptionsDialogComponent); | ||
component = fixture.componentInstance; | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("defaults set", async () => { | ||
expect(fixture.componentInstance.allRows).toEqual(data.allRows); | ||
expect(fixture.componentInstance.columns).toEqual(data.columns); | ||
expect(fixture.componentInstance.fileName).toEqual(data.name); | ||
expect(fixture.componentInstance.selectedRows).toEqual(data.selectedRows); | ||
expect(fixture.componentInstance.visibleRows).toEqual(data.visibleRows); | ||
|
||
expect(fixture.componentInstance.visibleColumns).toEqual(data.columns.filter(c => !c.hide)); | ||
expect(fixture.componentInstance.columns).toEqual(data.columns); | ||
}); | ||
|
||
it("default submission", async () => { | ||
const cbs = await loader.getAllHarnesses(MatCheckboxHarness); | ||
expect(cbs.length).toBe(2); | ||
|
||
fixture.componentInstance.onSubmit(); | ||
expect(spyRef.close.calls.count()).toBe(1); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...portal/src/app/shared/generic-table/download-options/download-options-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Component, Inject } from "@angular/core"; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; | ||
import { ColDef, CsvExportParams } from "ag-grid-community"; | ||
|
||
/** | ||
* Data passed to DownloadOptionsComponent from the grid | ||
*/ | ||
export interface DownloadOptionsDialogData { | ||
name: string; | ||
|
||
columns: ColDef<unknown>[]; | ||
|
||
/** | ||
* Number of rows selected, should be undefined when only a single. | ||
*/ | ||
selectedRows: number | undefined; | ||
|
||
visibleRows: number; | ||
|
||
allRows: number; | ||
} | ||
|
||
/** | ||
* Controller for the DownloadOptions component. | ||
*/ | ||
@Component({ | ||
selector: "tp-download-options", | ||
styleUrls: ["./download-options-dialog.component.scss"], | ||
templateUrl: "./download-options-dialog.component.html" | ||
}) | ||
export class DownloadOptionsDialogComponent { | ||
public fileName: string; | ||
|
||
public visibleColumns: Array<ColDef<unknown>>; | ||
|
||
public columns: Array<ColDef<unknown>>; | ||
|
||
public includeHidden = false; | ||
public includeHeaders = true; | ||
|
||
public includeFiltered = false; | ||
|
||
public onlySelected = false; | ||
|
||
/** | ||
* Number of selected rows, undefined if single selection. | ||
*/ | ||
public selectedRows: number | undefined; | ||
public allRows: number; | ||
public visibleRows: number; | ||
|
||
/** 'C'SV delimiter */ | ||
public seperator = ","; | ||
|
||
constructor(private readonly dialogRef: MatDialogRef<DownloadOptionsDialogComponent, | ||
CsvExportParams>, @Inject(MAT_DIALOG_DATA) data: DownloadOptionsDialogData) { | ||
this.fileName = data.name; | ||
this.selectedRows = data.selectedRows; | ||
this.allRows = data.allRows; | ||
this.visibleRows = data.visibleRows; | ||
this.visibleColumns = []; | ||
this.columns = []; | ||
for(const col of data.columns) { | ||
if(!col.hide) { | ||
this.visibleColumns.push(col); | ||
} | ||
this.columns.push(col); | ||
} | ||
} | ||
|
||
/** | ||
* Called when submitting the form, converts data into export params. | ||
*/ | ||
public onSubmit(): void { | ||
const params: CsvExportParams = { | ||
allColumns: this.includeHidden, | ||
columnSeparator: this.seperator, | ||
exportedRows: this.includeFiltered ? "all" : "filteredAndSorted", | ||
fileName: `${this.fileName}.csv`, | ||
onlySelected: this.onlySelected, | ||
skipColumnHeaders: !this.includeHeaders, | ||
}; | ||
this.dialogRef.close(params); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters