Skip to content

data explorer: update comms with convert to code messages #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 50 additions & 0 deletions crates/amalthea/src/comm/data_explorer_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ pub struct ExportedData {
pub format: ExportFormat
}

/// Code snippet for the data view
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct ExportedCode {
/// Exported code as a string suitable for copy and paste
pub code: String
}

/// Code syntaxes available for export
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct CodeSyntaxOptions {
/// Available code syntaxes supported for export
pub code_syntaxes: Vec<String>
}

/// The result of applying filters to a table
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct FilterResult {
Expand Down Expand Up @@ -1073,6 +1087,22 @@ pub struct ExportDataSelectionParams {
pub format: ExportFormat,
}

/// Parameters for the TranslateToCode method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct TranslateToCodeParams {
/// Zero or more column filters to apply
pub column_filters: Vec<ColumnFilter>,

/// Zero or more row filters to apply
pub row_filters: Vec<RowFilter>,

/// Zero or more sort keys to apply
pub sort_keys: Vec<ColumnSortKey>,

/// The code syntax to use for translation
pub code_syntax: String,
}

/// Parameters for the SetColumnFilters method.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct SetColumnFiltersParams {
Expand Down Expand Up @@ -1164,6 +1194,20 @@ pub enum DataExplorerBackendRequest {
#[serde(rename = "export_data_selection")]
ExportDataSelection(ExportDataSelectionParams),

/// Translates the current data view into a code snippet.
///
/// Translate filters and sort keys as code in different syntaxes like
/// pandas, polars, data.table, dplyr
#[serde(rename = "translate_to_code")]
TranslateToCode(TranslateToCodeParams),

/// Get code syntaxes supported for code translation
///
/// Get all available code syntaxes supported for translation for a data
/// view
#[serde(rename = "get_code_syntaxes")]
GetCodeSyntaxes,

/// Set column filters to select subset of table columns
///
/// Set or clear column filters on table, replacing any previous filters
Expand Down Expand Up @@ -1220,6 +1264,12 @@ pub enum DataExplorerBackendReply {
/// Exported result
ExportDataSelectionReply(ExportedData),

/// Code snippet for the data view
TranslateToCodeReply(ExportedCode),

/// Code syntaxes available for export
GetCodeSyntaxesReply(CodeSyntaxOptions),

/// Reply for the set_column_filters method (no result)
SetColumnFiltersReply(),

Expand Down
1 change: 1 addition & 0 deletions crates/ark/src/data_explorer/r_data_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ impl RDataExplorer {
format,
},
)),
DataExplorerBackendRequest::TranslateToCode(_) | DataExplorerBackendRequest::GetCodeSyntaxes => todo!(),
}
}
}
Expand Down
Loading