index.tsx 7.7 KB

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