index.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import LoadingIndicator from 'sentry/components/loadingIndicator';
  3. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  4. import {t} from 'sentry/locale';
  5. import {Organization, Project, ProjectKey} from 'sentry/types';
  6. import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  7. import useApi from 'sentry/utils/useApi';
  8. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  9. import RouteError from 'sentry/views/routeError';
  10. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  11. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  12. import {KeySettings} from 'sentry/views/settings/project/projectKeys/details/keySettings';
  13. import KeyStats from 'sentry/views/settings/project/projectKeys/details/keyStats';
  14. type Props = {
  15. organization: Organization;
  16. project: Project;
  17. } & RouteComponentProps<
  18. {
  19. keyId: string;
  20. projectId: string;
  21. },
  22. {}
  23. >;
  24. export default function ProjectKeyDetails({organization, params, project}: Props) {
  25. const {keyId, projectId} = params;
  26. const api = useApi();
  27. const queryClient = useQueryClient();
  28. const {
  29. data: projKeyData,
  30. isError,
  31. isLoading,
  32. } = useApiQuery<ProjectKey>(
  33. [`/projects/${organization.slug}/${projectId}/keys/${keyId}/`],
  34. {staleTime: 0}
  35. );
  36. function onDataChange(data: ProjectKey) {
  37. setApiQueryData<ProjectKey>(
  38. queryClient,
  39. [`/projects/${organization.slug}/${projectId}/keys/${keyId}/`],
  40. oldData => {
  41. return {...oldData, data};
  42. }
  43. );
  44. }
  45. const handleRemove = () => {
  46. browserHistory.push(
  47. normalizeUrl(`/settings/${organization.slug}/projects/${projectId}/keys/`)
  48. );
  49. };
  50. if (isError) {
  51. return <RouteError />;
  52. }
  53. if (isLoading) {
  54. return <LoadingIndicator />;
  55. }
  56. return (
  57. <SentryDocumentTitle title={t('Key Details')}>
  58. <SettingsPageHeader title={t('Key Details')} data-test-id="key-details" />
  59. <PermissionAlert project={project} />
  60. <KeyStats api={api} organization={organization} params={params} />
  61. <KeySettings
  62. data={projKeyData}
  63. updateData={onDataChange}
  64. onRemove={handleRemove}
  65. organization={organization}
  66. project={project}
  67. params={params}
  68. />
  69. </SentryDocumentTitle>
  70. );
  71. }