index.tsx 2.3 KB

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