AAE 22837 Move confirm to core (#9750)

* confirm dialog is used in many places and should be part of the core

* fix

* Update confirm.dialog.spec.ts

* Update public-api.ts
This commit is contained in:
Eugenio Romano
2024-06-09 01:14:20 +02:00
committed by VitoAlbano
parent 47ebbbd94f
commit e006409584
32 changed files with 51 additions and 115 deletions

View File

@@ -23,7 +23,7 @@ import { Subject } from 'rxjs';
import { ContentService } from '../common/services/content.service';
import { SharedLinksApiService } from './services/shared-links-api.service';
import { SharedLinkBodyCreate } from '@alfresco/js-api';
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
import { ConfirmDialogComponent } from '@alfresco/adf-core';
import { ContentNodeShareSettings } from './content-node-share.settings';
import { RenditionService } from '../common/services/rendition.service';
import { format, add, endOfDay, isBefore } from 'date-fns';

View File

@@ -1,20 +0,0 @@
<h1 mat-dialog-title data-automation-id="adf-confirm-dialog-title">{{ title | translate }}</h1>
<mat-dialog-content>
<div class="adf-confirm-dialog-content">
<p *ngIf="!htmlContent; else cutomContent" data-automation-id="adf-confirm-dialog-base-message">
{{ message | translate }}
</p>
<ng-template #cutomContent>
<span [innerHTML]="sanitizedHtmlContent()" data-automation-id="adf-confirm-dialog-custom-content">
</span>
</ng-template>
</div>
</mat-dialog-content>
<mat-dialog-actions>
<span class="adf-dialog-spacer" data-automation-id="adf-confirm-dialog-spacer"></span>
<button id="adf-confirm-accept" class="adf-confirm-dialog-button" mat-button color="primary" data-automation-id="adf-confirm-dialog-confirmation"
[mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button id="adf-confirm-all" class="adf-confirm-dialog-button" mat-button *ngIf="thirdOptionLabel" [mat-dialog-close]="thirdOptionLabel" data-automation-id="adf-confirm-dialog-confirm-all">{{ thirdOptionLabel | translate }}</button>
<button id="adf-confirm-cancel" class="adf-confirm-dialog-button" mat-button [mat-dialog-close]="false" data-automation-id="adf-confirm-dialog-reject"
cdkFocusInitial>{{ noLabel | translate }}</button>
</mat-dialog-actions>

View File

@@ -1,13 +0,0 @@
.adf-dialog-spacer {
flex: 1 1 auto;
}
.adf-confirm-dialog {
& .adf-confirm-dialog-button {
text-transform: uppercase;
}
& .adf-confirm-dialog-content {
margin: 0 -24px;
}
}

View File

@@ -1,140 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { TestBed, ComponentFixture } from '@angular/core/testing';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ConfirmDialogComponent } from './confirm.dialog';
import { ContentTestingModule } from '../testing/content.testing.module';
import { By } from '@angular/platform-browser';
describe('Confirm Dialog Component', () => {
let fixture: ComponentFixture<ConfirmDialogComponent>;
let component: ConfirmDialogComponent;
const dialogRef = {
close: jasmine.createSpy('close')
};
const data = {
title: 'Fake Title',
message: 'Base Message',
yesLabel: 'TAKE THIS',
noLabel: 'MAYBE NO'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule],
providers: [
{ provide: MatDialogRef, useValue: dialogRef },
{ provide: MAT_DIALOG_DATA, useValue: data }
]
});
dialogRef.close.calls.reset();
fixture = TestBed.createComponent(ConfirmDialogComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
describe('When no html is given', () => {
beforeEach(() => {
fixture.detectChanges();
});
it('should init form with folder name and description', () => {
expect(component.title).toBe('Fake Title');
expect(component.message).toBe('Base Message');
expect(component.yesLabel).toBe('TAKE THIS');
expect(component.noLabel).toBe('MAYBE NO');
});
it('should render the title', () => {
const titleElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-title"]'));
expect(titleElement).not.toBeNull();
expect(titleElement.nativeElement.innerText).toBe('Fake Title');
});
it('should render the message', () => {
const messageElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-base-message"]'));
expect(messageElement).not.toBeNull();
expect(messageElement.nativeElement.innerText).toBe('Base Message');
});
it('should render the YES label', () => {
const messageElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-confirmation"]'));
expect(messageElement).not.toBeNull();
expect(messageElement.nativeElement.innerText).toBe('TAKE THIS');
});
it('should render the NO label', () => {
const messageElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-reject"]'));
expect(messageElement).not.toBeNull();
expect(messageElement.nativeElement.innerText).toBe('MAYBE NO');
});
});
describe('When custom html is given', () => {
beforeEach(() => {
component.htmlContent = `<div> I am about to do to you what Limp Bizkit did to music in the late 90s.</div>`;
fixture.detectChanges();
});
it('should render the title', () => {
const titleElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-title"]'));
expect(titleElement).not.toBeNull();
expect(titleElement.nativeElement.innerText).toBe('Fake Title');
});
it('should render the custom html', () => {
const customElement = fixture.nativeElement.querySelector('[data-automation-id="adf-confirm-dialog-custom-content"] div');
expect(customElement).not.toBeNull();
expect(customElement.innerText).toBe('I am about to do to you what Limp Bizkit did to music in the late 90s.');
});
it('should render the YES label', () => {
const messageElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-confirmation"]'));
expect(messageElement).not.toBeNull();
expect(messageElement.nativeElement.innerText).toBe('TAKE THIS');
});
it('should render the NO label', () => {
const messageElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-reject"]'));
expect(messageElement).not.toBeNull();
expect(messageElement.nativeElement.innerText).toBe('MAYBE NO');
});
});
describe('thirdOptionLabel is given', () => {
it('should NOT render the thirdOption if is thirdOptionLabel is not passed', () => {
component.thirdOptionLabel = undefined;
fixture.detectChanges();
const thirdOptionElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-confirm-all"]'));
expect(thirdOptionElement).toBeFalsy();
});
it('should render the thirdOption if thirdOptionLabel is passed', () => {
component.thirdOptionLabel = 'Yes All';
fixture.detectChanges();
const thirdOptionElement = fixture.debugElement.query(By.css('[data-automation-id="adf-confirm-dialog-confirm-all"]'));
expect(thirdOptionElement).not.toBeNull();
expect(thirdOptionElement.nativeElement.innerText.toUpperCase()).toBe('YES ALL');
});
});
});

