Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/app/pages/sbom-list/sbom-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ISbomSearchContext {
| "labels"
| "vulnerabilities",
"name" | "published",
"" | "published" | "labels" | "license",
"name" | "published" | "labels" | "license",
string
>;

Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/sbom-list/sbom-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const SbomSearchProvider: React.FunctionComponent<ISbomProvider> = ({
isFilterEnabled: true,
filterCategories: [
{
categoryKey: FILTER_TEXT_CATEGORY_KEY,
categoryKey: "name",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider centralizing the "name" filter key instead of hardcoding it.

This key is now referenced in multiple places (provider, search menu, search tabs, setFilterValues, etc.), so hardcoding it in each file increases the risk of inconsistencies if it ever changes. Exposing a shared constant (like the previous FILTER_TEXT_CATEGORY_KEY) and reusing it would keep the key definition in one place and make future changes safer.

Suggested implementation:

    isFilterEnabled: true,
    filterCategories: [
      {
        categoryKey: FILTER_TEXT_CATEGORY_KEY,
        title: "Filter text",
        placeholderText: "Search",
        type: FilterType.search,
  1. Ensure FILTER_TEXT_CATEGORY_KEY is defined in a shared constants module (e.g. client/src/app/pages/sbom-list/constants.ts or an existing filters-constants file), with a value of "name", and exported:
    • export const FILTER_TEXT_CATEGORY_KEY = "name";
  2. Import FILTER_TEXT_CATEGORY_KEY at the top of sbom-provider.tsx from that shared constants module:
    • import { FILTER_TEXT_CATEGORY_KEY } from "./constants"; (or the correct relative path for your project).
  3. In all other places that currently hardcode "name" for this same filter (provider, search menu, search tabs, setFilterValues, etc.), replace the string literal with FILTER_TEXT_CATEGORY_KEY and add the same import there. This keeps the filter key centralized and consistent.

title: "Filter text",
placeholderText: "Search",
type: FilterType.search,
Expand Down
10 changes: 7 additions & 3 deletions client/src/app/pages/search/components/SearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function useAllEntities(filterText: string, disableSearch: boolean) {
page: { pageNumber: 1, itemsPerPage: 5 },
};

const sbomParams: HubRequestParams = {
filters: [{ field: "name", operator: "~", value: filterText }],
page: { pageNumber: 1, itemsPerPage: 5 },
};

const {
isFetching: isFetchingAdvisories,
result: { data: advisories },
Expand All @@ -76,7 +81,7 @@ function useAllEntities(filterText: string, disableSearch: boolean) {
const {
isFetching: isFetchingSBOMs,
result: { data: sboms },
} = useFetchSBOMs(null, { ...params }, [], disableSearch);
} = useFetchSBOMs(null, { ...sbomParams }, [], disableSearch);

const {
isFetching: isFetchingVulnerabilities,
Expand Down Expand Up @@ -170,8 +175,7 @@ export const SearchMenu: React.FC<ISearchMenu> = ({ onChangeSearch }) => {
// (no useMemo in the useUrlParams → useFilterState → context chain), but the
// extracted string only changes when the URL filter param actually changes.
const appliedSearchValue =
sbomTableControls.filterState.filterValues[FILTER_TEXT_CATEGORY_KEY]?.[0] ??
"";
sbomTableControls.filterState.filterValues["name"]?.[0] ?? "";

const [searchValue, setSearchValue] = React.useState("");
const [isSearchValueDirty, setIsSearchValueDirty] = React.useState(false);
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/pages/search/components/SearchTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface SearchTabsProps {
>;
sbomFilterPanelProps: IFilterPanelProps<
SbomSummary,
"" | "published" | "labels" | "license"
"name" | "published" | "labels" | "license"
>;
vulnerabilityFilterPanelProps: IFilterPanelProps<
VulnerabilitySummary,
Expand Down Expand Up @@ -117,7 +117,7 @@ export const SearchTabs: React.FC<SearchTabsProps> = ({
<CardBody style={{ width: 241 }}>
{isTabActive("sboms") ? (
<FilterPanel
omitFilterCategoryKeys={[""]}
omitFilterCategoryKeys={["name"]}
{...sbomFilterPanelProps}
/>
) : isTabActive("packages") ? (
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const Search: React.FC<SearchPageProps> = ({ searchBodyOverride }) => {
if (searchValue === undefined) return;
sbomTableControls.filterState.setFilterValues({
...sbomTableControls.filterState.filterValues,
[FILTER_TEXT_CATEGORY_KEY]: [searchValue],
["name"]: [searchValue],
});
packageTableControls.filterState.setFilterValues({
...packageTableControls.filterState.filterValues,
Expand Down
Loading