Skip to content

Commit abc3d07

Browse files
committed
Refactor C++ leaves_only to group_rollup_mode
Signed-off-by: Andrew Stein <steinlink@gmail.com>
1 parent bfc12d8 commit abc3d07

21 files changed

Lines changed: 894 additions & 177 deletions

File tree

rust/perspective-client/perspective.proto

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ message ViewToColumnsStringReq {
393393
optional bool id = 2;
394394
optional bool index = 3;
395395
optional bool formatted = 4;
396-
optional bool leaves_only = 5;
397396
}
398397

399398
message ViewToColumnsStringResp {
@@ -405,7 +404,6 @@ message ViewToRowsStringReq {
405404
optional bool id = 2;
406405
optional bool index = 3;
407406
optional bool formatted = 4;
408-
optional bool leaves_only = 5;
409407
}
410408

411409
message ViewToRowsStringResp {
@@ -417,7 +415,6 @@ message ViewToNdjsonStringReq {
417415
optional bool id = 2;
418416
optional bool index = 3;
419417
optional bool formatted = 4;
420-
optional bool leaves_only = 5;
421418
}
422419

423420
message ViewToNdjsonStringResp {
@@ -522,6 +519,7 @@ message ViewConfig {
522519
map<string, AggList> aggregates = 7;
523520
FilterReducer filter_op = 8;
524521
optional uint32 group_by_depth = 9;
522+
optional GroupRollupMode group_rollup_mode = 10;
525523

526524
message AggList {
527525
repeated string aggregations = 1;
@@ -542,6 +540,12 @@ message ViewConfig {
542540
AND = 0;
543541
OR = 1;
544542
}
543+
544+
enum GroupRollupMode {
545+
ROLLUP = 0;
546+
FLAT = 1;
547+
// TOTAL = 2;
548+
}
545549
}
546550

547551
message ColumnsUpdate {

rust/perspective-client/src/rust/config/view_config.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
1212

1313
use std::collections::HashMap;
14+
use std::fmt::Display;
1415

1516
use serde::{Deserialize, Serialize};
1617
use ts_rs::TS;
@@ -22,6 +23,48 @@ use super::sort::*;
2223
use crate::proto;
2324
use crate::proto::columns_update;
2425

26+
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq, TS)]
27+
pub enum GroupRollupMode {
28+
#[default]
29+
#[serde(rename = "rollup")]
30+
Rollup,
31+
32+
#[serde(rename = "flat")]
33+
Flat,
34+
// #[serde(rename = "total")]
35+
// Total,
36+
}
37+
38+
impl Display for GroupRollupMode {
39+
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
40+
write!(fmt, "{}", match self {
41+
Self::Rollup => "Rollup",
42+
Self::Flat => "Flat",
43+
// Self::Total => "Total",
44+
})
45+
}
46+
}
47+
48+
impl From<proto::view_config::GroupRollupMode> for GroupRollupMode {
49+
fn from(value: proto::view_config::GroupRollupMode) -> Self {
50+
match value {
51+
proto::view_config::GroupRollupMode::Rollup => Self::Rollup,
52+
proto::view_config::GroupRollupMode::Flat => Self::Flat,
53+
// proto::view_config::GroupRollupMode::Total => Self::Total,
54+
}
55+
}
56+
}
57+
58+
impl From<GroupRollupMode> for proto::view_config::GroupRollupMode {
59+
fn from(value: GroupRollupMode) -> Self {
60+
match value {
61+
GroupRollupMode::Rollup => proto::view_config::GroupRollupMode::Rollup,
62+
GroupRollupMode::Flat => proto::view_config::GroupRollupMode::Flat,
63+
// GroupRollupMode::Total => proto::view_config::GroupRollupMode::Total,
64+
}
65+
}
66+
}
67+
2568
#[derive(Clone, Debug, Deserialize, Default, PartialEq, Serialize, TS)]
2669
#[serde(deny_unknown_fields)]
2770
pub struct ViewConfig {
@@ -37,6 +80,10 @@ pub struct ViewConfig {
3780
#[serde(default)]
3881
pub filter: Vec<Filter>,
3982

83+
// #[serde(skip_serializing_if = "is_default_value")]
84+
#[serde(default)]
85+
pub group_rollup_mode: GroupRollupMode,
86+
4087
#[serde(skip_serializing_if = "is_default_value")]
4188
#[serde(default)]
4289
pub filter_op: FilterReducer,
@@ -164,6 +211,11 @@ pub struct ViewConfigUpdate {
164211
#[serde(default)]
165212
#[ts(optional)]
166213
pub filter_op: Option<FilterReducer>,
214+
215+
#[serde(skip_serializing_if = "Option::is_none")]
216+
#[serde(default)]
217+
#[ts(optional)]
218+
pub group_rollup_mode: Option<GroupRollupMode>,
167219
}
168220

169221
impl From<ViewConfigUpdate> for proto::ViewConfig {
@@ -202,6 +254,9 @@ impl From<ViewConfigUpdate> for proto::ViewConfig {
202254
.map(|(x, y)| (x, y.into()))
203255
.collect(),
204256
group_by_depth: value.group_by_depth,
257+
group_rollup_mode: value
258+
.group_rollup_mode
259+
.map(|x| proto::view_config::GroupRollupMode::from(x).into()),
205260
}
206261
}
207262
}
@@ -236,6 +291,7 @@ impl From<ViewConfig> for ViewConfigUpdate {
236291
expressions: Some(value.expressions),
237292
aggregates: Some(value.aggregates),
238293
group_by_depth: value.group_by_depth,
294+
group_rollup_mode: Some(value.group_rollup_mode),
239295
}
240296
}
241297
}
@@ -265,6 +321,12 @@ impl From<proto::ViewConfig> for ViewConfig {
265321
.map(|(x, y)| (x, y.into()))
266322
.collect(),
267323
group_by_depth: value.group_by_depth,
324+
group_rollup_mode: value
325+
.group_rollup_mode
326+
.map(proto::view_config::GroupRollupMode::try_from)
327+
.and_then(|x| x.ok())
328+
.map(|x| x.into())
329+
.unwrap_or_default(),
268330
}
269331
}
270332
}
@@ -281,6 +343,7 @@ impl From<ViewConfigUpdate> for ViewConfig {
281343
expressions: value.expressions.unwrap_or_default(),
282344
aggregates: value.aggregates.unwrap_or_default(),
283345
group_by_depth: value.group_by_depth,
346+
group_rollup_mode: value.group_rollup_mode.unwrap_or_default(),
284347
}
285348
}
286349
}
@@ -312,6 +375,10 @@ impl From<proto::ViewConfig> for ViewConfigUpdate {
312375
.collect(),
313376
),
314377
group_by_depth: value.group_by_depth,
378+
group_rollup_mode: value
379+
.group_rollup_mode
380+
.and_then(|x| proto::view_config::GroupRollupMode::try_from(x).ok())
381+
.map(|x| x.into()),
315382
}
316383
}
317384
}
@@ -346,6 +413,7 @@ impl ViewConfig {
346413
changed = Self::_apply(&mut self.sort, update.sort) || changed;
347414
changed = Self::_apply(&mut self.aggregates, update.aggregates) || changed;
348415
changed = Self::_apply(&mut self.expressions, update.expressions) || changed;
416+
changed = Self::_apply(&mut self.group_rollup_mode, update.group_rollup_mode) || changed;
349417
changed
350418
}
351419

