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