move upload and create to extensions

This commit is contained in:
Denys Vuika
2023-03-01 17:27:36 +00:00
committed by Sheena Malhotra
parent 52cbf442d4
commit 69204a2c13
10 changed files with 170 additions and 227 deletions

View File

@@ -1,25 +1,3 @@
<adf-toolbar class="adf-toolbar--inline">
<button mat-flat-button data-automation-id="create-button" *ngIf="canShowCreateButton()"
[matMenuTriggerFor]="createMenu"
[attr.title]="'APP.HEADER.BUTTONS.CREATE_TOOLTIP' | translate">
{{ 'APP.HEADER.BUTTONS.CREATE' | translate }}
</button>
<mat-menu #createMenu="matMenu" role="menu" class="app-create-menu__root-menu app-create-menu__sub-menu" [overlapTrigger]="false" yPosition="below">
<div *ngFor="let action of createActions; trackBy: trackByActionId">
<app-toolbar-menu-item [actionRef]="action"></app-toolbar-menu-item>
</div>
</mat-menu>
<button mat-flat-button color="primary" data-automation-id="upload-button" *ngIf="canShowUploadButton()"
[matMenuTriggerFor]="uploadMenu"
[attr.title]="'APP.HEADER.BUTTONS.UPLOAD_TOOLTIP' | translate">
{{ 'APP.HEADER.BUTTONS.UPLOAD' | translate }}
</button>
<mat-menu #uploadMenu="matMenu" role="menu" class="app-upload-menu__root-menu app-upload-menu__sub-menu" [overlapTrigger]="false" yPosition="below">
<div *ngFor="let action of uploadActions; trackBy: trackByActionId">
<app-toolbar-menu-item [actionRef]="action"></app-toolbar-menu-item>
</div>
</mat-menu>
<aca-search-input class="app-search-input"></aca-search-input>
</adf-toolbar>

View File

@@ -1,106 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module';
import { HeaderActionsComponent } from './header-actions.component';
import { ContentActionType } from '@alfresco/adf-extensions';
import { AppExtensionService } from '@alfresco/aca-shared';
import { of } from 'rxjs';
import { By } from '@angular/platform-browser';
import { CoreModule } from '@alfresco/adf-core';
import { AppHeaderActionsModule } from './header-actions.module';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
describe('HeaderActionsComponent', () => {
let fixture: ComponentFixture<HeaderActionsComponent>;
let router: Router;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, CoreModule.forRoot(), AppHeaderActionsModule, RouterTestingModule],
declarations: [HeaderActionsComponent]
});
const extensionService = TestBed.inject(AppExtensionService);
spyOn(extensionService, 'getCreateActions').and.returnValue(
of([
{
id: 'action1',
type: ContentActionType.button,
title: 'create action one'
},
{
id: 'action2',
type: ContentActionType.button,
title: 'create action two'
}
])
);
spyOn(extensionService, 'getUploadActions').and.returnValue(
of([
{
id: 'action3',
type: ContentActionType.button,
title: 'upload action one'
}
])
);
router = TestBed.inject(Router);
fixture = TestBed.createComponent(HeaderActionsComponent);
fixture.detectChanges();
});
const getCreateButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
const getUploadButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id="upload-button"]')).nativeElement;
it('should render menu items when create menu is opened', async () => {
spyOnProperty(router, 'url').and.returnValue('/personal-files');
fixture.detectChanges();
await fixture.whenStable();
getCreateButton().click();
const menuItems = fixture.debugElement.queryAll(By.css('.app-toolbar-menu-item'));
expect(menuItems.length).toBe(2);
const menuItemOne = (menuItems[0].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
const menuItemTwo = (menuItems[1].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
expect(menuItemOne.innerText).toBe('create action one');
expect(menuItemTwo.innerText).toBe('create action two');
});
it('should render menu items when upload menu is opened', async () => {
spyOnProperty(router, 'url').and.returnValue('/personal-files');
fixture.detectChanges();
await fixture.whenStable();
getUploadButton().click();
const menuItems = fixture.debugElement.queryAll(By.css('.app-toolbar-menu-item'));
expect(menuItems.length).toBe(1);
const menuItemOne = (menuItems[0].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
expect(menuItemOne.innerText).toBe('upload action one');
});
});

View File

@@ -23,12 +23,10 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnDestroy, ViewEncapsulation } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppExtensionService } from '@alfresco/aca-shared';
import { SetCurrentFolderAction, AppStore } from '@alfresco/aca-shared/store';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
@Component({
@@ -37,29 +35,10 @@ import { Subject } from 'rxjs';
styleUrls: ['./header-actions.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class HeaderActionsComponent implements OnInit, OnDestroy {
export class HeaderActionsComponent implements OnDestroy {
private onDestroy$ = new Subject<boolean>();
createActions: Array<ContentActionRef> = [];
uploadActions: Array<ContentActionRef> = [];
constructor(private store: Store<AppStore>, private extensions: AppExtensionService) {}
ngOnInit(): void {
this.extensions
.getCreateActions()
.pipe(takeUntil(this.onDestroy$))
.subscribe((actions) => {
this.createActions = actions;
});
this.extensions
.getUploadActions()
.pipe(takeUntil(this.onDestroy$))
.subscribe((actions) => {
this.uploadActions = actions;
});
}
constructor(private store: Store<AppStore>) {}
ngOnDestroy() {
this.onDestroy$.next(true);
@@ -70,12 +49,4 @@ export class HeaderActionsComponent implements OnInit, OnDestroy {
trackByActionId(_: number, action: ContentActionRef) {
return action.id;
}
canShowCreateButton(): boolean {
return this.createActions.length > 0;
}
canShowUploadButton(): boolean {
return this.uploadActions.length > 0;
}
}