Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions crates/agent_ui/src/ui/end_trial_upsell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ impl Component for EndTrialUpsell {
"End of Trial Upsell Banner"
}

fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
Some(
v_flex()
.child(EndTrialUpsell {
dismiss_upsell: Arc::new(|_, _| {}),
})
.into_any_element(),
)
fn description() -> &'static str {
"A banner shown in the agent panel when a user's trial has ended, \
inviting them to upgrade to a paid plan to continue using the agent."
}

fn preview(_window: &mut Window, _cx: &mut App) -> AnyElement {
v_flex()
.child(EndTrialUpsell {
dismiss_upsell: Arc::new(|_, _| {}),
})
.into_any_element()
}
}
78 changes: 41 additions & 37 deletions crates/ai_onboarding/src/ai_onboarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,13 @@ impl Component for ZedAiOnboarding {
"Agent New User Onboarding"
}

fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
fn description() -> &'static str {
"The onboarding surface shown to new agent panel users, \
guiding them through signing in to Zed and selecting a plan \
before they can start using the agent."
}

fn preview(_window: &mut Window, _cx: &mut App) -> AnyElement {
fn onboarding(
sign_in_status: SignInStatus,
plan: Option<Plan>,
Expand All @@ -402,41 +408,39 @@ impl Component for ZedAiOnboarding {
.into_any_element()
}

Some(
v_flex()
.min_w_0()
.gap_4()
.children(vec![
single_example(
"Not Signed-in",
onboarding(SignInStatus::SignedOut, None, false),
),
single_example(
"Young Account",
onboarding(SignInStatus::SignedIn, None, true),
),
single_example(
"Free Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedFree), false),
),
single_example(
"Pro Trial",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedProTrial), false),
),
single_example(
"Pro Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedPro), false),
),
single_example(
"Business Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedBusiness), false),
),
single_example(
"Student Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedStudent), false),
),
])
.into_any_element(),
)
v_flex()
.min_w_0()
.gap_4()
.children(vec![
single_example(
"Not Signed-in",
onboarding(SignInStatus::SignedOut, None, false),
),
single_example(
"Young Account",
onboarding(SignInStatus::SignedIn, None, true),
),
single_example(
"Free Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedFree), false),
),
single_example(
"Pro Trial",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedProTrial), false),
),
single_example(
"Pro Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedPro), false),
),
single_example(
"Business Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedBusiness), false),
),
single_example(
"Student Plan",
onboarding(SignInStatus::SignedIn, Some(Plan::ZedStudent), false),
),
])
.into_any_element()
}
}
42 changes: 19 additions & 23 deletions crates/component/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ pub fn register_component<T: Component>() {
let id = T::id();
let metadata = ComponentMetadata {
id: id.clone(),
description: T::description().map(Into::into),
description: SharedString::new_static(T::description()),
name: SharedString::new_static(T::name()),
preview: Some(T::preview),
preview: T::preview,
scope: T::scope(),
sort_name: SharedString::new_static(T::sort_name()),
status: T::status(),
Expand All @@ -69,15 +69,12 @@ pub struct ComponentRegistry {
}

impl ComponentRegistry {
pub fn previews(&self) -> Vec<&ComponentMetadata> {
self.components
.values()
.filter(|c| c.preview.is_some())
.collect()
pub fn previews(&self) -> impl Iterator<Item = &ComponentMetadata> {
self.components.values()
}

pub fn sorted_previews(&self) -> Vec<ComponentMetadata> {
let mut previews: Vec<ComponentMetadata> = self.previews().into_iter().cloned().collect();
let mut previews: Vec<_> = self.previews().cloned().collect();
previews.sort_by_key(|a| a.name());
previews
}
Expand Down Expand Up @@ -112,9 +109,9 @@ pub struct ComponentId(pub &'static str);
#[derive(Clone)]
pub struct ComponentMetadata {
id: ComponentId,
description: Option<SharedString>,
description: SharedString,
name: SharedString,
preview: Option<fn(&mut Window, &mut App) -> Option<AnyElement>>,
preview: fn(&mut Window, &mut App) -> AnyElement,
scope: ComponentScope,
sort_name: SharedString,
status: ComponentStatus,
Expand All @@ -125,15 +122,15 @@ impl ComponentMetadata {
self.id.clone()
}

pub fn description(&self) -> Option<SharedString> {
pub fn description(&self) -> SharedString {
self.description.clone()
}

pub fn name(&self) -> SharedString {
self.name.clone()
}

pub fn preview(&self) -> Option<fn(&mut Window, &mut App) -> Option<AnyElement>> {
pub fn preview(&self) -> fn(&mut Window, &mut App) -> AnyElement {
self.preview
}

Expand Down Expand Up @@ -234,17 +231,15 @@ pub trait Component {
/// struct MyComponent;
///
/// impl MyComponent {
/// fn description() -> Option<&'static str> {
/// Some(Self::DOCS)
/// fn description() -> &'static str {
/// Self::DOCS
/// }
/// }
/// ```
///
/// This will result in "This is a doc comment." being passed
/// to the component's description.
fn description() -> Option<&'static str> {
None
}
fn description() -> &'static str;
/// The component's preview.
///
/// An element returned here will be shown in the component's preview.
Expand All @@ -259,9 +254,7 @@ pub trait Component {
/// This is useful for displaying related UI to the component you are
/// trying to preview, such as a button that opens a modal or shows a
/// tooltip on hover, or a grid of icons showcasing all the icons available.
fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
None
}
fn preview(_window: &mut Window, _cx: &mut App) -> AnyElement;
}

/// The ready status of this component.
Expand All @@ -286,14 +279,17 @@ impl ComponentStatus {
pub fn description(&self) -> &str {
match self {
ComponentStatus::WorkInProgress => {
"These components are still being designed or refined. They shouldn't be used in the app yet."
"These components are still being designed or refined. \
They shouldn't be used in the app yet."
}
ComponentStatus::EngineeringReady => {
"These components are design complete or partially implemented, and are ready for an engineer to complete their implementation."
"These components are design complete or partially implemented, \
and are ready for an engineer to complete their implementation."
}
ComponentStatus::Live => "These components are ready for use in the app.",
ComponentStatus::Deprecated => {
"These components are no longer recommended for use in the app, and may be removed in a future release."
"These components are no longer recommended for use in the app, \
and may be removed in a future release."
}
}
}
Expand Down
Loading
Loading