mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
[ui] Edit volumes (#7061)
* Update volumes * Proxy use ipv4 * Static ui files * e2e tests
This commit is contained in:
@@ -220,6 +220,31 @@ describe('devfile editor spec', () => {
|
||||
.should('contain.text', 'Yes')
|
||||
});
|
||||
|
||||
it('displays a modified volume', () => {
|
||||
cy.init();
|
||||
|
||||
cy.selectTab(TAB_VOLUMES);
|
||||
cy.getByDataCy('volume-name').type('created-volume');
|
||||
cy.getByDataCy('volume-size').type('512Mi');
|
||||
cy.getByDataCy('volume-ephemeral').click();
|
||||
cy.getByDataCy('volume-create').click();
|
||||
|
||||
cy.getByDataCy('volume-info').first()
|
||||
.should('contain.text', 'created-volume')
|
||||
.should('contain.text', '512Mi')
|
||||
.should('contain.text', 'Yes');
|
||||
|
||||
cy.getByDataCy('volume-edit').click();
|
||||
cy.getByDataCy('volume-size').type('{selectAll}{del}1Gi');
|
||||
cy.getByDataCy('volume-ephemeral').click();
|
||||
cy.getByDataCy('volume-save').click();
|
||||
|
||||
cy.getByDataCy('volume-info').first()
|
||||
.should('contain.text', 'created-volume')
|
||||
.should('contain.text', '1Gi')
|
||||
.should('contain.text', 'No');
|
||||
});
|
||||
|
||||
it('creates an exec command with a new container', () => {
|
||||
cy.init();
|
||||
|
||||
|
||||
1
ui/src/app/api-gen/.openapi-generator/FILES
generated
1
ui/src/app/api-gen/.openapi-generator/FILES
generated
@@ -31,6 +31,7 @@ model/devstateImagePostRequest.ts
|
||||
model/devstateQuantityValidPostRequest.ts
|
||||
model/devstateResourcePostRequest.ts
|
||||
model/devstateVolumePostRequest.ts
|
||||
model/devstateVolumeVolumeNamePatchRequest.ts
|
||||
model/endpoint.ts
|
||||
model/env.ts
|
||||
model/events.ts
|
||||
|
||||
71
ui/src/app/api-gen/api/devstate.service.ts
generated
71
ui/src/app/api-gen/api/devstate.service.ts
generated
@@ -47,6 +47,8 @@ import { DevstateResourcePostRequest } from '../model/devstateResourcePostReques
|
||||
// @ts-ignore
|
||||
import { DevstateVolumePostRequest } from '../model/devstateVolumePostRequest';
|
||||
// @ts-ignore
|
||||
import { DevstateVolumeVolumeNamePatchRequest } from '../model/devstateVolumeVolumeNamePatchRequest';
|
||||
// @ts-ignore
|
||||
import { GeneralError } from '../model/generalError';
|
||||
// @ts-ignore
|
||||
import { GeneralSuccess } from '../model/generalSuccess';
|
||||
@@ -1486,4 +1488,73 @@ export class DevstateService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a volume
|
||||
* @param volumeName Volume name to update
|
||||
* @param devstateVolumeVolumeNamePatchRequest
|
||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.
|
||||
*/
|
||||
public devstateVolumeVolumeNamePatch(volumeName: string, devstateVolumeVolumeNamePatchRequest?: DevstateVolumeVolumeNamePatchRequest, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<GeneralSuccess>;
|
||||
public devstateVolumeVolumeNamePatch(volumeName: string, devstateVolumeVolumeNamePatchRequest?: DevstateVolumeVolumeNamePatchRequest, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<GeneralSuccess>>;
|
||||
public devstateVolumeVolumeNamePatch(volumeName: string, devstateVolumeVolumeNamePatchRequest?: DevstateVolumeVolumeNamePatchRequest, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<GeneralSuccess>>;
|
||||
public devstateVolumeVolumeNamePatch(volumeName: string, devstateVolumeVolumeNamePatchRequest?: DevstateVolumeVolumeNamePatchRequest, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
|
||||
if (volumeName === null || volumeName === undefined) {
|
||||
throw new Error('Required parameter volumeName was null or undefined when calling devstateVolumeVolumeNamePatch.');
|
||||
}
|
||||
|
||||
let localVarHeaders = this.defaultHeaders;
|
||||
|
||||
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
|
||||
if (localVarHttpHeaderAcceptSelected === undefined) {
|
||||
// to determine the Accept header
|
||||
const httpHeaderAccepts: string[] = [
|
||||
'application/json'
|
||||
];
|
||||
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
|
||||
}
|
||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||
}
|
||||
|
||||
let localVarHttpContext: HttpContext | undefined = options && options.context;
|
||||
if (localVarHttpContext === undefined) {
|
||||
localVarHttpContext = new HttpContext();
|
||||
}
|
||||
|
||||
|
||||
// to determine the Content-Type header
|
||||
const consumes: string[] = [
|
||||
'application/json'
|
||||
];
|
||||
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
|
||||
if (httpContentTypeSelected !== undefined) {
|
||||
localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected);
|
||||
}
|
||||
|
||||
let responseType_: 'text' | 'json' | 'blob' = 'json';
|
||||
if (localVarHttpHeaderAcceptSelected) {
|
||||
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
|
||||
responseType_ = 'text';
|
||||
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
|
||||
responseType_ = 'json';
|
||||
} else {
|
||||
responseType_ = 'blob';
|
||||
}
|
||||
}
|
||||
|
||||
let localVarPath = `/devstate/volume/${this.configuration.encodeParam({name: "volumeName", value: volumeName, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`;
|
||||
return this.httpClient.request<GeneralSuccess>('patch', `${this.configuration.basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
body: devstateVolumeVolumeNamePatchRequest,
|
||||
responseType: <any>responseType_,
|
||||
withCredentials: this.configuration.withCredentials,
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
reportProgress: reportProgress
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
ui/src/app/api-gen/model/devstateVolumeVolumeNamePatchRequest.ts
generated
Normal file
24
ui/src/app/api-gen/model/devstateVolumeVolumeNamePatchRequest.ts
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* odo dev
|
||||
* API interface for \'odo dev\'
|
||||
*
|
||||
* The version of the OpenAPI document: 0.1
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface DevstateVolumeVolumeNamePatchRequest {
|
||||
/**
|
||||
* Minimal size of the volume
|
||||
*/
|
||||
size?: string;
|
||||
/**
|
||||
* True if the Volume is Ephemeral
|
||||
*/
|
||||
ephemeral?: boolean;
|
||||
}
|
||||
|
||||
1
ui/src/app/api-gen/model/models.ts
generated
1
ui/src/app/api-gen/model/models.ts
generated
@@ -21,6 +21,7 @@ export * from './devstateImagePostRequest';
|
||||
export * from './devstateQuantityValidPostRequest';
|
||||
export * from './devstateResourcePostRequest';
|
||||
export * from './devstateVolumePostRequest';
|
||||
export * from './devstateVolumeVolumeNamePatchRequest';
|
||||
export * from './endpoint';
|
||||
export * from './env';
|
||||
export * from './events';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<div class="main">
|
||||
<h2>Add a new volume</h2>
|
||||
<h2 *ngIf="!volume">Add a new volume</h2>
|
||||
<h2 *ngIf="volume">Edit volume <i>{{volume.name}}</i></h2>
|
||||
<div class="description">A volume can be mounted and shared by several containers.</div>
|
||||
<form [formGroup]="form">
|
||||
<mat-form-field appearance="outline" class="mid-width">
|
||||
@@ -15,6 +16,7 @@
|
||||
|
||||
</form>
|
||||
|
||||
<button data-cy="volume-create" [disabled]="form.invalid" mat-flat-button color="primary" matTooltip="create new volume" (click)="create()">Create</button>
|
||||
<button *ngIf="!volume" data-cy="volume-create" [disabled]="form.invalid" mat-flat-button color="primary" matTooltip="create new volume" (click)="create()">Create</button>
|
||||
<button *ngIf="volume" data-cy="volume-save" [disabled]="form.invalid" mat-flat-button color="primary" matTooltip="save volume" (click)="save()">Save</button>
|
||||
<button *ngIf="cancelable" mat-flat-button (click)="cancel()">Cancel</button>
|
||||
</div>
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { Component, EventEmitter, Input, Output, SimpleChanges } from '@angular/core';
|
||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { Volume } from 'src/app/api-gen';
|
||||
import { TelemetryService } from 'src/app/services/telemetry.service';
|
||||
@@ -12,8 +12,11 @@ import { DevstateService } from 'src/app/services/devstate.service';
|
||||
})
|
||||
export class VolumeComponent {
|
||||
@Input() cancelable: boolean = false;
|
||||
@Input() volume: Volume | undefined;
|
||||
|
||||
@Output() canceled = new EventEmitter<void>();
|
||||
@Output() created = new EventEmitter<Volume>();
|
||||
@Output() saved = new EventEmitter<Volume>();
|
||||
|
||||
form: FormGroup;
|
||||
|
||||
@@ -33,7 +36,28 @@ export class VolumeComponent {
|
||||
this.created.emit(this.form.value);
|
||||
}
|
||||
|
||||
save() {
|
||||
const newValue = this.form.value;
|
||||
newValue.name = this.volume?.name;
|
||||
this.telemetry.track("[ui] edit volume");
|
||||
this.saved.emit(this.form.value);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.canceled.emit();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (!changes['volume']) {
|
||||
return;
|
||||
}
|
||||
const vol = changes['volume'].currentValue;
|
||||
if (vol == undefined) {
|
||||
this.form.get('name')?.enable();
|
||||
} else {
|
||||
this.form.reset();
|
||||
this.form.patchValue(vol);
|
||||
this.form.get('name')?.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,13 @@ export class DevstateService {
|
||||
});
|
||||
}
|
||||
|
||||
saveVolume(volume: Volume): Observable<DevfileContent> {
|
||||
return this.http.patch<DevfileContent>(this.base+"/volume/"+volume.name, {
|
||||
ephemeral: volume.ephemeral,
|
||||
size: volume.size,
|
||||
});
|
||||
}
|
||||
|
||||
addExecCommand(name: string, cmd: ExecCommand): Observable<DevfileContent> {
|
||||
return this.http.post<DevfileContent>(this.base+"/execCommand", {
|
||||
name: name,
|
||||
|
||||
@@ -19,19 +19,22 @@
|
||||
|
||||
<mat-card-actions>
|
||||
<button mat-button color="warn" (click)="delete(volume.name)">Delete</button>
|
||||
<button data-cy="volume-edit" mat-button (click)="edit(volume)">Edit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</mat-card>
|
||||
|
||||
<app-volume
|
||||
*ngIf="forceDisplayAdd || volumes == undefined || volumes.length == 0"
|
||||
[cancelable]="forceDisplayAdd"
|
||||
*ngIf="forceDisplayForm || volumes == undefined || volumes.length == 0"
|
||||
[cancelable]="forceDisplayForm"
|
||||
(canceled)="undisplayAddForm()"
|
||||
(created)="onCreated($event)"
|
||||
[volume]="editingVolume"
|
||||
(saved)="onSaved($event)"
|
||||
></app-volume>
|
||||
</div>
|
||||
|
||||
<ng-container *ngIf="!forceDisplayAdd && volumes != undefined && volumes.length > 0">
|
||||
<ng-container *ngIf="!forceDisplayForm && volumes != undefined && volumes.length > 0">
|
||||
<button class="fab" mat-fab color="primary" (click)="displayAddForm()">
|
||||
<mat-icon class="material-icons-outlined">add</mat-icon>
|
||||
</button>
|
||||
|
||||
@@ -10,8 +10,9 @@ import { StateService } from 'src/app/services/state.service';
|
||||
})
|
||||
export class VolumesComponent {
|
||||
|
||||
forceDisplayAdd: boolean = false;
|
||||
forceDisplayForm: boolean = false;
|
||||
volumes: Volume[] | undefined = [];
|
||||
editingVolume: Volume | undefined;
|
||||
|
||||
constructor(
|
||||
private state: StateService,
|
||||
@@ -25,19 +26,24 @@ export class VolumesComponent {
|
||||
if (this.volumes == null) {
|
||||
return
|
||||
}
|
||||
that.forceDisplayAdd = false;
|
||||
that.forceDisplayForm = false;
|
||||
});
|
||||
}
|
||||
|
||||
displayAddForm() {
|
||||
this.forceDisplayAdd = true;
|
||||
this.editingVolume = undefined;
|
||||
this.displayForm();
|
||||
}
|
||||
|
||||
displayForm() {
|
||||
this.forceDisplayForm = true;
|
||||
setTimeout(() => {
|
||||
this.scrollToBottom();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
undisplayAddForm() {
|
||||
this.forceDisplayAdd = false;
|
||||
this.forceDisplayForm = false;
|
||||
}
|
||||
|
||||
delete(name: string) {
|
||||
@@ -54,6 +60,11 @@ export class VolumesComponent {
|
||||
}
|
||||
}
|
||||
|
||||
edit(volume: Volume) {
|
||||
this.editingVolume = volume;
|
||||
this.displayForm();
|
||||
}
|
||||
|
||||
onCreated(volume: Volume) {
|
||||
const result = this.devstate.addVolume(volume);
|
||||
result.subscribe({
|
||||
@@ -66,6 +77,18 @@ export class VolumesComponent {
|
||||
});
|
||||
}
|
||||
|
||||
onSaved(volume: Volume) {
|
||||
const result = this.devstate.saveVolume(volume);
|
||||
result.subscribe({
|
||||
next: value => {
|
||||
this.state.changeDevfileYaml(value);
|
||||
},
|
||||
error: error => {
|
||||
alert(error.error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
scrollToBottom() {
|
||||
window.scrollTo(0,document.body.scrollHeight);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"/api/v1": {
|
||||
"target": "http://localhost:20000",
|
||||
"target": "http://127.0.0.1:20000",
|
||||
"secure": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user