Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integration-directory): plugin detailed view #16821

Merged
merged 18 commits into from Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sentry/api/endpoints/organization_plugins_configs.py
Expand Up @@ -105,6 +105,7 @@ def get(self, request, organization):
"projectName": project.name, # TODO(steve): do we need?
"enabled": plugin_info["enabled"],
"configured": plugin_info["configured"], # TODO(steve): do we need?
"projectPlatform": project.platform,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to add this so we can render the project badge

}
)
serialized_plugins.append(serialized_plugin)
Expand Down
15 changes: 15 additions & 0 deletions src/sentry/static/sentry/app/routes.jsx
Expand Up @@ -829,6 +829,20 @@ function routes() {
</Route>
</Route>

<Redirect from="plugins/" to="integrations/" />
<Route name="Integrations" path="plugins/">
<Route
name="Integration Details"
path=":pluginSlug/"
componentPromise={() =>
import(
/* webpackChunkName: "ConfigureIntegration" */ 'app/views/organizationIntegrations/pluginDetailedView'
)
}
component={errorHandler(LazyLoad)}
/>
</Route>

<Redirect from="sentry-apps/" to="integrations/" />
<Route name="Integrations" path="sentry-apps/">
<Route
Expand All @@ -842,6 +856,7 @@ function routes() {
component={errorHandler(LazyLoad)}
/>
</Route>

<Route name="Integrations" path="integrations/">
<IndexRoute
componentPromise={() =>
Expand Down
22 changes: 15 additions & 7 deletions src/sentry/static/sentry/app/types/index.tsx
Expand Up @@ -305,20 +305,28 @@ export type PluginNoProject = {
isHidden: boolean;
description?: string;
resourceLinks?: Array<{title: string; url: string}>;
features: string[];
featureDescriptions: Array<{
description: string;
featureGate: string;
}>;
};

export type Plugin = PluginNoProject & {
enabled: boolean;
};

export type PluginProjectItem = {
projectId: string;
projectSlug: string;
projectName: string;
projectPlatform: string | null;
enabled: boolean;
configured: boolean;
};

export type PluginWithProjectList = PluginNoProject & {
projectList: Array<{
projectId: string;
projectSlug: string;
projectName: string;
enabled: boolean;
configured: boolean;
}>;
projectList: PluginProjectItem[];
};

export type GlobalSelection = {
Expand Down
@@ -0,0 +1,165 @@
import React from 'react';
import styled from '@emotion/styled';

import {t} from 'app/locale';
import Access from 'app/components/acl/access';
import Button from 'app/components/button';
import Confirm from 'app/components/confirm';
import Alert from 'app/components/alert';
import ProjectBadge from 'app/components/idBadge/projectBadge';
import withApi from 'app/utils/withApi';
import {Client} from 'app/api';
import {
addErrorMessage,
addSuccessMessage,
addLoadingMessage,
} from 'app/actionCreators/indicator';
import {PluginNoProject, PluginProjectItem, Organization, AvatarProject} from 'app/types';

export type Props = {
api: Client;
plugin: PluginNoProject;
projectItem: PluginProjectItem;
organization: Organization;
onResetConfiguration: (projectId: string) => void;
onEnablePlugin: (projectId: string) => void;
className?: string;
};

export class InstalledPlugin extends React.Component<Props> {
getConfirmMessage() {
return (
<React.Fragment>
<Alert type="error" icon="icon-circle-exclamation">
{t(
'Deleting this installation will disable the integration for this project and remove any configurations.'
)}
</Alert>
</React.Fragment>
);
}

pluginUpdate = async (data: object) => {
const {organization, projectItem, plugin} = this.props;
// no try/catch so the caller will have to have it
await this.props.api.requestPromise(
`/projects/${organization.slug}/${projectItem.projectSlug}/plugins/${plugin.id}/`,
NisanthanNanthakumar marked this conversation as resolved.
Show resolved Hide resolved
{
method: 'POST',
data,
}
);
};

handleReset = async () => {
try {
addLoadingMessage(t('Removing...'));
await this.pluginUpdate({reset: true});
addSuccessMessage(t('Configuration was removed'));
this.props.onResetConfiguration(this.props.projectItem.projectId);
} catch (_err) {
addErrorMessage(t('Unable to remove configuration'));
}
};

handleUninstallClick = () => {
//TODO: Analytics
};

enablePlugin = async () => {
try {
addLoadingMessage(t('Enabling...'));
await this.pluginUpdate({enabled: true});
addSuccessMessage(t('Configuration was enabled'));
this.props.onEnablePlugin(this.props.projectItem.projectId);
} catch (_err) {
addErrorMessage(t('Unable to enable configuration'));
}
};

get projectForBadge(): AvatarProject {
//this function returns the project as needed for the ProjectBadge component
const {projectItem} = this.props;
return {
slug: projectItem.projectSlug,
platform: projectItem.projectPlatform ? projectItem.projectPlatform : undefined,
};
}

render() {
const {className, plugin, organization, projectItem} = this.props;

return (
<Container>
<Access access={['org:integrations']}>
{({hasAccess}) => (
<IntegrationFlex className={className}>
<IntegrationItemBox>
<ProjectBadge project={this.projectForBadge} />
</IntegrationItemBox>
<div>
{!projectItem.enabled ? (
<Button size="small" priority="primary" onClick={this.enablePlugin}>
{t('Enable')}
</Button>
) : (
<StyledButton
borderless
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why borderless in this context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanpurkhiser It definitely doesn't look good here, that's for sure. We really just copy-pasted these buttons from the existing integrations page where it looks better:

Screen Shot 2020-02-05 at 11 20 21 AM

Right now, we are waiting for a proper design from Chris. We'll tune up all the styling on this page once we know what it should look like.

icon="icon-settings"
disabled={!hasAccess}
to={`/settings/${organization.slug}/projects/${projectItem.projectSlug}/plugins/${plugin.id}/`}
data-test-id="integration-configure-button"
>
{t('Configure')}
</StyledButton>
)}
</div>
<div>
<Confirm
priority="danger"
onConfirming={this.handleUninstallClick}
disabled={!hasAccess}
confirmText="Delete Installation"
onConfirm={() => this.handleReset()}
message={this.getConfirmMessage()}
>
<StyledButton
disabled={!hasAccess}
borderless
icon="icon-trash"
data-test-id="integration-remove-button"
>
{t('Uninstall')}
</StyledButton>
</Confirm>
</div>
</IntegrationFlex>
)}
</Access>
</Container>
);
}
}

export default withApi(InstalledPlugin);

const Container = styled('div')`
margin: 10px;
`;

const StyledButton = styled(Button)`
color: ${p => p.theme.gray2};
`;

const IntegrationFlex = styled('div')`
display: flex;
align-items: center;
`;

const IntegrationItemBox = styled('div')`
flex: 1;
box-sizing: border-box;
display: flex;
flex-direction: row;
min-width: 0;
`;
Expand Up @@ -40,7 +40,7 @@ export default class PluginRow extends React.Component<Props> {
<ProviderDetails>
<Status enabled={this.isEnabled} />
<StyledLink
to={`/settings/${slug}/plugins/${plugin.slug}?tab=configurations`}
to={`/settings/${slug}/plugins/${plugin.slug}/?tab=configurations`}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to add the trailing / so the link works properly

>{`${plugin.projectList.length} Configurations`}</StyledLink>
</ProviderDetails>
</Container>
Expand Down
Expand Up @@ -46,7 +46,7 @@ export default class ProviderRow extends React.Component<Props> {
<ProviderDetails>
<Status enabled={this.isEnabled} />
<StyledLink
to={`/settings/${slug}/integrations/${provider.key}?tab=configurations`}
to={`/settings/${slug}/integrations/${provider.key}/?tab=configurations`}
>{`${integrations.length} Configurations`}</StyledLink>
</ProviderDetails>
</div>
Expand Down