index.tsx 7.1 KB

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