Skip to content

Commit fa6c7ab

Browse files
authored
data explorer: update comms with convert to code messages (#873)
* update comms with copy to code messages * add todo for new comms * sync with other comms * add convert to code features * add placeholder replies for testing * update names from review
1 parent a29d626 commit fa6c7ab

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

crates/amalthea/src/comm/data_explorer_comm.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ pub struct ExportedData {
3838
pub format: ExportFormat
3939
}
4040

41+
/// Code snippet for the data view
42+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
43+
pub struct ConvertedCode {
44+
/// Lines of code that implement filters and sort keys
45+
pub converted_code: Vec<String>
46+
}
47+
48+
/// Syntax to use for code conversion
49+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
50+
pub struct CodeSyntaxName {
51+
/// The name of the code syntax, eg, pandas, polars, dplyr, etc.
52+
pub code_syntax_name: String
53+
}
54+
4155
/// The result of applying filters to a table
4256
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
4357
pub struct FilterResult {
@@ -537,7 +551,10 @@ pub struct SupportedFeatures {
537551
pub set_sort_columns: SetSortColumnsFeatures,
538552

539553
/// Support for 'export_data_selection' RPC and its features
540-
pub export_data_selection: ExportDataSelectionFeatures
554+
pub export_data_selection: ExportDataSelectionFeatures,
555+
556+
/// Support for 'convert_to_code' RPC and its features
557+
pub convert_to_code: ConvertToCodeFeatures
541558
}
542559

543560
/// Feature flags for 'search_schema' RPC
@@ -600,6 +617,16 @@ pub struct SetSortColumnsFeatures {
600617
pub support_status: SupportStatus
601618
}
602619

620+
/// Feature flags for convert to code RPC
621+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
622+
pub struct ConvertToCodeFeatures {
623+
/// The support status for this RPC method
624+
pub support_status: SupportStatus,
625+
626+
/// The syntaxes for converted code
627+
pub code_syntaxes: Option<Vec<CodeSyntaxName>>
628+
}
629+
603630
/// A selection on the data grid, for copying to the clipboard or other
604631
/// actions
605632
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
@@ -1073,6 +1100,22 @@ pub struct ExportDataSelectionParams {
10731100
pub format: ExportFormat,
10741101
}
10751102

1103+
/// Parameters for the ConvertToCode method.
1104+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
1105+
pub struct ConvertToCodeParams {
1106+
/// Zero or more column filters to apply
1107+
pub column_filters: Vec<ColumnFilter>,
1108+
1109+
/// Zero or more row filters to apply
1110+
pub row_filters: Vec<RowFilter>,
1111+
1112+
/// Zero or more sort keys to apply
1113+
pub sort_keys: Vec<ColumnSortKey>,
1114+
1115+
/// The code syntax to use for conversion
1116+
pub code_syntax_name: CodeSyntaxName,
1117+
}
1118+
10761119
/// Parameters for the SetColumnFilters method.
10771120
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
10781121
pub struct SetColumnFiltersParams {
@@ -1164,6 +1207,20 @@ pub enum DataExplorerBackendRequest {
11641207
#[serde(rename = "export_data_selection")]
11651208
ExportDataSelection(ExportDataSelectionParams),
11661209

1210+
/// Converts the current data view into a code snippet.
1211+
///
1212+
/// Converts filters and sort keys as code in different syntaxes like
1213+
/// pandas, polars, data.table, dplyr
1214+
#[serde(rename = "convert_to_code")]
1215+
ConvertToCode(ConvertToCodeParams),
1216+
1217+
/// Suggest code syntax for code conversion
1218+
///
1219+
/// Suggest code syntax for code conversion based on the current backend
1220+
/// state
1221+
#[serde(rename = "suggest_code_syntax")]
1222+
SuggestCodeSyntax,
1223+
11671224
/// Set column filters to select subset of table columns
11681225
///
11691226
/// Set or clear column filters on table, replacing any previous filters
@@ -1220,6 +1277,12 @@ pub enum DataExplorerBackendReply {
12201277
/// Exported result
12211278
ExportDataSelectionReply(ExportedData),
12221279

1280+
/// Code snippet for the data view
1281+
ConvertToCodeReply(ConvertedCode),
1282+
1283+
/// Syntax to use for code conversion
1284+
SuggestCodeSyntaxReply(CodeSyntaxName),
1285+
12231286
/// Reply for the set_column_filters method (no result)
12241287
SetColumnFiltersReply(),
12251288

crates/ark/src/data_explorer/r_data_explorer.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::collections::HashMap;
1111
use amalthea::comm::comm_channel::CommMsg;
1212
use amalthea::comm::data_explorer_comm::ArraySelection;
1313
use amalthea::comm::data_explorer_comm::BackendState;
14+
use amalthea::comm::data_explorer_comm::CodeSyntaxName;
1415
use amalthea::comm::data_explorer_comm::ColumnDisplayType;
1516
use amalthea::comm::data_explorer_comm::ColumnFilter;
1617
use amalthea::comm::data_explorer_comm::ColumnProfileType;
@@ -19,6 +20,8 @@ use amalthea::comm::data_explorer_comm::ColumnSchema;
1920
use amalthea::comm::data_explorer_comm::ColumnSelection;
2021
use amalthea::comm::data_explorer_comm::ColumnSortKey;
2122
use amalthea::comm::data_explorer_comm::ColumnValue;
23+
use amalthea::comm::data_explorer_comm::ConvertToCodeFeatures;
24+
use amalthea::comm::data_explorer_comm::ConvertedCode;
2225
use amalthea::comm::data_explorer_comm::DataExplorerBackendReply;
2326
use amalthea::comm::data_explorer_comm::DataExplorerBackendRequest;
2427
use amalthea::comm::data_explorer_comm::DataExplorerFrontendEvent;
@@ -556,6 +559,16 @@ impl RDataExplorer {
556559
format,
557560
},
558561
)),
562+
DataExplorerBackendRequest::ConvertToCode(_) => Ok(
563+
DataExplorerBackendReply::ConvertToCodeReply(ConvertedCode {
564+
converted_code: vec!["not yet implemented".to_string()],
565+
}),
566+
),
567+
DataExplorerBackendRequest::SuggestCodeSyntax => Ok(
568+
DataExplorerBackendReply::SuggestCodeSyntaxReply(CodeSyntaxName {
569+
code_syntax_name: "base".into(),
570+
}),
571+
),
559572
}
560573
}
561574
}
@@ -981,6 +994,20 @@ impl RDataExplorer {
981994
ExportFormat::Html,
982995
],
983996
},
997+
convert_to_code: ConvertToCodeFeatures {
998+
support_status: SupportStatus::Supported,
999+
code_syntaxes: Some(vec![
1000+
CodeSyntaxName {
1001+
code_syntax_name: "base".into(),
1002+
},
1003+
CodeSyntaxName {
1004+
code_syntax_name: "data.table".into(),
1005+
},
1006+
CodeSyntaxName {
1007+
code_syntax_name: "dplyr".into(),
1008+
},
1009+
]),
1010+
},
9841011
},
9851012
};
9861013
Ok(DataExplorerBackendReply::GetStateReply(state))

0 commit comments

Comments
 (0)