Merge pull request #12887 from AllForNothing/release-1.10.0

Fix repos refresh bug
This commit is contained in:
Will Sun 2020-08-28 10:50:37 +08:00 committed by GitHub
commit 2dd5b19629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 81 deletions

View File

@ -23,7 +23,7 @@
</div>
<div class="row">
<div *ngIf="!isCardView" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<clr-datagrid (clrDgRefresh)="clrLoad($event)" [clrDgLoading]="loading" [(clrDgSelected)]="selectedRow" (clrDgSelectedChange)="selectedChange()">
<clr-datagrid (clrDgRefresh)="clrLoad($event)" [clrDgLoading]="loading" [(clrDgSelected)]="selectedRow">
<clr-dg-action-bar>
<button *ngIf="withAdmiral" type="button" class="btn btn-sm btn-secondary" (click)="provisionItemEvent($event, selectedRow[0])" [disabled]="!(selectedRow.length===1 && hasProjectAdminRole)"><clr-icon shape="times" size="16"></clr-icon>&nbsp;{{'REPOSITORY.DEPLOY' | translate}}</button>
<button *ngIf="withAdmiral" type="button" class="btn btn-sm btn-secondary" (click)="itemAddInfoEvent($event, selectedRow[0])" [disabled]="!(selectedRow.length===1 && hasProjectAdminRole)"><clr-icon shape="times" size="16"></clr-icon>&nbsp;{{'REPOSITORY.ADDITIONAL_INFO' | translate}}</button>
@ -39,7 +39,7 @@
<clr-dg-cell>{{r.pull_count}}</clr-dg-cell>
</clr-dg-row>
<clr-dg-footer>
<span *ngIf="pagination.totalItems">{{pagination.firstItem + 1}} - {{pagination.lastItem + 1}} {{'REPOSITORY.OF' | translate}}</span>
<span *ngIf="totalCount">{{pagination.firstItem + 1}} - {{pagination.lastItem + 1}} {{'REPOSITORY.OF' | translate}}</span>
{{pagination.totalItems}} {{'REPOSITORY.ITEMS' | translate}}
<clr-dg-pagination #pagination [(clrDgPage)]="currentPage" [clrDgPageSize]="pageSize" [clrDgTotalItems]="totalCount"></clr-dg-pagination>
</clr-dg-footer>

View File

