Skip to content

Commit

Permalink
Merge pull request #148 from iver-wharf/fix-quick-run-dropdown
Browse files Browse the repository at this point in the history
Fix click on stage specific dropdown run options
  • Loading branch information
fredx30 authored May 12, 2022
2 parents ac5dfa7 + 9428442 commit 23f6b36
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).

## v1.6.2 (WIP)

- Fixed an issue where input was being ignored on a dropdown for
selecting a specific build stage to run. (#148)

- Fixed log not streaming. (#147)

## v1.6.1 (2022-05-10)
Expand Down
7 changes: 4 additions & 3 deletions src/app/projects/actions-modal/actions-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ActionsModalComponent implements OnInit, OnDestroy {
});
}
// eslint-disable-next-line no-underscore-dangle
this.initialFormState.branch = this.editedProjectInstance.branches.find(o => o._default);
this.initialFormState.branch = this.editedProjectInstance.branches?.find(o => o._default) ?? '';
this.initialFormState.environment =
this.editedProjectInstance.build.environments[1] // 1 to skip the first noEnvironment
|| this.projectUtilsService.noEnvironment;
Expand All @@ -131,6 +131,7 @@ export class ActionsModalComponent implements OnInit, OnDestroy {
inputsGroup.environment = new FormControl('');
inputsGroup.engine = new FormControl('');
this.actionsFormGroup = new FormGroup(inputsGroup);
this.initialFormState.engine = this.initialFormState.engine ?? '';
this.actionsFormGroup.setValue(this.initialFormState);
}

Expand All @@ -147,7 +148,7 @@ export class ActionsModalComponent implements OnInit, OnDestroy {
}

