index.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. oldData => {
  42. return {...oldData, data};
  43. }
  44. );
  45. }
  46. const handleRemove = () => {
  47. browserHistory.push(
  48. normalizeUrl(`/settings/${organization.slug}/projects/${projectId}/keys/`)
  49. );
  50. };
  51. if (isError) {
  52. return <RouteError />;
  53. }
  54. if (isLoading) {
  55. return <LoadingIndicator />;
  56. }
  57. return (
  58. <SentryDocumentTitle title={t('Key Details')}>
  59. <SettingsPageHeader title={t('Key Details')} data-test-id="key-details" />
  60. <PermissionAlert project={project} />
  61. <KeyStats api={api} organization={organization} params={params} />
  62. <KeySettings
  63. data={projKeyData}
  64. updateData={onDataChange}
  65. onRemove={handleRemove}
  66. organization={organization}
  67. project={project}
  68. params={params}
  69. />
  70. </SentryDocumentTitle>
  71. );
  72. }