Skip to repository content50 lines · 1.3 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:31:31.904Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
sorting_by_column.rs
1use ui::table_row::TableRow;
2
3use crate::types::{AnyColumn, DataRow, TableCell};
4
5#[derive(Debug, PartialEq, Eq, Clone, Copy)]
6pub enum SortDirection {
7 Asc,
8 Desc,
9}
10
11/// Config or currently active sorting
12#[derive(Debug, Clone, Copy)]
13pub struct AppliedSorting {
14 /// 0-based column index
15 pub col_idx: AnyColumn,
16 /// Direction of sorting (asc/desc)
17 pub direction: SortDirection,
18}
19
20pub fn sort_data_rows(
21 content_rows: &[TableRow<TableCell>],
22 mut data_row_ids: Vec<DataRow>,
23 sorting: AppliedSorting,
24) -> Vec<DataRow> {
25 data_row_ids.sort_by(|&a, &b| {
26 let row_a = &content_rows[*a];
27 let row_b = &content_rows[*b];
28
29 // TODO: Decide how to handle nulls (on top or on bottom)
30 let val_a = row_a
31 .get(sorting.col_idx)
32 .and_then(|tc| tc.display_value())
33 .map(|tc| tc.as_str())
34 .unwrap_or("");
35 let val_b = row_b
36 .get(sorting.col_idx)
37 .and_then(|tc| tc.display_value())
38 .map(|tc| tc.as_str())
39 .unwrap_or("");
40
41 let cmp = val_a.cmp(val_b);
42 match sorting.direction {
43 SortDirection::Asc => cmp,
44 SortDirection::Desc => cmp.reverse(),
45 }
46 });
47
48 data_row_ids
49}
50