Skip to content

Commit

Permalink
Merge pull request #1 from carlosthe19916/usecase3-xiaofen1
Browse files Browse the repository at this point in the history
Add packages tab to the universal search
  • Loading branch information
bxf12315 authored Oct 27, 2023
2 parents 0a400a1 + d9c2647 commit 98f62d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spog/ui/crates/components/src/packages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl TableEntryRenderer<Column> for PackagesEntry {
match context.column {
Column::Name => html!(
<Link<AppRoute>
target={AppRoute::Packages(View::Content{id: self.package.href.clone().unwrap_or_default()})}
target={AppRoute::Package{id: self.package.purl.clone().unwrap_or_default()}}
>{ self.package.name.clone().unwrap_or_default() }</Link<AppRoute>>
),
Column::Version => html!( <>
Expand Down
29 changes: 28 additions & 1 deletion spog/ui/src/pages/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use spog_ui_components::{
common::Visible,
cve::{use_cve_search, CveResult, CveSearchControls},
hooks::UseStandardSearch,
packages::{use_package_search, PackagesResult},
sbom::{use_sbom_search, SbomResult, SbomSearchControls},
search::{DynamicSearchParameters, SearchMode, SearchModeAction},
};
Expand All @@ -22,6 +23,7 @@ pub enum TabIndex {
SbomsByPackage,
#[default]
Cves,
Packages,
}

#[derive(PartialEq, Properties)]
Expand All @@ -38,6 +40,7 @@ pub struct PageState {
pub sbom: TabState,
pub sbom_by_dependency: TabState,
pub cve: TabState,
pub package: TabState,
}

#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -119,6 +122,15 @@ pub fn search(props: &SearchProperties) -> Html {
use_cve_search,
);

// Package search

let package = use_unified_search(
&page_state,
|page_state| page_state.package.search_params.clone(),
|page_state| page_state.package.pagination,
use_package_search,
);

// update search terms

use_effect_with(
Expand All @@ -128,12 +140,14 @@ pub fn search(props: &SearchProperties) -> Html {
sbom.search_params.clone(),
sbom_by_dependency.search_params.clone(),
cve.search_params.clone(),
package.search_params.clone(),
),
|(search_terms, advisory, sbom, sbom_by_dependency, cve)| {
|(search_terms, advisory, sbom, sbom_by_dependency, cve, package)| {
advisory.dispatch(SearchModeAction::SetSimpleTerms(search_terms.clone()));
sbom.dispatch(SearchModeAction::SetSimpleTerms(search_terms.clone()));
sbom_by_dependency.dispatch(SearchModeAction::SetSimpleTerms(search_terms.clone()));
cve.dispatch(SearchModeAction::SetSimpleTerms(search_terms.clone()));
package.dispatch(SearchModeAction::SetSimpleTerms(search_terms.clone()));
},
);

Expand All @@ -160,6 +174,10 @@ pub fn search(props: &SearchProperties) -> Html {
pagination: **cve.pagination,
search_params: (*cve.search_params).clone(),
},
package: TabState {
pagination: **package.pagination,
search_params: (*package.search_params).clone(),
},
},
);

Expand Down Expand Up @@ -211,6 +229,9 @@ pub fn search(props: &SearchProperties) -> Html {
<Visible visible={*tab == TabIndex::Advisories}>
<AdvisorySearchControls search_params={advisory.search_params.clone()} />
</Visible>
<Visible visible={*tab == TabIndex::Packages}>
<SbomSearchControls search_params={package.search_params.clone()} />
</Visible>
<Visible visible={*tab == TabIndex::Sboms}>
<SbomSearchControls search_params={sbom.search_params.clone()} />
</Visible>
Expand All @@ -231,6 +252,7 @@ pub fn search(props: &SearchProperties) -> Html {
r#box=true
>
<Tab<TabIndex> index={TabIndex::Cves} title={count_tab_title("CVEs", &*cve.state)} />
<Tab<TabIndex> index={TabIndex::Packages} title={count_tab_title("Packages", &*package.state)} />
<Tab<TabIndex> index={TabIndex::Sboms} title={count_tab_title("Products and containers", &*sbom.state)} />
<Tab<TabIndex> index={TabIndex::Advisories} title={count_tab_title("Advisories", &*advisory.state)} />
// <Tab<TabIndex> index={TabIndex::SbomsByPackage} title={count_tab_title("SBOMs (by dependency)", &*sbom_by_dependency.state)} />
Expand All @@ -242,6 +264,11 @@ pub fn search(props: &SearchProperties) -> Html {
<AdvisoryResult state={(*advisory.state).clone()} onsort={&advisory.onsort} />
</PaginationWrapped>
}
if *tab == TabIndex::Packages {
<PaginationWrapped pagination={package.pagination} total={*package.total}>
<PackagesResult state={(*package.state).clone()} onsort={&package.onsort} />
</PaginationWrapped>
}
if *tab == TabIndex::Sboms {
<PaginationWrapped pagination={sbom.pagination} total={*sbom.total}>
<SbomResult state={(*sbom.state).clone()} onsort={&sbom.onsort} />
Expand Down

0 comments on commit 98f62d8

Please sign in to comment.