assistant2: Setup storybook (#11228)

This PR sets up the `assistant2` crate with the storybook so that UI
elements can be iterated on in isolation.

To start, we have some stories for the `ChatMessage` component:

```sh
cargo run -p storybook -- components/assistant_chat_message
```

<img width="1233" alt="Screenshot 2024-04-30 at 5 20 03 PM"
src="https://github.com/zed-industries/zed/assets/1486634/510967ea-0e9b-4fa9-94fb-421ee74bcc45">

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-04-30 17:33:32 -04:00 committed by GitHub
parent 96b1fc4650
commit f2a1226e18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 139 additions and 19 deletions

View file

@ -1,7 +1,7 @@
mod assistant_settings;
mod completion_provider;
mod tools;
mod ui;
pub mod ui;
use ::ui::{div, prelude::*, Color, ViewContext};
use anyhow::{Context, Result};
@ -222,7 +222,7 @@ impl FocusableView for AssistantPanel {
}
}
struct AssistantChat {
pub struct AssistantChat {
model: String,
messages: Vec<ChatMessage>,
list_state: ListState,
@ -574,12 +574,15 @@ impl AssistantChat {
.map(|element| {
if self.editing_message_id.as_ref() == Some(id) {
element.child(Composer::new(
cx.view().downgrade(),
self.model.clone(),
body.clone(),
self.user_store.read(cx).current_user(),
self.can_submit(),
self.tool_registry.clone(),
crate::ui::ModelSelector::new(
cx.view().downgrade(),
self.model.clone(),
)
.into_any_element(),
))
} else {
element
@ -744,18 +747,18 @@ impl Render for AssistantChat {
.text_color(Color::Default.color(cx))
.child(list(self.list_state.clone()).flex_1())
.child(Composer::new(
cx.view().downgrade(),
self.model.clone(),
self.composer_editor.clone(),
self.user_store.read(cx).current_user(),
self.can_submit(),
self.tool_registry.clone(),
crate::ui::ModelSelector::new(cx.view().downgrade(), self.model.clone())
.into_any_element(),
))
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
struct MessageId(usize);
pub struct MessageId(usize);
impl MessageId {
fn post_inc(&mut self) -> Self {