Skip to content

Commit

Permalink
Merge pull request #871 from europeana/feat/MET-6239-Add-Debias-Info-…
Browse files Browse the repository at this point in the history
…Prevent-Double-Load

MET-6239 Prevent Double Load
  • Loading branch information
andyjmaclean authored Nov 21, 2024
2 parents 6b64b0d + a7c0a39 commit 1cb20ea
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
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 @@ -60,6 +61,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 @@ -69,6 +72,7 @@ export class DebiasComponent extends DataPollingComponent {
},
false,
(debiasReport: DebiasReport) => {
this.isBusy = false;
if (debiasReport) {
this.debiasReport = debiasReport;
if (debiasReport.state === DebiasState.COMPLETED) {
Expand Down

0 comments on commit 1cb20ea

Please sign in to comment.