Skip to content

Commit

Permalink
feat(releases): Remove withRepositories, withReleaseRepos
Browse files Browse the repository at this point in the history
switch to useApiQuery

these old HoC are just a goofy way of fetching data that we now do via react query.
  • Loading branch information
scttcper committed Nov 22, 2024
1 parent a89abbe commit b59cc98
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 449 deletions.
44 changes: 44 additions & 0 deletions static/app/utils/useReleaseRepositories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {Repository} from 'sentry/types/integrations';
import {
type ApiQueryKey,
useApiQuery,
type UseApiQueryOptions,
} from 'sentry/utils/queryClient';

function getReleaseRepositoriesQueryKey({
orgSlug,
projectSlug,
release,
}: {
orgSlug: string;
projectSlug: string;
release: string;
}): ApiQueryKey {
return [`/projects/${orgSlug}/${projectSlug}/releases/${release}/repositories/`];
}

interface UseReleaseReposProps {
orgSlug: string;
projectSlug: string;
release: string;
options?: Partial<UseApiQueryOptions<Repository[]>>;
}

export function useReleaseRepositories({
orgSlug,
projectSlug,
release,
options,
}: UseReleaseReposProps) {
return useApiQuery<Repository[]>(
getReleaseRepositoriesQueryKey({
orgSlug,
projectSlug,
release: encodeURIComponent(release),
}),
{
staleTime: Infinity,
...options,
}
);
}
89 changes: 0 additions & 89 deletions static/app/utils/withRepositories.spec.tsx

This file was deleted.

91 changes: 0 additions & 91 deletions static/app/utils/withRepositories.tsx

This file was deleted.

16 changes: 10 additions & 6 deletions static/app/views/releases/detail/commitsAndFiles/commits.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
import {render, screen} from 'sentry-test/reactTestingLibrary';
import selectEvent from 'sentry-test/selectEvent';

import RepositoryStore from 'sentry/stores/repositoryStore';
import type {ReleaseProject} from 'sentry/types/release';
import {ReleaseContext} from 'sentry/views/releases/detail';

Expand All @@ -16,7 +15,7 @@ import Commits from './commits';
describe('Commits', () => {
const release = ReleaseFixture();
const project = ReleaseProjectFixture() as Required<ReleaseProject>;
const {routerProps, router, organization} = initializeOrg({
const {router, organization} = initializeOrg({
router: {params: {release: release.version}},
});
const repos = [RepositoryFixture({integrationId: '1'})];
Expand All @@ -34,7 +33,7 @@ describe('Commits', () => {
releaseMeta: {} as any,
}}
>
<Commits releaseRepos={[]} projectSlug={project.slug} {...routerProps} />
<Commits />
</ReleaseContext.Provider>,
{router}
);
Expand All @@ -46,7 +45,12 @@ describe('Commits', () => {
url: `/organizations/${organization.slug}/repos/`,
body: repos,
});
RepositoryStore.init();
MockApiClient.addMockResponse({
url: `/projects/${organization.slug}/${project.slug}/releases/${encodeURIComponent(
release.version
)}/repositories/`,
body: repos,
});
});

it('should render no repositories message', async () => {
Expand Down Expand Up @@ -133,7 +137,7 @@ describe('Commits', () => {
integrationId: '1',
});
// Current repo is stored in query parameter activeRepo
const {router: newRouterContext, routerProps: newRouterProps} = initializeOrg({
const {router: newRouterContext} = initializeOrg({
router: {
params: {release: release.version},
location: {query: {activeRepo: otherRepo.name}},
Expand Down Expand Up @@ -168,7 +172,7 @@ describe('Commits', () => {
releaseMeta: {} as any,
}}
>
<Commits releaseRepos={[]} projectSlug={project.slug} {...newRouterProps} />
<Commits />
</ReleaseContext.Provider>,
{router: newRouterContext}
);
Expand Down
Loading

0 comments on commit b59cc98

Please sign in to comment.