Skip to content

feat(app-platform): Sort Integrations #12697

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

Merged
merged 1 commit into from
Apr 15, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions src/sentry/static/sentry/app/components/avatar/sentryAppAvatar.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ class OrganizationIntegrations extends AsyncComponent {

// Rendering

renderBody() {
const {reloading, applications, appInstalls} = this.state;
const providers = this.providers
.sort((a, b) => b.isInstalled - a.isInstalled)
.map(provider => (
renderProvider(provider) {
return (
<IntegrationRow key={`row-${provider.key}`}>
<ProviderRow
key={provider.key}
provider={provider}
Expand All @@ -148,7 +146,55 @@ class OrganizationIntegrations extends AsyncComponent {
onReinstall={this.onInstall}
enabledPlugins={this.enabledPlugins}
/>
));
</IntegrationRow>
);
}

renderSentryApps(apps, key) {
const {appInstalls} = this.state;

return (
<IntegrationRow key={`row-${key}`}>
<SentryAppInstallations
key={key}
orgId={this.props.params.orgId}
installs={appInstalls}
applications={apps}
/>
</IntegrationRow>
);
}

renderBody() {
const {reloading, applications, appInstalls} = this.state;

const installedProviders = this.providers
Copy link
Member

Choose a reason for hiding this comment

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

There's kind of a lot of duplicated and/or very similar code, we could use lodash.partition to cut back some code. Downside of this is that readers will need to look up what partition does. (Current code is fine too though).

const [installedProviders, uninstalledProviders] = _.partition(this.providers.map(p => [p, this.renderProvider(p)]), ([provider,]) => provider.isInstalled);

.filter(p => p.isInstalled)
.map(p => [p.name, this.renderProvider(p)]);

const uninstalledProviders = this.providers
.filter(p => !p.isInstalled)
.map(p => [p.name, this.renderProvider(p)]);

const installedSentryApps = (applications || [])
.filter(a => appInstalls.find(i => i.app.slug === a.slug))
.map(a => [a.name, this.renderSentryApps([a], a.slug)]);

const uninstalledSentryApps = (applications || [])
.filter(a => !appInstalls.find(i => i.app.slug === a.slug))
.map(a => [a.name, this.renderSentryApps([a], a.slug)]);

// Combine the list of Providers and Sentry Apps that have installations.
const installed = installedProviders
.concat(installedSentryApps)
.sort((a, b) => a[0].localeCompare(b[0]))
Copy link
Member

Choose a reason for hiding this comment

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

imo, destructuring adds some more code but can be a bit more clear about what you're retrieving from the array:

const installed = installedProviders
      .concat(installedSentryApps)
      .sort(([name1,], [name2,]) => name1.localeCompare(name2))
      .map([,Component] => Component);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, more "punctuation", but definitely clearer 👍

.map(i => i[1]);

// Combine the list of Providers and Sentry Apps that have no installations.
const uninstalled = uninstalledProviders
.concat(uninstalledSentryApps)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(i => i[1]);

return (
<React.Fragment>
Expand All @@ -169,21 +215,17 @@ class OrganizationIntegrations extends AsyncComponent {
{reloading && <StyledLoadingIndicator mini />}
</PanelHeader>
<PanelBody>
{providers}
{applications && (
<SentryAppInstallations
orgId={this.props.params.orgId}
installs={appInstalls}
applications={applications}
/>
)}
{installed}
{uninstalled}
</PanelBody>
</Panel>
</React.Fragment>
);
}
}

const IntegrationRow = styled.div``;

const StyledLoadingIndicator = styled(LoadingIndicator)`
position: absolute;
right: 7px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Access from 'app/components/acl/access';
import Button from 'app/components/button';
import Confirm from 'app/components/confirm';
import ConfirmDelete from 'app/components/confirmDelete';
import SentryAppAvatar from 'app/components/avatar/sentryAppAvatar';
import PropTypes from 'prop-types';
import SentryTypes from 'app/sentryTypes';
import Tooltip from 'app/components/tooltip';
Expand All @@ -15,6 +14,7 @@ import styled from 'react-emotion';
import space from 'app/styles/space';
import {withTheme} from 'emotion-theming';
import CircleIndicator from 'app/components/circleIndicator';
import PluginIcon from 'app/plugins/components/pluginIcon';

export default class SentryApplicationRow extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -72,7 +72,7 @@ export default class SentryApplicationRow extends React.PureComponent {
return (
<SentryAppItem>
<StyledFlex>
<SentryAppAvatar size={36} sentryApp={app} />
<PluginIcon size={36} pluginId={app.slug} />
<SentryAppBox>
<SentryAppName>
{showPublishStatus ? (
Expand Down
Loading