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

MES-9118 Prevent search when offline #1473

Merged
merged 2 commits into from
Dec 20, 2023
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
4 changes: 3 additions & 1 deletion src/app/pages/rekey-search/rekey-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</ion-header>

<ion-content>
<offline-banner [isOffline]="pageState.isOffline$ | async"></offline-banner>

<div class="search-inputs">
<tabs>
<tab [tabTitle]="'Rekey search'" id="tab-search-rekey">
Expand Down Expand Up @@ -63,7 +65,7 @@
</ion-row>
<ion-row class="ion-padding-top">
<ion-button
[disabled]="(pageState.isLoading$ | async)"
[disabled]="(pageState.isLoading$ | async) || (pageState.isOffline$ | async)"
class="mes-primary-button search-tests"
id="rekey-search-search-tests-btn"
(click)="searchTests()"
Expand Down
4 changes: 4 additions & 0 deletions src/app/pages/rekey-search/rekey-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import {
getRekeySearchError,
} from '@pages/rekey-search/rekey-search.selector';
import { OrientationMonitorProvider } from '@providers/orientation-monitor/orientation-monitor.provider';
import { NetworkStateProvider } from '@providers/network-state/network-state';

interface RekeySearchPageState {
isLoading$: Observable<boolean>;
hasSearched$: Observable<boolean>;
bookedTestSlot$: Observable<TestSlot>;
rekeySearchErr$: Observable<RekeySearchError | HttpErrorResponse>;
isOffline$: Observable<boolean>;
}

@Component({
Expand All @@ -44,6 +46,7 @@ export class RekeySearchPage extends BasePageComponent implements OnInit {

constructor(
public orientationMonitorProvider: OrientationMonitorProvider,
private networkStateProvider: NetworkStateProvider,
injector: Injector,
) {
super(injector);
Expand All @@ -67,6 +70,7 @@ export class RekeySearchPage extends BasePageComponent implements OnInit {
rekeySearchErr$: rekeySearch$.pipe(
map(getRekeySearchError),
),
isOffline$: this.networkStateProvider.isOffline$,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { TestCentre } from '@dvsa/mes-journal-schema';
import { TestResultsSearchPage } from '../test-results-search';
import { TestResultsSearchComponentsModule } from '../components/test-results-search-components.module';
import { HttpStatusCode } from '@angular/common/http';
import { NetworkStateProvider } from '@providers/network-state/network-state';
import { NetworkStateProviderMock } from '@providers/network-state/__mocks__/network-state.mock';

enum SearchBy {
DriverNumber = 'driverNumber',
Expand Down Expand Up @@ -76,6 +78,10 @@ describe('TestResultsSearchPage', () => {
provide: AppComponent,
useClass: MockAppComponent,
},
{
provide: NetworkStateProvider,
useClass: NetworkStateProviderMock,
}
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<ion-row>
<ion-button
(click)="searchTests()"
[disabled]="!!showSpinner"
[disabled]="!!showSpinner || isOffline"
class="mes-primary-button search-tests"
id="advanced-search-button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class AdvancedSearchComponent {
@Input()
testCentres: TestCentre[] = [];

@Input()
isOffline: boolean;

@Output()
onSearchTests = new EventEmitter<AdvancedSearchParams>();

Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/test-results-search/test-results-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</ion-header>

<ion-content forceOverscroll="false">
<offline-banner [isOffline]="pageState.isOffline$ | async"></offline-banner>

<div class="search-inputs">
<tabs>
<tab [tabTitle]="'Candidate details'" id="tab-search-candidate-details">
Expand Down Expand Up @@ -80,7 +82,7 @@
<ion-row class="ion-padding-top">
<ion-button
id="test-result-search-button"
[attr.disabled]="showSearchSpinner ? 'true' : isEmpty(candidateInfo)"
[attr.disabled]="showSearchSpinner || (pageState.isOffline$ | async) ? 'true' : isEmpty(candidateInfo)"
class="mes-primary-button search-tests"
(click)="searchTests()"
>
Expand All @@ -99,6 +101,7 @@
[testCentres]="pageState.activeTestCentres$ | async"
(onSearchTests)="advancedSearch($event)"
[showSpinner]="showAdvancedSearchSpinner"
[isOffline]="pageState.isOffline$ | async"
>
</advanced-search>
</tab>
Expand Down
4 changes: 4 additions & 0 deletions src/app/pages/test-results-search/test-results-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { LogType } from '@shared/models/log.model';
import { MesError } from '@shared/models/mes-error.model';
import { AppConfigProvider } from '@providers/app-config/app-config';
import { NetworkStateProvider } from '@providers/network-state/network-state';
import { SearchProvider } from '@providers/search/search';
import { AdvancedSearchParams } from '@providers/search/search.models';
import { ExaminerRole } from '@providers/app-config/constants/examiner-role.constants';
Expand All @@ -35,6 +36,7 @@

interface TestResultPageState {
activeTestCentres$: Observable<JournalTestCentre[]>;
isOffline$: Observable<boolean>;
}

@Component({
Expand All @@ -61,6 +63,7 @@
public searchProvider: SearchProvider,
private appConfig: AppConfigProvider,
private accessibilityService: AccessibilityService,
private networkStateProvider: NetworkStateProvider,
injector: Injector,
) {
super(injector);
Expand All @@ -73,6 +76,7 @@
map(getTestCentres),
map(getActiveTestCentres),
),
isOffline$: this.networkStateProvider.isOffline$,
};
this.merged$ = merge(
this.pageState.activeTestCentres$,
Expand Down Expand Up @@ -201,7 +205,7 @@
await this.showError(err);
this.hasSearched = false;
}
console.log('ERROR', JSON.stringify(err));

Check warning on line 208 in src/app/pages/test-results-search/test-results-search.ts

View workflow job for this annotation

GitHub Actions / ci-checks

Unexpected console statement
return of();
}),
)
Expand Down
Loading