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

MET-6239 Prevent Double Load #871

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -2,6 +2,7 @@
<a
tabindex="0"
class="debias-link"
[attr.disabled]="(cmpDebias && cmpDebias.isBusy) || null"
(click)="runOrShowDebiasReport(runEnabled)"
[attr.data-linkText]="(runEnabled ? 'run' : 'view') + ' report'"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ $slide-down-duration: 0.4s;
display: flex;
justify-content: flex-end;

&[disabled] {
pointer-events: none;
cursor: default;
color: $gray-light;
}
&::before {
content: attr(data-linkText);
}
Expand All @@ -273,7 +278,3 @@ $slide-down-duration: 0.4s;
width: 3.5em;
}
}

.debias-link-wrapper {
float: right;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import {
async,
ComponentFixture,
discardPeriodicTasks,
fakeAsync,
TestBed,
tick
} from '@angular/core/testing';
import { Observable, of } from 'rxjs';
// sonar-disable-next-statement (sonar doesn't read tsconfig paths entry)
import { MockModalConfirmService, ModalConfirmService } from 'shared';
Expand Down Expand Up @@ -69,8 +76,8 @@ describe('DatasetInfoComponent', () => {
expect(component.datasetInfo).toBeFalsy();

component.datasetId = '1';
expect(component.datasetInfo).toBeFalsy();
tick(1);

expect(component.datasetInfo).toBeTruthy();
}));

Expand Down Expand Up @@ -112,7 +119,6 @@ describe('DatasetInfoComponent', () => {

component.datasetId = '2';
tick(1);

expect(component.checkIfCanRunDebias).toHaveBeenCalledTimes(2);
}));

Expand Down Expand Up @@ -179,12 +185,33 @@ describe('DatasetInfoComponent', () => {
expect(component.fullInfoOpen).toBeFalsy();
});

it('should run the debias report', fakeAsync(() => {
it('should run the debias report unless busy', fakeAsync(() => {
expect(component.canRunDebias).toBeFalsy();
expect(component.canRunDebias).toBeFalsy();

fixture.detectChanges();

spyOn(component.cmpDebias, 'startPolling').and.callThrough();

component.cmpDebias.isBusy = true;
component.runOrShowDebiasReport(false);
expect(component.cmpDebias.startPolling).not.toHaveBeenCalled();

expect(component.canRunDebias).toBeUndefined();

component.cmpDebias.isBusy = false;
component.runOrShowDebiasReport(false);
expect(component.canRunDebias).toBeUndefined();

expect(component.cmpDebias.startPolling).toHaveBeenCalledTimes(1);
expect(component.cmpDebias.isBusy).toBeFalsy();

component.runOrShowDebiasReport(true);
tick(1);
expect(component.canRunDebias).not.toBeUndefined();
expect(component.canRunDebias).toBeFalsy();

expect(component.cmpDebias.startPolling).toHaveBeenCalledTimes(1);
discardPeriodicTasks();
}));

it('should initiate polling in the debias component', fakeAsync(() => {
Expand All @@ -195,6 +222,6 @@ describe('DatasetInfoComponent', () => {

component.runOrShowDebiasReport(false);
expect(component.cmpDebias.startPolling).toHaveBeenCalled();
tick(1);
discardPeriodicTasks();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,22 @@ export class DatasetInfoComponent extends SubscriptionManager {
* @param { boolean } run - flags action
**/
runOrShowDebiasReport(run: boolean): void {
if (this.cmpDebias.isBusy) {
return;
}
this.cmpDebias.isBusy = true;
if (run) {
this.subs.push(
this.sandbox.runDebiasReport(this.datasetId).subscribe(() => {
this.canRunDebias = false;
this.cmpDebias.isBusy = false;
})
);
} else {
const pollerId = this.cmpDebias.startPolling();
this.subs.push(
this.modalConfirms.open(this.modalIdPrefix + this.modalIdDebias).subscribe(() => {
console.log(this.cmpDebias.clearDataPollerByIdentifier(pollerId));
this.cmpDebias.clearDataPollerByIdentifier(pollerId);
})
);
}
Expand Down
4 changes: 4 additions & 0 deletions projects/sandbox/src/app/debias/debias.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { isoLanguageNames } from '../_data';
export class DebiasComponent extends DataPollingComponent {
debiasHeaderOpen = false;
debiasReport: DebiasReport;
isBusy: boolean;
private readonly sandbox = inject(SandboxService);
private readonly csv = inject(ExportCSVService);
public apiSettings = apiSettings;
Expand All @@ -61,6 +62,8 @@ export class DebiasComponent extends DataPollingComponent {
* begins the data poller for the debias data
**/
startPolling(): string {
this.isBusy = true;

const pollerId = this.datasetId + '-debias-' + new Date().toISOString();

this.createNewDataPoller(
Expand All @@ -70,6 +73,7 @@ export class DebiasComponent extends DataPollingComponent {
},
false,
(debiasReport: DebiasReport) => {
this.isBusy = false;
if (debiasReport) {
this.debiasReport = debiasReport;
if (debiasReport.state === DebiasState.COMPLETED) {
Expand Down