Skip to content

Commit e9f7bdb

Browse files
committed
feat: move logic for converting index up & fix err
1 parent be3b17b commit e9f7bdb

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/app/data.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,22 @@ impl Data {
136136
}
137137
}
138138

139+
/// If the points are not filtered returns the input otherwise translates it from the filtered array
140+
fn get_real_index(&self, index: usize) -> usize {
141+
if let Some(filtered) = self.filtered_rows.as_ref() {
142+
filtered[index]
143+
} else {
144+
index
145+
}
146+
}
147+
139148
pub fn selected_row_data_as_slice(
140149
&mut self,
141150
common_fields: &BTreeSet<String>,
142151
) -> Option<&[(String, String)]> {
143152
let selected_row_index = self.selected_row?;
144-
// TODO 1: Fix here to use appropriate list
145-
Some(self.rows[selected_row_index].as_slice(common_fields))
153+
let real_index = self.get_real_index(selected_row_index);
154+
Some(self.rows[real_index].as_slice(common_fields))
146155
}
147156

148157
pub fn move_selected_to_next(&mut self) {

src/app/data/data_iter.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@ impl<'a> Iterator for DataIter<'a> {
1616
type Item = &'a LogRow;
1717

1818
fn next(&mut self) -> Option<Self::Item> {
19-
let result = match self.data.filtered_rows.as_ref() {
20-
Some(filtered) => {
21-
if self.pos >= filtered.len() {
22-
return None;
23-
}
24-
Some(&self.data.rows[filtered[self.pos]])
25-
}
26-
None => {
27-
if self.pos >= self.data.rows.len() {
28-
return None;
29-
}
30-
Some(&self.data.rows[self.pos])
31-
}
32-
};
19+
if self.pos >= self.data.len() {
20+
return None;
21+
}
22+
let real_index = self.data.get_real_index(self.pos);
3323
self.pos += 1;
34-
result
24+
Some(&self.data.rows[real_index])
3525
}
3626

3727
fn nth(&mut self, n: usize) -> Option<Self::Item> {

0 commit comments

Comments
 (0)