Skip to content

Commit 9d2f603

Browse files
committed
Fix cypress test and subcategory url reading
1 parent 7b2946f commit 9d2f603

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ describe('Add Integration - Real API', () => {
172172

173173
it('should filter integrations by category', () => {
174174
setupIntegrations();
175-
cy.getBySel(getIntegrationCategories('aws')).click();
175+
cy.getBySel(getIntegrationCategories('aws')).click({ scrollBehavior: false });
176+
176177
cy.getBySel(INTEGRATIONS_SEARCHBAR.BADGE).contains('AWS').should('exist');
177178
cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length.greaterThan', 29);
178179

x-pack/plugins/fleet/public/applications/integrations/sections/epm/components/package_list_grid.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export interface Props {
6464
showCardLabels?: boolean;
6565
title?: string;
6666
availableSubCategories?: CategoryFacet[];
67-
selectedSubCategory?: CategoryFacet;
68-
setSelectedSubCategory?: (c: CategoryFacet | undefined) => void;
67+
selectedSubCategory?: string;
68+
setSelectedSubCategory?: (c: string | undefined) => void;
6969
showMissingIntegrationMessage?: boolean;
7070
}
7171

@@ -111,7 +111,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
111111
setUrlandReplaceHistory({
112112
searchString: queryText,
113113
categoryId: selectedCategory,
114-
subCategoryId: selectedSubCategory?.id,
114+
subCategoryId: selectedSubCategory,
115115
});
116116
};
117117

@@ -121,11 +121,11 @@ export const PackageListGrid: FunctionComponent<Props> = ({
121121
};
122122

123123
const onSubCategoryClick = useCallback(
124-
(subCategory: CategoryFacet) => {
124+
(subCategory: string) => {
125125
if (setSelectedSubCategory) setSelectedSubCategory(subCategory);
126126
setUrlandPushHistory({
127127
categoryId: selectedCategory,
128-
subCategoryId: subCategory.id,
128+
subCategoryId: subCategory,
129129
});
130130
},
131131
[selectedCategory, setSelectedSubCategory, setUrlandPushHistory]
@@ -171,7 +171,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
171171
<EuiContextMenuItem
172172
key={subCategory.id}
173173
onClick={() => {
174-
onSubCategoryClick(subCategory);
174+
onSubCategoryClick(subCategory.id);
175175
closePopover();
176176
}}
177177
>
@@ -194,7 +194,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
194194
>
195195
<ControlsColumn controls={controls} title={title} />
196196
</EuiFlexItem>
197-
<EuiFlexItem grow={5}>
197+
<EuiFlexItem grow={5} data-test-subj="epmList.mainColumn">
198198
<EuiFieldSearch
199199
data-test-subj="epmList.searchBar"
200200
placeholder={i18n.translate('xpack.fleet.epmList.searchPackagesPlaceholder', {
@@ -269,7 +269,7 @@ export const PackageListGrid: FunctionComponent<Props> = ({
269269
<EuiButton
270270
color="text"
271271
aria-label={subCategory?.title}
272-
onClick={() => onSubCategoryClick(subCategory)}
272+
onClick={() => onSubCategoryClick(subCategory.id)}
273273
>
274274
<FormattedMessage
275275
id="xpack.fleet.epmList.subcategoriesButton"

x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/hooks/use_available_packages.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ export const useAvailablePackages = () => {
114114
const { http } = useStartServices();
115115
const addBasePath = http.basePath.prepend;
116116

117-
const { selectedCategory: initialSelectedCategory, searchParam } = getParams(
118-
useParams<CategoryParams>(),
119-
useLocation().search
120-
);
117+
const {
118+
selectedCategory: initialSelectedCategory,
119+
selectedSubcategory: initialSubcategory,
120+
searchParam,
121+
} = getParams(useParams<CategoryParams>(), useLocation().search);
122+
121123
const [selectedCategory, setCategory] = useState(initialSelectedCategory);
122-
const [selectedSubCategory, setSelectedSubCategory] = useState<CategoryFacet | undefined>();
124+
const [selectedSubCategory, setSelectedSubCategory] = useState<string | undefined>(
125+
initialSubcategory
126+
);
123127
const [searchTerm, setSearchTerm] = useState(searchParam || '');
124128

125129
const { getHref, getAbsolutePath } = useLink();
@@ -211,7 +215,7 @@ export const useAvailablePackages = () => {
211215
}
212216
if (!selectedSubCategory) return c.categories.includes(selectedCategory);
213217

214-
return c.categories.includes(selectedSubCategory.id);
218+
return c.categories.includes(selectedSubCategory);
215219
}),
216220
[cards, selectedCategory, selectedSubCategory]
217221
);

x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ import { AvailablePackages } from './available_packages';
3535

3636
export interface CategoryParams {
3737
category?: ExtendedIntegrationCategory;
38+
subcategory?: string;
3839
}
3940

4041
export const getParams = (params: CategoryParams, search: string) => {
41-
const { category } = params;
42+
const { category, subcategory } = params;
4243
const selectedCategory: ExtendedIntegrationCategory = category || '';
4344
const queryParams = new URLSearchParams(search);
4445
const searchParam = queryParams.get(INTEGRATIONS_SEARCH_QUERYPARAM) || '';
45-
return { selectedCategory, searchParam };
46+
return { selectedCategory, searchParam, selectedSubcategory: subcategory };
4647
};
4748

4849
export const categoryExists = (category: string, categories: CategoryFacet[]) => {

x-pack/plugins/fleet/public/constants/page_paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const FLEET_ROUTING_PATHS = {
9191
export const INTEGRATIONS_SEARCH_QUERYPARAM = 'q';
9292
export const INTEGRATIONS_ROUTING_PATHS = {
9393
integrations: '/:tabId',
94-
integrations_all: '/browse/:category?',
94+
integrations_all: '/browse/:category?/:subcategory?',
9595
integrations_installed: '/installed/:category?',
9696
integrations_installed_updates_available: '/installed/updates_available/:category?',
9797
integration_details: '/detail/:pkgkey/:panel?',

0 commit comments

Comments
 (0)