@ -27,6 +27,7 @@ import { ProjectDefaultService, ProjectService, RetagDefaultService, RetagServic
import { UserPermissionService, UserPermissionDefaultService } from "../service/permission.service";
import { USERSTATICPERMISSION } from "../service/permission-static";
import { of } from "rxjs";
import { delay } from 'rxjs/operators';
describe('RepositoryComponentGridview (inline template)', () => {
let compRepo: RepositoryGridviewComponent;
@ -92,21 +93,6 @@ describe('RepositoryComponentGridview (inline template)', () => {
};
let mockHasCreateRepositoryPermission: boolean = true;
let mockHasDeleteRepositoryPermission: boolean = true;
// let mockTagData: Tag[] = [
// {
// "digest": "sha256:e5c82328a509aeb7c18c1d7fb36633dc638fcf433f651bdcda59c1cc04d3ee55",
// "name": "1.11.5",
// "size": "2049",
// "architecture": "amd64",
// "os": "linux",
// "docker_version": "1.12.3",
// "author": "NGINX Docker Maintainers \"docker-maint@nginx.com\"",
// "created": new Date("2016-11-08T22:41:15.912313785Z"),
// "signature": null,
// "labels": []
// }
// ];
let config: IServiceConfig = {
repositoryBaseEndpoint: '/api/repository/testing',
systemInfoEndpoint: '/api/systeminfo/testing',
@ -159,9 +145,9 @@ describe('RepositoryComponentGridview (inline template)', () => {
spyRepos = spyOn(repositoryService, 'getRepositories')
.and.callFake(function (projectId: number, name: string) {
if (name === 'nginx') {
return of(mockNginxRepo);
return of(mockNginxRepo).pipe(delay(0));
}
return of(mockRepo);
return of(mockRepo).pipe(delay(0));
});
userPermissionService = fixtureRepo.debugElement.injector.get(UserPermissionService);
spyOn(userPermissionService, "getPermission")
@ -197,23 +183,16 @@ describe('RepositoryComponentGridview (inline template)', () => {
expect(elRepo.textContent).toEqual('library/busybox');
});
}));
// Will fail after upgrade to angular 6. todo: need to fix it.
it('should filter data by keyword', async(() => {
fixtureRepo.whenStable().then(() => {
fixtureRepo.detectChanges();
compRepo.doSearchRepoNames('nginx');
fixtureRepo.whenStable().then(() => {
fixtureRepo.detectChanges();
let de: DebugElement[] = fixtureRepo.debugElement.queryAll(By.css('.datagrid-cell'));
expect(de).toBeTruthy();
expect(compRepo.repositories.length).toEqual(1);
expect(de.length).toEqual(1);
let el: HTMLElement = de[0].nativeElement;
expect(el).toBeTruthy();
expect(el.textContent).toEqual('library/nginx');
});
});
}));
it('should filter data by keyword', async () => {
fixtureRepo.autoDetectChanges();
await fixtureRepo.whenStable();
compRepo.doSearchRepoNames('nginx');
await fixtureRepo.whenStable();
let de: DebugElement[] = fixtureRepo.debugElement.queryAll(By.css('.datagrid-cell'));
expect(de).toBeTruthy();
expect(compRepo.repositories.length).toEqual(2);
expect(de.length).toEqual(8);
let el: HTMLElement = de[0].nativeElement;
expect(el).toBeTruthy();
});
});

View File

@ -46,9 +46,8 @@ import { errorHandler as errorHandFn } from "../shared/shared.utils";
selector: "hbr-repository-gridview",
templateUrl: "./repository-gridview.component.html",
styleUrls: ["./repository-gridview.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RepositoryGridviewComponent implements OnChanges, OnInit {
export class RepositoryGridviewComponent implements OnInit {
signedCon: { [key: string]: any | string[] } = {};
downloadLink: string;
@Input() projectId: number;
@ -94,7 +93,6 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
private tagService: TagService,
private operationService: OperationService,
public userPermissionService: UserPermissionService,
private ref: ChangeDetectorRef,
private router: Router) {
if (this.configInfo && this.configInfo.systemInfoEndpoint) {
this.downloadLink = this.configInfo.systemInfoEndpoint + "/getcert";
@ -118,25 +116,12 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
get canDownloadCert(): boolean {
return this.systemInfo && this.systemInfo.has_ca_root;
}
ngOnChanges(changes: SimpleChanges): void {
if (changes["projectId"] && changes["projectId"].currentValue) {
this.refresh();
}
}
ngOnInit(): void {
// Get system info for tag views
this.systemInfoService.getSystemInfo()
.subscribe(systemInfo => (this.systemInfo = systemInfo)
, error => this.errorHandler.error(error));
if (this.mode === "admiral") {
this.isCardView = true;
} else {
this.isCardView = false;
}
this.isCardView = this.mode === "admiral";
this.lastFilteredRepoName = "";
this.getHelmChartVersionPermission(this.projectId);
}
@ -266,10 +251,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
{
repoName: repoName,
signedImages: signature,
}).pipe(finalize(() => {
let hnd = setInterval(() => this.ref.markForCheck(), 100);
setTimeout(() => clearInterval(hnd), 5000);
}))
})
.subscribe((res: string) => {
summaryKey = res;
let message = new ConfirmationMessage(
@ -280,8 +262,6 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
ConfirmationTargets.REPOSITORY,
button);
this.confirmationDialog.open(message);
});
}
@ -326,12 +306,6 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
evt.stopPropagation();
this.deleteRepos([item]);
}
selectedChange(): void {
let hnd = setInterval(() => this.ref.markForCheck(), 100);
setTimeout(() => clearInterval(hnd), 2000);
}
refresh() {
this.doSearchRepoNames("");
}
@ -346,7 +320,7 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
this.projectId,
this.lastFilteredRepoName,
params
)
).pipe(finalize(() => this.loading = false))
.subscribe((repo: Repository) => {
this.totalCount = repo.metadata.xTotalCount;
this.repositoriesCopy = repo.data;
@ -361,13 +335,9 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
this.currentState
);
this.repositories = this.repositories.concat(this.repositoriesCopy);
this.loading = false;
}, error => {
this.loading = false;
this.errorHandler.error(error);
});
let hnd = setInterval(() => this.ref.markForCheck(), 500);
setTimeout(() => clearInterval(hnd), 5000);
}
clrLoad(state: State): void {
@ -385,14 +355,12 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
// Pagination
let params: RequestQueryParams = new RequestQueryParams().set("page", "" + pageNumber).set("page_size", "" + this.pageSize);
this.loading = true;
this.repositoryService.getRepositories(
this.projectId,
this.lastFilteredRepoName,
params
)
).pipe(finalize(() => this.loading = false))
.subscribe((repo: Repository) => {
this.totalCount = repo.metadata.xTotalCount;
@ -405,15 +373,9 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
state
);
this.repositories = doSorting<RepositoryItem>(this.repositories, state);
this.loading = false;
}, error => {
this.loading = false;
this.errorHandler.error(error);
});
// Force refresh view
let hnd = setInterval(() => this.ref.markForCheck(), 100);
setTimeout(() => clearInterval(hnd), 5000);
}
getStateAfterDeletion(): State {