🚧 Feedback modal UI 🚧 (#3536)

[[PR Description]]

TODO: 
- [x] Add placeholder text to editor
- [x] Add external link icon to "Community repo" button
- [x] Show `not-allowed` cursor for disabled buttons
- [ ] Add `Headline` ui component
- [ ] Finish UI pass
- [ ] Fix `IconPosition` on button (should swap the icon side)
- [ ] Add conditional tooltip for disabled "Send feedback" button.
- [ ] Add common/top feedback link.
- [ ] Add `vw`/`vh` units to allow sizing the modal based on viewport
size.

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2023-12-08 13:30:42 -05:00 committed by GitHub
commit f4c93abad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 165 additions and 130 deletions

View file

@ -32,7 +32,7 @@ impl Render for DeployFeedbackButton {
IconButton::new("give-feedback", Icon::Envelope) IconButton::new("give-feedback", Icon::Envelope)
.style(ui::ButtonStyle::Subtle) .style(ui::ButtonStyle::Subtle)
.selected(is_open) .selected(is_open)
.tooltip(|cx| Tooltip::text("Give Feedback", cx)) .tooltip(|cx| Tooltip::text("Share Feedback", cx))
.on_click(|_, cx| { .on_click(|_, cx| {
cx.dispatch_action(Box::new(GiveFeedback)); cx.dispatch_action(Box::new(GiveFeedback));
}) })

View file

@ -6,15 +6,15 @@ use db::kvp::KEY_VALUE_STORE;
use editor::{Editor, EditorEvent}; use editor::{Editor, EditorEvent};
use futures::AsyncReadExt; use futures::AsyncReadExt;
use gpui::{ use gpui::{
div, red, rems, serde_json, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, div, rems, serde_json, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView,
FocusableView, Model, PromptLevel, Render, Task, View, ViewContext, Model, PromptLevel, Render, Task, View, ViewContext,
}; };
use isahc::Request; use isahc::Request;
use language::Buffer; use language::Buffer;
use project::Project; use project::Project;
use regex::Regex; use regex::Regex;
use serde_derive::Serialize; use serde_derive::Serialize;
use ui::{prelude::*, Button, ButtonStyle, Label, Tooltip}; use ui::{prelude::*, Button, ButtonStyle, IconPosition, Tooltip};
use util::ResultExt; use util::ResultExt;
use workspace::Workspace; use workspace::Workspace;
@ -104,6 +104,11 @@ impl FeedbackModal {
let feedback_editor = cx.build_view(|cx| { let feedback_editor = cx.build_view(|cx| {
let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx); let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx);
editor.set_placeholder_text(
"You can use markdown to add links or organize feedback.",
cx,
);
// editor.set_show_gutter(false, cx);
editor.set_vertical_scroll_margin(5, cx); editor.set_vertical_scroll_margin(5, cx);
editor editor
}); });
@ -251,12 +256,6 @@ impl Render for FeedbackModal {
}; };
let valid_character_count = FEEDBACK_CHAR_LIMIT.contains(&self.character_count); let valid_character_count = FEEDBACK_CHAR_LIMIT.contains(&self.character_count);
let characters_remaining =
if valid_character_count || self.character_count > *FEEDBACK_CHAR_LIMIT.end() {
*FEEDBACK_CHAR_LIMIT.end() as i32 - self.character_count as i32
} else {
self.character_count as i32 - *FEEDBACK_CHAR_LIMIT.start() as i32
};
let allow_submission = let allow_submission =
valid_character_count && valid_email_address && !self.pending_submission; valid_character_count && valid_email_address && !self.pending_submission;
@ -264,9 +263,9 @@ impl Render for FeedbackModal {
let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some(); let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some();
let submit_button_text = if self.pending_submission { let submit_button_text = if self.pending_submission {
"Sending..." "Submitting..."
} else { } else {
"Send Feedback" "Submit"
}; };
let dismiss = cx.listener(|_, _, cx| { let dismiss = cx.listener(|_, _, cx| {
cx.emit(DismissEvent); cx.emit(DismissEvent);
@ -285,66 +284,82 @@ impl Render for FeedbackModal {
let open_community_repo = let open_community_repo =
cx.listener(|_, _, cx| cx.dispatch_action(Box::new(OpenZedCommunityRepo))); cx.listener(|_, _, cx| cx.dispatch_action(Box::new(OpenZedCommunityRepo)));
// TODO: Nate UI pass // Moved this here because providing it inline breaks rustfmt
let provide_an_email_address =
"Provide an email address if you want us to be able to reply.";
v_stack() v_stack()
.elevation_3(cx) .elevation_3(cx)
.key_context("GiveFeedback") .key_context("GiveFeedback")
.on_action(cx.listener(Self::cancel)) .on_action(cx.listener(Self::cancel))
.min_w(rems(40.)) .min_w(rems(40.))
.max_w(rems(96.)) .max_w(rems(96.))
.border() .h(rems(32.))
.border_color(red()) .p_4()
.h(rems(40.)) .gap_4()
.p_2() .child(v_stack().child(
.gap_2() // TODO: Add Headline component to `ui2`
div().text_xl().child("Share Feedback"),
))
.child( .child(
v_stack().child( Label::new(if self.character_count < *FEEDBACK_CHAR_LIMIT.start() {
div() format!(
.size_full() "Feedback must be at least {} characters.",
.child(Label::new("Give Feedback").color(Color::Default)) FEEDBACK_CHAR_LIMIT.start()
.child(Label::new("This editor supports markdown").color(Color::Muted)), )
), } else if self.character_count > *FEEDBACK_CHAR_LIMIT.end() {
format!(
"Feedback must be less than {} characters.",
FEEDBACK_CHAR_LIMIT.end()
)
} else {
format!(
"Characters: {}",
*FEEDBACK_CHAR_LIMIT.end() - self.character_count
)
})
.color(if valid_character_count {
Color::Success
} else {
Color::Error
}),
) )
.child( .child(
div() div()
.flex_1() .flex_1()
.bg(cx.theme().colors().editor_background) .bg(cx.theme().colors().editor_background)
.p_2()
.border() .border()
.rounded_md()
.border_color(cx.theme().colors().border) .border_color(cx.theme().colors().border)
.child(self.feedback_editor.clone()), .child(self.feedback_editor.clone()),
) )
.child(
div().child(
Label::new(format!(
"Characters: {}",
characters_remaining
))
.color(
if valid_character_count {
Color::Success
} else {
Color::Error
}
)
),
)
.child( .child(
div() div()
.child(
h_stack()
.bg(cx.theme().colors().editor_background) .bg(cx.theme().colors().editor_background)
.p_2()
.border() .border()
.rounded_md()
.border_color(cx.theme().colors().border) .border_color(cx.theme().colors().border)
.child(self.email_address_editor.clone()) .child(self.email_address_editor.clone()),
) )
.child( .child(
h_stack() h_stack()
.justify_between() .justify_between()
.gap_1() .gap_1()
.child(Button::new("community_repo", "Community Repo") .child(
.style(ButtonStyle::Filled) Button::new("community_repo", "Community Repo")
.color(Color::Muted) .style(ButtonStyle::Transparent)
.on_click(open_community_repo) .icon(Icon::ExternalLink)
.icon_position(IconPosition::End)
.icon_size(IconSize::Small)
.on_click(open_community_repo),
) )
.child(h_stack().justify_between().gap_1() .child(
h_stack()
.gap_1()
.child( .child(
Button::new("cancel_feedback", "Cancel") Button::new("cancel_feedback", "Cancel")
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
@ -357,30 +372,33 @@ impl Render for FeedbackModal {
} else { } else {
this.on_click(dismiss) this.on_click(dismiss)
} }
}) }),
) )
.child( .child(
Button::new("send_feedback", submit_button_text) Button::new("send_feedback", submit_button_text)
.color(Color::Accent) .color(Color::Accent)
.style(ButtonStyle::Filled) .style(ButtonStyle::Filled)
// TODO: Ensure that while submitting, "Sending..." is shown and disable the button // TODO: Ensure that while submitting, "Sending..." is shown and disable the button
// TODO: If submit errors: show popup with error, don't close modal, set text back to "Send Feedback", and re-enable button // TODO: If submit errors: show popup with error, don't close modal, set text back to "Submit", and re-enable button
// TODO: If submit is successful, close the modal // TODO: If submit is successful, close the modal
.on_click(cx.listener(|this, _, cx| { .on_click(cx.listener(|this, _, cx| {
let _ = this.submit(cx); let _ = this.submit(cx);
})) }))
.tooltip(|cx| { .tooltip(move |cx| {
Tooltip::with_meta( Tooltip::with_meta(
"Submit feedback to the Zed team.", "Submit feedback to the Zed team.",
None, None,
"Provide an email address if you want us to be able to reply.", provide_an_email_address,
cx, cx,
) )
}) })
.when(!allow_submission, |this| this.disabled(true)) .when(!allow_submission, |this| this.disabled(true)),
),
),
), ),
) )
}
}
) // TODO: Add compilation flags to enable debug mode, where we can simulate sending feedback that both succeeds and fails, so we can test the UI
} // TODO: Maybe store email address whenever the modal is closed, versus just on submit, so users can remove it if they want without submitting
}