View File

@@ -1,61 +0,0 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* 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 { Component, Inject, ViewEncapsulation, SecurityContext } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DomSanitizer } from '@angular/platform-browser';
export interface ConfirmDialogComponentProps {
title?: string;
message?: string;
yesLabel?: string;
thirdOptionLabel?: string;
noLabel?: string;
htmlContent?: string;
}
@Component({
selector: 'adf-confirm-dialog',
templateUrl: './confirm.dialog.html',
styleUrls: ['./confirm.dialog.scss'],
host: { class: 'adf-confirm-dialog' },
encapsulation: ViewEncapsulation.None
})
export class ConfirmDialogComponent {
title: string;
message: string;
yesLabel: string;
noLabel: string;
thirdOptionLabel: string;
htmlContent: string;
constructor(@Inject(MAT_DIALOG_DATA) data: ConfirmDialogComponentProps, private sanitizer: DomSanitizer) {
data = data || {};
this.title = data.title || 'ADF_CONFIRM_DIALOG.TITLE';
this.message = data.message || 'ADF_CONFIRM_DIALOG.MESSAGE';
this.yesLabel = data.yesLabel || 'ADF_CONFIRM_DIALOG.YES_LABEL';
this.thirdOptionLabel = data.thirdOptionLabel;
this.noLabel = data.noLabel || 'ADF_CONFIRM_DIALOG.NO_LABEL';
this.htmlContent = data.htmlContent;
}
sanitizedHtmlContent(): string {
return this.sanitizer.sanitize(SecurityContext.HTML, this.htmlContent);
}
}

View File

@@ -23,7 +23,6 @@ import { CoreModule } from '@alfresco/adf-core';
import { MaterialModule } from '../material.module';
import { FolderDialogComponent } from './folder.dialog';
import { NodeLockDialogComponent } from './node-lock.dialog';
import { ConfirmDialogComponent } from './confirm.dialog';
import { MatDatetimepickerModule } from '@mat-datetimepicker/core';
import { LibraryDialogComponent } from './library/library.dialog';
import { ContentDirectiveModule } from '../directives';
@@ -46,14 +45,12 @@ import { CategoriesModule } from '../category';
declarations: [
FolderDialogComponent,
NodeLockDialogComponent,
ConfirmDialogComponent,
LibraryDialogComponent,
CategorySelectorDialogComponent
],
exports: [
FolderDialogComponent,
NodeLockDialogComponent,
ConfirmDialogComponent,
LibraryDialogComponent,
CategorySelectorDialogComponent
]

