index.tsx 7.6 KB

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