-
Notifications
You must be signed in to change notification settings - Fork 32
Migrate asciicinema component from hashicorp/ember-asciinema-player repo #3102
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
23801cc
chore: 🤖 add asciinema-player dependency
hashicc 4959fc7
chore: 🤖 migrate component and test from addon repo
hashicc 9b44b1f
chore: 🤖 update component references in tests
hashicc 76cffc3
chore: 🤖 swap styles import to asciinema-player
hashicc 90e485e
chore: 🤖 Use specific version of ascii-cinema for our styles
hashicc 79d0864
chore: 🤖 import setupRenderingTest from app helpers
hashicc 7f41ff1
chore: 🤖 update reference to test .cast file fetched
hashicc 6112e67
style: 💄 prettier formatting updates
hashicc 7ede0b8
chore: 🤖 refactor to using element modifier
hashicc ef4f739
chore: 🤖 remove unused/unreferenced property
hashicc 811a952
chore: 🤖 remove unused css classname
hashicc a81cc6e
chore: 🤖 rename asciinema player component class name
hashicc 2beee61
refactor: 💡 simplify implementation
hashicc 50803c8
refactor: 💡 replace addon component with app component
hashicc 34df5d0
fix: 🐛 pass in data as an object with the key data
hashicc bcb9da9
refactor: 💡 remove @tracked on player property
hashicc b7aac5d
chore: 🤖 remove hashicorp/ember-asciinema-player dependency
hashicc 607964d
fix: 🐛 update to correct location of asciinema-player.css
hashicc 7b5effe
Merge branch 'main' into migrate-asciicinema-components
lisbet-alvarez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
ui/admin/app/components/session-recording/player/asciinema-player.hbs
This file contains hidden or 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,6 @@ | ||
| {{! | ||
| Copyright (c) HashiCorp, Inc. | ||
| SPDX-License-Identifier: MPL-2.0 | ||
| }} | ||
|
|
||
| <div ...attributes {{this.initializePlayer data=@data}}></div> | ||
lisbet-alvarez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
72 changes: 72 additions & 0 deletions
72
ui/admin/app/components/session-recording/player/asciinema-player.js
This file contains hidden or 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 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import * as AsciinemaPlayer from 'asciinema-player'; | ||
| import { modifier } from 'ember-modifier'; | ||
|
|
||
| export default class SessionRecordingPlayerAsciinemaPlayerComponent extends Component { | ||
| // =properties | ||
|
|
||
| /** | ||
| * @type {?AsciinemaPlayer} | ||
| */ | ||
| player = null; | ||
lisbet-alvarez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Options of the underlying AsciinemaPlayer supported by this component, | ||
| * which may be passed as named arguments to the player. | ||
| * @type {string[]} | ||
| * @see https://github.com/asciinema/asciinema-player#options | ||
| */ | ||
| supportedOptions = new Array( | ||
| 'autoPlay', | ||
| 'loop', | ||
| 'startAt', | ||
| 'speed', | ||
| 'idleTimeLimit', | ||
| 'theme', | ||
| 'poster', | ||
| 'fit', | ||
| 'controls', | ||
| 'markers', | ||
| 'pauseOnMarkers', | ||
| ); | ||
|
|
||
| /** | ||
| * An object of options where each possible key from `supportOptions` is | ||
| * included if and only if its associated value was passed to the component | ||
| * as an argument. | ||
| * | ||
| * E.g. `@autoPlay={{true}} @fit='both'` results in | ||
| * the options object `{autoPlay: true, fit: 'both'}`. | ||
| * @type {object} | ||
| * @see https://github.com/asciinema/asciinema-player#options | ||
| */ | ||
| get options() { | ||
| return this.supportedOptions.reduce((obj, key) => { | ||
| return this.args?.[key] !== undefined | ||
| ? { ...obj, [key]: this.args[key] } | ||
| : obj; | ||
| }, {}); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an AsciinemaPlayer within the passed `containerElement`. | ||
| */ | ||
| initializePlayer = modifier((containerElement, _, { data }) => { | ||
| if (!data) return; | ||
| this.player = AsciinemaPlayer.create( | ||
| { data }, | ||
| containerElement, | ||
| this.options, | ||
| ); | ||
|
|
||
| return () => { | ||
| this.player?.dispose(); | ||
| this.player = null; | ||
| }; | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
ui/admin/tests/integration/components/session-recording/player/asciinema-player-test.js
This file contains hidden or 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,36 @@ | ||
| /** | ||
| * Copyright (c) HashiCorp, Inc. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| import { module, test } from 'qunit'; | ||
| import { render, waitUntil } from '@ember/test-helpers'; | ||
| import { setupRenderingTest } from 'admin/tests/helpers'; | ||
| import { hbs } from 'ember-cli-htmlbars'; | ||
|
|
||
| module( | ||
| 'Integration | Component | session-recording/player/asciinema-player', | ||
| function (hooks) { | ||
| setupRenderingTest(hooks); | ||
|
|
||
| test('it renders', async function (assert) { | ||
| assert.expect(1); | ||
|
|
||
| const asciicast = await fetch('/session.cast'); | ||
lisbet-alvarez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const asciicastContent = await asciicast.text(); | ||
| this.set('data', asciicastContent); | ||
|
|
||
| await render( | ||
| hbs`<SessionRecording::Player::AsciinemaPlayer @data={{this.data}} @poster='npt:1:30' />`, | ||
| ); | ||
| // AsciinemaPlayer does not come with a "ready" event, and its | ||
| // initialization is async. Therefore tests must `waitUntil` the expected | ||
| // DOM state is reached. | ||
| await waitUntil(() => | ||
| assert | ||
| .dom('.ap-player') | ||
| .hasAnyText('ember-asciinema-player git:(main*)'), | ||
| ); | ||
| }); | ||
| }, | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.