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
106 changes: 59 additions & 47 deletions crates/desktop/src/app/chrome/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ impl ProbeApp {
}

let add_view = cx.weak_entity();
let add_disabled = busy || dirty;
let import_view = cx.weak_entity();
let import_disabled = self.postman_environment_import_disabled();
let create_disabled =
busy || dirty || self.loaded_workspace.is_none() || self.has_active_workspace_write();
let add_disabled = create_disabled && import_disabled;
let add_label = if dirty {
"Add environment. Save or discard unsaved changes first."
} else {
Expand Down Expand Up @@ -139,56 +143,64 @@ impl ProbeApp {
.child("ENVIRONMENTS"),
)
.child(
components::icon_button(
theme,
"environment-manager-add",
add_label,
components::plus_icon(theme).text_color(if add_disabled {
theme.colors.actions.disabled_foreground
} else {
theme.colors.text.secondary
Popover::new("environment-manager-add-menu")
.trigger(
components::icon_button(
theme,
"environment-manager-add",
add_label,
components::plus_icon(theme).text_color(if add_disabled {
theme.colors.actions.disabled_foreground
} else {
theme.colors.text.secondary
}),
|_, _, _| {},
)
.flex_none()
.disabled(add_disabled),
)
.content(move |_, _, cx| {
let create_menu = cx.weak_entity();
let import_menu = cx.weak_entity();
components::popup_surface(
theme,
"environment-manager-add-popup",
220.0,
)
.child(components::menu_button_with_enabled(
theme,
"environment-manager-create",
"Create environment…",
None,
!create_disabled,
move |window, cx| {
let _ = create_menu
.update(cx, |menu, cx| menu.dismiss(window, cx));
let _ = add_view.update(cx, |view, cx| {
view.open_create_environment_dialog(window, cx);
});
},
))
.child(
components::menu_button_with_enabled(
theme,
"environment-manager-import-postman",
"Import from Postman…",
None,
!import_disabled,
move |window, cx| {
let _ = import_menu
.update(cx, |menu, cx| menu.dismiss(window, cx));
let _ = import_view.update(cx, |view, cx| {
view.choose_postman_environment(window, cx);
});
},
),
)
}),
move |_, window, cx| {
let _ = add_view.update(cx, |view, cx| {
view.open_create_environment_dialog(window, cx);
});
},
)
.flex_none()
.disabled(add_disabled),
),
)
.child(environment_list)
.child(Self::render_postman_environment_import(
theme,
self.postman_environment_import_disabled(),
cx,
))
}

pub(super) fn render_postman_environment_import(
theme: Theme,
disabled: bool,
cx: &mut Context<Self>,
) -> gpui_kit::Div {
let view = cx.weak_entity();
div()
.mt(px(theme.metrics.spacing_3))
.flex()
.flex_col()
.child(components::dialog_action_button(
theme,
"environment-manager-import-postman",
"Import from Postman...",
components::DialogActionStyle::Secondary,
None,
disabled,
move |_, window, cx| {
let _ = view.update(cx, |view, cx| {
view.choose_postman_environment(window, cx);
});
},
))
}

fn environment_field_focus(
Expand Down
3 changes: 2 additions & 1 deletion crates/desktop/src/app/chrome/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl ProbeApp {
label: "Import",
width: 210.0,
items: vec![
DesktopMenuItem::action("Postman Collection…", ImportPostmanExport),
DesktopMenuItem::action("Yaak Export…", ImportYaakExport),
DesktopMenuItem::action("cURL…", ImportCurl),
],
Expand Down Expand Up @@ -358,7 +359,7 @@ impl ProbeApp {
.child(components::menu_button(
theme,
"workspace-switcher-import-postman",
"Postman Export…",
"Postman Collection…",
None,
move |window, cx| {
let _ = import_postman_view.update(cx, |view, cx| {
Expand Down
2 changes: 1 addition & 1 deletion crates/desktop/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ fn system_menus(pane_layout: PaneLayout) -> [Menu; 5] {
MenuItem::action("New Collection…", NewCollection),
MenuItem::action("Open Collection…", OpenWorkspace),
MenuItem::submenu(Menu::new("Import From…").items([
MenuItem::action("Postman Export…", ImportPostmanExport),
MenuItem::action("Postman Collection…", ImportPostmanExport),
MenuItem::action("Yaak Export…", ImportYaakExport),
MenuItem::action("cURL…", ImportCurl),
])),
Expand Down
10 changes: 5 additions & 5 deletions crates/desktop/src/app/render/request_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ impl ProbeApp {
view.open_create_environment_dialog(window, cx);
});
})
.with_action("Import Postman environment…", move |window, cx| {
let _ = import_environment_view.update(cx, |view, cx| {
view.choose_postman_environment(window, cx);
});
})
.with_action("Manage environments…", move |window, cx| {
let _ = manage_environment_view.update(cx, |view, cx| {
view.open_environment_manager_dialog(window, cx);
});
})
.with_action("Import from Postman…", move |window, cx| {
let _ = import_environment_view.update(cx, |view, cx| {
view.choose_postman_environment(window, cx);
});
}),
),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/desktop/src/app/render/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl ProbeApp {
.child(components::menu_button(
theme,
"sidebar-import-postman",
"Postman Export…",
"Postman Collection…",
None,
move |window, cx| {
let _ = sidebar_import_postman_view.update(cx, |view, cx| {
Expand Down
24 changes: 22 additions & 2 deletions crates/desktop/src/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ fn macos_system_menu_delegates_services_to_the_operating_system() {
MenuItem::Action { name: postman, .. },
MenuItem::Action { name: yaak, .. },
MenuItem::Action { name: curl, .. },
] if postman == "Postman Export…" && yaak == "Yaak Export…"
] if postman == "Postman Collection…" && yaak == "Yaak Export…"
&& curl == "cURL…"
)
)
Expand Down Expand Up @@ -817,14 +817,34 @@ fn view_menu_state_changes_are_persisted(cx: &mut TestAppContext) {

#[gpui_kit::test]
fn desktop_menu_action_opens_the_requested_menu(cx: &mut TestAppContext) {
use super::{DesktopMenuItem, ImportCurl, ImportPostmanExport, ImportYaakExport};
cx.update(Theme::init);
let window = cx.open_window(size(px(900.0), px(640.0)), |window, cx| {
ProbeApp::new(window, cx)
});
cx.run_until_parked();

window
.update(cx, |_, window, cx| {
.update(cx, |view, window, cx| {
let definition = view.desktop_menu_definition(DesktopMenu::File);
let imports = definition
.items
.iter()
.find_map(|item| match item {
DesktopMenuItem::Submenu("Import From…", _, submenu) => Some(&submenu.items),
_ => None,
})
.expect("File should offer Import From");
assert!(matches!(imports.as_slice(), [
DesktopMenuItem::Action(postman, postman_action, _),
DesktopMenuItem::Action(yaak, yaak_action, _),
DesktopMenuItem::Action(curl, curl_action, _),
] if *postman == "Postman Collection…"
&& postman_action.as_any().is::<ImportPostmanExport>()
&& *yaak == "Yaak Export…"
&& yaak_action.as_any().is::<ImportYaakExport>()
&& *curl == "cURL…"
&& curl_action.as_any().is::<ImportCurl>()));
window.dispatch_action(Box::new(OpenFileMenu), cx);
})
.expect("test window should remain open");
Expand Down
91 changes: 87 additions & 4 deletions crates/desktop/src/app/tests/environments/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,95 @@ fn environment_switcher_is_available_without_a_request_and_offers_actions(cx: &m
.expect("environment switcher should render without a selected request");
visual.simulate_click(trigger.center(), Modifiers::default());
visual.run_until_parked();
visual
let create = visual
.debug_bounds("request-environment-action-0")
.expect("environment switcher should include Create environment");
visual
let import = visual
.debug_bounds("request-environment-action-1")
.expect("environment switcher should include Manage environments");
.expect("environment switcher should include Import Postman environment");
let manage = visual
.debug_bounds("request-environment-action-2")
.expect("environment switcher should include Manage environments last");
assert!(create.top() < import.top() && import.top() < manage.top());
visual.simulate_click(manage.center(), Modifiers::default());
visual.run_until_parked();
let add = visual.debug_bounds("environment-manager-add").unwrap();
assert!(
visual
.debug_bounds("environment-manager-import-postman")
.is_none()
);
visual.simulate_click(add.center(), Modifiers::default());
visual.run_until_parked();
let create = visual.debug_bounds("environment-manager-create").unwrap();
let import = visual
.debug_bounds("environment-manager-import-postman")
.unwrap();
assert!(create.top() < import.top());
visual.simulate_click(create.center(), Modifiers::default());
visual.run_until_parked();
workspace.update(&mut visual, |view, _, _| {
assert!(view.create_environment_dialog.is_some());
});
}

#[gpui_kit::test]
fn environment_manager_add_menu_respects_each_actions_availability(cx: &mut TestAppContext) {
let workspace = EnvironmentWorkspace::open(cx);
workspace.open_manager(cx, "development");
workspace.update(cx, |view, _, cx| {
view.pending_environment_saves
.insert(("development".into(), "host".into()));
cx.notify();
});
cx.run_until_parked();
{
let mut visual = workspace.visual(cx);
let add = visual.debug_bounds("environment-manager-add").unwrap();
visual.simulate_click(add.center(), Modifiers::default());
visual.run_until_parked();
let import = visual
.debug_bounds("environment-manager-import-postman")
.expect("unavailable import should remain visible");
visual.simulate_click(import.center(), Modifiers::default());
visual.run_until_parked();
assert!(!visual.did_prompt_for_paths());
let create = visual
.debug_bounds("environment-manager-create")
.expect("disabled import should leave the menu open");
visual.simulate_click(create.center(), Modifiers::default());
visual.run_until_parked();
}
workspace.update(cx, |view, window, cx| {
assert!(view.create_environment_dialog.is_some());
view.close_create_environment_dialog(window, cx);
view.pending_environment_saves.clear();
view.request_save_task = Some(cx.spawn(async |_, _| std::future::pending::<()>().await));
cx.notify();
});
cx.run_until_parked();
{
let mut visual = workspace.visual(cx);
let add = visual.debug_bounds("environment-manager-add").unwrap();
visual.simulate_click(add.center(), Modifiers::default());
visual.run_until_parked();
assert!(
visual.debug_bounds("environment-manager-create").is_none(),
"a workspace write should disable the add menu trigger"
);
}
workspace.update(cx, |view, _, cx| {
view.request_save_task = None;
cx.notify();
});
cx.run_until_parked();
let mut visual = workspace.visual(cx);
let add = visual.debug_bounds("environment-manager-add").unwrap();
visual.simulate_click(add.center(), Modifiers::default());
visual.run_until_parked();
visual
.debug_bounds("environment-manager-create")
.expect("add menu should become available after the write");
}

#[gpui_kit::test]
Expand Down Expand Up @@ -2313,7 +2396,7 @@ fn environment_manager_first_open_shortcut_duplicates_without_activating(cx: &mu
let trigger = visual.debug_bounds("request-environment-trigger").unwrap();
visual.simulate_click(trigger.center(), Modifiers::default());
visual.run_until_parked();
let manage = visual.debug_bounds("request-environment-action-1").unwrap();
let manage = visual.debug_bounds("request-environment-action-2").unwrap();
visual.simulate_click(manage.center(), Modifiers::default());
visual.run_until_parked();
workspace.update(&mut visual, |view, _, _| {
Expand Down
11 changes: 10 additions & 1 deletion crates/desktop/src/app/tests/environments/postman_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ fn choose_source(workspace: &EnvironmentWorkspace, cx: &mut TestAppContext, sour
workspace.store.allow_execution_reads();
{
let mut visual = workspace.visual(cx);
assert!(
visual
.debug_bounds("environment-manager-import-postman")
.is_none()
);
let add = visual.debug_bounds("environment-manager-add").unwrap();
visual.simulate_click(add.center(), Modifiers::default());
visual.run_until_parked();
visual.debug_bounds("environment-manager-create").unwrap();
let action = visual
.debug_bounds("environment-manager-import-postman")
.unwrap();
Expand Down Expand Up @@ -353,7 +362,7 @@ fn postman_environment_import_is_available_for_an_empty_collection(cx: &mut Test
let trigger = visual.debug_bounds("request-environment-trigger").unwrap();
visual.simulate_click(trigger.center(), Modifiers::default());
visual.run_until_parked();
let action = visual.debug_bounds("request-environment-action-2").unwrap();
let action = visual.debug_bounds("request-environment-action-1").unwrap();
visual.simulate_click(action.center(), Modifiers::default());
visual.run_until_parked();
}
Expand Down
13 changes: 12 additions & 1 deletion crates/desktop/src/components/menus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ pub(crate) fn menu_button(
label: impl Into<String>,
shortcut: Option<String>,
on_activate: impl Fn(&mut Window, &mut App) + 'static,
) -> impl IntoElement {
menu_button_with_enabled(theme, id, label, shortcut, true, on_activate)
}

pub(crate) fn menu_button_with_enabled(
theme: Theme,
id: impl Into<ElementId>,
label: impl Into<String>,
shortcut: Option<String>,
enabled: bool,
on_activate: impl Fn(&mut Window, &mut App) + 'static,
) -> impl IntoElement {
menu_button_with_style(
theme,
id,
MenuButtonContent::new(label, shortcut),
true,
enabled,
MenuButtonStyle {
height: theme.metrics.control_height + 4.0,
padding_x: theme.metrics.spacing_2,
Expand Down
4 changes: 2 additions & 2 deletions crates/desktop/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ pub(crate) use icons::{
use menus::{MenuButtonContent, MenuButtonStyle, context_menu_separator, menu_button_with_style};
pub(crate) use menus::{
app_menu_trigger, cascading_menu, checked_menu_button, destructive_menu_button,
import_submenu_menu_button, menu_button, menu_button_with_leading, menu_separator,
pane_layout_toggle, positioned_cascading_menu, shortcut_label_for_action,
import_submenu_menu_button, menu_button, menu_button_with_enabled, menu_button_with_leading,
menu_separator, pane_layout_toggle, positioned_cascading_menu, shortcut_label_for_action,
shortcut_label_for_action_in_context, switch,
};
pub(crate) use splitter::pane_splitter;
Expand Down
Loading