Skip to content

Commit 248d51a

Browse files
committed
feat(ui): Use endpoint for fetching InfrastructureService on edit
Previously, the edit pages fetched all infrastructure services of the entity and filtered the desired service by name on the client side. With the new endpoint to get an `InfrastructureService` by its name, the pages now fetch the service directly from the backend. Resolves #758. Signed-off-by: Onur Demirci <[email protected]>
1 parent 05db18b commit 248d51a

File tree

2 files changed

+20
-32
lines changed
  • ui/src/routes/organizations/$orgId
    • infrastructure-services/$serviceName/edit
    • products/$productId/repositories/$repoId/_repo-layout/infrastructure-services/$serviceName/edit

2 files changed

+20
-32
lines changed

ui/src/routes/organizations/$orgId/infrastructure-services/$serviceName/edit/index.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useForm } from 'react-hook-form';
2525
import { z } from 'zod';
2626

2727
import {
28-
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesKey,
28+
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName,
2929
useOrganizationsServicePatchApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName,
3030
} from '@/api/queries';
3131
import { useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdSecretsSuspense } from '@/api/queries/suspense';
@@ -85,29 +85,21 @@ const EditInfrastructureServicePage = () => {
8585
}
8686
);
8787

88-
/* Search service details from all infrastructure services of the organization
89-
* TODO: Edit this to fetch the details from:
90-
* GET /api/v1/organizations/{organizationId}/infrastructure-services/{serviceName}
91-
* when the endpoint is implemented
92-
*/
93-
const { data: infrastructureServices } = useSuspenseQuery({
88+
const { data: service } = useSuspenseQuery({
9489
queryKey: [
95-
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesKey,
90+
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName,
9691
params.orgId,
92+
params.serviceName,
9793
],
9894
queryFn: () =>
99-
OrganizationsService.getApiV1OrganizationsByOrganizationIdInfrastructureServices(
95+
OrganizationsService.getApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName(
10096
{
10197
organizationId: Number.parseInt(params.orgId),
102-
limit: ALL_ITEMS,
98+
serviceName: params.serviceName,
10399
}
104100
),
105101
});
106102

107-
const service = infrastructureServices?.data.find(
108-
(service) => service.name === params.serviceName
109-
);
110-
111103
const { mutateAsync, isPending } =
112104
useOrganizationsServicePatchApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName(
113105
{
@@ -359,14 +351,15 @@ export const Route = createFileRoute(
359351
loader: async ({ context, params }) => {
360352
await context.queryClient.ensureQueryData({
361353
queryKey: [
362-
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesKey,
354+
useOrganizationsServiceGetApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName,
363355
params.orgId,
356+
params.serviceName,
364357
],
365358
queryFn: () =>
366-
OrganizationsService.getApiV1OrganizationsByOrganizationIdInfrastructureServices(
359+
OrganizationsService.getApiV1OrganizationsByOrganizationIdInfrastructureServicesByServiceName(
367360
{
368361
organizationId: Number.parseInt(params.orgId),
369-
limit: ALL_ITEMS,
362+
serviceName: params.serviceName,
370363
}
371364
),
372365
});

ui/src/routes/organizations/$orgId/products/$productId/repositories/$repoId/_repo-layout/infrastructure-services/$serviceName/edit/index.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import { Loader2 } from 'lucide-react';
2424
import { useForm } from 'react-hook-form';
2525
import { z } from 'zod';
2626

27-
import {
28-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdInfrastructureServicesKey,
29-
useRepositoriesServicePatchApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName,
30-
} from '@/api/queries';
27+
import { useRepositoriesServicePatchApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName } from '@/api/queries';
3128
import { useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdSecretsSuspense } from '@/api/queries/suspense.ts';
3229
import { ApiError, RepositoriesService } from '@/api/requests';
3330
import { MultiSelectField } from '@/components/form/multi-select-field.tsx';
@@ -83,24 +80,21 @@ const EditInfrastructureServicePage = () => {
8380
limit: ALL_ITEMS,
8481
});
8582

86-
const { data: infrastructureServices } = useSuspenseQuery({
83+
const { data: service } = useSuspenseQuery({
8784
queryKey: [
88-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdInfrastructureServicesKey,
85+
useRepositoriesServicePatchApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName,
8986
params.repoId,
87+
params.serviceName,
9088
],
9189
queryFn: () =>
92-
RepositoriesService.getApiV1RepositoriesByRepositoryIdInfrastructureServices(
90+
RepositoriesService.getApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName(
9391
{
9492
repositoryId: Number.parseInt(params.repoId),
95-
limit: ALL_ITEMS,
93+
serviceName: params.serviceName,
9694
}
9795
),
9896
});
9997

100-
const service = infrastructureServices?.data.find(
101-
(service) => service.name === params.serviceName
102-
);
103-
10498
const { mutateAsync, isPending } =
10599
useRepositoriesServicePatchApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName(
106100
{
@@ -360,14 +354,15 @@ export const Route = createFileRoute(
360354
loader: async ({ context, params }) => {
361355
await context.queryClient.ensureQueryData({
362356
queryKey: [
363-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdInfrastructureServicesKey,
357+
useRepositoriesServicePatchApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName,
364358
params.repoId,
359+
params.serviceName,
365360
],
366361
queryFn: () =>
367-
RepositoriesService.getApiV1RepositoriesByRepositoryIdInfrastructureServices(
362+
RepositoriesService.getApiV1RepositoriesByRepositoryIdInfrastructureServicesByServiceName(
368363
{
369364
repositoryId: Number.parseInt(params.repoId),
370-
limit: ALL_ITEMS,
365+
serviceName: params.serviceName,
371366
}
372367
),
373368
});

0 commit comments

Comments
 (0)