Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Extract PR state into separate coponent

Oliver Günther4c66fc1d18e0
diff --git a/modules/github_integration/frontend/module/main.ts b/modules/github_integration/frontend/module/main.ts
index 6f0bec286f3..7d8f937e64a 100644
--- a/modules/github_integration/frontend/module/main.ts
+++ b/modules/github_integration/frontend/module/main.ts
@@ -45,8 +45,8 @@ import {
githubPullRequestMacroSelector,
PullRequestMacroComponent,
} from './pull-request/pull-request-macro.component';
-import { HookService } from 'core-app/features/plugins/hook-service';
import { DynamicBootstrapper } from 'core-app/core/setup/globals/dynamic-bootstrapper';
+import { PullRequestStateComponent } from './pull-request/pull-request-state.component';
export function workPackageGithubPrsCount(
workPackage:WorkPackageResource,
@@ -87,6 +87,7 @@ export function initializeGithubIntegrationPlugin(injector:Injector) {
GitActionsMenuComponent,
PullRequestComponent,
PullRequestMacroComponent,
+ PullRequestStateComponent,
],
exports: [
GitHubTabComponent,
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.html b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.html
index 51fdd970ae6..794b385ecf9 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.html
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.html
@@ -1,6 +1,13 @@
-<ng-container *ngIf="(pullRequest$ | async) as pr; else loadingTemplate">
- foo
-</ng-container>
+<div
+ class="op-pull-request-macro"
+ *ngIf="(pullRequest$ | async) as pr; else loadingTemplate">
+ <op-github-pull-request-state
+ class="op-pull-request-macro--state"
+ [small]="true"
+ [state]="pullRequestState"
+ ></op-github-pull-request-state>
+ <span [innerHTML]="displayText$ | async"></span>
+</div>
<ng-template #loadingTemplate>
<op-content-loader
viewBox="0 0 200 5"
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.sass b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.sass
new file mode 100644
index 00000000000..b2886439280
--- /dev/null
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.sass
@@ -0,0 +1,34 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+@import "helpers"
+
+.op-pull-request-macro
+ &--state
+ display: inline-block
+ margin-right: 0.25rem
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.ts b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.ts
index e05266dc6bf..712d83588fd 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.ts
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-macro.component.ts
@@ -39,14 +39,16 @@ import { populateInputsFromDataset } from 'core-app/shared/components/dataset-in
import { IGithubPullRequest } from '../state/github-pull-request.model';
import { GithubPullRequestResourceService } from '../state/github-pull-request.service';
import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { PullRequestState } from './pull-request-state.component';
export const githubPullRequestMacroSelector = 'macro.github_pull_request';
-export type PullRequestState = 'opened'|'closed'|'referenced'|'ready_for_review'|'merged'|'draft';
-
@Component({
selector: githubPullRequestMacroSelector,
templateUrl: './pull-request-macro.component.html',
+ styleUrls: ['./pull-request-macro.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
HalResourceEditingService,
@@ -59,10 +61,13 @@ export class PullRequestMacroComponent implements OnInit {
pullRequest$:Observable<IGithubPullRequest>;
+ displayText$:Observable<string>;
+
constructor(
readonly elementRef:ElementRef,
readonly injector:Injector,
readonly pullRequests:GithubPullRequestResourceService,
+ readonly I18n:I18nService,
) {
populateInputsFromDataset(this);
}
@@ -71,5 +76,40 @@ export class PullRequestMacroComponent implements OnInit {
this.pullRequest$ = this
.pullRequests
.requireSingle(this.pullRequestId);
+
+ this.displayText$ = this
+ .pullRequest$
+ .pipe(
+ map((pr) => this.buildText(pr)),
+ );
+ }
+
+ private buildText(pr:IGithubPullRequest):string {
+ const githubUserLink = this.htmlLink(pr._embedded.githubUser.htmlUrl, pr._embedded.githubUser.login);
+ const repositoryLink = this.htmlLink(pr.repositoryHtmlUrl, pr.repository);
+ const prLink = this.htmlLink(pr.htmlUrl, pr.title);
+
+ const message = this.pullRequestState === 'referenced' ? 'referenced_message' : 'message';
+ return this.I18n.t(
+ `js.github_integration.pull_requests.${message}`,
+ {
+ pr_number: pr.number,
+ pr_link: prLink,
+ repository_link: repositoryLink,
+ pr_state: this.I18n.t(
+ `js.github_integration.pull_requests.states.${this.pullRequestState}`,
+ { defaultValue: this.pullRequestState || '(unknown state)' },
+ ),
+ github_user_link: githubUserLink,
+ },
+ );
+ }
+
+ private htmlLink(href:string, title:string):string {
+ const link = document.createElement('a');
+ link.href = href;
+ link.textContent = title;
+
+ return link.outerHTML;
}
}
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.html b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.html
index 4b788cb54c0..182d926c680 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.html
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.html
@@ -1,68 +1,7 @@
-<a
- class='op-pull-request--link'
- [href]="pullRequest.htmlUrl"
- target="blank"
- [textContent]="pullRequest.repository + '#' + pullRequest.number"
-></a>
-
-<div
- class='op-pull-request--title'
- [textContent]="pullRequest.title"
-></div>
-
-<div class="op-pull-request--info">
- {{ text.label_created_by }}
- <img
- *ngIf="pullRequest._embedded.githubUser"
- alt='PR author avatar'
- class='op-pull-request--avatar op-avatar op-avatar_mini'
- [src]="pullRequest._embedded.githubUser.avatarUrl"
- />
- <span class='op-pull-request--user'>
- <a
- *ngIf="pullRequest._embedded.githubUser"
- [href]="pullRequest._embedded.githubUser.htmlUrl"
- [textContent]="pullRequest._embedded.githubUser.login"
- ></a>.
- </span>
-
- <span class='op-pull-request--date'>
- {{ text.label_last_updated_on }}
- <op-date-time [dateTimeValue]="pullRequest.githubUpdatedAt"></op-date-time>
- </span>.
-</div>
-
-<span class='op-pull-request--state' [ngClass]="'op-pull-request--state_' + state">
+<span
+ class="op-pull-request-state"
+ [class.op-pull-request-state_small]="small"
+ [ngClass]="'op-pull-request-state_' + state">
<op-icon icon-classes="button--icon icon-merge-branch"></op-icon>
- {{state}}
+ {{displayText}}
</span>
-
-<span class="op-pull-request--checks-label"
- *ngIf="pullRequest._embedded.checkRuns?.length"
- [textContent]="text.label_actions"
-></span>
-
-<ul
- *ngIf="pullRequest._embedded.checkRuns?.length"
- [attr.aria-label]="text.label_actions"
- class='op-pull-request--checks'
->
- <li class='op-pr-check' *ngFor="let checkRun of pullRequest._embedded.checkRuns">
- <span class='op-pr-check--state-icon' [ngClass]="'op-pr-check--state-icon_' + checkRunState(checkRun)">
- <op-icon icon-classes="icon-{{ checkRunStateIcon(checkRun) }}"
- [icon-title]="checkRunStateText(checkRun)"></op-icon>
- </span>
- <span class='op-pr-check--avatar'><img alt='app owner avatar' [src]="checkRun.appOwnerAvatarUrl"/></span>
-
- <span class='op-pr-check--info'>
- <span class='op-pr-check--name' [textContent]="checkRun.name"></span>
- <span class='op-pr-check--state' [textContent]="checkRunStateText(checkRun)"></span>
- </span>
-
- <span class='op-pr-check--details'>
- <a [href]="checkRun.detailsUrl">
- {{ text.label_details }}
- </a>
- </span>
- </li>
-</ul>
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.sass b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.sass
index af93ca99cdf..45273f76a6a 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.sass
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.sass
@@ -28,76 +28,25 @@
@import "helpers"
-:host,
-.op-pull-request
- display: grid
- grid-template-columns: auto 1fr auto auto
- grid-template-areas: "link link link link" "title title title state" "info info info info" "checks-label checks-label checks-label checks-label" "checks checks checks checks"
- margin-bottom: 11px
- padding-bottom: 11px
- border-bottom: 1px solid #dddddd
-
- &:last-child
- border-bottom: none
-
- &--title
- @include text-shortener
- font-weight: bold
- grid-area: title
- // have the same line height as the status "button" next to it
- line-height: 32px
- margin-right: 20px
-
- &--avatar
- grid-area: info
-
- &--info
- display: block
- grid-area: info
- margin-bottom: 3px
- font-size: 0.9rem
- grid-area: info
- color: var(--gray-dark)
- // The mini avatar is much higher than the text line. Compensate it.
- margin-top: -4px
-
- &--date
- grid-area: info
-
- &--link
- grid-area: link
- margin-top: 6px
- font-size: 0.9rem
-
- &--state
- grid-area: state
- display: inline-block
- padding: 8px 11px
- border-radius: 16px
- border: 1px solid #fff
- color: #fff
- font-size: 0.9rem
- text-transform: capitalize
-
- &_draft
- background-color: #6a737d
-
- &_open
- background-color: #28a745
-
- &_merged
- background-color: #6f42c1
-
- &_closed
- background-color: #d73a49
-
- &--checks-label
- grid-area: checks-label
- margin-top: 12px
- font-size: 0.9rem
- font-weight: bold
-
- &--checks
- margin-top: 12px
- margin-left: 0
- grid-area: checks
+.op-pull-request-state
+ display: inline-block
+ padding: 8px 11px
+ border-radius: 16px
+ border: 1px solid #fff
+ color: #fff
+ font-size: 0.9rem
+ text-transform: capitalize
+ background-color: #6a737d
+
+ &_small
+ padding: 0 10px
+ font-size: 0.75rem
+
+ &_open
+ background-color: #28a745
+
+ &_merged
+ background-color: #6f42c1
+
+ &_closed
+ background-color: #d73a49
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.ts b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.ts
index e69de29bb2d..696b02be594 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request-state.component.ts
+++ b/modules/github_integration/frontend/module/pull-request/pull-request-state.component.ts
@@ -0,0 +1,68 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+import {
+ ChangeDetectionStrategy,
+ Component,
+ Input,
+ OnInit,
+} from '@angular/core';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+
+export type PullRequestState = 'opened'|'closed'|'referenced'|'ready_for_review'|'merged'|'draft';
+
+@Component({
+ selector: 'op-github-pull-request-state',
+ templateUrl: './pull-request-state.component.html',
+ styleUrls: [
+ './pull-request-state.component.sass',
+ ],
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class PullRequestStateComponent implements OnInit {
+ @Input() state:PullRequestState;
+
+ @Input() small = false;
+
+ displayText:string;
+
+ constructor(
+ readonly PathHelper:PathHelperService,
+ readonly I18n:I18nService,
+ ) {
+ }
+
+ ngOnInit():void {
+ this.displayText = this.I18n.t(
+ `js.github_integration.pull_requests.states.${this.state}`,
+ { defaultValue: this.state || '(unknown state)' },
+ );
+ }
+}
+
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request.component.html b/modules/github_integration/frontend/module/pull-request/pull-request.component.html
index 4b788cb54c0..e948823fd28 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request.component.html
+++ b/modules/github_integration/frontend/module/pull-request/pull-request.component.html
@@ -32,10 +32,10 @@
</span>.
</div>
-<span class='op-pull-request--state' [ngClass]="'op-pull-request--state_' + state">
- <op-icon icon-classes="button--icon icon-merge-branch"></op-icon>
- {{state}}
-</span>
+<op-github-pull-request-state
+ class='op-pull-request--state'
+ [state]="state">
+</op-github-pull-request-state>
<span class="op-pull-request--checks-label"
*ngIf="pullRequest._embedded.checkRuns?.length"
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request.component.sass b/modules/github_integration/frontend/module/pull-request/pull-request.component.sass
index af93ca99cdf..db233ffaf62 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request.component.sass
+++ b/modules/github_integration/frontend/module/pull-request/pull-request.component.sass
@@ -71,25 +71,6 @@
&--state
grid-area: state
- display: inline-block
- padding: 8px 11px
- border-radius: 16px
- border: 1px solid #fff
- color: #fff
- font-size: 0.9rem
- text-transform: capitalize
-
- &_draft
- background-color: #6a737d
-
- &_open
- background-color: #28a745
-
- &_merged
- background-color: #6f42c1
-
- &_closed
- background-color: #d73a49
&--checks-label
grid-area: checks-label
diff --git a/modules/github_integration/frontend/module/pull-request/pull-request.component.ts b/modules/github_integration/frontend/module/pull-request/pull-request.component.ts
index f744de9d294..cfaa782077e 100644
--- a/modules/github_integration/frontend/module/pull-request/pull-request.component.ts
+++ b/modules/github_integration/frontend/module/pull-request/pull-request.component.ts
@@ -67,7 +67,7 @@ export class PullRequestComponent {
) {
}
- get state() {
+ get state():string {
if (this.pullRequest.state === 'open') {
return (this.pullRequest.draft ? 'draft' : 'open');
}
diff --git a/modules/github_integration/frontend/module/state/github-pull-request.model.ts b/modules/github_integration/frontend/module/state/github-pull-request.model.ts
index 50d5a214387..780a76631e2 100644
--- a/modules/github_integration/frontend/module/state/github-pull-request.model.ts
+++ b/modules/github_integration/frontend/module/state/github-pull-request.model.ts
@@ -36,9 +36,9 @@ export interface IGithubPullRequestResourceLinks extends IHalResourceLinks {
}
export interface IGithubPullRequestResourceEmbedded {
- githubUser?:IGithubUserResource;
+ githubUser:IGithubUserResource;
mergedBy?:IGithubUserResource;
- checkRuns?:IGithubCheckRunResource[];
+ checkRuns:IGithubCheckRunResource[];
}
export interface IGithubPullRequest {
@@ -55,15 +55,16 @@ export interface IGithubPullRequest {
deletionsCount?:number;
draft?:boolean;
githubUpdatedAt?:string;
- htmlUrl?:string;
+ htmlUrl:string;
labels?:string[];
merged?:boolean;
mergedAt?:string;
number?:number;
- repository?:string;
+ repository:string;
+ repositoryHtmlUrl:string;
reviewCommentsCount?:number;
state?:string;
- title?:string;
+ title:string;
updatedAt?:string;
_links:IGithubPullRequestResourceLinks;