index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import ListLink from 'sentry/components/links/listLink';
  5. import NavTabs from 'sentry/components/navTabs';
  6. import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels';
  7. import {t} from 'sentry/locale';
  8. import {InternetProtocol} from 'sentry/types';
  9. import recreateRoute from 'sentry/utils/recreateRoute';
  10. import AsyncView from 'sentry/views/asyncView';
  11. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  12. import SessionRow from './sessionRow';
  13. import {tableLayout} from './utils';
  14. type Props = RouteComponentProps<{}, {}>;
  15. type State = {
  16. ipList: Array<InternetProtocol> | null;
  17. } & AsyncView['state'];
  18. class SessionHistory extends AsyncView<Props, State> {
  19. getTitle() {
  20. return t('Session History');
  21. }
  22. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  23. return [['ipList', '/users/me/ips/']];
  24. }
  25. renderBody() {
  26. const {ipList} = this.state;
  27. if (!ipList) {
  28. return null;
  29. }
  30. const {routes, params, location} = this.props;
  31. const recreateRouteProps = {routes, params, location};
  32. return (
  33. <Fragment>
  34. <SettingsPageHeader
  35. title={t('Security')}
  36. tabs={
  37. <NavTabs underlined>
  38. <ListLink
  39. to={recreateRoute('', {...recreateRouteProps, stepBack: -1})}
  40. index
  41. >
  42. {t('Settings')}
  43. </ListLink>
  44. <ListLink to={recreateRoute('', recreateRouteProps)}>
  45. {t('Session History')}
  46. </ListLink>
  47. </NavTabs>
  48. }
  49. />
  50. <Panel>
  51. <SessionPanelHeader>
  52. <div>{t('Sessions')}</div>
  53. <div>{t('First Seen')}</div>
  54. <div>{t('Last Seen')}</div>
  55. </SessionPanelHeader>
  56. <PanelBody>
  57. {ipList.map(({id, ...ipObj}) => (
  58. <SessionRow key={id} {...ipObj} />
  59. ))}
  60. </PanelBody>
  61. </Panel>
  62. </Fragment>
  63. );
  64. }
  65. }
  66. export default SessionHistory;
  67. const SessionPanelHeader = styled(PanelHeader)`
  68. ${tableLayout}
  69. justify-content: initial;
  70. `;