first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use enclose::enclose;
|
||||
use itertools::Itertools as _;
|
||||
use markdown_parser::{FormattedText, FormattedTextFragment, FormattedTextLine};
|
||||
use pathfinder_color::ColorU;
|
||||
use pathfinder_geometry::vector::vec2f;
|
||||
use galaxy_core::ui::appearance::Appearance;
|
||||
use galaxy_core::ui::Icon;
|
||||
use galaxy_graphql::billing::AddonCreditsOption;
|
||||
use galaxy_graphql::error::BudgetExceededError;
|
||||
use galaxyui::elements::{
|
||||
Align, Border, ChildAnchor, ChildView, ConstrainedBox, Container, CornerRadius,
|
||||
CrossAxisAlignment, DropShadow, Expanded, Flex, FormattedTextElement, HighlightedHyperlink,
|
||||
@@ -15,10 +20,6 @@ use galaxyui::fonts::Weight;
|
||||
use galaxyui::ui_components::button::ButtonVariant;
|
||||
use galaxyui::ui_components::components::{Coords, UiComponent as _, UiComponentStyles};
|
||||
use galaxyui::{AppContext, Element, Entity, SingletonEntity as _, View, ViewContext, ViewHandle};
|
||||
use itertools::Itertools as _;
|
||||
use markdown_parser::{FormattedText, FormattedTextFragment, FormattedTextLine};
|
||||
use pathfinder_color::ColorU;
|
||||
use pathfinder_geometry::vector::vec2f;
|
||||
|
||||
use crate::ai::request_usage_model::{
|
||||
AIRequestUsageModel, AIRequestUsageModelEvent, BuyCreditsBannerDisplayState,
|
||||
@@ -31,9 +32,8 @@ use crate::send_telemetry_from_ctx;
|
||||
use crate::server::ids::ServerId;
|
||||
use crate::server::telemetry::{OutOfCreditsBannerAction, TelemetryEvent};
|
||||
use crate::settings_view::create_discount_badge;
|
||||
use crate::view_components::Dropdown;
|
||||
use crate::view_components::{Dropdown, DropdownAction};
|
||||
use crate::workspaces::user_workspaces::{UserWorkspaces, UserWorkspacesEvent};
|
||||
use galaxy_graphql::error::BudgetExceededError;
|
||||
|
||||
#[derive(Default)]
|
||||
struct MouseStates {
|
||||
@@ -137,6 +137,15 @@ impl BuyCreditsBanner {
|
||||
.addon_credits_options
|
||||
.get(self.selected_denomination_index)
|
||||
.map(|option| option.credits);
|
||||
let has_admin_permissions = {
|
||||
let auth_state = AuthStateProvider::as_ref(ctx).get();
|
||||
let current_team = UserWorkspaces::as_ref(ctx).current_team();
|
||||
auth_state
|
||||
.user_email()
|
||||
.zip(current_team)
|
||||
.map(|(email, team)| team.has_admin_permissions(&email))
|
||||
.unwrap_or_default()
|
||||
};
|
||||
|
||||
// Things we always do:
|
||||
// - emit telemetry
|
||||
@@ -161,7 +170,7 @@ impl BuyCreditsBanner {
|
||||
// - Banner toggle flow: optionally enable auto-reload immediately.
|
||||
// - Post-purchase modal flow: show the modal.
|
||||
if banner_toggle_flag_enabled {
|
||||
if self.auto_reload_enabled {
|
||||
if has_admin_permissions && self.auto_reload_enabled {
|
||||
self.banner_auto_reload_update_in_flight = true;
|
||||
|
||||
if let Some(team_uid) = UserWorkspaces::as_ref(ctx).current_team_uid() {
|
||||
@@ -176,7 +185,7 @@ impl BuyCreditsBanner {
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if post_purchase_modal_flag_enabled {
|
||||
} else if has_admin_permissions && post_purchase_modal_flag_enabled {
|
||||
// Default selection in the modal should match the denomination the user clicked "buy" on.
|
||||
ctx.emit(BuyCreditsBannerEvent::OpenAutoReloadModal {
|
||||
purchased_credits: selected_credits.unwrap_or(0),
|
||||
@@ -359,11 +368,15 @@ impl BuyCreditsBanner {
|
||||
})),
|
||||
Some(primary_text)
|
||||
)
|
||||
.with_on_select_action(Action::SelectDenomination(index).into())
|
||||
.with_on_select_action(DropdownAction::select_action_and_close(
|
||||
Action::SelectDenomination(index),
|
||||
))
|
||||
.into_item()
|
||||
} else {
|
||||
MenuItemFields::new(primary_text.clone())
|
||||
.with_on_select_action(Action::SelectDenomination(index).into())
|
||||
.with_on_select_action(DropdownAction::select_action_and_close(
|
||||
Action::SelectDenomination(index),
|
||||
))
|
||||
.into_item()
|
||||
}
|
||||
})
|
||||
@@ -830,7 +843,7 @@ impl View for BuyCreditsBanner {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Action {
|
||||
SelectDenomination(usize),
|
||||
Close,
|
||||
|
||||
Reference in New Issue
Block a user