Skip to content

Commit

Permalink
TEMP state
Browse files Browse the repository at this point in the history
Signed-off-by: Mirjam Aulbach <[email protected]>
  • Loading branch information
programmiri committed Oct 6, 2023
1 parent 51caeed commit bb96540
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 69 deletions.
2 changes: 1 addition & 1 deletion coral/src/app/features/approvals/acls/AclApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function AclApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
environmentsFor={"TOPIC_AND_ACL"}
/>,
<StatusFilter key={"status"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function ConnectorApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getAllEnvironmentsForConnector"}
environmentsFor={"CONNECTOR"}
/>,
<StatusFilter key={"status"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
5 changes: 1 addition & 4 deletions coral/src/app/features/approvals/schemas/SchemaApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,7 @@ function SchemaApprovals() {
{errorQuickActions && <Alert type="error">{errorQuickActions}</Alert>}
<TableLayout
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getAllEnvironmentsForSchema"}
/>,
<EnvironmentFilter key={"environment"} environmentsFor={"SCHEMA"} />,
<StatusFilter key={"status"} />,
<RequestTypeFilter key={"requestType"} />,
<SearchTopicFilter key={"topic"} />,
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/approvals/topics/TopicApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function TopicApprovals() {
filters={[
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
environmentsFor={"TOPIC_AND_ACL"}
/>,
<StatusFilter key={"status"} />,
<RequestTypeFilter key={"requestType"} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,11 +17,6 @@ const mockGetEnvironments =
typeof getAllEnvironmentsForTopicAndAcl
>;

const mockGetSchemaRegistryEnvironments =
getAllEnvironmentsForSchema as jest.MockedFunction<
typeof getAllEnvironmentsForSchema
>;

const mockGetSyncConnectorsEnvironments =
getAllEnvironmentsForConnector as jest.MockedFunction<
typeof getAllEnvironmentsForConnector
Expand All @@ -42,18 +36,13 @@ const mockEnvironments = [
const filterLabel = "Filter by Environment";

const WrappedEnvironmentFilter = withFiltersContext({
element: (
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
/>
),
element: <EnvironmentFilter environmentsFor={"TOPIC_AND_ACL"} />,
});

describe("EnvironmentFilter.tsx", () => {
describe("uses a given endpoint to fetch environments", () => {
beforeEach(() => {
mockGetEnvironments.mockResolvedValue([]);
mockGetSchemaRegistryEnvironments.mockResolvedValue([]);
mockGetSyncConnectorsEnvironments.mockResolvedValue([]);
});
afterEach(() => {
Expand All @@ -74,11 +63,7 @@ describe("EnvironmentFilter.tsx", () => {

it("fetches from the getAllEnvironmentsForSchema endpoint", () => {
const WrappedEnvironmentFilter = withFiltersContext({
element: (
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForSchema"}
/>
),
element: <EnvironmentFilter environmentsFor={"SCHEMA"} />,
});
customRender(<WrappedEnvironmentFilter />, {
memoryRouter: true,
Expand All @@ -92,11 +77,7 @@ describe("EnvironmentFilter.tsx", () => {

it("fetches from the getAllEnvironmentsForConnector endpoint", () => {
const WrappedEnvironmentFilter = withFiltersContext({
element: (
<EnvironmentFilter
environmentEndpoint={"getAllEnvironmentsForConnector"}
/>
),
element: <EnvironmentFilter environmentsFor={"CONNECTOR"} />,
});
customRender(<WrappedEnvironmentFilter />, {
memoryRouter: true,
Expand Down
63 changes: 49 additions & 14 deletions coral/src/app/features/components/filters/EnvironmentFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Environment[]>;
[key in EnvironmentFor]: {
apiEndpoint: () => Promise<Environment[]>;
// 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<Environment[], HTTPError>(
[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;
}
},
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ function BrowseConnectors() {
<TableLayout
filters={[
<TeamFilter key={"team"} />,
<EnvironmentFilter
key={"environment"}
environmentEndpoint={"getAllEnvironmentsForConnector"}
/>,
<EnvironmentFilter key={"environment"} environmentsFor={"CONNECTOR"} />,
<SearchConnectorFilter key="connector-name" />,
]}
table={
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/requests/acls/AclRequests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function AclRequests() {
filters={[
<EnvironmentFilter
key="environment"
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
environmentsFor={"TOPIC_AND_ACL"}
/>,
<AclTypeFilter key="aclType" />,
<StatusFilter key="status" />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ function ConnectorRequests() {
{errorQuickActions && <Alert type="error">{errorQuickActions}</Alert>}
<TableLayout
filters={[
<EnvironmentFilter
key="environment"
environmentEndpoint="getAllEnvironmentsForConnector"
/>,
<EnvironmentFilter key="environment" environmentsFor="CONNECTOR" />,
<StatusFilter key="request-status" />,
<RequestTypeFilter key={"request-type"} />,
<SearchConnectorFilter key="connector" />,
Expand Down
5 changes: 1 addition & 4 deletions coral/src/app/features/requests/schemas/SchemaRequests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ function SchemaRequests() {
{errorQuickActions && <Alert type="error">{errorQuickActions}</Alert>}
<TableLayout
filters={[
<EnvironmentFilter
key={"environments"}
environmentEndpoint={"getAllEnvironmentsForSchema"}
/>,
<EnvironmentFilter key={"environments"} environmentsFor={"SCHEMA"} />,
<StatusFilter key={"request-status"} />,
<RequestTypeFilter key={"request-type"} />,
<SearchTopicFilter key={"topic"} />,
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/requests/topics/TopicRequests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function TopicRequests() {
filters={[
<EnvironmentFilter
key="environments"
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
environmentsFor={"TOPIC_AND_ACL"}
/>,
<StatusFilter key="request-status" />,
<RequestTypeFilter key={"request-type"} />,
Expand Down
2 changes: 1 addition & 1 deletion coral/src/app/features/topics/browse/BrowseTopics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function BrowseTopics() {
<TeamFilter key="team" />,
<EnvironmentFilter
key="environment"
environmentEndpoint={"getAllEnvironmentsForTopicAndAcl"}
environmentsFor={"TOPIC_AND_ACL"}
/>,
<SearchTopicFilter key={"search"} />,
]}
Expand Down
20 changes: 11 additions & 9 deletions coral/src/domain/environment/environment-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const getAllEnvironmentsForTopicAndAcl = async (): Promise<Environment[]> => {
return transformEnvironmentApiResponse(apiResponse);
};

const getEnvironmentsForSchema = async (): Promise<Environment[]> => {
const apiResponse = await api.get<KlawApiResponse<"getEnvs">>(
API_PATHS.getEnvs
);

const filteredEnvs = apiResponse.filter((env) => env.associatedEnv);
console.log(filteredEnvs);
return transformEnvironmentApiResponse(apiResponse);
};

const getPaginatedEnvironmentsForTopicAndAcl = async (
params: KlawApiRequestQueryParameters<"getKafkaEnvsPaginated">
): Promise<EnvironmentPaginatedApiResponse> => {
Expand All @@ -51,14 +61,6 @@ const getEnvironmentsForTopicRequest = async (): Promise<Environment[]> => {
return transformEnvironmentApiResponse(apiResponse);
};

const getAllEnvironmentsForSchema = async (): Promise<Environment[]> => {
const apiResponse = await api.get<KlawApiResponse<"getSchemaRegEnvs">>(
API_PATHS.getSchemaRegEnvs
);

return transformEnvironmentApiResponse(apiResponse);
};

const getPaginatedEnvironmentsForSchema = async (
params: KlawApiRequestQueryParameters<"getSchemaRegEnvsPaginated">
): Promise<EnvironmentPaginatedApiResponse> => {
Expand Down Expand Up @@ -112,9 +114,9 @@ export {
getAllEnvironmentsForTopicAndAcl,
getPaginatedEnvironmentsForTopicAndAcl,
getEnvironmentsForTopicRequest,
getAllEnvironmentsForSchema,
getPaginatedEnvironmentsForSchema,
getAllEnvironmentsForConnector,
getPaginatedEnvironmentsForConnector,
getUpdateEnvStatus,
getEnvironmentsForSchema,
};
2 changes: 0 additions & 2 deletions coral/src/domain/environment/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
getAllEnvironmentsForConnector,
getAllEnvironmentsForSchema,
getAllEnvironmentsForTopicAndAcl,
getEnvironmentsForTopicRequest,
getPaginatedEnvironmentsForConnector,
Expand All @@ -18,7 +17,6 @@ import {
export {
ALL_ENVIRONMENTS_VALUE,
getAllEnvironmentsForConnector,
getAllEnvironmentsForSchema,
getAllEnvironmentsForTopicAndAcl,
getEnvironmentsForTopicRequest,
getPaginatedEnvironmentsForConnector,
Expand Down

0 comments on commit bb96540

Please sign in to comment.