diff --git a/pgml-dashboard/content/blog/how-to-improve-search-results-with-machine-learning.md b/pgml-dashboard/content/blog/how-to-improve-search-results-with-machine-learning.md index 2011dd3dd..e78c1b615 100644 --- a/pgml-dashboard/content/blog/how-to-improve-search-results-with-machine-learning.md +++ b/pgml-dashboard/content/blog/how-to-improve-search-results-with-machine-learning.md @@ -216,7 +216,7 @@ This is considered a Supervised Learning problem, because we have a labeled data ### Training Data -First things first, we need to record some user clicks on our search results. We'll create a new table to store our training data, which are the observed inputs and output of our new relevance function. In a real system, we'd probably have separate tables to record **sessions**, **searches**, **results**, **clicks** and other events, but for simplicity in this example, we'll just record the exact information we need to train our model in a single table. Everytime we perform a search, we'll record the `ts_rank` for the both the **title** and **body**, and whether the user **clicked** on the result. +First things first, we need to record some user clicks on our search results. We'll create a new table to store our training data, which are the observed inputs and output of our new relevance function. In a real system, we'd probably have separate tables to record **sessions**, **searches**, **results**, **clicks** and other events, but for simplicity in this example, we'll just record the exact information we need to train our model in a single table. Everytime we perform a search, we'll record the `ts_rank` for both the **title** and **body**, and whether the user **clicked** on the result. !!! generic diff --git a/pgml-dashboard/src/components/dropdown/dropdown.scss b/pgml-dashboard/src/components/dropdown/dropdown.scss index 79c0d89ba..938595b94 100644 --- a/pgml-dashboard/src/components/dropdown/dropdown.scss +++ b/pgml-dashboard/src/components/dropdown/dropdown.scss @@ -39,6 +39,7 @@ display: flex; justify-content: space-between; font-weight: $font-weight-normal; + padding: 16px 20px; --bs-btn-border-color: transparent; --bs-btn-border-width: 1px; @@ -48,6 +49,10 @@ --bs-btn-active-color: #{$gray-100}; --bs-btn-hover-color: #{$gray-100}; + &.error { + border-color: #{$error}; + } + .material-symbols-outlined { color: #{$neon-shade-100}; } @@ -73,7 +78,7 @@ } .menu-item { - a { + a, div { padding: 8px 12px; overflow: hidden; text-overflow: ellipsis; diff --git a/pgml-dashboard/src/components/dropdown/mod.rs b/pgml-dashboard/src/components/dropdown/mod.rs index a53394e1b..77f71b1ce 100644 --- a/pgml-dashboard/src/components/dropdown/mod.rs +++ b/pgml-dashboard/src/components/dropdown/mod.rs @@ -1,3 +1,5 @@ +use crate::components::navigation::dropdown_link::DropdownLink; +use crate::components::stimulus::stimulus_target::StimulusTarget; use pgml_components::component; use pgml_components::Component; use sailfish::TemplateOnce; @@ -21,35 +23,57 @@ pub struct Dropdown { /// The currently selected value. value: DropdownValue, - /// The list of dropdown links to render. - links: Vec, + /// The list of dropdown items to render. + items: Vec, /// Position of the dropdown menu. offset: String, - /// Whether or not the dropdown is collapsble. + /// Whether or not the dropdown is collapsable. collapsable: bool, offset_collapsed: String, /// Where the dropdown menu should appear menu_position: String, expandable: bool, + + /// target to control value + value_target: StimulusTarget, } impl Dropdown { - pub fn new(links: Vec) -> Self { + pub fn new() -> Self { + Dropdown { + items: Vec::new(), + value: DropdownValue::Text("Dropdown".to_owned().into()), + offset: "0, 10".to_owned(), + offset_collapsed: "68, -44".to_owned(), + menu_position: "".to_owned(), + ..Default::default() + } + } + + pub fn nav(links: Vec) -> Self { let binding = links .iter() .filter(|link| link.active) .collect::>(); + let active = binding.first(); let value = if let Some(active) = active { active.name.to_owned() } else { - "Menu".to_owned() + "Dropdown Nav".to_owned() }; + + let mut items = Vec::new(); + for link in links { + let item = DropdownLink::new(link); + items.push(item.into()); + } + Dropdown { - links, + items, value: DropdownValue::Text(value.into()), offset: "0, 10".to_owned(), offset_collapsed: "68, -44".to_owned(), @@ -58,6 +82,11 @@ impl Dropdown { } } + pub fn items(mut self, items: Vec) -> Self { + self.items = items; + self + } + pub fn text(mut self, value: Component) -> Self { self.value = DropdownValue::Text(value); self @@ -97,6 +126,11 @@ impl Dropdown { self.expandable = true; self } + + pub fn value_target(mut self, value_target: StimulusTarget) -> Self { + self.value_target = value_target; + self + } } component!(Dropdown); diff --git a/pgml-dashboard/src/components/dropdown/template.html b/pgml-dashboard/src/components/dropdown/template.html index ace19b342..697b834db 100644 --- a/pgml-dashboard/src/components/dropdown/template.html +++ b/pgml-dashboard/src/components/dropdown/template.html @@ -20,7 +20,7 @@ data-bs-toggle="dropdown" data-bs-offset="<%= offset %>" aria-expanded="false"> - <%+ text %> + ><%+ text %> expand_more @@ -41,15 +41,9 @@ <% } %> -