pluginList.tsx 2.0 KB

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