private populateFieldsOfEditableProject() {
if (this.project.build.inputs) {
if (this.project?.build?.inputs) {
Object.values(this.project.build.inputs).map((input, index) => {
const inputField: InputField = {
default: input.default,
Expand All @@ -160,7 +161,7 @@ export class ActionsModalComponent implements OnInit, OnDestroy {
}
});
}
if (this.project.build.environments) {
if (this.project?.build?.environments) {
this.populateEnvironments();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h4>{{project.name}}</h4>
<ng-template pTemplate="side-header-override">
<p-splitButton *ngIf="project.actions" class="button-container"
label="{{projectUtilsService.runAllActionName}}"
[model]="projectUtilsService.getActionsMenuItems(project)"
[model]="buildStageMenuItems"
(onClick)="projectUtilsService.openActions(projectUtilsService.runAllActionName,project)">
</p-splitButton>
</ng-template>
Expand Down
3 changes: 3 additions & 0 deletions src/app/projects/project-details/project-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ActionsModalStore } from '../actions-modal/actions-modal.service';
import { ProjectService } from 'api-client';
import { ActivatedRoute } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { MenuItem } from 'primeng/api/menuitem';

@Component({
selector: 'wh-project-details',
Expand All @@ -23,6 +24,7 @@ export class ProjectDetailsComponent implements OnInit {
buildsTotalCount = 0;
rowsCount = 10;
destroyed$ = new Subject<void>();
buildStageMenuItems: MenuItem[];

constructor(
public projectUtilsService: ProjectUtilsService,
Expand All @@ -47,6 +49,7 @@ export class ProjectDetailsComponent implements OnInit {
const projectId = this.route.snapshot.paramMap.get('projectId');
this.projectService.getProject(Number(projectId)).subscribe(project => {
this.project = project;
this.buildStageMenuItems = this.projectUtilsService.getActionsMenuItems(this.project);
// Temporary initialization to render table, after that loadBuildsLazy handles builds fetching
this.project.buildHistory = [];
this.updateTitle();
Expand Down
12 changes: 7 additions & 5 deletions src/app/projects/project-list/project-list-item.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<td class="col-name">{{project.name}}</td>
<td class="col-name url-link"><a [routerLink]="['/project', project.projectId]">{{project.name}}</a></td>
<td class="col-group">{{project.groupName}}</td>
<td class="col-provider">{{providerHostname}}</td>
<td class="col-status"><span class="not-available">N/A</span></td>
<td class="col-actions">
<p-splitButton *ngIf="projectUtilsService.getActionsMenuItems(project).length > 0"
label="{{projectUtilsService.runAllActionName}}" [model]="projectUtilsService.getActionsMenuItems(project)"
<p-splitButton
[disabled]="!menuItems.length"
[pTooltip]="noStagesTooltip"
label="{{projectUtilsService.runAllActionName}}"
[model]="menuItems"
(onClick)="projectUtilsService.openActions(projectUtilsService.runAllActionName, project)"
(click)="$event.stopPropagation()">
</p-splitButton>
></p-splitButton>
</td>
<td class="col-quickactions">
<wh-project-refresh-icon (refreshed)="refreshed.emit($event)" [project]="project"></wh-project-refresh-icon>
Expand Down
21 changes: 19 additions & 2 deletions src/app/projects/project-list/project-list-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import {
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
} from '@angular/core';
import { WharfProject } from 'src/app/models/main-project.model';
import { NgChanges } from 'src/app/shared/util/ngchanges';
import { LocalStorageProjectsService } from '../local-storage-projects.service';
import { ProjectFavoriteClickEvent } from '../project-favorite/project-favorite-button.component';
import { ProjectRefreshedEvent } from '../project-refresh';
import { ProjectUtilsService } from '../project-utils.service';
import { MenuItem } from 'primeng/api/menuitem';

@Component({
selector: 'wh-project-list-item',
templateUrl: './project-list-item.component.html',
})
export class ProjectListItemComponent implements OnChanges {
export class ProjectListItemComponent implements OnInit, OnChanges {
@Input() project: WharfProject;

@Output() refreshed = new EventEmitter<ProjectRefreshedEvent>();
@Output() favoriteClick = new EventEmitter<ProjectFavoriteClickEvent>();

isRefreshAnimationPlaying: boolean;
providerHostname: string;
menuItems: MenuItem[];
noStagesTooltip;

constructor(
public localStorageProjectsService: LocalStorageProjectsService,
public projectUtilsService: ProjectUtilsService,
) { }

ngOnInit() {
this.menuItems = this.projectUtilsService.getActionsMenuItems(this.project);
if (!this.menuItems.length) {
this.noStagesTooltip = 'There are no stages for this project!';
}
}

ngOnChanges(changes: NgChanges<ProjectListItemComponent>): void {
if (changes.project && this.project?.provider?.url) {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/app/projects/project-list/project-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
[project]="project"
(refreshed)="onProjectRefreshed($event)"
(favoriteClick)="initFavoriteProjects()"
role="button"
(click)="onProjectRowClicked($event, project)"></wh-project-list-item>
></wh-project-list-item>
</ng-template>
</p-table>
</ng-template>
Expand Down
4 changes: 0 additions & 4 deletions src/app/projects/project-list/project-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export class ProjectListComponent implements OnInit {
});
}

onProjectRowClicked(event: MouseEvent, project: WharfProject) {
this.router.navigate(['/project', project.projectId]);
}

onProjectRefreshed(event: ProjectRefreshedEvent) {
this.replaceProject(event.projectId);
}
Expand Down
22 changes: 4 additions & 18 deletions src/app/projects/project-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,10 @@ export class ProjectUtilsService {

getActionsMenuItems(proj: WharfProject): MenuItem[] {
if (proj.build != null) {
proj.actions = [];
return Object.keys(proj.build)
const actions: MenuItem[] = Object.keys(proj.build)
.filter(x => !this.actionsExcludedElements.includes(x))
.map((x) => {
proj.actions.push({ label: x, value: x });
return { label: x, command: () => this.openActions(x, proj) };
});
}
return [];
}

getActionsEnvironments(proj: WharfProject): string[] {
if (proj.build != null) {
const actions = Object.keys(proj.build || {})
.filter(x => !this.actionsExcludedElements.includes(x))
.map(x => proj.build[x].environments);

return [...new Set<string>([].concat.apply([], actions))];
.map<MenuItem>(x => ({ label: x, value: x, command: () => this.openActions(x, proj) }));
return actions;
}
return [];
}
Expand All @@ -47,7 +33,7 @@ export class ProjectUtilsService {
return [...new Set<string>(Object.keys(proj.build.environments || {}))];
}

openActions(label, proj) {
openActions(label, proj: WharfProject) {
this.actionsModalStore.openModal(
{
project: proj,
Expand Down
4 changes: 0 additions & 4 deletions src/scss/project-list-item.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ body .p-datatable .p-datatable-tbody > wh-project-list-item {

&:hover {
background-color: $wharf_table_row_hover_background_color;

&[role="button"] {
cursor: pointer;
}
}

> td {
Expand Down

0 comments on commit 23f6b36

Please sign in to comment.