import {Fragment} from 'react'; import {RouteComponentProps} from 'react-router'; import { addErrorMessage, addLoadingMessage, clearIndicators, } from 'sentry/actionCreators/indicator'; import Button from 'sentry/components/button'; import Field from 'sentry/components/forms/field'; import Link from 'sentry/components/links/link'; import {Panel, PanelAlert, PanelBody, PanelHeader} from 'sentry/components/panels'; import Switch from 'sentry/components/switchButton'; import Truncate from 'sentry/components/truncate'; import {IconAdd} from 'sentry/icons'; import {t} from 'sentry/locale'; import {Organization, ServiceHook} from 'sentry/types'; import withOrganization from 'sentry/utils/withOrganization'; import AsyncView from 'sentry/views/asyncView'; import EmptyMessage from 'sentry/views/settings/components/emptyMessage'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; type RowProps = { hook: ServiceHook; onToggleActive: () => void; orgId: string; projectId: string; }; function ServiceHookRow({orgId, projectId, hook, onToggleActive}: RowProps) { return ( } help={ {hook.events && hook.events.length !== 0 ? ( hook.events.join(', ') ) : ( {t('no events configured')} )} } > ); } type Props = RouteComponentProps<{orgId: string; projectId: string}, {}> & { organization: Organization; }; type State = { hookList: null | ServiceHook[]; } & AsyncView['state']; class ProjectServiceHooks extends AsyncView { getEndpoints(): ReturnType { const {orgId, projectId} = this.props.params; return [['hookList', `/projects/${orgId}/${projectId}/hooks/`]]; } onToggleActive = (hook: ServiceHook) => { const {orgId, projectId} = this.props.params; const {hookList} = this.state; if (!hookList) { return; } addLoadingMessage(t('Saving changes\u2026')); this.api.request(`/projects/${orgId}/${projectId}/hooks/${hook.id}/`, { method: 'PUT', data: { isActive: hook.status !== 'active', }, success: data => { clearIndicators(); this.setState({ hookList: hookList.map(h => { if (h.id === data.id) { return { ...h, ...data, }; } return h; }), }); }, error: () => { addErrorMessage(t('Unable to remove application. Please try again.')); }, }); }; renderEmpty() { return ( {t('There are no service hooks associated with this project.')} ); } renderResults() { const {orgId, projectId} = this.props.params; return ( {t('Service Hook')} {t( 'Service Hooks are an early adopter preview feature and will change in the future.' )} {this.state.hookList?.map(hook => ( ))} ); } renderBody() { const {hookList} = this.state; const body = hookList && hookList.length > 0 ? this.renderResults() : this.renderEmpty(); const {orgId, projectId} = this.props.params; const access = new Set(this.props.organization.access); return ( } > {t('Create New Hook')} ) : null } /> {body} ); } } export default withOrganization(ProjectServiceHooks);