View File

@@ -17,7 +17,6 @@
export * from './folder.dialog';
export * from './node-lock.dialog';
export * from './confirm.dialog';
export * from './category-selector.dialog';
export * from './dialog.module';

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "أيقونة السهم الأيمن"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "تأكيد",
"ACTION": "هل تريد المتابعة؟",
"YES_LABEL": "نعم",
"NO_LABEL": "لا"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "هذا المجلد فارغ"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Ikona se šipkou doprava"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Potvrdit",
"ACTION": "Chcete pokračovat?",
"YES_LABEL": "Ano",
"NO_LABEL": "Ne"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Tato složka je prázdná"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Pil højre ikon"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Bekræft",
"ACTION": "Vil du fortsætte?",
"YES_LABEL": "Ja",
"NO_LABEL": "Nej"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Denne mappe er tom"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Pfeil-nach-rechts-Symbol"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Bestätigen",
"ACTION": "Möchten Sie fortfahren?",
"YES_LABEL": "Ja",
"NO_LABEL": "Nein"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Dieser Ordner ist leer"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Arrow right icon"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Confirm",
"ACTION": "Do you want to proceed?",
"YES_LABEL": "Yes",
"NO_LABEL": "No"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "This folder is empty"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Icono de dirección a la derecha"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Confirmar",
"ACTION": "¿Desea continuar?",
"YES_LABEL": "Sí",
"NO_LABEL": "No"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Esta carpeta está vacía"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Oikea nuoli -kuvake"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Vahvista",
"ACTION": "Haluatko jatkaa?",
"YES_LABEL": "Kyllä",
"NO_LABEL": "Ei"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Tämä kansio on tyhjä"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Icône flèche vers la droite"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Confirmer",
"ACTION": "Voulez-vous continuer ?",
"YES_LABEL": "Oui",
"NO_LABEL": "Non"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Ce dossier est vide"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Icona freccia destra"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Conferma",
"ACTION": "Procedere?",
"YES_LABEL": "Sì",
"NO_LABEL": "No"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Questa cartella è vuota"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "右矢印アイコン"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "確認",
"ACTION": "作業を続けますか?",
"YES_LABEL": "はい",
"NO_LABEL": "いいえ"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "このフォルダは空です"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Høyrepil-ikon"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Bekreft",
"ACTION": "Vil du fortsette?",
"YES_LABEL": "Ja",
"NO_LABEL": "Nei"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Denne mappen er tom"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Pictogram pijl-rechts"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Bevestigen",
"ACTION": "Wilt u doorgaan?",
"YES_LABEL": "Ja",
"NO_LABEL": "Nee"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Deze map is leeg"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Ikona strzałki w prawo"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Potwierdź",
"ACTION": "Czy chcesz kontynuować?",
"YES_LABEL": "Tak",
"NO_LABEL": "Nie"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Ten folder jest pusty"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Ícone de seta direita"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Confirmar",
"ACTION": "Deseja continuar?",
"YES_LABEL": "Sim",
"NO_LABEL": "Não"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Esta pasta está vazia"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Значок правой стрелки"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Подтвердить",
"ACTION": "Хотите продолжить?",
"YES_LABEL": "Да",
"NO_LABEL": "Нет"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Эта папка пуста"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "Ikon för högerpil"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "Bekräfta",
"ACTION": "Vill du fortsätta?",
"YES_LABEL": "Ja",
"NO_LABEL": "Nej"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "Den här mappen är tom"

View File

@@ -46,12 +46,6 @@
"ARROW_ICON": "右箭头图标"
}
},
"ADF_CONFIRM_DIALOG": {
"TITLE": "确认",
"ACTION": "是否要继续?",
"YES_LABEL": "是",
"NO_LABEL": "否"
},
"ADF-DOCUMENT-LIST": {
"EMPTY": {
"HEADER": "此文件夹为空"

View File

@@ -19,7 +19,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
import { Component, Input, OnChanges, ViewEncapsulation, EventEmitter, Output, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { VersionsApi, Node, VersionEntry, NodesApi, NodeEntry, ContentApi, ContentPagingQuery } from '@alfresco/js-api';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '../dialogs';
import { ConfirmDialogComponent } from '@alfresco/adf-core';
import { ContentVersionService } from './content-version.service';
import { ContentService } from '../common';
import { InfiniteScrollDatasource } from '../infinite-scroll-datasource';