diff --git a/coral/src/app/features/approvals/acls/AclApprovals.tsx b/coral/src/app/features/approvals/acls/AclApprovals.tsx index 1db622c4a8..801a6fdbd1 100644 --- a/coral/src/app/features/approvals/acls/AclApprovals.tsx +++ b/coral/src/app/features/approvals/acls/AclApprovals.tsx @@ -242,7 +242,7 @@ function AclApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx index cc589fc6e1..803d0a5440 100644 --- a/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx +++ b/coral/src/app/features/approvals/connectors/ConnectorApprovals.tsx @@ -266,7 +266,7 @@ function ConnectorApprovals() { filters={[ , , , diff --git a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx index e5a96e808e..cc3cd1bcef 100644 --- a/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx +++ b/coral/src/app/features/approvals/schemas/SchemaApprovals.tsx @@ -263,10 +263,7 @@ function SchemaApprovals() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/approvals/topics/TopicApprovals.tsx b/coral/src/app/features/approvals/topics/TopicApprovals.tsx index 661154e064..29d0130d6d 100644 --- a/coral/src/app/features/approvals/topics/TopicApprovals.tsx +++ b/coral/src/app/features/approvals/topics/TopicApprovals.tsx @@ -286,7 +286,7 @@ function TopicApprovals() { filters={[ , , , diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx index 1dc03380e1..66d0544df7 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.test.tsx @@ -5,7 +5,6 @@ import EnvironmentFilter from "src/app/features/components/filters/EnvironmentFi import { withFiltersContext } from "src/app/features/components/filters/useFiltersContext"; import { getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { createEnvironment } from "src/domain/environment/environment-test-helper"; @@ -18,11 +17,6 @@ const mockGetEnvironments = typeof getAllEnvironmentsForTopicAndAcl >; -const mockGetSchemaRegistryEnvironments = - getAllEnvironmentsForSchema as jest.MockedFunction< - typeof getAllEnvironmentsForSchema - >; - const mockGetSyncConnectorsEnvironments = getAllEnvironmentsForConnector as jest.MockedFunction< typeof getAllEnvironmentsForConnector @@ -42,18 +36,13 @@ const mockEnvironments = [ const filterLabel = "Filter by Environment"; const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); describe("EnvironmentFilter.tsx", () => { describe("uses a given endpoint to fetch environments", () => { beforeEach(() => { mockGetEnvironments.mockResolvedValue([]); - mockGetSchemaRegistryEnvironments.mockResolvedValue([]); mockGetSyncConnectorsEnvironments.mockResolvedValue([]); }); afterEach(() => { @@ -74,11 +63,7 @@ describe("EnvironmentFilter.tsx", () => { it("fetches from the getAllEnvironmentsForSchema endpoint", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, @@ -92,11 +77,7 @@ describe("EnvironmentFilter.tsx", () => { it("fetches from the getAllEnvironmentsForConnector endpoint", () => { const WrappedEnvironmentFilter = withFiltersContext({ - element: ( - - ), + element: , }); customRender(, { memoryRouter: true, diff --git a/coral/src/app/features/components/filters/EnvironmentFilter.tsx b/coral/src/app/features/components/filters/EnvironmentFilter.tsx index dea4e9b757..5fc9a4e786 100644 --- a/coral/src/app/features/components/filters/EnvironmentFilter.tsx +++ b/coral/src/app/features/components/filters/EnvironmentFilter.tsx @@ -4,35 +4,70 @@ import { useFiltersContext } from "src/app/features/components/filters/useFilter import { Environment, getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema, getAllEnvironmentsForConnector, } from "src/domain/environment"; import { HTTPError } from "src/services/api"; -type EnvironmentEndpoint = - | "getAllEnvironmentsForTopicAndAcl" - | "getAllEnvironmentsForSchema" - | "getAllEnvironmentsForConnector"; +type EnvironmentFor = "TOPIC_AND_ACL" | "SCHEMA" | "CONNECTOR"; interface EnvironmentFilterProps { - isSchemaRegistryEnvironments?: boolean; - environmentEndpoint: EnvironmentEndpoint; + environmentsFor: EnvironmentFor; } const environmentEndpointMap: { - [key in EnvironmentEndpoint]: () => Promise; + [key in EnvironmentFor]: { + apiEndpoint: () => Promise; + // we use the api function name as query usually, so we + // want to keep that pattern here, too. + queryFn: string; + }; } = { - getAllEnvironmentsForTopicAndAcl: getAllEnvironmentsForTopicAndAcl, - getAllEnvironmentsForSchema: getAllEnvironmentsForSchema, - getAllEnvironmentsForConnector: getAllEnvironmentsForConnector, + TOPIC_AND_ACL: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + SCHEMA: { + apiEndpoint: getAllEnvironmentsForTopicAndAcl, + queryFn: "getAllEnvironmentsForTopicAndAcl", + }, + CONNECTOR: { + apiEndpoint: getAllEnvironmentsForConnector, + queryFn: "getAllEnvironmentsForConnector", + }, }; -function EnvironmentFilter({ environmentEndpoint }: EnvironmentFilterProps) { +function filterEnvironmentsForSchema( + environments: Environment[] +): Environment[] { + return environments + .map((env) => { + if (env.associatedEnv) { + return { + ...env, + id: env.associatedEnv.id, + name: env.associatedEnv.name, + }; + } + }) + .filter((entry) => entry !== undefined) as Environment[]; +} + +function EnvironmentFilter({ environmentsFor }: EnvironmentFilterProps) { const { environment, setFilterValue } = useFiltersContext(); const { data: environments } = useQuery( - [environmentEndpoint], + [environmentEndpointMap[environmentsFor].queryFn], { - queryFn: environmentEndpointMap[environmentEndpoint], + queryFn: environmentEndpointMap[environmentsFor].apiEndpoint, + select: (environments) => { + if (environmentsFor === "SCHEMA") { + const filtered = filterEnvironmentsForSchema(environments); + console.log("filtered", filtered); + return filtered; + } else { + console.log("else"); + return environments; + } + }, } ); diff --git a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx index 2fa6f14396..11d71cec07 100644 --- a/coral/src/app/features/connectors/browse/BrowseConnectors.tsx +++ b/coral/src/app/features/connectors/browse/BrowseConnectors.tsx @@ -54,10 +54,7 @@ function BrowseConnectors() { , - , + , , ]} table={ diff --git a/coral/src/app/features/requests/acls/AclRequests.tsx b/coral/src/app/features/requests/acls/AclRequests.tsx index 6bc7c92d51..6e895f50c4 100644 --- a/coral/src/app/features/requests/acls/AclRequests.tsx +++ b/coral/src/app/features/requests/acls/AclRequests.tsx @@ -170,7 +170,7 @@ function AclRequests() { filters={[ , , , diff --git a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx index 902a0011b2..2185da2d2b 100644 --- a/coral/src/app/features/requests/connectors/ConnectorRequests.tsx +++ b/coral/src/app/features/requests/connectors/ConnectorRequests.tsx @@ -150,10 +150,7 @@ function ConnectorRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/schemas/SchemaRequests.tsx b/coral/src/app/features/requests/schemas/SchemaRequests.tsx index 480362e143..a59d7752a1 100644 --- a/coral/src/app/features/requests/schemas/SchemaRequests.tsx +++ b/coral/src/app/features/requests/schemas/SchemaRequests.tsx @@ -160,10 +160,7 @@ function SchemaRequests() { {errorQuickActions && {errorQuickActions}} , + , , , , diff --git a/coral/src/app/features/requests/topics/TopicRequests.tsx b/coral/src/app/features/requests/topics/TopicRequests.tsx index 79b408eb3e..a0e2faa9a6 100644 --- a/coral/src/app/features/requests/topics/TopicRequests.tsx +++ b/coral/src/app/features/requests/topics/TopicRequests.tsx @@ -152,7 +152,7 @@ function TopicRequests() { filters={[ , , , diff --git a/coral/src/app/features/topics/browse/BrowseTopics.tsx b/coral/src/app/features/topics/browse/BrowseTopics.tsx index 0bea56788d..7a873ae48e 100644 --- a/coral/src/app/features/topics/browse/BrowseTopics.tsx +++ b/coral/src/app/features/topics/browse/BrowseTopics.tsx @@ -57,7 +57,7 @@ function BrowseTopics() { , , , ]} diff --git a/coral/src/domain/environment/environment-api.ts b/coral/src/domain/environment/environment-api.ts index 63fbee03f2..61c7203ae7 100644 --- a/coral/src/domain/environment/environment-api.ts +++ b/coral/src/domain/environment/environment-api.ts @@ -27,6 +27,16 @@ const getAllEnvironmentsForTopicAndAcl = async (): Promise => { return transformEnvironmentApiResponse(apiResponse); }; +const getEnvironmentsForSchema = async (): Promise => { + const apiResponse = await api.get>( + API_PATHS.getEnvs + ); + + const filteredEnvs = apiResponse.filter((env) => env.associatedEnv); + console.log(filteredEnvs); + return transformEnvironmentApiResponse(apiResponse); +}; + const getPaginatedEnvironmentsForTopicAndAcl = async ( params: KlawApiRequestQueryParameters<"getKafkaEnvsPaginated"> ): Promise => { @@ -51,14 +61,6 @@ const getEnvironmentsForTopicRequest = async (): Promise => { return transformEnvironmentApiResponse(apiResponse); }; -const getAllEnvironmentsForSchema = async (): Promise => { - const apiResponse = await api.get>( - API_PATHS.getSchemaRegEnvs - ); - - return transformEnvironmentApiResponse(apiResponse); -}; - const getPaginatedEnvironmentsForSchema = async ( params: KlawApiRequestQueryParameters<"getSchemaRegEnvsPaginated"> ): Promise => { @@ -112,9 +114,9 @@ export { getAllEnvironmentsForTopicAndAcl, getPaginatedEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, - getAllEnvironmentsForSchema, getPaginatedEnvironmentsForSchema, getAllEnvironmentsForConnector, getPaginatedEnvironmentsForConnector, getUpdateEnvStatus, + getEnvironmentsForSchema, }; diff --git a/coral/src/domain/environment/index.ts b/coral/src/domain/environment/index.ts index 84801895e8..d9bd1bcece 100644 --- a/coral/src/domain/environment/index.ts +++ b/coral/src/domain/environment/index.ts @@ -1,6 +1,5 @@ import { getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector, @@ -18,7 +17,6 @@ import { export { ALL_ENVIRONMENTS_VALUE, getAllEnvironmentsForConnector, - getAllEnvironmentsForSchema, getAllEnvironmentsForTopicAndAcl, getEnvironmentsForTopicRequest, getPaginatedEnvironmentsForConnector,