pluginList.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import React from 'react';
  2. import {disablePlugin, enablePlugin} from 'app/actionCreators/plugins';
  3. import InactivePlugins from 'app/components/inactivePlugins';
  4. import PluginConfig from 'app/components/pluginConfig';
  5. import {t} from 'app/locale';
  6. import {Organization, Plugin, Project} from 'app/types';
  7. import {Panel, PanelItem} from './panels';
  8. type Props = {
  9. organization: Organization;
  10. project: Project;
  11. pluginList: Plugin[];
  12. onDisablePlugin?: (plugin: Plugin) => void;
  13. onEnablePlugin?: (plugin: Plugin) => void;
  14. };
  15. const PluginList = ({
  16. organization,
  17. project,
  18. pluginList,
  19. onDisablePlugin = () => {},
  20. onEnablePlugin = () => {},
  21. }: Props) => {
  22. const handleEnablePlugin = (plugin: Plugin) => {
  23. enablePlugin({
  24. projectId: project.slug,
  25. orgId: organization.slug,
  26. pluginId: plugin.slug,
  27. });
  28. onEnablePlugin(plugin);
  29. };
  30. const handleDisablePlugin = (plugin: Plugin) => {
  31. disablePlugin({
  32. projectId: project.slug,
  33. orgId: organization.slug,
  34. pluginId: plugin.slug,
  35. });
  36. onDisablePlugin(plugin);
  37. };
  38. if (!pluginList.length) {
  39. return (
  40. <Panel>
  41. <PanelItem>
  42. {t("Oops! Looks like there aren't any available integrations installed.")}
  43. </PanelItem>
  44. </Panel>
  45. );
  46. }
  47. return (
  48. <div>
  49. {pluginList
  50. .filter(p => p.enabled)
  51. .map(data => (
  52. <PluginConfig
  53. data={data}
  54. organization={organization}
  55. project={project}
  56. key={data.id}
  57. onDisablePlugin={handleDisablePlugin}
  58. />
  59. ))}
  60. <InactivePlugins
  61. plugins={pluginList.filter(p => !p.enabled && !p.isHidden)}
  62. onEnablePlugin={handleEnablePlugin}
  63. />
  64. </div>
  65. );
  66. };
  67. export default PluginList;