123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import {Component} from 'react';
- import type {RouteComponentProps} from 'react-router';
- import moment from 'moment';
- import type {Client} from 'sentry/api';
- import LinkWithConfirmation from 'sentry/components/links/linkWithConfirmation';
- import ResultGrid from 'sentry/components/resultGrid';
- import {t} from 'sentry/locale';
- import withApi from 'sentry/utils/withApi';
- const prettyDate = (x: string) => moment(x).format('ll LTS');
- type Props = RouteComponentProps<{}, {}> & {api: Client};
- type State = {
- loading: boolean;
- };
- type RelayRow = {
- firstSeen: string;
- id: string;
- lastSeen: string;
- publicKey: string;
- relayId: string;
- };
- class AdminRelays extends Component<Props, State> {
- state: State = {
- loading: false,
- };
- onDelete(key: string) {
- this.setState({loading: true});
- this.props.api.request(`/relays/${key}/`, {
- method: 'DELETE',
- success: () => this.setState({loading: false}),
- error: () => this.setState({loading: false}),
- });
- }
- getRow(row: RelayRow) {
- return [
- <td key="id">
- <strong>{row.relayId}</strong>
- </td>,
- <td key="key">{row.publicKey}</td>,
- <td key="firstSeen" style={{textAlign: 'right'}}>
- {prettyDate(row.firstSeen)}
- </td>,
- <td key="lastSeen" style={{textAlign: 'right'}}>
- {prettyDate(row.lastSeen)}
- </td>,
- <td key="tools" style={{textAlign: 'right'}}>
- <span className="editor-tools">
- <LinkWithConfirmation
- className="danger"
- title="Remove"
- message={t('Are you sure you wish to delete this relay?')}
- onConfirm={() => this.onDelete(row.id)}
- >
- {t('Remove')}
- </LinkWithConfirmation>
- </span>
- </td>,
- ];
- }
- render() {
- const columns = [
- <th key="id" style={{width: 350, textAlign: 'left'}}>
- Relay
- </th>,
- <th key="key">Public Key</th>,
- <th key="firstSeen" style={{width: 150, textAlign: 'right'}}>
- First seen
- </th>,
- <th key="lastSeen" style={{width: 150, textAlign: 'right'}}>
- Last seen
- </th>,
- <th key="tools" />,
- ];
- return (
- <div>
- <h3>{t('Relays')}</h3>
- <ResultGrid
- path="/manage/relays/"
- endpoint="/relays/"
- method="GET"
- columns={columns}
- columnsForRow={this.getRow}
- hasSearch={false}
- sortOptions={[
- ['firstSeen', 'First seen'],
- ['lastSeen', 'Last seen'],
- ['relayId', 'Relay ID'],
- ]}
- defaultSort="firstSeen"
- {...this.props}
- />
- </div>
- );
- }
- }
- export {AdminRelays};
- export default withApi(AdminRelays);
|