index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {BarChart} from 'sentry/components/charts/barChart';
  4. import type {LineChartSeries} from 'sentry/components/charts/lineChart';
  5. import {LineChart} from 'sentry/components/charts/lineChart';
  6. import {DateTime} from 'sentry/components/dateTime';
  7. import Link from 'sentry/components/links/link';
  8. import Panel from 'sentry/components/panels/panel';
  9. import PanelBody from 'sentry/components/panels/panelBody';
  10. import PanelFooter from 'sentry/components/panels/panelFooter';
  11. import PanelHeader from 'sentry/components/panels/panelHeader';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import type {SentryApp} from 'sentry/types/integrations';
  15. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  16. import type {Organization} from 'sentry/types/organization';
  17. import withOrganization from 'sentry/utils/withOrganization';
  18. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  19. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  20. import RequestLog from './requestLog';
  21. type Props = RouteComponentProps<{appSlug: string}, {}> & {
  22. organization: Organization;
  23. };
  24. type State = DeprecatedAsyncView['state'] & {
  25. app: SentryApp;
  26. interactions: {
  27. componentInteractions: {
  28. [key: string]: [number, number][];
  29. };
  30. views: [number, number][];
  31. };
  32. stats: {
  33. installStats: [number, number][];
  34. totalInstalls: number;
  35. totalUninstalls: number;
  36. uninstallStats: [number, number][];
  37. };
  38. };
  39. class SentryApplicationDashboard extends DeprecatedAsyncView<Props, State> {
  40. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  41. const {appSlug} = this.props.params;
  42. // Default time range for now: 90 days ago to now
  43. const now = Math.floor(new Date().getTime() / 1000);
  44. const ninety_days_ago = 3600 * 24 * 90;
  45. return [
  46. [
  47. 'stats',
  48. `/sentry-apps/${appSlug}/stats/`,
  49. {query: {since: now - ninety_days_ago, until: now}},
  50. ],
  51. [
  52. 'interactions',
  53. `/sentry-apps/${appSlug}/interaction/`,
  54. {query: {since: now - ninety_days_ago, until: now}},
  55. ],
  56. ['app', `/sentry-apps/${appSlug}/`],
  57. ];
  58. }
  59. getTitle() {
  60. return t('Integration Dashboard');
  61. }
  62. renderInstallData() {
  63. const {app, stats} = this.state;
  64. const {totalUninstalls, totalInstalls} = stats;
  65. return (
  66. <Fragment>
  67. <h5>{t('Installation & Interaction Data')}</h5>
  68. <Row>
  69. {app.datePublished ? (
  70. <StatsSection>
  71. <StatsHeader>{t('Date published')}</StatsHeader>
  72. <DateTime dateOnly date={app.datePublished} />
  73. </StatsSection>
  74. ) : null}
  75. <StatsSection data-test-id="installs">
  76. <StatsHeader>{t('Total installs')}</StatsHeader>
  77. <p>{totalInstalls}</p>
  78. </StatsSection>
  79. <StatsSection data-test-id="uninstalls">
  80. <StatsHeader>{t('Total uninstalls')}</StatsHeader>
  81. <p>{totalUninstalls}</p>
  82. </StatsSection>
  83. </Row>
  84. {this.renderInstallCharts()}
  85. </Fragment>
  86. );
  87. }
  88. renderInstallCharts() {
  89. const {installStats, uninstallStats} = this.state.stats;
  90. const installSeries = {
  91. data: installStats.map(point => ({
  92. name: point[0] * 1000,
  93. value: point[1],
  94. })),
  95. seriesName: t('installed'),
  96. };
  97. const uninstallSeries = {
  98. data: uninstallStats.map(point => ({
  99. name: point[0] * 1000,
  100. value: point[1],
  101. })),
  102. seriesName: t('uninstalled'),
  103. };
  104. return (
  105. <Panel>
  106. <PanelHeader>{t('Installations/Uninstallations over Last 90 Days')}</PanelHeader>
  107. <ChartWrapper>
  108. <BarChart
  109. series={[installSeries, uninstallSeries]}
  110. height={150}
  111. stacked
  112. isGroupedByDate
  113. legend={{
  114. show: true,
  115. orient: 'horizontal',
  116. data: ['installed', 'uninstalled'],
  117. itemWidth: 15,
  118. }}
  119. yAxis={{type: 'value', minInterval: 1, max: 'dataMax'}}
  120. xAxis={{type: 'time'}}
  121. grid={{left: space(4), right: space(4)}}
  122. />
  123. </ChartWrapper>
  124. </Panel>
  125. );
  126. }
  127. renderIntegrationViews() {
  128. const {views} = this.state.interactions;
  129. const {organization} = this.props;
  130. const {appSlug} = this.props.params;
  131. return (
  132. <Panel>
  133. <PanelHeader>{t('Integration Views')}</PanelHeader>
  134. <PanelBody>
  135. <InteractionsChart data={{Views: views}} />
  136. </PanelBody>
  137. <PanelFooter>
  138. <StyledFooter>
  139. {t('Integration views are measured through views on the ')}
  140. <Link to={`/sentry-apps/${appSlug}/external-install/`}>
  141. {t('external installation page')}
  142. </Link>
  143. {t(' and views on the Learn More/Install modal on the ')}
  144. <Link to={`/settings/${organization.slug}/integrations/`}>
  145. {t('integrations page')}
  146. </Link>
  147. </StyledFooter>
  148. </PanelFooter>
  149. </Panel>
  150. );
  151. }
  152. renderComponentInteractions() {
  153. const {componentInteractions} = this.state.interactions;
  154. const componentInteractionsDetails = {
  155. 'stacktrace-link': t(
  156. 'Each link click or context menu open counts as one interaction'
  157. ),
  158. 'issue-link': t('Each open of the issue link modal counts as one interaction'),
  159. };
  160. return (
  161. <Panel>
  162. <PanelHeader>{t('Component Interactions')}</PanelHeader>
  163. <PanelBody>
  164. <InteractionsChart data={componentInteractions} />
  165. </PanelBody>
  166. <PanelFooter>
  167. <StyledFooter>
  168. {Object.keys(componentInteractions).map(
  169. (component, idx) =>
  170. componentInteractionsDetails[component] && (
  171. <Fragment key={idx}>
  172. <strong>{`${component}: `}</strong>
  173. {componentInteractionsDetails[component]}
  174. <br />
  175. </Fragment>
  176. )
  177. )}
  178. </StyledFooter>
  179. </PanelFooter>
  180. </Panel>
  181. );
  182. }
  183. renderBody() {
  184. const {app} = this.state;
  185. return (
  186. <div>
  187. <SettingsPageHeader title={`${t('Integration Dashboard')} - ${app.name}`} />
  188. {app.status === 'published' && this.renderInstallData()}
  189. {app.status === 'published' && this.renderIntegrationViews()}
  190. {app.schema.elements && this.renderComponentInteractions()}
  191. <RequestLog app={app} />
  192. </div>
  193. );
  194. }
  195. }
  196. export default withOrganization(SentryApplicationDashboard);
  197. type InteractionsChartProps = {
  198. data: {
  199. [key: string]: [number, number][];
  200. };
  201. };
  202. function InteractionsChart({data}: InteractionsChartProps) {
  203. const elementInteractionsSeries: LineChartSeries[] = Object.keys(data).map(
  204. (key: string) => {
  205. const seriesData = data[key].map(point => ({
  206. value: point[1],
  207. name: point[0] * 1000,
  208. }));
  209. return {
  210. seriesName: key,
  211. data: seriesData,
  212. };
  213. }
  214. );
  215. return (
  216. <ChartWrapper>
  217. <LineChart
  218. isGroupedByDate
  219. series={elementInteractionsSeries}
  220. grid={{left: space(4), right: space(4)}}
  221. legend={{
  222. show: true,
  223. orient: 'horizontal',
  224. data: Object.keys(data),
  225. }}
  226. />
  227. </ChartWrapper>
  228. );
  229. }
  230. const Row = styled('div')`
  231. display: flex;
  232. `;
  233. const StatsSection = styled('div')`
  234. margin-right: ${space(4)};
  235. `;
  236. const StatsHeader = styled('h6')`
  237. margin-bottom: ${space(1)};
  238. font-size: 12px;
  239. text-transform: uppercase;
  240. color: ${p => p.theme.subText};
  241. `;
  242. const StyledFooter = styled('div')`
  243. padding: ${space(1.5)};
  244. `;
  245. const ChartWrapper = styled('div')`
  246. padding-top: ${space(3)};
  247. `;