-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: otter training - components (#2173)
## Proposed change Creation of components that will be used in the Otter training (such as a code editor, etc) ## Related issues - 🐛 Fixes #(issue) - 🚀 Feature #(issue) <!-- Please make sure to follow the contributing guidelines on https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
- Loading branch information
Showing
40 changed files
with
866 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
dist-e2e-playwright | ||
playwright-reports | ||
test-results | ||
training-assets |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copy necessary assets for the Otter training | ||
*/ | ||
const fs = require('node:fs'); | ||
const path = require('node:path'); | ||
|
||
const temporaryAssetsDirectory = path.resolve( __dirname, '..', '..', 'training-assets'); | ||
|
||
function getAbsolutePath(packageName) { | ||
const packageJsonPath = require.resolve(`${packageName}/package.json`); | ||
return path.dirname(packageJsonPath); | ||
} | ||
|
||
// @vscode/codicons | ||
const vscodePath = path.join(getAbsolutePath('@vscode/codicons'), 'dist'); | ||
const vscodeDestinationPath = `${temporaryAssetsDirectory}/@vscode/codicons/dist`; | ||
fs.cpSync(vscodePath, vscodeDestinationPath, {recursive: true}); | ||
|
||
// @xterm/xterm | ||
const xtermPath = path.join(getAbsolutePath('@xterm/xterm'), 'css/xterm.css'); | ||
const xtermDestinationPath = `${temporaryAssetsDirectory}/@xterm/xterm/css/xterm.css`; | ||
fs.cpSync(xtermPath, xtermDestinationPath, {recursive: true}); | ||
|
||
// monaco-editor | ||
const monacoEditorPath = path.join(getAbsolutePath('monaco-editor')); | ||
const monacoEditorDestinationPath = `${temporaryAssetsDirectory}/monaco-editor`; | ||
fs.cpSync(monacoEditorPath, monacoEditorDestinationPath, {recursive: true}); | ||
|
||
// ngx-monaco-tree | ||
const ngxMonacoTreePath = path.join(getAbsolutePath('ngx-monaco-tree'), 'assets'); | ||
const ngxMonacoTreeDestinationPath = `${temporaryAssetsDirectory}/ngx-monaco-tree/assets`; | ||
fs.cpSync(ngxMonacoTreePath, ngxMonacoTreeDestinationPath, {recursive: true}); |
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
2 changes: 1 addition & 1 deletion
2
apps/showcase/src/app/run-app-locally/run-app-locally.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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './showcase/index'; | ||
export * from './training/index'; | ||
export * from './utilities/index'; |
34 changes: 34 additions & 0 deletions
34
apps/showcase/src/components/training/code-editor-control/code-editor-control.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,34 @@ | ||
<ul ngbNav #nav="ngbNav" class="nav nav-tabs"> | ||
<li ngbNavItem class="nav-item" role="presentation" [destroyOnHide]="false"> | ||
<a ngbNavLink class="nav-link" [class.active]="activeTab === 'preview'" (click)="activeTab = 'preview'">Preview</a> | ||
<ng-template ngbNavContent> | ||
<iframe class="w-100 h-100" #iframe allow="cross-origin-isolated" [srcdoc]="'Loading...'"></iframe> | ||
</ng-template> | ||
</li> | ||
<li ngbNavItem class="nav-item" role="presentation" [destroyOnHide]="false"> | ||
<a ngbNavLink class="nav-link" [class.active]="activeTab === 'output'" (click)="activeTab = 'output'">Output</a> | ||
<ng-template ngbNavContent> | ||
<code-editor-terminal id="tab-content2" class="d-block h-100" | ||
(disposed)="webContainerService.runner.disposeCommandOutputTerminal()" | ||
(terminalUpdated)="webContainerService.runner.registerCommandOutputTerminal($event)"> | ||
</code-editor-terminal> | ||
</ng-template> | ||
</li> | ||
<li ngbNavItem class="nav-item" role="presentation" [destroyOnHide]="false"> | ||
<a ngbNavLink class="nav-link" [class.active]="activeTab === 'terminal'" (click)="activeTab = 'terminal'">Terminal</a> | ||
<ng-template ngbNavContent> | ||
<code-editor-terminal id="tab-content3" class="d-block h-100" | ||
(disposed)="webContainerService.runner.disposeShell()" | ||
(terminalUpdated)="webContainerService.runner.registerShell($event)"> | ||
</code-editor-terminal> | ||
</ng-template> | ||
</li> | ||
<button type="button" class="btn btn-outline-secondary df-btn-icononly align-self-center ms-auto" | ||
[class.fa-chevron-down]="!show" | ||
[class.fa-chevron-up]="show" | ||
(click)="show = !show"> | ||
<span class="visually-hidden">{{show ? 'Hide' : 'Show'}}</span> | ||
</button> | ||
</ul> | ||
<div class="h-100 command-panel" [class.d-none]="!show" [ngbNavOutlet]="nav"></div> | ||
|
16 changes: 16 additions & 0 deletions
16
apps/showcase/src/components/training/code-editor-control/code-editor-control.component.scss
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,16 @@ | ||
code-editor-control { | ||
|
||
&:has(.command-panel.d-none) { | ||
min-height: 3rem; | ||
} | ||
|
||
.tab-content { | ||
--df-tabs-content-tab-pane-padding: 0; | ||
overflow: hidden; | ||
} | ||
|
||
.tab-pane { | ||
border: 1px solid black; | ||
height: 100%; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...howcase/src/components/training/code-editor-control/code-editor-control.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,22 @@ | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
|
||
import {CodeEditorControlComponent} from './code-editor-control.component'; | ||
|
||
describe('ViewComponent', () => { | ||
let component: CodeEditorControlComponent; | ||
let fixture: ComponentFixture<CodeEditorControlComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [CodeEditorControlComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CodeEditorControlComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
apps/showcase/src/components/training/code-editor-control/code-editor-control.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,72 @@ | ||
import { | ||
AfterViewInit, | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
inject, | ||
Input, | ||
OnDestroy, | ||
ViewChild, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
import {NgbNav, NgbNavContent, NgbNavItem, NgbNavLink, NgbNavOutlet} from '@ng-bootstrap/ng-bootstrap'; | ||
import {WebContainerService} from '../../../services'; | ||
import {CodeEditorTerminalComponent} from '../code-editor-terminal'; | ||
|
||
@Component({ | ||
selector: 'code-editor-control', | ||
standalone: true, | ||
imports: [ | ||
CodeEditorTerminalComponent, | ||
NgbNav, | ||
NgbNavContent, | ||
NgbNavItem, | ||
NgbNavLink, | ||
NgbNavOutlet | ||
], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
templateUrl: './code-editor-control.component.html', | ||
styleUrl: './code-editor-control.component.scss' | ||
}) | ||
export class CodeEditorControlComponent implements OnDestroy, AfterViewInit { | ||
/** | ||
* Show the terminal used as output for the command process | ||
*/ | ||
@Input() public showOutput = true; | ||
|
||
/** | ||
* Reference to the iframe used to display the content of the application served in the web container | ||
*/ | ||
@ViewChild('iframe') | ||
public iframeEl!: ElementRef<HTMLIFrameElement>; | ||
|
||
/** | ||
* Manage the web-container commands and outputs. | ||
*/ | ||
public readonly webContainerService = inject(WebContainerService); | ||
|
||
/** | ||
* Whether to show the panels - if set to false, hide all the panels and only display the tab bar | ||
*/ | ||
public show = true; | ||
|
||
/** | ||
* Current tab displayed | ||
*/ | ||
public activeTab: 'preview' | 'output' | 'terminal' = 'preview'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public ngAfterViewInit() { | ||
this.webContainerService.runner.registerIframe(this.iframeEl.nativeElement); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public ngOnDestroy() { | ||
this.webContainerService.runner.registerIframe(null); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
apps/showcase/src/components/training/code-editor-control/index.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 @@ | ||
export * from './code-editor-control.component'; |
22 changes: 22 additions & 0 deletions
22
...wcase/src/components/training/code-editor-terminal/code-editor-terminal.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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { CodeEditorTerminalComponent } from './code-editor-terminal.component'; | ||
|
||
describe('ViewComponent', () => { | ||
let component: CodeEditorTerminalComponent; | ||
let fixture: ComponentFixture<CodeEditorTerminalComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [CodeEditorTerminalComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CodeEditorTerminalComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.