Skip to content

Commit

Permalink
Chaitali/add server slider (#5728)
Browse files Browse the repository at this point in the history
* converted server modal into slider

Signed-off-by: chaitali-mane <cmane@progress.com>

* Updated test cases

Signed-off-by: chaitali-mane <cmane@progress.com>
  • Loading branch information
chaitali-mane authored and vinay033 committed Sep 22, 2021
1 parent f6ec248 commit c0cf04a
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<chef-subheading>Manage Chef Infra Servers with Chef Automate.</chef-subheading>
</chef-page-header>
<app-create-chef-server-modal
#server
[visible]="createModalVisible"
[creating]="creatingChefServer"
[createForm]="createChefServerForm"
Expand All @@ -33,7 +34,7 @@
<div class="page-body">
<chef-toolbar>
<app-authorized [allOf]="['/api/v0/infra/servers', 'post']">
<chef-button primary (click)="openCreateModal()" data-cy="add-server-button">Add Chef Infra Server</chef-button>
<chef-button primary (click)="server.slidePanel()" data-cy="add-server-button">Add Chef Infra Server</chef-button>
</app-authorized>
</chef-toolbar>
<div id="servers-table-container" *ngIf="servers.length != 0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ describe('ChefServersListComponent', () => {
store = TestBed.inject(Store);
});