rust/perspective-client/src/rust/view.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ pub struct ViewWindow {
100100
#[serde(skip_serializing_if = "Option::is_none")]
101101
pub index: Option<bool>,
102102

103-
#[ts(optional)]
104-
#[serde(skip_serializing_if = "Option::is_none")]
105-
pub leaves_only: Option<bool>,
106-
107103
/// Only impacts [`View::to_csv`]
108104
#[ts(optional)]
109105
#[serde(skip_serializing_if = "Option::is_none")]
@@ -383,7 +379,7 @@ impl View {
383379
id: window.id,
384380
index: window.index,
385381
formatted: window.formatted,
386-
leaves_only: window.leaves_only,
382+
387383
}));
388384

389385
match self.client.oneshot(&msg).await? {
@@ -402,7 +398,7 @@ impl View {
402398
id: window.id,
403399
index: window.index,
404400
formatted: window.formatted,
405-
leaves_only: window.leaves_only,
401+
406402
}));
407403

408404
match self.client.oneshot(&msg).await? {
@@ -422,7 +418,7 @@ impl View {
422418
id: window.id,
423419
index: window.index,
424420
formatted: window.formatted,
425-
leaves_only: window.leaves_only,
421+
426422
}));
427423

428424
match self.client.oneshot(&msg).await? {

rust/perspective-js/test/js/filters.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ const datetime_data_local = [
522522
group_by: [],
523523
sort: [],
524524
split_by: [],
525+
group_rollup_mode: "rollup",
525526
});
526527

527528
view.delete();

0 commit comments

Comments
 (0)