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
42 changes: 42 additions & 0 deletions crates/edit_prediction/src/zed_edit_prediction_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use edit_prediction_types::{
DataCollectionState, EditPredictionDelegate, EditPredictionDiscardReason,
EditPredictionIconSet, SuggestionDisplayType,
};
use feature_flags::FeatureFlagAppExt;
use gpui::{App, Entity, prelude::*};
use language::{Buffer, ToPoint as _};
use project::Project;
Expand Down Expand Up @@ -73,6 +74,24 @@ impl EditPredictionDelegate for ZedEditPredictionDelegate {
self.store
.read(cx)
.is_file_open_source(&self.project, file, cx);

if let Some(organization_configuration) = self
.store
.read(cx)
.user_store
.read(cx)
.current_organization_configuration()
{
if !organization_configuration
.edit_prediction
.is_feedback_enabled
{
return DataCollectionState::Disabled {
is_project_open_source,
};
}
}

if self.store.read(cx).data_collection_choice.is_enabled(cx) {
DataCollectionState::Enabled {
is_project_open_source,
Expand All @@ -89,6 +108,29 @@ impl EditPredictionDelegate for ZedEditPredictionDelegate {
}
}

fn can_toggle_data_collection(&self, cx: &App) -> bool {
if cx.is_staff() {
return false;
}

if let Some(organization_configuration) = self
.store
.read(cx)
.user_store
.read(cx)
.current_organization_configuration()
{
if !organization_configuration
.edit_prediction
.is_feedback_enabled
{
return false;
}
}

true
}

fn toggle_data_collection(&mut self, cx: &mut App) {
self.store.update(cx, |store, cx| {
store.toggle_data_collection_choice(cx);
Expand Down
9 changes: 9 additions & 0 deletions crates/edit_prediction_types/src/edit_prediction_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ pub trait EditPredictionDelegate: 'static + Sized {
None
}

fn can_toggle_data_collection(&self, _cx: &App) -> bool {
true
}

fn toggle_data_collection(&mut self, _cx: &mut App) {}
fn is_enabled(
&self,
Expand Down Expand Up @@ -209,6 +213,7 @@ pub trait EditPredictionDelegateHandle {
fn icons(&self, cx: &App) -> EditPredictionIconSet;
fn data_collection_state(&self, cx: &App) -> DataCollectionState;
fn usage(&self, cx: &App) -> Option<EditPredictionUsage>;
fn can_toggle_data_collection(&self, cx: &App) -> bool;
fn toggle_data_collection(&self, cx: &mut App);
fn is_refreshing(&self, cx: &App) -> bool;
fn refresh(
Expand Down Expand Up @@ -265,6 +270,10 @@ where
self.read(cx).usage(cx)
}

fn can_toggle_data_collection(&self, cx: &App) -> bool {
self.read(cx).can_toggle_data_collection(cx)
}

fn toggle_data_collection(&self, cx: &mut App) {
self.update(cx, |this, cx| this.toggle_data_collection(cx))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/edit_prediction_ui/src/edit_prediction_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl EditPredictionButton {
.toggleable(IconPosition::Start, data_collection.is_enabled())
.icon(icon_name)
.icon_color(icon_color)
.disabled(cx.is_staff())
.disabled(!provider.can_toggle_data_collection(cx))
.documentation_aside(DocumentationSide::Left, move |cx| {
let (msg, label_color, icon_name, icon_color) = match (is_open_source, is_collecting) {
(true, true) => (
Expand Down
Loading