index.tsx 7.4 KB

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