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

[ui] Fix Add/Remove events #7027

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
2 changes: 1 addition & 1 deletion pkg/apiserver-impl/ui/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ui/cypress/e2e/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export const TAB_YAML = 0;
export const TAB_CHART = 1;
export const TAB_METADATA = 2;
export const TAB_COMMANDS = 3;
export const TAB_VOLUMES = 4;
export const TAB_EVENTS = 4;
export const TAB_CONTAINERS = 5;
export const TAB_IMAGES = 6;
export const TAB_RESOURCES = 7;
export const TAB_VOLUMES = 8;
17 changes: 16 additions & 1 deletion ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TAB_COMMANDS, TAB_CONTAINERS, TAB_IMAGES, TAB_METADATA, TAB_RESOURCES} from './consts';
import {TAB_YAML, TAB_COMMANDS, TAB_CONTAINERS, TAB_IMAGES, TAB_METADATA, TAB_RESOURCES, TAB_EVENTS} from './consts';

describe('devfile editor spec', () => {

Expand Down Expand Up @@ -224,4 +224,19 @@ describe('devfile editor spec', () => {
.should('contain.text', 'some command')
.should('contain.text', 'some arg');
});

it('adds an event with an existing command', () => {
cy.init();
cy.fixture('input/with-exec-command.yaml').then(yaml => {
cy.setDevfile(yaml);
});
cy.selectTab(TAB_EVENTS);
cy.get('[data-cy="prestop"] [data-cy="input"]').click().type("{downArrow}{enter}");
cy.selectTab(TAB_YAML);
cy.get('[data-cy="yaml-input"]').should("contain.value", "events:\n preStop:\n - command1");
cy.selectTab(TAB_EVENTS);
cy.get('[data-cy="prestop"] button.mat-mdc-chip-remove').click();
cy.selectTab(TAB_YAML);
cy.get('[data-cy="yaml-input"]').should("contain.value", "events: {}");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</button>
</mat-chip-row>
</mat-chip-grid>
<input placeholder="New command..." #commandInput [formControl]="commandCtrl"
<input data-cy="input" placeholder="New command..." #commandInput [formControl]="commandCtrl"
[matChipInputFor]="chipGrid" [matAutocomplete]="auto"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="add($event)"/>
Expand Down
10 changes: 6 additions & 4 deletions ui/src/app/controls/chips-events/chips-events.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, Output, SimpleChanges } from '@angular/core';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { MatChipInputEvent } from '@angular/material/chips';
import {COMMA, ENTER} from '@angular/cdk/keycodes';
Expand All @@ -17,10 +17,12 @@ export class ChipsEventsComponent {

separatorKeysCodes: number[] = [ENTER, COMMA];
commandCtrl = new FormControl('');
filteredCommands: Observable<string[]>;
filteredCommands = new (Observable<string[]>);


constructor(public commandInput :ElementRef<HTMLInputElement>) {
constructor(public commandInput :ElementRef<HTMLInputElement>) {}

ngOnChanges(changes: SimpleChanges) {
this.filteredCommands = this.commandCtrl.valueChanges.pipe(
startWith(null),
map((cmd: string | null) => (cmd ? this._filter(cmd) : this.allCommands.slice())),
Expand All @@ -44,7 +46,7 @@ export class ChipsEventsComponent {

remove(command: string): void {
const index = this.commands.indexOf(command);

if (index >= 0) {
this.commands.splice(index, 1);
this.updated.emit(this.commands);
Expand Down
8 changes: 4 additions & 4 deletions ui/src/app/tabs/events/events.component.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<div class="main">
<h2>Pre-Start event</h2>
<div class="description">Pre-Start commands are executed before the inner loop is started, inside init-containers (not implemented by odo).</div>
<app-chips-events
<app-chips-events data-cy="prestart"
[commands]="events?.preStart ?? []"
[allCommands]="allCommands ?? []"
(updated)="onUpdate('preStart', $event)"
></app-chips-events>

<h2>Post-Start event</h2>
<div class="description">Post-Start commands are executed at the beginning of the inner loop, inside pre-fetched containers.</div>
<app-chips-events
<app-chips-events data-cy="poststart"
[commands]="events?.postStart ?? []"
[allCommands]="allCommands ?? []"
(updated)="onUpdate('postStart', $event)"
></app-chips-events>

<h2>Pre-Stop event</h2>
<div class="description">Pre-Stop commands are executed at the end of the inner loop, inside pre-fetched containers.</div>
<app-chips-events
<app-chips-events data-cy="prestop"
[commands]="events?.preStop ?? []"
[allCommands]="allCommands ?? []"
(updated)="onUpdate('preStop', $event)"
></app-chips-events>

<h2>Post-Stop event</h2>
<div class="description">Post-Stop commands are executed after the inner loop is finished (not implemented by odo).</div>
<app-chips-events
<app-chips-events data-cy="poststop"
[commands]="events?.postStop ?? []"
[allCommands]="allCommands ?? []"
(updated)="onUpdate('postStop', $event)"
Expand Down
15 changes: 15 additions & 0 deletions ui/src/app/tabs/events/events.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ export class EventsComponent {
ngOnInit() {
this.state.state.subscribe(async newContent => {
this.events = newContent?.events;
if (this.events == undefined) {
this.events = {};
}
if (this.events.preStart == undefined) {
this.events.preStart = [];
}
if (this.events.preStop == undefined) {
this.events.preStop = [];
}
if (this.events.postStart == undefined) {
this.events.postStart = [];
}
if (this.events.postStop == undefined) {
this.events.postStop = [];
}
this.allCommands = newContent?.commands?.map(c => c.name);
});
}
Expand Down