mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Add filters by update available (#91526)
This commit is contained in:
committed by
GitHub
parent
2e3f48a49d
commit
0c4e02ba14
@@ -94,6 +94,21 @@ describe('Browse list of plugins', () => {
|
||||
expect(queryByText('Plugin 2')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should list plugins with update when filtering by update', async () => {
|
||||
const { queryByText } = renderBrowse('/plugins?filterBy=has-update', [
|
||||
getCatalogPluginMock({ id: 'plugin-1', name: 'Plugin 1', isInstalled: true, hasUpdate: true }),
|
||||
getCatalogPluginMock({ id: 'plugin-2', name: 'Plugin 2', isInstalled: false }),
|
||||
getCatalogPluginMock({ id: 'plugin-3', name: 'Plugin 3', isInstalled: true, hasUpdate: true }),
|
||||
getCatalogPluginMock({ id: 'plugin-4', name: 'Plugin 4', isInstalled: true, isCore: true }),
|
||||
]);
|
||||
|
||||
await waitFor(() => expect(queryByText('Plugin 1')).toBeInTheDocument());
|
||||
expect(queryByText('Plugin 3')).toBeInTheDocument();
|
||||
|
||||
expect(queryByText('Plugin 2')).not.toBeInTheDocument();
|
||||
expect(queryByText('Plugin 4')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should list all plugins (including disabled plugins) when filtering by all', async () => {
|
||||
const { queryByText } = renderBrowse('/plugins?filterBy=all&filterByType=all', [
|
||||
getCatalogPluginMock({ id: 'plugin-1', name: 'Plugin 1', isInstalled: true }),
|
||||
|
||||
@@ -37,6 +37,7 @@ export default function Browse({ route }: GrafanaRouteComponentProps): ReactElem
|
||||
keyword,
|
||||
type: filterByType !== 'all' ? filterByType : undefined,
|
||||
isInstalled: filterBy === 'installed' ? true : undefined,
|
||||
hasUpdate: filterBy === 'has-update' ? true : undefined,
|
||||
},
|
||||
sortBy
|
||||
);
|
||||
@@ -44,6 +45,7 @@ export default function Browse({ route }: GrafanaRouteComponentProps): ReactElem
|
||||
const filterByOptions = [
|
||||
{ value: 'all', label: 'All' },
|
||||
{ value: 'installed', label: 'Installed' },
|
||||
{ value: 'has-update', label: 'New Updates' },
|
||||
];
|
||||
|
||||
const onSortByChange = (value: SelectableValue<string>) => {
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('Plugins Selectors', () => {
|
||||
isInstalled: true,
|
||||
type: PluginType.app,
|
||||
isCore: false,
|
||||
hasUpdate: true,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
@@ -81,6 +82,13 @@ describe('Plugins Selectors', () => {
|
||||
expect(results.map(({ name }) => name)).toEqual(['Plugin 4']);
|
||||
});
|
||||
|
||||
it('should be possible to only search for with update', () => {
|
||||
const results = selectPlugins({ hasUpdate: true })(store.getState());
|
||||
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results.map(({ name }) => name)).toEqual(['Plugin 5']);
|
||||
});
|
||||
|
||||
it('should be possible to search by multiple filters', () => {
|
||||
const results = selectPlugins({ keyword: '2', type: PluginType.datasource })(store.getState());
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ export type PluginFilters = {
|
||||
|
||||
// (Optional, only applied if set)
|
||||
isEnterprise?: boolean;
|
||||
|
||||
// (Optional, only applied if set)
|
||||
hasUpdate?: boolean;
|
||||
};
|
||||
|
||||
export const selectPlugins = (filters: PluginFilters) =>
|
||||
@@ -60,6 +63,10 @@ export const selectPlugins = (filters: PluginFilters) =>
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filters.hasUpdate !== undefined && plugin.hasUpdate !== filters.hasUpdate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user