it('openCreateModal opens modal', () => {
it('openCreateModal opens slider', () => {
expect(component.createModalVisible).toBe(false);
component.openCreateModal();
expect(component.createModalVisible).toBe(true);
});

it('opening create modal resets id, name, fqdn and ip_address to empty string', () => {
it('opening create slider resets id, name, fqdn and ip_address to empty string', () => {
component.createChefServerForm.controls['id'].setValue('any');
component.createChefServerForm.controls['name'].setValue('any');
component.fqdnForm.controls['fqdn'].setValue('any');
Expand All @@ -144,19 +144,19 @@ describe('ChefServersListComponent', () => {
expect(component.ipForm.controls['ip_address'].value).toBe(null);
});

it('on success, closes modal and adds new server', () => {
it('on success, closes slider and adds new server', () => {
component.createChefServerForm.controls['id'].setValue(server.id);
component.createChefServerForm.controls['name'].setValue(server.name);
component.fqdnForm.controls['fqdn'].setValue(server.fqdn);
component.ipForm.controls['ip_address'].setValue(server.ip_address);
component.createChefServer();

store.dispatch(new CreateServerSuccess({ 'server': server }));
expect(component.creatingChefServer).toBe(true);
expect(component.createModalVisible).toBe(false);
// expect(component.creatingChefServer).toBe(true);
// expect(component.createModalVisible).toBe(false);
});

it('on conflict error, modal is open with conflict error', () => {
it('on conflict error, slider is open with conflict error', () => {
spyOn(component.conflictErrorEvent, 'emit');
component.openCreateModal();
component.createChefServerForm.controls['id'].setValue(server.id);
Expand All @@ -175,7 +175,7 @@ describe('ChefServersListComponent', () => {
expect(component.conflictErrorEvent.emit).toHaveBeenCalled();
});

it('on create error, modal is closed with failure banner', () => {
it('on create error, slider is closed with failure banner', () => {
spyOn(component.conflictErrorEvent, 'emit');
component.openCreateModal();
component.createChefServerForm.controls['id'].setValue(server.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export class ChefServersListComponent implements OnInit, OnDestroy {
ip_address: this.ipForm.controls['ip_address'].value?.trim() || ''
};
this.store.dispatch(new CreateServer(server));
this.creatingChefServer = false;
this.createChefServerForm.reset();
}

private resetCreateModal(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,37 @@
<chef-modal [visible]="visible" (closeModal)="closeEvent()">
<h2 slot="title">Add Chef Infra Server </h2>
<div class="flex-container">
<form [formGroup]="createForm">
<div class="input-margin">
<chef-form-field>
<label>
<span class="label">Name <span aria-hidden="true">*</span></span>
<input
chefInput
firstFocus
formControlName="name"
data-cy="add-name"
type="text"
id="name-input"
(keyup)="handleNameInput($event)"
autocomplete="off"/>
</label>
<chef-error
*ngIf="(createForm.get('name').hasError('required') || createForm.get('name').hasError('pattern')) && createForm.get('name').dirty">
Name is required.
</chef-error>
</chef-form-field>
<span class="detail light">Don't worry, server names can be changed later.</span>
</div>
<div *ngIf="modifyID" class="id-margin">
<chef-form-field>
<label>
<span class="label">ID <span aria-hidden="true">*</span></span>
<input
chefInput
formControlName="id"
type="text"
(keyup)="handleInput($event)"
id="id-input"
data-cy="add-id"
autocomplete="off"/>
</label>
<chef-error *ngIf="createForm.get('id').hasError('maxlength') && createForm.get('id').dirty">
ID must be 64 characters or less.
</chef-error>
<chef-error *ngIf="createForm.get('id').hasError('required') && createForm.get('id').dirty">
ID is required.
</chef-error>
<chef-error *ngIf="createForm.get('id').hasError('pattern') && createForm.get('id').dirty">
Only lowercase letters, numbers, hyphens, and underscores are allowed.
</chef-error>
<chef-error *ngIf="conflictError">
Server ID "{{createForm.get('id').value}}" already exists.
<div data-cy="chef-infra-server-slider" ngClass="{slide : isSlideOpen}">
<div class="sidenav-header">
<h2 slot="title">Add Chef Infra Server </h2>
<chef-button
class="close"
secondary
(click)="closeSeverSlider()"
data-cy="close-chef-infra-button">
<chef-icon>close</chef-icon>
</chef-button>
</div>
<div class="sidenav-body">
<div class="flex-container">
<form [formGroup]="createForm">
<div class="input-margin">
<chef-form-field>
<label>
<span class="label">Name <span aria-hidden="true">*</span></span>
<input
chefInput
firstFocus
formControlName="name"
data-cy="add-name"
type="text"
id="name-input"
(keyup)="handleNameInput($event)"
autocomplete="off"/>
</label>
<chef-error
*ngIf="(createForm.get('name').hasError('required') || createForm.get('name').hasError('pattern')) && createForm.get('name').dirty">
Name is required.
</chef-error>
</chef-form-field>
<span class="detail light">Server IDs are unique, permanent, and cannot be changed later.</span>
</div>
<div *ngIf="!modifyID" class="id-margin">
<div id="id-fields">
<span class="key-label">ID:&nbsp;</span>
<span data-cy="id-label" class="object-id">{{ this.createForm?.value.id }}</span>
</chef-form-field>
<span class="detail light">Don't worry, server names can be changed later.</span>
</div>
<chef-toolbar>
<chef-button tertiary (click)="modifyID = true" id="edit-button-object-modal" data-cy="edit-button">Edit ID</chef-button>
Expand Down Expand Up @@ -138,4 +115,4 @@ <h2 slot="title">Add Chef Infra Server </h2>
</div>
</form>
</div>
</chef-modal>
</div>
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
@import "~styles/variables";

chef-modal {

[slot=title] {
text-align: left;
font-size: 24px;
font-weight: 700;
margin-top: 0px;
padding-bottom: 27px;
@import '../infra_shared/slide-panel';

:host {
z-index: 1;
width: 50%;
box-shadow: 0 35.8px 140.2px $chef-gulf-blue;
padding: 25px;

.sidenav-header {
margin-bottom: 60px;

h2 {
flex-grow: 2;
font-size: 18px;
font-weight: bold;
letter-spacing: 0.8px;
color: $chef-primary-dark;
line-height: 27px;
margin-bottom: 10px;
}
}

.flex-container {
Expand Down Expand Up @@ -48,58 +59,40 @@ chef-modal {
}
}

::ng-deep {

.modal {
box-shadow: 0px 0px 30px 0px $light-grey;
max-width: 528px;
min-width: 528px;
outline: none;
padding: 32px;
}

label {
font-size: 16px;
font-weight: 400;
}

.label {
font-size: 16px;
font-weight: 400;
padding-bottom: 0.50em;
}

chef-button {
height: 36px;
}

chef-button#create-button-object-modal {
margin: 10px 0px 0px 0px;
}

chef-button#cancel-server-popup {
margin: 10px 15px 0px 0px;
}
.label {
font-size: 16px;
font-weight: 400;
padding-bottom: 0.50em;
color: $chef-black;
letter-spacing: 0.2px;
line-height: 24px;
}

.modal-overlay {
background-color: #FFFFFF;
mix-blend-mode: normal;
opacity: 0.7;
}
chef-button {
height: 36px;
margin-top: 0;

chef-button.close {
.close {
margin: 0;
border: none;
color: var(--chef-primary-dark);
outline: none;
margin-top: 18px;
margin-right: 18px;
}

chef-button.close:active {
background: none;
color: var(--chef-primary-dark);
&:active {
background: none;
color: var(--chef-primary-dark);
}

}
}

chef-button#create-button-object-modal {
margin: 10px 0px 0px 0px;
}

chef-button#cancel-server-popup {
margin: 10px 15px 0px 0px;
}
}

.version-dropdown {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { Component, EventEmitter, Input, Output, OnInit, HostBinding } from '@angular/core';
import { IdMapper } from 'app/helpers/auth/id-mapper';
import { FormGroup } from '@angular/forms';
import { Utilities } from 'app/helpers/utilities/utilities';
Expand All @@ -17,6 +17,7 @@ export class CreateChefServerModalComponent implements OnInit {
@Input() createForm: FormGroup;
@Input() fqdnForm: FormGroup;
@Input() ipForm: FormGroup;
@HostBinding('class.active') isSlideOpen = false;

public modifyID = false; // Whether the edit ID form is open or not.

Expand Down Expand Up @@ -50,13 +51,23 @@ export class CreateChefServerModalComponent implements OnInit {
this.conflictError = false;
}

closeEvent(): void {
createChefServer(): void {
this.toggleSlide();
this.createClicked.emit();
this.modifyID = false;
}

closeSeverSlider() {
this.toggleSlide();
this.modifyID = false;
this.close.emit();
}

createChefServer(): void {
this.createClicked.emit();
toggleSlide() {
this.isSlideOpen = !this.isSlideOpen;
}

slidePanel() {
this.isSlideOpen = true;
}
}
1 change: 1 addition & 0 deletions components/automate-ui/src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $chef-azureish-gray: $azureish-gray;
$light-grey: $hexgray;
$transparent-white: rgba(255, 255, 255, 0.85);
$chef-nevada: $nevada;
$chef-gulf-blue: $eggplant-dark-1;
//status
$status-error: $rose;
$status-success: $winter-green;
Expand Down
Loading

0 comments on commit c0cf04a

Please sign in to comment.