-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a custom component for transform engine selection. (#113)
- Loading branch information
1 parent
cd44300
commit de8f692
Showing
12 changed files
with
237 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...transform/components/engine-section/components/engine-select/engine-select.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="dropdown" #dropdown (click)="clickInput()"> | ||
<div class="preview"> | ||
<input | ||
type="text" | ||
placeholder="Dropdown menu" | ||
readonly | ||
#input | ||
[value]="value" | ||
readonly | ||
data-test-id="input-dropdown" | ||
/> | ||
<img | ||
class="selectedImage" | ||
[src]="getLogo(engine).url_logo" | ||
#selectedImage | ||
/> | ||
</div> | ||
<div class="option" #option *ngIf="showDropdown"> | ||
<ng-container *ngFor="let item of data; let i = index"> | ||
<div (click)="clickShowDropdown(item)"> | ||
<img [src]="getLogo(item.name).url_logo" alt="" /> | ||
{{ getLogo(item.name).label }} | ||
</div> | ||
</ng-container> | ||
</div> | ||
</div> |
58 changes: 58 additions & 0 deletions
58
...transform/components/engine-section/components/engine-select/engine-select.component.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
.dropdown | ||
box-sizing: border-box | ||
position: relative | ||
width: 350px | ||
height: 35px | ||
input | ||
position: absolute | ||
top: 0 | ||
left: 0 | ||
width: 100% | ||
height: 100% | ||
cursor: pointer | ||
outline: none | ||
border-radius: 6px | ||
padding-left: 55px | ||
border: 1px solid #ced4da | ||
&:focus | ||
border: 1px solid #86b7fe | ||
box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25) | ||
.selectedImage | ||
position: absolute | ||
top: 8px | ||
left: 16px | ||
max-width: 30px | ||
&::before | ||
content: '' | ||
position: absolute | ||
width: 6px | ||
height: 6px | ||
border: 2px solid #333 | ||
right: 20px | ||
top: 15px | ||
z-index: 1000 | ||
border-top: 2px solid #fff | ||
border-right: 2px solid #fff | ||
transform: rotate(-45deg) | ||
transition: 0.5s | ||
pointer-events: none | ||
.option | ||
position: absolute | ||
top: 37px | ||
width: 350px | ||
background: #fff | ||
padding: 6px 10px | ||
border-radius: 5px | ||
overflow: hidden | ||
border: 1px solid #ced4da | ||
div | ||
padding: 10px 10px | ||
cursor: pointer | ||
display: flex | ||
align-items: center | ||
img | ||
margin-right: 10px | ||
max-width: 30px | ||
&:hover | ||
background: #62baea | ||
color: #fff |
39 changes: 39 additions & 0 deletions
39
...nsform/components/engine-section/components/engine-select/engine-select.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { EngineSelectComponent } from "./engine-select.component"; | ||
import { mockEngines } from "../../../../mock.data"; | ||
import { emitClickOnElementByDataTestId } from "src/app/common/base-test.helpers.spec"; | ||
|
||
describe("EngineSelectComponent", () => { | ||
let component: EngineSelectComponent; | ||
let fixture: ComponentFixture<EngineSelectComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [EngineSelectComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(EngineSelectComponent); | ||
component = fixture.componentInstance; | ||
component.data = mockEngines.data.knownEngines; | ||
component.engine = "spark"; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should check open dropdown", () => { | ||
expect(component.showDropdown).toEqual(false); | ||
emitClickOnElementByDataTestId(fixture, "input-dropdown"); | ||
expect(component.showDropdown).toEqual(true); | ||
}); | ||
|
||
it("should check close dropdown when click dropdown outside", () => { | ||
expect(component.showDropdown).toEqual(false); | ||
emitClickOnElementByDataTestId(fixture, "input-dropdown"); | ||
expect(component.showDropdown).toEqual(true); | ||
document.dispatchEvent(new MouseEvent("click")); | ||
expect(component.showDropdown).toEqual(false); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
...t-transform/components/engine-section/components/engine-select/engine-select.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
EventEmitter, | ||
HostListener, | ||
Input, | ||
OnInit, | ||
Output, | ||
Renderer2, | ||
ViewChild, | ||
} from "@angular/core"; | ||
import { EngineDesc } from "src/app/api/kamu.graphql.interface"; | ||
import { DataHelpers } from "src/app/common/data.helpers"; | ||
import { EventPropertyLogo } from "src/app/dataset-block/metadata-block/components/event-details/supported.events"; | ||
|
||
@Component({ | ||
selector: "app-engine-select", | ||
templateUrl: "./engine-select.component.html", | ||
styleUrls: ["./engine-select.component.sass"], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class EngineSelectComponent implements OnInit { | ||
@ViewChild("input", { static: true }) input: ElementRef; | ||
@ViewChild("dropdown", { static: true }) | ||
dropdown: ElementRef<HTMLDivElement>; | ||
@ViewChild("selectedImage", { static: true }) | ||
selectedImage: ElementRef<HTMLImageElement>; | ||
public showDropdown = false; | ||
@Input() data: EngineDesc[]; | ||
@Input() engine: string; | ||
@Output() selectedEngineEmitter = new EventEmitter<string>(); | ||
|
||
constructor(private render: Renderer2) {} | ||
|
||
@HostListener("document:click", ["$event"]) | ||
clickout(event: Event) { | ||
if (!this.dropdown.nativeElement.contains(event.target as Element)) { | ||
this.showDropdown = false; | ||
} | ||
} | ||
|
||
ngOnInit(): void { | ||
const defaultEngine = this.data.find( | ||
(item: EngineDesc) => item.name === this.engine, | ||
); | ||
if (defaultEngine) { | ||
this.clickShowDropdown(defaultEngine); | ||
} | ||
} | ||
public get value(): string { | ||
return DataHelpers.descriptionForEngine(this.engine).label ?? ""; | ||
} | ||
|
||
public getLogo(name: string): EventPropertyLogo { | ||
return DataHelpers.descriptionForEngine( | ||
name.toUpperCase().toLowerCase(), | ||
); | ||
} | ||
|
||
public clickShowDropdown(item: EngineDesc): void { | ||
const description = item.name.toUpperCase().toLowerCase(); | ||
this.render.setAttribute( | ||
this.selectedImage.nativeElement, | ||
"src", | ||
this.getLogo(description).url_logo ?? "", | ||
); | ||
this.selectedEngineEmitter.emit(description); | ||
} | ||
|
||
public clickInput(): void { | ||
this.showDropdown = !this.showDropdown; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters