Skip to content

Commit

Permalink
fneat(training): set solution as readonly (#2679)
Browse files Browse the repository at this point in the history
## Proposed change

If enabled, show terminal but deactivate code edition for exercise
solutions

Set input as signal on training step

## Related issues

<!--
Please make sure to follow the [contribution
guidelines](https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md)
-->

*- No issue associated -*

<!-- * 🐛 Fix #issue -->
<!-- * 🐛 Fix resolves #issue -->
<!-- * 🚀 Feature #issue -->
<!-- * 🚀 Feature resolves #issue -->
<!-- * :octocat: Pull Request #issue -->
  • Loading branch information
cpaulve-1A authored Jan 8, 2025
2 parents 6905db3 + 8122ec8 commit 8b1f644
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</as-split>
</form>
</as-split-area>
@if (editorMode() === 'interactive') {
@if (displayTerminal()) {
<as-split-area [size]="50">
<code-editor-control class="d-flex flex-column h-100"></code-editor-control>
</as-split-area>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,24 @@ export class CodeEditorViewComponent implements OnDestroy {
* Allow to edit the code in the monaco editor
*/
public editorMode = input<EditorMode>('readonly');

/**
* Display terminal
*/
public displayTerminal = input<boolean>(true);

/**
* Project to load in the code editor.
* It should describe the files to load, the starting file, the folder dedicated to the project as well as the
* commands to initialize the project
*/
public project = input.required<TrainingProject>();

/**
* Service to load files and run commands in the application instance of the webcontainer.
*/
public readonly webContainerService = inject(WebContainerService);

/**
* File tree loaded in the project folder within the web container instance.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<div class="h-100">
<as-split direction="horizontal">
@if (instructions) {
<as-split-area [size]="project ? 50 : 100">
@if (instructions()) {
<as-split-area [size]="project() ? 50 : 100">
<div class="instructions h-100 overflow-auto pe-6">
<h2>{{title}}</h2>
<markdown clipboard [data]="instructions"></markdown>
<h2>{{title()}}</h2>
<markdown clipboard [data]="instructions()"></markdown>
</div>
</as-split-area>
}
@if (project) {
<as-split-area [size]="instructions ? 50 : 100">
@if (project()) {
<as-split-area [size]="instructions() ? 50 : 100">
<div class="h-100 overflow-hidden">
<code-editor-view
[project]="project"
[editorMode]="editorMode"
[project]="project()"
[editorMode]="editorMode()"
[displayTerminal]="displayTerminal()"
></code-editor-view>
</div>
</as-split-area>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ChangeDetectionStrategy,
Component,
Input,
input,
} from '@angular/core';
import {
AngularSplitModule,
Expand All @@ -27,17 +27,21 @@ export class TrainingStepPresComponent {
/**
* Description of the coding project to load in the code view editor
*/
@Input() public project?: TrainingProject;
public project = input<TrainingProject>();
/**
* Whether to allow the user to modify the project files in the editor
*/
@Input() public editorMode?: EditorMode;
public editorMode = input<EditorMode>();
/**
* Training step title
*/
@Input() public title?: string;
public title = input<string>();
/**
* Training instructions to do the exercise
*/
@Input() public instructions?: string;
public instructions = input<string>();
/**
* Display terminal
*/
public displayTerminal = input<boolean>(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h1 class="m-0 flex-grow-1">{{title()}}</h1>
[instructions]="currentStep.dynamicContent.htmlContent()"
[title]="currentStep.description.stepTitle"
[project]="showSolution() ? currentStep.dynamicContent.solutionProject() : currentStep.dynamicContent.project()"
[editorMode]="currentStep.description.filesConfiguration?.mode">
[editorMode]="showSolution() ? 'readonly' : currentStep.description.filesConfiguration?.mode"
[displayTerminal]="currentStep.description.filesConfiguration?.mode === 'interactive'">
</o3r-training-step-pres>
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ export class TrainingComponent implements OnInit {
return;

Check warning on line 233 in apps/showcase/src/components/training/training.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/showcase/src/components/training/training.component.ts#L233

Added line #L233 was not covered by tests
}
this.currentStepIndex.set(index);
this.showSolution.set(false);

Check warning on line 236 in apps/showcase/src/components/training/training.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/showcase/src/components/training/training.component.ts#L235-L236

Added lines #L235 - L236 were not covered by tests

const newHash = currentStepLocationRegExp.test(location.hash)
? location.hash.replace(currentStepLocationRegExp, `#${this.currentStepIndex()}`)
: `${location.hash}#${this.currentStepIndex()}`;
history.pushState(null, '', newHash);

Check warning on line 241 in apps/showcase/src/components/training/training.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/showcase/src/components/training/training.component.ts#L241

Added line #L241 was not covered by tests
this.showSolution.set(false);
}

/**
Expand Down

0 comments on commit 8b1f644

Please sign in to comment.