tablo_core/column/
file.rs1use derive_where::derive_where;
4use topcoat::{context::Cx, view::*};
5
6use super::{Column, ColumnBase, ColumnWidth};
7use crate::Lens;
8
9#[derive_where(Clone, Debug)]
20pub struct FileColumn<M> {
21 lens: Lens<M, String>,
22 base: ColumnBase,
23}
24
25impl<M> FileColumn<M>
26where
27 M: toasty::schema::Model,
28{
29 pub fn new(lens: Lens<M, String>) -> Self {
31 Self {
32 base: ColumnBase::new(lens.path(), ColumnWidth::Grow),
33 lens,
34 }
35 }
36
37 base_builders!();
38}
39
40impl<M> Column<M> for FileColumn<M>
41where
42 M: toasty::schema::Model + Send + Sync + 'static,
43{
44 base_column_methods!(binding);
45
46 fn text(&self, _cx: &Cx, row: &M) -> String {
47 self.lens.read(row).clone()
48 }
49
50 fn cell<'a>(&self, cx: &'a Cx, row: &M) -> BoxView<'a> {
51 let path = self.lens.read(row);
52 if path.trim().is_empty() {
53 return crate::schema::value_cell(cx, path);
54 }
55 crate::schema::stored_upload(cx, path)
56 }
57}