Skip to content

Commit

Permalink
[sc-7997] blank status column in pending resource list (#1173)
Browse files Browse the repository at this point in the history
* Fix [sc-7950] when loading the page just from the domain

The previous fix was working well when going through the login flow with an account containing only one KB. But when already logged in such account, we still had the undefined zone in the route if loading the app by using only the domain (like http://nuclia.cloud).

* Fix [sc-7997] preload processing status

* Fix unit tests
  • Loading branch information
mpellerin42 authored Dec 7, 2023
1 parent 359f453 commit c96728d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
14 changes: 10 additions & 4 deletions libs/common/src/lib/guards/select-kb.guard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { NavigationService, SelectAccountKbService } from '@flaps/common';
import { inject } from '@angular/core';
import { SDKService } from '@flaps/core';
import { SDKService, ZoneService } from '@flaps/core';
import { filter, of, switchMap } from 'rxjs';
import { map } from 'rxjs/operators';

Expand All @@ -10,6 +10,7 @@ export const selectKbGuard = (route: ActivatedRouteSnapshot) => {
const navigation: NavigationService = inject(NavigationService);
const sdk: SDKService = inject(SDKService);
const router: Router = inject(Router);
const zoneService: ZoneService = inject(ZoneService);

const accountSlug = route.paramMap.get('account');

Expand All @@ -24,9 +25,9 @@ export const selectKbGuard = (route: ActivatedRouteSnapshot) => {
);

return accountSlug
? isKbListReady.pipe(
switchMap(() => sdk.kbList),
switchMap((kbs) => {
? zoneService.getZones().pipe(
switchMap((zones) => isKbListReady.pipe(switchMap(() => sdk.kbList.pipe(map((kbs) => ({ kbs, zones })))))),
switchMap(({ kbs, zones }) => {
if (kbs.length === 0) {
return selectService.standalone
? of(true)
Expand All @@ -39,6 +40,11 @@ export const selectKbGuard = (route: ActivatedRouteSnapshot) => {
// if there's only one KB, and we're not in NucliaDB admin app, then we automatically select the KB
if (sdk.useRegionalSystem) {
sdk.nuclia.options.zone = kbs[0].zone;
} else {
const zone = zones.find((zone) => zone.id === kbs[0].zone);
if (zone) {
sdk.nuclia.options.zone = zone.slug;
}
}
return of(router.createUrlTree([navigation.getKbUrl(accountSlug, kbs[0].slug || '')]));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@guillotinaweb/pastanaga-angular';
import { SDKService } from '@flaps/core';
import { of } from 'rxjs';
import { Nuclia, WritableKnowledgeBox } from '@nuclia/core';
import { Account, Nuclia, WritableKnowledgeBox } from '@nuclia/core';
import { RouterTestingModule } from '@angular/router/testing';
import { SisModalService, SisToastService } from '@nuclia/sistema';
import { UploadService } from '../../../upload/upload.service';
Expand All @@ -35,6 +35,7 @@ describe('ErrorResourcesTableComponent', () => {
],
providers: [
MockProvider(SDKService, {
currentAccount: of({ id: '123' } as Account),
currentKb: of({
admin: true,
catalog: jest.fn(() => of()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<pa-table-cell center>
<span class="body-s">{{ row.resource.created | formatDate: { default: true } }}</span>
</pa-table-cell>
<pa-table-cell center>
<pa-table-cell>
<span class="body-s">{{ row.status }}</span>
</pa-table-cell>
<pa-table-cell-menu *ngIf="isAdminOrContrib | async">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@guillotinaweb/pastanaga-angular';
import { SDKService } from '@flaps/core';
import { of } from 'rxjs';
import { Nuclia, WritableKnowledgeBox } from '@nuclia/core';
import { Account, Nuclia, WritableKnowledgeBox } from '@nuclia/core';
import { DropdownButtonComponent, SisModalService, SisToastService } from '@nuclia/sistema';
import { RouterTestingModule } from '@angular/router/testing';

Expand All @@ -37,6 +37,7 @@ describe('ResourceTableComponent', () => {
],
providers: [
MockProvider(SDKService, {
currentAccount: of({ id: '123' } as Account),
currentKb: of({
admin: true,
catalog: jest.fn(() => of()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ export class ResourceListService {
}
set status(status: RESOURCE_STATUS) {
this._status = status;
if (status === RESOURCE_STATUS.PENDING && !this.sdk.nuclia.options.standalone) {
if (!this.sdk.nuclia.options.standalone) {
forkJoin([this.sdk.currentAccount.pipe(take(1)), this.sdk.currentKb.pipe(take(1))])
.pipe(
take(1),
switchMap(([account]) => this.sdk.nuclia.db.getProcessingStatus(account.id)),
)
.subscribe((processingStatus) => (this.processingStatus = processingStatus));
.subscribe((processingStatus) => {
this.processingStatus = processingStatus;
});
}
}

Expand Down

0 comments on commit c96728d

Please sign in to comment.