-
Notifications
You must be signed in to change notification settings - Fork 1
Add support for SmartConversation::Message component #464
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
Open
phndiaye
wants to merge
6
commits into
master
Choose a base branch
from
pn/vel-7659
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b41b83b
add support for SmartConversation::Message component
phndiaye c8ffcc6
add tests
phndiaye 83989cf
add missing max-width
phndiaye b229c44
fix pr feedbacks
phndiaye 4295146
Convert collapsible getter into an optional arg (defaulted to true)
olxmpe bb91f47
Make collapsible getter private
olxmpe 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <div | ||
| class={{this.computedClasses}} | ||
| role="button" | ||
| data-control-name="smart-conversation-message" | ||
| {{on "click" this.toggleCollapsed}} | ||
| > | ||
| <div class="content"> | ||
| {{#if (eq @type "smart_reply")}} | ||
| <Utils::SmartBlob @size="md" /> | ||
| {{/if}} | ||
|
|
||
| <div class="fx-col fx-gap-px-18"> | ||
| <span>{{@value}}</span> | ||
|
|
||
| {{#if (has-block "extra-content")}} | ||
| {{yield to="extra-content"}} | ||
| {{/if}} | ||
| </div> | ||
| </div> | ||
|
|
||
| <span class="font-color-gray-400 font-size-xs">{{this.formattedTimestamp}}</span> | ||
| </div> | ||
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,43 @@ | ||
| import { action } from '@ember/object'; | ||
| import Component from '@glimmer/component'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
|
|
||
| import moment from 'moment'; | ||
|
|
||
| interface UtilsSmartConversationMessageComponentSignature { | ||
| type: 'smart_reply' | 'user_prompt'; | ||
| collapsible?: boolean; | ||
| value: string; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| export default class UtilsSmartConversationMessageComponent extends Component<UtilsSmartConversationMessageComponentSignature> { | ||
| @tracked collapsed: boolean = true; | ||
|
|
||
| get computedClasses(): string { | ||
| const classes = ['smart-conversation-message', `smart-conversation-message--${this.args.type}`]; | ||
|
|
||
| if (this.collapsible && this.collapsed) { | ||
| classes.push('smart-conversation-message--collapsed'); | ||
| } | ||
|
|
||
| return classes.join(' '); | ||
| } | ||
|
|
||
| get formattedTimestamp(): string { | ||
| return moment(this.args.timestamp).format('DD/MM/YYYY, HH:mm'); | ||
| } | ||
|
|
||
| @action | ||
| toggleCollapsed(event: MouseEvent): void { | ||
| event.stopPropagation(); | ||
|
|
||
| if (!this.collapsible) return; | ||
|
|
||
| this.collapsed = !this.collapsed; | ||
| } | ||
|
|
||
| private get collapsible(): boolean { | ||
| return this.args.collapsible ?? true; | ||
| } | ||
| } |
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 @@ | ||
| export { default } from '@upfluence/ember-upf-utils/components/utils/smart-conversation/message'; |
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,48 @@ | ||
| @import url('https://fonts.googleapis.com/css?family=Reddit+Sans:wght@400,600&family=Open+Sans:400,400i,600,600i,700,700i&display=swap&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese'); | ||
|
|
||
| .smart-conversation-message { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--spacing-px-3); | ||
| align-items: flex-end; | ||
| max-width: 70%; | ||
|
|
||
| .content { | ||
| border-radius: var(--border-radius-lg); | ||
| display: flex; | ||
| gap: var(--spacing-px-18); | ||
| padding: var(--spacing-px-12) var(--spacing-px-18); | ||
| font-size: var(--font-size-md); | ||
| font-family: 'Reddit Sans', sans-serif; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New font? |
||
| position: relative; | ||
| } | ||
|
|
||
| &--smart_reply .content { | ||
| border: 1px solid transparent; | ||
| background: linear-gradient(45deg, var(--color-white) 0%, var(--color-primary-50) 100%) padding-box, | ||
| linear-gradient(90deg, var(--color-primary-100) 0%, var(--color-white) 72.5%) border-box; | ||
|
|
||
| color: var(--color-primary-400); | ||
| } | ||
|
|
||
| &--user_prompt .content { | ||
| background-color: var(--color-gray-100); | ||
| color: var(--color-gray-900); | ||
| padding: var(--spacing-px-12); | ||
| } | ||
|
|
||
| &--collapsed .content { | ||
| max-height: 130px; | ||
| overflow-y: hidden; | ||
|
|
||
| &::after { | ||
| content: ''; | ||
| position: absolute; | ||
| bottom: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 40px; | ||
| background: linear-gradient(to top, var(--color-gray-50), transparent 40px); | ||
| } | ||
| } | ||
| } | ||
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
147 changes: 147 additions & 0 deletions
147
tests/integration/components/utils/smart-conversation/message-test.ts
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,147 @@ | ||
| import { module, test } from 'qunit'; | ||
| import { setupRenderingTest } from 'ember-qunit'; | ||
| import { click, render } from '@ember/test-helpers'; | ||
| import { hbs } from 'ember-cli-htmlbars'; | ||
| import moment from 'moment'; | ||
|
|
||
| module('Integration | Component | utils/smart-conversation/message', function (hooks) { | ||
| setupRenderingTest(hooks); | ||
|
|
||
| module('User prompt', function (hooks) { | ||
| hooks.beforeEach(function () { | ||
| this.type = 'user_prompt'; | ||
| this.value = 'Gimme, gimme, gimme a creator after midnight'; | ||
| this.timestamp = moment('2026-05-05').valueOf(); | ||
| }); | ||
|
|
||
| test('it renders properly', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message').exists(); | ||
| assert.dom('.smart-conversation-message').hasClass('smart-conversation-message--user_prompt'); | ||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
| assert.dom('.smart-conversation-message .content').hasText('Gimme, gimme, gimme a creator after midnight'); | ||
| assert.dom('.smart-conversation-message span.font-color-gray-400').hasText('05/05/2026, 00:00'); | ||
| }); | ||
|
|
||
| test('the extra-content named block is rendered when provided', async function (assert) { | ||
| await render( | ||
| hbs` | ||
| <Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}> | ||
| <:extra-content> | ||
| <div class="extra-content">Extra content</div> | ||
| </:extra-content> | ||
| </Utils::SmartConversation::Message> | ||
| ` | ||
| ); | ||
|
|
||
| assert.dom('.extra-content').exists(); | ||
| assert.dom('.extra-content').hasText('Extra content'); | ||
| }); | ||
| }); | ||
|
|
||
| module('Smart reply', function (hooks) { | ||
| hooks.beforeEach(function () { | ||
| this.type = 'smart_reply'; | ||
| this.value = 'This is a smart reply'; | ||
| this.timestamp = moment('2026-04-22').valueOf(); | ||
| }); | ||
|
|
||
| test('it renders properly', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message').exists(); | ||
| assert.dom('.smart-conversation-message').hasClass('smart-conversation-message--smart_reply'); | ||
| assert.dom('.smart-conversation-message').hasClass('smart-conversation-message--collapsed'); | ||
| assert.dom('.smart-conversation-message .content').hasText(this.value); | ||
| assert.dom('.smart-conversation-message span.font-color-gray-400').hasText('22/04/2026, 00:00'); | ||
| }); | ||
|
|
||
| test('the extra-content named block is rendered when provided', async function (assert) { | ||
| await render( | ||
| hbs` | ||
| <Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}> | ||
| <:extra-content> | ||
| <div class="extra-content">Extra content</div> | ||
| </:extra-content> | ||
| </Utils::SmartConversation::Message> | ||
| ` | ||
| ); | ||
|
|
||
| assert.dom('.extra-content').exists(); | ||
| assert.dom('.extra-content').hasText('Extra content'); | ||
| }); | ||
| }); | ||
|
|
||
| module('Collapsible message', function () { | ||
| ['user_prompt', 'smart_reply'].forEach((type) => { | ||
| hooks.beforeEach(function () { | ||
| this.type = type; | ||
| }); | ||
|
|
||
| test(`By default, message is collapsible for ${type}`, async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
|
|
||
| await click('.smart-conversation-message'); | ||
| assert.dom('.smart-conversation-message--collapsed').doesNotExist(); | ||
| }); | ||
|
|
||
| test('when no @collapsible argument is provided, it defaults to true', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
| }); | ||
|
|
||
| test('when a falsy @collapsible argument is provided, message is not collapsed', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @collapsible={{false}} @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').doesNotExist(); | ||
| }); | ||
|
|
||
| test('when a falsy @collapsible argument is provided, message is not collapsible', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @collapsible={{false}} @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').doesNotExist(); | ||
|
|
||
| await click('.smart-conversation-message'); | ||
| assert.dom('.smart-conversation-message--collapsed').doesNotExist(); | ||
| }); | ||
|
|
||
| test('when a truthy @collapsible argument is provided, message is collapsed', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @collapsible={{true}} @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
| }); | ||
|
|
||
| test('it toggles collapsed state on click', async function (assert) { | ||
| await render( | ||
| hbs`<Utils::SmartConversation::Message @type={{this.type}} @value={{this.value}} @timestamp={{this.timestamp}}/>` | ||
| ); | ||
|
|
||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
|
|
||
| await click('.smart-conversation-message'); | ||
| assert.dom('.smart-conversation-message--collapsed').doesNotExist(); | ||
|
|
||
| await click('.smart-conversation-message'); | ||
| assert.dom('.smart-conversation-message--collapsed').exists(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can add in the splattributes just-in-case