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

Send telemetry for profile searches and add search button #6840

Merged
merged 4 commits into from
Apr 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@
<chef-heading>Profiles</chef-heading>
<chef-subheading>Compliance profiles manage security and compliance scans.</chef-subheading>

<div class="profiles-search" *ngIf="!profilesEmpty || isAvailableProfilesVisible">
<div class="profiles-search" *ngIf="!profilesEmpty || isAvailableProfilesVisible"
[class.active]="formActive">
<input
#search_box
chefInput
type="text"
aria-label="Search profiles"
placeholder="Search profiles..."
(input)="onSearchInput($event)"/>
autocomplete="off"
(focus)="toggleFocus()"
(blur)="toggleFocus()"/>
<button
type="submit"
class="primary"
primary
(click)="onSearchInput(search_box.value)">
<span aria-hidden="true" class="hidden">Submit Search</span>
<chef-icon>search</chef-icon>
</button>
</div>

<chef-tab-selector *ngIf="isAvailableProfilesVisible" class="profiles-tabs" [value]="selectedTab" (change)="onTabChange($event)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,47 @@
}

.profiles-search {
padding: 18px 0 14px;
display: flex;
margin: 18px 0 14px;
flex-direction: row;
width: 100%;

chef-input {
&.active {
box-shadow: 0px 0px 0px 1px $chef-primary-bright; // Mimic default outline
}

input {
width: 100%;
font-size: 14px;
border-radius: 4px 0px 0px 4px;
transition: 0s; // Remove default transition

&:focus {
border: 0; // Accessibility is being noted around containing form
}
}

button {
background: #E6EBEE;
width: 45px;
box-shadow: 0 1px 14px #E6EBEE;
border: 0px solid transparent;
border-radius: 0px 4px 4px 0px;
cursor: pointer;
font-size: 16px;

&:focus {
outline: none;
border: 1px solid $chef-primary-bright;
}

&[disabled] {
cursor: auto;
}

.hidden {
display: none;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { UploadService } from 'app/services/profiles/upload.service';
import { ChefSessionService } from 'app/services/chef-session/chef-session.service';
import { ProductDeployedService } from 'app/services/product-deployed/product-deployed.service';
import { MockComponent } from 'ng2-mock-component';
import { TelemetryService } from 'app/services/telemetry/telemetry.service';

class MockProductDeployedService {
constructor(private products: string[]) { }
Expand All @@ -38,6 +39,10 @@ class MockUploadService {
}
}

class MockTelemetryService {
track() { }
}

describe('ProfilesOverviewComponent', () => {
let store: Store<NgrxStateAtom>;
let fixture, component, element;
Expand Down Expand Up @@ -68,7 +73,8 @@ describe('ProfilesOverviewComponent', () => {
{provide: ChefSessionService, useValue: mockSession},
{provide: UploadService, useClass: MockUploadService},
FeatureFlagsService,
{ provide: ProductDeployedService, useValue: new MockProductDeployedService([]) }
{ provide: ProductDeployedService, useValue: new MockProductDeployedService([]) },
{ provide: TelemetryService, useClass: MockTelemetryService }
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
});
Expand Down Expand Up @@ -428,7 +434,8 @@ describe('ProfilesOverviewComponent', () => {
{provide: ChefSessionService, useValue: mockSession},
{provide: UploadService, useClass: MockUploadService},
FeatureFlagsService,
{ provide: ProductDeployedService, useValue: new MockProductDeployedService([]) }
{ provide: ProductDeployedService, useValue: new MockProductDeployedService([]) },
{ provide: TelemetryService, useClass: MockTelemetryService }
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
});
Expand Down Expand Up @@ -515,7 +522,9 @@ describe('ProfilesOverviewComponent', () => {
{provide: UploadService, useClass: MockUploadService},
FeatureFlagsService,
// This installs the Desktop offering
{ provide: ProductDeployedService, useValue: new MockProductDeployedService(['desktop']) }
{ provide: ProductDeployedService,
useValue: new MockProductDeployedService(['desktop']) },
{ provide: TelemetryService, useClass: MockTelemetryService }
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
});
Expand Down Expand Up @@ -601,7 +610,9 @@ describe('ProfilesOverviewComponent', () => {
{provide: UploadService, useClass: MockUploadService},
FeatureFlagsService,
// This installs the Desktop offering
{ provide: ProductDeployedService, useValue: new MockProductDeployedService(['desktop']) }
{ provide: ProductDeployedService,
useValue: new MockProductDeployedService(['desktop']) },
{ provide: TelemetryService, useClass: MockTelemetryService }
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChefSessionService } from 'app/services/chef-session/chef-session.servi
import { find } from 'lodash';
import { ProductDeployedService } from 'app/services/product-deployed/product-deployed.service';
import { HttpStatus } from 'app/types/types';
import { TelemetryService } from 'app/services/telemetry/telemetry.service';

interface Profile {
name: String;
Expand Down Expand Up @@ -54,6 +55,7 @@ export class ProfileOverviewComponent implements OnInit, OnDestroy {
filteredAvailableProfiles: Array<Profile> = [];
filteredProfilesLength = 0;
filteredAvailableProfilesLength = 0;
formActive = false;

// shows setup page when false
profilesEnabled = true;
Expand Down Expand Up @@ -88,7 +90,8 @@ export class ProfileOverviewComponent implements OnInit, OnDestroy {
private uploadService: UploadService,
private chefSessionService: ChefSessionService,
private layoutFacade: LayoutFacadeService,
private productDeployedService: ProductDeployedService
private productDeployedService: ProductDeployedService,
private telemetryService: TelemetryService
) {
this.isAvailableProfilesVisible = !this.productDeployedService.isProductDeployed('desktop');
}
Expand All @@ -109,15 +112,16 @@ export class ProfileOverviewComponent implements OnInit, OnDestroy {
});
}

onSearchInput(event) {
const value = event.target.value;
onSearchInput(searchText) {
const value = searchText;
const filter = profile => {
return ['name', 'version', 'title'].some(key => {
return profile[key].toLowerCase().includes(value.toLowerCase());
});
};
this.filteredProfiles = this.installedProfiles.filter(filter);
this.filteredAvailableProfiles = this.availableProfiles.filter(filter);
this.telemetryService.track('Compliance_Profiles_Search', { searchText });
}

// load the user's profiles
Expand Down Expand Up @@ -315,4 +319,8 @@ export class ProfileOverviewComponent implements OnInit, OnDestroy {
selectTab(tabToSelect: 'installed' | 'available') {
this.selectedTab = tabToSelect;
}

toggleFocus(): void {
this.formActive = !this.formActive;
}
}