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

[37265] Make github tabs instance of op-scrollable-tabs

Oliver Günther3b2d90f74e35
diff --git a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.spec.ts b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.spec.ts
index 5aa22fd7289..8632febd0dc 100644
--- a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.spec.ts
+++ b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.spec.ts
@@ -66,11 +66,11 @@ describe('GitActionsMenuComponent', () => {
it('should select tab', () => {
const tabToSelect = component.tabs[0];
- component.selectTab(tabToSelect);
+ component.selectedTab = tabToSelect;
fixture.detectChanges();
- expect(component.selectedTab()).toBe(tabToSelect);
+ expect(component.selectedTab).toBe(tabToSelect);
});
it('should select tab', () => {
@@ -78,7 +78,7 @@ describe('GitActionsMenuComponent', () => {
const copyButton = fixture.debugElement.query(By.css('button')).nativeElement;
gitActionsService.branchName.and.returnValue('test branch');
- component.selectTab(tabToSelect);
+ component.selectedTab = tabToSelect;
copyButton.click();
fixture.detectChanges();
diff --git a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.ts b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.ts
index 5cefb63d4a7..30cbc93322f 100644
--- a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.ts
+++ b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.component.ts
@@ -27,17 +27,20 @@
//++
import copy from 'copy-text-to-clipboard';
-import {Component, Inject, Input} from '@angular/core';
-import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
-import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
-import { GitActionsService} from '../git-actions/git-actions.service';
+import { Component, Inject, Input } from '@angular/core';
+import { WorkPackageResource } from 'core-app/modules/hal/resources/work-package-resource';
+import { I18nService } from 'core-app/modules/common/i18n/i18n.service';
+import { GitActionsService } from '../git-actions/git-actions.service';
import { OPContextMenuComponent } from 'core-app/components/op-context-menu/op-context-menu.component';
-import { OpContextMenuLocalsMap, OpContextMenuLocalsToken } from 'core-app/components/op-context-menu/op-context-menu.types';
+import {
+ OpContextMenuLocalsMap,
+ OpContextMenuLocalsToken
+} from 'core-app/components/op-context-menu/op-context-menu.types';
import { ITab } from "core-app/modules/plugins/linked/openproject-github_integration/typings";
@Component({
- selector: 'git-actions-menu',
+ selector: 'op-git-actions-menu',
templateUrl: './git-actions-menu.template.html',
styleUrls: [
'./styles/git-actions-menu.sass'
@@ -60,28 +63,30 @@ export class GitActionsMenuComponent extends OPContextMenuComponent {
public tabs:ITab[] = [
{
- label: this.I18n.t('js.github_integration.tab_header.git_actions.branch'),
+ id: 'branch',
+ name: this.I18n.t('js.github_integration.tab_header.git_actions.branch'),
help: this.I18n.t('js.github_integration.tab_header.git_actions.branch_help'),
- selected: true,
lines: 1,
textToCopy: () => this.gitActions.branchName(this.workPackage)
},
{
- label: this.I18n.t('js.github_integration.tab_header.git_actions.message'),
+ id: 'message',
+ name: this.I18n.t('js.github_integration.tab_header.git_actions.message'),
help: this.I18n.t('js.github_integration.tab_header.git_actions.message_help'),
- selected: false,
lines: 6,
textToCopy: () => this.gitActions.commitMessage(this.workPackage)
},
{
- label: this.I18n.t('js.github_integration.tab_header.git_actions.cmd'),
+ id: 'command',
+ name: this.I18n.t('js.github_integration.tab_header.git_actions.cmd'),
help: this.I18n.t('js.github_integration.tab_header.git_actions.cmd_help'),
- selected: false,
lines: 6,
textToCopy: () => this.gitActions.gitCommand(this.workPackage)
},
];
+ public selectedTab:ITab = this.tabs[0];
+
constructor(@Inject(OpContextMenuLocalsToken)
public locals:OpContextMenuLocalsMap,
readonly I18n:I18nService,
@@ -90,17 +95,7 @@ export class GitActionsMenuComponent extends OPContextMenuComponent {
this.workPackage = this.locals.workPackage;
}
- public selectedTab():ITab {
- const selectedTabs = this.tabs.filter((tab)=>tab.selected);
- return(selectedTabs[0] || this.tabs[0]);
- }
-
- public selectTab(tab:ITab) {
- this.tabs.forEach(tab => tab.selected = false);
- tab.selected = true;
- }
-
- public onCopyButtonClick() {
+ public onCopyButtonClick():void {
const success = this.copySelectedTabText();
if (success) {
@@ -109,10 +104,12 @@ export class GitActionsMenuComponent extends OPContextMenuComponent {
this.lastCopyResult = this.text.copyResult.error;
}
this.showCopyResult = true;
- window.setTimeout(() => { this.showCopyResult = false;}, 2000);
+ window.setTimeout(() => {
+ this.showCopyResult = false;
+ }, 2000);
}
- public copySelectedTabText() {
- return copy(this.selectedTab().textToCopy());
+ public copySelectedTabText():boolean {
+ return copy(this.selectedTab.textToCopy());
}
}
diff --git a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.template.html b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.template.html
index 7442353abee..b710272c7f8 100644
--- a/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.template.html
+++ b/modules/github_integration/frontend/module/git-actions-menu/git-actions-menu.template.html
@@ -3,20 +3,14 @@
<op-icon icon-classes="button--icon icon-console-light"></op-icon>
{{text.title}}
</h3>
- <ul class="op-tab-row">
- <li
- *ngFor="let tab of tabs"
- class="op-tab-row--tab"
- >
- <a
- href=""
- (click)="selectTab(tab)"
- [class.op-tab-row--link_selected]="tab.selected"
- [textContent]="tab.label"></a>
- </li>
- </ul>
+ <op-scrollable-tabs
+ [tabs]="tabs"
+ [currentTabId]="selectedTab.id"
+ (tabSelected)="selectedTab = $event"
+ >
+ </op-scrollable-tabs>
<div class="copy-wrapper">
- <textarea class="copy-content" [textContent]="selectedTab().textToCopy()" [style.height.em]="selectedTab().lines" readonly="true"></textarea>
+ <textarea class="copy-content" [textContent]="selectedTab.textToCopy()" [style.height.em]="selectedTab.lines" readonly="true"></textarea>
<button class="button copy-button"
type="button"
[attr.aria-label]="text.copyButtonHelpText"
@@ -25,5 +19,5 @@
</button>
<div class="copy-result-message" *ngIf="showCopyResult" [textContent]="lastCopyResult"></div>
</div>
- <div class="help-text" [textContent]="selectedTab().help"></div>
+ <div class="help-text" [textContent]="selectedTab.help"></div>
</div>
diff --git a/modules/github_integration/frontend/module/main.ts b/modules/github_integration/frontend/module/main.ts
index d39728a619d..0c4c610e668 100644
--- a/modules/github_integration/frontend/module/main.ts
+++ b/modules/github_integration/frontend/module/main.ts
@@ -35,6 +35,7 @@ import { GitActionsMenuComponent } from './git-actions-menu/git-actions-menu.com
import { WorkPackagesGithubPrsService } from './tab-prs/wp-github-prs.service';
import { PullRequestComponent } from './pull-request/pull-request.component';
import { WorkPackageTabsService } from "core-components/wp-tabs/services/wp-tabs/wp-tabs.service";
+import { OpenprojectTabsModule } from "core-app/modules/common/tabs/openproject-tabs.module";
export function initializeGithubIntegrationPlugin(injector:Injector) {
const wpTabService = injector.get(WorkPackageTabsService);
@@ -50,6 +51,7 @@ export function initializeGithubIntegrationPlugin(injector:Injector) {
@NgModule({
imports: [
OpenprojectCommonModule,
+ OpenprojectTabsModule,
],
providers: [
WorkPackagesGithubPrsService,
diff --git a/modules/github_integration/frontend/module/typings.d.ts b/modules/github_integration/frontend/module/typings.d.ts
index e0f46bda1c2..bd18c280e86 100644
--- a/modules/github_integration/frontend/module/typings.d.ts
+++ b/modules/github_integration/frontend/module/typings.d.ts
@@ -1,14 +1,13 @@
-import { HalResource } from "../../../../frontend/src/app/modules/hal/resources/hal-resource";
+import { TabDefinition } from "core-app/modules/common/tabs/tab.interface";
+import { HalResourceClass } from "core-app/modules/hal/resources/hal-resource";
-export interface ITab {
- label:string,
+export interface ITab extends TabDefinition {
help:string,
- selected:boolean,
lines:number,
textToCopy: ()=>string
}
-export interface IGithubPullRequestResource extends HalResource {
+export interface IGithubPullRequestResource extends HalResourceClass {
additionsCount?:number;
body?:{
format?:string;