index.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import type {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 type {Organization} from 'sentry/types/organization';
  6. import type {Project, ProjectKey} from 'sentry/types/project';
  7. import {browserHistory} from 'sentry/utils/browserHistory';
  8. import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  9. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  10. import useApi from 'sentry/utils/useApi';
  11. import RouteError from 'sentry/views/routeError';
  12. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  13. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  14. import {KeySettings} from 'sentry/views/settings/project/projectKeys/details/keySettings';
  15. import KeyStats from 'sentry/views/settings/project/projectKeys/details/keyStats';
  16. type Props = {
  17. organization: Organization;
  18. project: Project;
  19. } & RouteComponentProps<
  20. {
  21. keyId: string;
  22. projectId: string;
  23. },
  24. {}
  25. >;
  26. export default function ProjectKeyDetails({organization, params, project}: Props) {
  27. const {keyId, projectId} = params;
  28. const api = useApi();
  29. const queryClient = useQueryClient();
  30. const {
  31. data: projKeyData,
  32. isError,
  33. isPending,
  34. } = useApiQuery<ProjectKey>(
  35. [`/projects/${organization.slug}/${projectId}/keys/${keyId}/`],
  36. {staleTime: 0}
  37. );
  38. function onDataChange(data: ProjectKey) {
  39. setApiQueryData<ProjectKey>(
  40. queryClient,
  41. [`/projects/${organization.slug}/${projectId}/keys/${keyId}/`],
  42. data
  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 (isPending) {
  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. }