Files
grafana/public/app/features/plugins/PluginListPage.tsx
T

69 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-10-27 13:08:08 +01:00
import React from 'react';
2018-09-25 14:53:55 +02:00
import { hot } from 'react-hot-loader';
2021-04-28 15:40:01 +03:00
import { connect, ConnectedProps } from 'react-redux';
import Page from 'app/core/components/Page/Page';
import PageActionBar from 'app/core/components/PageActionBar/PageActionBar';
2018-09-25 14:53:55 +02:00
import PluginList from './PluginList';
import { loadPlugins } from './state/actions';
import { getNavModel } from 'app/core/selectors/navModel';
import { getPlugins, getPluginsSearchQuery } from './state/selectors';
import { StoreState } from 'app/types';
import { setPluginsSearchQuery } from './state/reducers';
2020-10-27 13:08:08 +01:00
import { useAsync } from 'react-use';
import { selectors } from '@grafana/e2e-selectors';
import { PluginsErrorsInfo } from './PluginsErrorsInfo';
2018-09-25 14:53:55 +02:00
2021-04-28 15:40:01 +03:00
const mapStateToProps = (state: StoreState) => ({
navModel: getNavModel(state.navIndex, 'plugins'),
plugins: getPlugins(state.plugins),
searchQuery: getPluginsSearchQuery(state.plugins),
hasFetched: state.plugins.hasFetched,
});
const mapDispatchToProps = {
loadPlugins,
setPluginsSearchQuery,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
export type Props = ConnectedProps<typeof connector>;
2018-09-25 14:53:55 +02:00
2020-10-27 13:08:08 +01:00
export const PluginListPage: React.FC<Props> = ({
hasFetched,
navModel,
plugins,
setPluginsSearchQuery,
searchQuery,
loadPlugins,
}) => {
useAsync(async () => {
loadPlugins();
}, [loadPlugins]);
2018-09-25 14:53:55 +02:00
let actionTarget: string | undefined = '_blank';
2020-10-27 13:08:08 +01:00
const linkButton = {
href: 'https://grafana.com/plugins?utm_source=grafana_plugin_list',
title: 'Find more plugins on Grafana.com',
};
2018-09-25 14:53:55 +02:00
2020-10-27 13:08:08 +01:00
return (
<Page navModel={navModel} aria-label={selectors.pages.PluginsList.page}>
<Page.Contents isLoading={!hasFetched}>
<>
<PageActionBar
2020-10-27 13:08:08 +01:00
searchQuery={searchQuery}
2021-01-20 07:59:48 +01:00
setSearchQuery={(query) => setPluginsSearchQuery(query)}
2020-10-27 13:08:08 +01:00
linkButton={linkButton}
placeholder="Search by name, author, description or type"
target={actionTarget}
2020-10-27 13:08:08 +01:00
/>
<PluginsErrorsInfo />
2020-10-27 13:08:08 +01:00
{hasFetched && plugins && <PluginList plugins={plugins} />}
</>
</Page.Contents>
</Page>
);
};
2018-09-25 14:53:55 +02:00
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(PluginListPage));