-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display attached card pills in sent message (#1005)
* allow messages to scroll into view * use Message component to display cards and card errors * revert some changes in base room card * add snapshot for message component with error state * update usage component * distinguish footer area from sent message background * lint fix
- Loading branch information
1 parent
040457a
commit 2aa6fd2
Showing
10 changed files
with
262 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ import type { SafeString } from '@ember/template'; | |
import Component from '@glimmer/component'; | ||
|
||
import { format as formatDate, formatISO } from 'date-fns'; | ||
import Modifier from 'ember-modifier'; | ||
|
||
import { Button } from '@cardstack/boxel-ui/components'; | ||
import { cn } from '@cardstack/boxel-ui/helpers'; | ||
import { FailureBordered } from '@cardstack/boxel-ui/icons'; | ||
|
||
import { type CardDef } from 'https://cardstack.com/base/card-api'; | ||
|
||
import assistantIcon1x from '../ai-assist-icon.webp'; | ||
import assistantIcon2x from '../[email protected]'; | ||
import assistantIcon3x from '../[email protected]'; | ||
|
@@ -21,17 +24,24 @@ interface Signature { | |
datetime: Date; | ||
isFromAssistant: boolean; | ||
profileAvatar?: ComponentLike; | ||
attachedCards?: CardDef[]; | ||
errorMessage?: string; | ||
retryAction?: () => void; | ||
}; | ||
Blocks: { default: [] }; | ||
} | ||
|
||
// TODO: Update Boxel::Message component | ||
class ScrollIntoView extends Modifier { | ||
modify(element: HTMLElement) { | ||
element.scrollIntoView(); | ||
} | ||
} | ||
|
||
export default class AiAssistantMessage extends Component<Signature> { | ||
<template> | ||
<div | ||
class={{cn 'ai-assistant-message' is-from-assistant=@isFromAssistant}} | ||
{{ScrollIntoView}} | ||
data-test-ai-assistant-message | ||
...attributes | ||
> | ||
|
@@ -53,7 +63,10 @@ export default class AiAssistantMessage extends Component<Signature> { | |
{{#if @errorMessage}} | ||
<div class='error-container'> | ||
<FailureBordered class='error-icon' /> | ||
<div class='error-message'>{{@errorMessage}}</div> | ||
<div class='error-message' data-test-card-error> | ||
Error: | ||
{{@errorMessage}} | ||
</div> | ||
{{#if @retryAction}} | ||
<Button | ||
{{on 'click' @retryAction}} | ||
|
@@ -66,13 +79,25 @@ export default class AiAssistantMessage extends Component<Signature> { | |
{{/if}} | ||
</div> | ||
{{/if}} | ||
|
||
<div class='content'> | ||
{{@formattedMessage}} | ||
|
||
<div>{{yield}}</div> | ||
|
||
{{#if @attachedCards.length}} | ||
<div class='cards' data-test-message-cards> | ||
{{#each this.cardResources as |resource|}} | ||
<div data-test-message-card={{resource.card.id}}> | ||
<resource.component /> | ||
</div> | ||
{{/each}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<style> | ||
.ai-assistant-message { | ||
--ai-assistant-message-avatar-size: 1.25rem; /* 20px. */ | ||
|
@@ -161,8 +186,22 @@ export default class AiAssistantMessage extends Component<Signature> { | |
--boxel-button-min-width: max-content; | ||
border-color: var(--boxel-light); | ||
} | ||
.cards { | ||
color: var(--boxel-dark); | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: var(--boxel-sp-xxs); | ||
} | ||
</style> | ||
</template> | ||
|
||
private get cardResources() { | ||
return this.args.attachedCards?.map((card) => ({ | ||
card, | ||
component: card.constructor.getComponent(card, 'atom'), | ||
})); | ||
} | ||
} | ||
|
||
interface AiAssistantConversationSignature { | ||
|
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
Oops, something went wrong.