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

fix UI issues #1791

Merged
merged 7 commits into from
Nov 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 components/builder-web/app/actions/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export function demotePackage(origin: string, name: string, version: string, rel
export function fetchPackage(pkg) {
return dispatch => {
depotApi.get(pkg.ident).then(response => {
dispatch(setCurrentPackage(response['results']));
const pkg = response['results'];
dispatch(setCurrentPackage(pkg));
dispatch(fetchPackageChannels(pkg.ident.origin, pkg.ident.name, pkg.ident.version, pkg.ident.release, pkg.target));
}).catch(error => {
dispatch(setCurrentPackage(undefined, error));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2022 Chef Software Inc. and/or applicable contributors
// Copyright (c) 2016-2023 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,7 +60,8 @@ export class PackageDetailComponent {
}

titleFrom(platform) {
return targetFrom('id', platform).title;
const target = targetFrom('id', platform);
return target ? target.title : '';
}

get memberOfOrigin() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2022 Chef Software Inc. and/or applicable contributors
// Copyright (c) 2016-2023 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
import { Component, OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { debounceTime, filter, take, takeUntil } from 'rxjs/operators';
import { AppStore } from '../../app.store';
import { requestRoute } from '../../actions/index';

Expand All @@ -25,6 +25,9 @@ import { requestRoute } from '../../actions/index';
export class PackageReleaseComponent implements OnDestroy {

private isDestroyed$: Subject<boolean> = new Subject();
// Wait fot this ms before checking for error
private debounceDuration = 500;
private maxAttempts = 5;

constructor(
private store: AppStore,
Expand All @@ -37,9 +40,14 @@ export class PackageReleaseComponent implements OnDestroy {
});

this.store.observe('packages.ui.current.errorMessage')
.pipe(takeUntil(this.isDestroyed$))
.subscribe(errorMessage => {
if (errorMessage) {
.pipe(
takeUntil(this.isDestroyed$),
filter(errorMessage => errorMessage !== null),
debounceTime(this.debounceDuration),
take(this.maxAttempts),
)
.subscribe((errorMessage) => {
if (errorMessage && errorMessage === 'Not Found') {
this.store.dispatch(requestRoute(['/pkgs']));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h3>Latest Stable</h3>
<a [routerLink]="['./', latestStable.ident.version, latestStable.ident.release]">
{{ latestStable.ident.version }}/{{ latestStable.ident.release }}
</a>
<span class="wbs" >{{ nameFrom(platform.id) }}</span>
<span class="wbs" >{{ nameFrom(latestStable.target) }}</span>
</p>
<p *ngIf="!latestStable && !loadingLatestStable">
None.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class PackageSidebarComponent {
}

nameFrom(platform) {
return targetFrom('id', platform).name;
const target = targetFrom('id', platform);
return target ? target.name : '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class PackageVersionsComponent implements OnDestroy {
}

nameFrom(platform) {
return targetFrom('id', platform).name;
const target = targetFrom('id', platform);
return target ? target.name : '';
}
}
40 changes: 29 additions & 11 deletions components/builder-web/app/package/package/package.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ export class PackageComponent implements OnInit, OnDestroy {
filter(([versionsLoading]) => !versionsLoading)
)
.subscribe(([versionsLoading, origin, name, target, platforms]) => {
const defaultTarget = platforms.length ? platforms[0] : allPlatforms[0];
const currentTarget = target ?
targetFrom('param', target || defaultTarget.param) :
targetFrom('id', this.target || defaultTarget.id);
const latestVersion = this.store.getState().packages.versions?.[0];
const tgt = target ? targetFrom('param', target).id : latestVersion ? latestVersion.platforms[0] : allPlatforms[0].id;
const currentTarget = targetFrom('id', tgt);
this.target = currentTarget.id;
this.store.dispatch(setCurrentPackageTarget(currentTarget));
this.fetchLatest();
this.fetchLatestStable();

// This particularly happens when we refresh the page
// Just ensure we are on the latest page
if (!this.ident.version && !this.ident.release) {
this.fetchLatest();
this.fetchLatestStable();
}
});

combineLatest(versionsLoading$, origin$, name$, target$, token$, origins$, platforms$)
Expand Down Expand Up @@ -246,12 +250,29 @@ export class PackageComponent implements OnInit, OnDestroy {
this.store.dispatch(fetchOrigin(this.origin));
}

private getLatestPlatform(target) {
const versions = this.store.getState().packages?.versions;
if (!versions) {
return target;
}

const platformFound = versions.some(item => item.platforms.includes(target));
if (platformFound) {
return target;
}

return versions[0].platforms[0];
}

private fetchLatest() {
this.store.dispatch(fetchLatestPackage(this.origin, this.name, this.target));
const target = this.getLatestPlatform(this.target);
this.store.dispatch(fetchLatestPackage(this.origin, this.name, target));
const currentTarget = targetFrom('id', target);
this.store.dispatch(setCurrentPackageTarget(currentTarget));
}

private fetchLatestStable() {
this.store.dispatch(fetchLatestInChannel(this.origin, this.name, 'stable', this.target));
this.store.dispatch(fetchLatestInChannel(this.origin, this.name, 'stable', this.getLatestPlatform(this.target)));
}

private fetchPackageSettings() {
Expand All @@ -277,8 +298,5 @@ export class PackageComponent implements OnInit, OnDestroy {

private fetchRelease() {
this.store.dispatch(fetchPackage({ ident: this.ident }));
this.store.dispatch(fetchPackageChannels(
this.ident.origin, this.ident.name, this.ident.version, this.ident.release
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ export class ProjectSettingsComponent implements OnChanges, OnDestroy, AfterView
}

nameFrom(platform) {
return targetFrom('id', platform).name;
const target = targetFrom('id', platform);
return target ? target.name : '';
}

pickInstallation(install) {
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test/builder-api/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ require('./jobs.js');
require('./ext.js');
require('./misc.js');
require('./roles.js');
require('./etc.js');
94 changes: 94 additions & 0 deletions test/builder-api/src/etc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const expect = require("chai").expect;
const supertest = require("supertest");
const request = supertest("http://localhost:9636/v1");
const fs = require("fs");

const release = '20231113160958';
const release1 = '20231116041041';

const file = fs.readFileSync(__dirname + `/../fixtures/neurosis-winapp-0.1.0-${release}-x86_64-windows.hart`);
const file1 = fs.readFileSync(__dirname + `/../fixtures/neurosis-winapp-0.1.0-${release1}-x86_64-windows.hart`);

describe("Additional APIs", function () {
describe("Package uploads", function () {
it('uploads a windows only package', function (done) {
request.post(`/depot/pkgs/neurosis/winapp/0.1.0/${release}`)
.set('Authorization', global.boboBearer)
.set('Content-Length', file.length)
.query({ checksum: 'b4dad6c7ee397919b0cfcbb85bed9d047b0a86c5e4ece6cc4ef651528dbabb85' })
.send(file)
.expect(201)
.end(function (err, res) {
expect(res.text).to.equal(`/pkgs/neurosis/winapp/0.1.0/${release}/download`);
done(err);
});
});

it('toggles the public setting for a package', function (done) {
request.patch(`/depot/pkgs/neurosis/winapp/0.1.0/${release}/public`)
.set('Authorization', global.boboBearer)
.type('application/json')
.accept('application/json')
.expect(200)
.end(function (err, res) {
expect(res.text).to.be.empty;
done(err);
});
});

it('puts the winapp package into the bar channel', function (done) {
request.put(`/depot/channels/neurosis/bar/pkgs/winapp/0.1.0/${release}/promote?target=x86_64-windows`)
.set('Authorization', global.boboBearer)
.expect(200)
.end(function (err, res) {
expect(res.text).to.be.empty;
done(err);
});
});

it('puts the winapp package into the stable channel', function (done) {
request.put(`/depot/channels/neurosis/stable/pkgs/winapp/0.1.0/${release}/promote?target=x86_64-windows`)
.set('Authorization', global.boboBearer)
.expect(200)
.end(function (err, res) {
expect(res.text).to.be.empty;
done(err);
});
});

it('uploads a latest package', function (done) {
request.post(`/depot/pkgs/neurosis/winapp/0.1.0/${release1}`)
.set('Authorization', global.boboBearer)
.set('Content-Length', file1.length)
.query({ checksum: '148ea3fc9b5818e76ab84150a3ba9e630ec608c591472b969ba32ca1b65dc136' })
.send(file1)
.expect(201)
.end(function (err, res) {
expect(res.text).to.equal(`/pkgs/neurosis/winapp/0.1.0/${release1}/download`);
done(err);
});
});

it('toggles the public setting for new release', function (done) {
request.patch(`/depot/pkgs/neurosis/winapp/0.1.0/${release1}/public`)
.set('Authorization', global.boboBearer)
.type('application/json')
.accept('application/json')
.expect(200)
.end(function (err, res) {
expect(res.text).to.be.empty;
done(err);
});
});

it('puts the new relase into the stable channel', function (done) {
request.put(`/depot/channels/neurosis/stable/pkgs/winapp/0.1.0/${release1}/promote?target=x86_64-windows`)
.set('Authorization', global.boboBearer)
.expect(200)
.end(function (err, res) {
expect(res.text).to.be.empty;
done(err);
});
});
});
});