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