View file

@ -245,6 +245,13 @@ pub trait Styled: Sized {
self self
} }
/// Sets the flex direction of the element to `column-reverse`.
/// [Docs](https://tailwindcss.com/docs/flex-direction#column-reverse)
fn flex_col_reverse(mut self) -> Self {
self.style().flex_direction = Some(FlexDirection::ColumnReverse);
self
}
/// Sets the flex direction of the element to `row`. /// Sets the flex direction of the element to `row`.
/// [Docs](https://tailwindcss.com/docs/flex-direction#row) /// [Docs](https://tailwindcss.com/docs/flex-direction#row)
fn flex_row(mut self) -> Self { fn flex_row(mut self) -> Self {
@ -252,6 +259,13 @@ pub trait Styled: Sized {
self self
} }
/// Sets the flex direction of the element to `row-reverse`.
/// [Docs](https://tailwindcss.com/docs/flex-direction#row-reverse)
fn flex_row_reverse(mut self) -> Self {
self.style().flex_direction = Some(FlexDirection::RowReverse);
self
}
/// Sets the element to allow a flex item to grow and shrink as needed, ignoring its initial size. /// Sets the element to allow a flex item to grow and shrink as needed, ignoring its initial size.
/// [Docs](https://tailwindcss.com/docs/flex#flex-1) /// [Docs](https://tailwindcss.com/docs/flex#flex-1)
fn flex_1(mut self) -> Self { fn flex_1(mut self) -> Self {

View file

@ -1,6 +1,6 @@
use gpui::{AnyView, DefiniteLength}; use gpui::{AnyView, DefiniteLength};
use crate::prelude::*; use crate::{prelude::*, IconPosition};
use crate::{ use crate::{
ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconSize, Label, LineHeightStyle, ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconSize, Label, LineHeightStyle,
}; };
@ -14,6 +14,7 @@ pub struct Button {
label_color: Option<Color>, label_color: Option<Color>,
selected_label: Option<SharedString>, selected_label: Option<SharedString>,
icon: Option<Icon>, icon: Option<Icon>,
icon_position: Option<IconPosition>,
icon_size: Option<IconSize>, icon_size: Option<IconSize>,
icon_color: Option<Color>, icon_color: Option<Color>,
selected_icon: Option<Icon>, selected_icon: Option<Icon>,
@ -27,6 +28,7 @@ impl Button {
label_color: None, label_color: None,
selected_label: None, selected_label: None,
icon: None, icon: None,
icon_position: None,
icon_size: None, icon_size: None,
icon_color: None, icon_color: None,
selected_icon: None, selected_icon: None,
@ -48,6 +50,11 @@ impl Button {
self self
} }
pub fn icon_position(mut self, icon_position: impl Into<Option<IconPosition>>) -> Self {
self.icon_position = icon_position.into();
self
}
pub fn icon_size(mut self, icon_size: impl Into<Option<IconSize>>) -> Self { pub fn icon_size(mut self, icon_size: impl Into<Option<IconSize>>) -> Self {
self.icon_size = icon_size.into(); self.icon_size = icon_size.into();
self self
@ -141,7 +148,21 @@ impl RenderOnce for Button {
self.label_color.unwrap_or_default() self.label_color.unwrap_or_default()
}; };
self.base self.base.child(
h_stack()
.gap_1()
.map(|this| {
if self.icon_position == Some(IconPosition::End) {
this.flex_row_reverse()
} else {
this
}
})
.child(
Label::new(label)
.color(label_color)
.line_height_style(LineHeightStyle::UILabel),
)
.children(self.icon.map(|icon| { .children(self.icon.map(|icon| {
ButtonIcon::new(icon) ButtonIcon::new(icon)
.disabled(is_disabled) .disabled(is_disabled)
@ -149,11 +170,7 @@ impl RenderOnce for Button {
.selected_icon(self.selected_icon) .selected_icon(self.selected_icon)
.size(self.icon_size) .size(self.icon_size)
.color(self.icon_color) .color(self.icon_color)
})) })),
.child(
Label::new(label)
.color(label_color)
.line_height_style(LineHeightStyle::UILabel),
) )
} }
} }

View file

@ -30,6 +30,13 @@ pub trait ButtonCommon: Clickable + Disableable {
fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self; fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self;
} }
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum IconPosition {
#[default]
Start,
End,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum ButtonStyle { pub enum ButtonStyle {
/// A filled button with a solid background color. Provides emphasis versus /// A filled button with a solid background color. Provides emphasis versus
@ -347,6 +354,7 @@ impl RenderOnce for ButtonLike {
ButtonSize::None => this, ButtonSize::None => this,
}) })
.bg(self.style.enabled(cx).background) .bg(self.style.enabled(cx).background)
.when(self.disabled, |this| this.cursor_not_allowed())
.when(!self.disabled, |this| { .when(!self.disabled, |this| {
this.cursor_pointer() this.cursor_pointer()
.hover(|hover| hover.bg(self.style.hovered(cx).background)) .hover(|hover| hover.bg(self.style.hovered(cx).background))

View file

@ -51,6 +51,7 @@ pub enum Icon {
CopilotDisabled, CopilotDisabled,
Dash, Dash,
Envelope, Envelope,
ExternalLink,
ExclamationTriangle, ExclamationTriangle,
Exit, Exit,
File, File,
@ -123,13 +124,13 @@ impl Icon {
Icon::Close => "icons/x.svg", Icon::Close => "icons/x.svg",
Icon::Collab => "icons/user_group_16.svg", Icon::Collab => "icons/user_group_16.svg",
Icon::Copilot => "icons/copilot.svg", Icon::Copilot => "icons/copilot.svg",
Icon::CopilotInit => "icons/copilot_init.svg", Icon::CopilotInit => "icons/copilot_init.svg",
Icon::CopilotError => "icons/copilot_error.svg", Icon::CopilotError => "icons/copilot_error.svg",
Icon::CopilotDisabled => "icons/copilot_disabled.svg", Icon::CopilotDisabled => "icons/copilot_disabled.svg",
Icon::Dash => "icons/dash.svg", Icon::Dash => "icons/dash.svg",
Icon::Envelope => "icons/feedback.svg", Icon::Envelope => "icons/feedback.svg",
Icon::ExclamationTriangle => "icons/warning.svg", Icon::ExclamationTriangle => "icons/warning.svg",
Icon::ExternalLink => "icons/external_link.svg",
Icon::Exit => "icons/exit.svg", Icon::Exit => "icons/exit.svg",
Icon::File => "icons/file.svg", Icon::File => "icons/file.svg",
Icon::FileDoc => "icons/file_icons/book.svg", Icon::FileDoc => "icons/file_icons/book.svg",

View file

@ -12,6 +12,6 @@ pub use crate::selectable::*;
pub use crate::{h_stack, v_stack}; pub use crate::{h_stack, v_stack};
pub use crate::{Button, ButtonSize, ButtonStyle, IconButton}; pub use crate::{Button, ButtonSize, ButtonStyle, IconButton};
pub use crate::{ButtonCommon, Color, StyledExt}; pub use crate::{ButtonCommon, Color, StyledExt};
pub use crate::{Icon, IconElement, IconSize}; pub use crate::{Icon, IconElement, IconPosition, IconSize};
pub use crate::{Label, LabelCommon, LabelSize, LineHeightStyle}; pub use crate::{Label, LabelCommon, LabelSize, LineHeightStyle};
pub use theme::ActiveTheme; pub use theme::ActiveTheme;

View file

@ -5,8 +5,8 @@ use gpui::{
div, AnyView, Div, IntoElement, ParentElement, Render, Styled, Subscription, View, ViewContext, div, AnyView, Div, IntoElement, ParentElement, Render, Styled, Subscription, View, ViewContext,
WindowContext, WindowContext,
}; };
use ui::h_stack;
use ui::prelude::*; use ui::prelude::*;
use ui::{h_stack, Icon, IconButton};
use util::ResultExt; use util::ResultExt;
pub trait StatusItemView: Render { pub trait StatusItemView: Render {
@ -48,30 +48,7 @@ impl Render for StatusBar {
.h_8() .h_8()
.bg(cx.theme().colors().status_bar_background) .bg(cx.theme().colors().status_bar_background)
.child(h_stack().gap_1().child(self.render_left_tools(cx))) .child(h_stack().gap_1().child(self.render_left_tools(cx)))
.child( .child(h_stack().gap_4().child(self.render_right_tools(cx)))
h_stack()
.gap_4()
.child(
h_stack().gap_1().child(
// Feedback Tool
div()
.border()
.border_color(gpui::red())
.child(IconButton::new("status-feedback", Icon::Envelope)),
),
)
.child(
// Right Dock
h_stack().gap_1().child(
// Terminal
div()
.border()
.border_color(gpui::red())
.child(IconButton::new("status-chat", Icon::MessageBubbles)),
),
)
.child(self.render_right_tools(cx)),
)
} }
} }