Skip to content

Commit

Permalink
feedback and fix to make input grow as you type to show content (#22330)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo-dotcms authored and victoralfaro-dotcms committed Jun 14, 2022
1 parent 36783b5 commit 31a8d60
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ <h4 (click)="editInlineActivate($event)">{{ contentType.name }}</h4>
#contentTypeNameInput
type="text"
[value]="contentType.name"
(keydown.enter)="fireChangeName()"
(keydown.escape)="dotEditInline.hideContent()"
(keyup)="inputValueHandler($event)"
pInputText
dotAutofocus
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ describe('ContentTypesLayoutComponent', () => {
de.query(By.css('.main-toolbar-left header p-inplace input')).nativeElement.value =
'changedName';
de.query(By.css('.main-toolbar-left header p-inplace input')).triggerEventHandler(
'keydown.enter',
'keyup',
{
stopPropagation: jasmine.createSpy('stopPropagation')
stopPropagation: jasmine.createSpy('stopPropagation'),
key: 'Enter'
}
);
expect(de.componentInstance.changeContentTypeName.emit).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ContentTypesLayoutComponent implements OnChanges, OnInit {
permissionURL: string;
pushHistoryURL: string;
relationshipURL: string;
contentTypeNameInputSize: string;
contentTypeNameInputSize: number;
showPermissionsTab: Observable<boolean>;

actions: MenuItem[];
Expand Down Expand Up @@ -91,10 +91,28 @@ export class ContentTypesLayoutComponent implements OnChanges, OnInit {
/**
* Sets the size of the H4 display to set it in the content textbox to eliminate UI jumps
*
* @param {MouseEvent} event
* @memberof ContentTypesLayoutComponent
*/
editInlineActivate(event): void {
this.contentTypeNameInputSize = event.target.offsetWidth;
editInlineActivate(event: MouseEvent): void {
this.contentTypeNameInputSize = event.target['offsetWidth'];
}

/**
* Based on keyboard input executes an action to Change Name/Hide Input/Change Input's size
*
* @param {KeyboardEvent} event
* @memberof ContentTypesLayoutComponent
*/
inputValueHandler(event: KeyboardEvent): void {
if (event.key === 'Enter') {
this.fireChangeName();
} else if (event.key === 'Escape') {
this.dotEditInline.hideContent();
} else {
const newInputSize = event.target['value'].length * 8 + 22;
this.contentTypeNameInputSize = newInputSize > 485 ? 485 : newInputSize;
}
}

private loadActions(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,14 @@ describe('DotContentTypesEditComponent', () => {
const contentTypeLayout = de.query(By.css('dot-content-type-layout'));
contentTypeLayout.triggerEventHandler('changeContentTypeName', 'CT changed');

const replacedWorkflowsPropContentType = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { layout, fields, workflows, ...replacedWorkflowsPropContentType } = {
...responseContentType
};

replacedWorkflowsPropContentType['workflow'] = fakeContentType.workflows.map(
(workflow) => workflow.id
);
delete replacedWorkflowsPropContentType.workflows;
delete replacedWorkflowsPropContentType.fields;
delete replacedWorkflowsPropContentType.layout;

expect(crudService.putData).toHaveBeenCalledWith(
'v1/contenttype/id/1234567890',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ export class DotContentTypesEditComponent implements OnInit, OnDestroy {
* @memberof DotContentTypesEditComponent
*/
editContentTypeName(name: string): void {
const updatedContentType = { ...this.data, name };
delete updatedContentType.layout;
delete updatedContentType.fields;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { layout, fields, ...updatedContentType } = { ...this.data, name };

this.updateContentType(updatedContentType);
this.updateContentType(updatedContentType as DotCMSContentType);
}

/**
Expand Down

0 comments on commit 31a8d60

Please sign in to comment.