Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACA-3745] Folder - update metadata default copies the name in the title field #5923

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/content-services/src/lib/dialogs/folder.dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ <h2 mat-dialog-title>
</mat-hint>
</mat-form-field>

<br />
<br />
<mat-form-field class="adf-full-width">
<input
id="adf-folder-title-input"
matInput
placeholder="{{ 'CORE.FOLDER_DIALOG.FOLDER_TITLE.LABEL' | translate }}"
[formControl]="form.controls['title']"/>
</mat-form-field>

<mat-form-field class="adf-full-width">
<textarea
Expand Down
14 changes: 11 additions & 3 deletions lib/content-services/src/lib/dialogs/folder.dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('FolderDialogComponent', () => {
id: 'node-id',
name: 'folder-name',
properties: {
['cm:title']: 'folder-title',
['cm:description']: 'folder-description'
}
}
Expand All @@ -71,6 +72,7 @@ describe('FolderDialogComponent', () => {

it('should init form with folder name and description', () => {
expect(component.name).toBe('folder-name');
expect(component.title).toBe('folder-title');
expect(component.description).toBe('folder-description');
});

Expand All @@ -82,16 +84,19 @@ describe('FolderDialogComponent', () => {

it('should update form input', () => {
component.form.controls['name'].setValue('folder-name-update');
component.form.controls['title'].setValue('folder-title-update');
component.form.controls['description'].setValue('folder-description-update');

expect(component.name).toBe('folder-name-update');
expect(component.title).toBe('folder-title-update');
expect(component.description).toBe('folder-description-update');
});

it('should submit updated values if form is valid', () => {
spyOn(nodesApi, 'updateNode').and.returnValue(of({}));

component.form.controls['name'].setValue('folder-name-update');
component.form.controls['title'].setValue('folder-title-update');
component.form.controls['description'].setValue('folder-description-update');

component.submit();
Expand All @@ -101,7 +106,7 @@ describe('FolderDialogComponent', () => {
{
name: 'folder-name-update',
properties: {
'cm:title': 'folder-name-update',
'cm:title': 'folder-title-update',
'cm:description': 'folder-description-update'
}
}
Expand Down Expand Up @@ -189,6 +194,7 @@ describe('FolderDialogComponent', () => {
spyOn(nodesApi, 'createFolder').and.returnValue(of({}));

component.form.controls['name'].setValue('folder-name-update');
component.form.controls['title'].setValue('folder-title-update');
component.form.controls['description'].setValue('folder-description-update');

component.submit();
Expand All @@ -198,7 +204,7 @@ describe('FolderDialogComponent', () => {
{
name: 'folder-name-update',
properties: {
'cm:title': 'folder-name-update',
'cm:title': 'folder-title-update',
'cm:description': 'folder-description-update'
},
nodeType: 'cm:folder'
Expand All @@ -210,6 +216,7 @@ describe('FolderDialogComponent', () => {
spyOn(nodesApi, 'createFolder').and.returnValue(of({}));

component.form.controls['name'].setValue('folder-name-update');
component.form.controls['title'].setValue('folder-title-update');
component.form.controls['description'].setValue('folder-description-update');
component.nodeType = 'cm:sushi';

Expand All @@ -220,7 +227,7 @@ describe('FolderDialogComponent', () => {
{
name: 'folder-name-update',
properties: {
'cm:title': 'folder-name-update',
'cm:title': 'folder-title-update',
'cm:description': 'folder-description-update'
},
nodeType: 'cm:sushi'
Expand All @@ -234,6 +241,7 @@ describe('FolderDialogComponent', () => {
};

component.form.controls['name'].setValue('name');
component.form.controls['title'].setValue('title');
component.form.controls['description'].setValue('description');

spyOn(nodesApi, 'createFolder').and.returnValue(of(folder));
Expand Down
13 changes: 11 additions & 2 deletions lib/content-services/src/lib/dialogs/folder.dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ export class FolderDialogComponent implements OnInit {
ngOnInit() {
const { folder } = this.data;
let name = '';
let title = '';
let description = '';

if (folder) {
const { properties } = folder;

name = folder.name || '';
description = properties ? properties['cm:description'] : '';
title = properties?.['cm:title'] ?? '';
description = properties?.['cm:description'] ?? '';
}

const validators = {
Expand All @@ -94,6 +96,7 @@ export class FolderDialogComponent implements OnInit {

this.form = this.formBuilder.group({
name: [ name, validators.name ],
title: [ title ],
description: [ description ]
});
}
Expand All @@ -104,14 +107,20 @@ export class FolderDialogComponent implements OnInit {
return (name || '').trim();
}

get title(): string {
const { title } = this.form.value;

return (title || '').trim();
}

get description(): string {
const { description } = this.form.value;

return (description || '').trim();
}

private get properties(): any {
const { name: title, description } = this;
const { title, description } = this;

return {
'cm:title': title,
Expand Down
3 changes: 3 additions & 0 deletions lib/core/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
"FOLDER_DESCRIPTION": {
"LABEL": "Description"
},
"FOLDER_TITLE": {
"LABEL": "Title"
},
"CREATE_BUTTON": {
"LABEL": "Create"
},
Expand Down