From 87eb4392a03b0d3911f9de192c4a63fd2878ae93 Mon Sep 17 00:00:00 2001 From: Ashera Silva Date: Wed, 12 Feb 2025 15:36:25 +0530 Subject: [PATCH] Add filtering logic to only show AI policies within AI APIs --- .../Apis/Details/Policies/Policies.tsx | 26 +++++++++++++++---- .../Policies/PolicyForm/GeneralDetails.tsx | 26 ++++++++++++------- .../Apis/Details/Policies/Types.d.ts | 4 +-- .../components/Shared/PoliciesUI/Types.d.ts | 4 +-- .../webapp/source/src/app/data/Constants.js | 4 ++- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx index 63711c3d11b..7da252e5d7e 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx @@ -217,11 +217,27 @@ const Policies: React.FC = () => { let filteredCommonPoliciesByAPITypeList = []; if (api.type === "HTTP" || api.type === "SOAP" || api.type === "SOAPTOREST") { - // Get HTTP supported policies - filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter( - (policy: Policy) => policy.supportedApiTypes.includes(api.type)); - filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter( - (policy: Policy) => policy.supportedApiTypes.includes(api.type)); + // Get API policies based on the API type + filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter((policy: Policy) => { + return policy.supportedApiTypes.some((item: any) => { + if (typeof item === 'string') { + return item === api.type; + } else if (typeof item === 'object') { + return item.apiType === api.type && item.subType === api.subtypeConfiguration?.subtype; + } + }); + }); + + // Get common policies based on the API type + filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter((policy: Policy) => { + return policy.supportedApiTypes.some((item: any) => { + if (typeof item === 'string') { + return item === api.type; + } else if (typeof item === 'object') { + return item.apiType === api.type && item.subType === api.subtypeConfiguration?.subtype; + } + }); + }); } setApiPolicies(filteredApiPoliciesByAPITypeList); diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/PolicyForm/GeneralDetails.tsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/PolicyForm/GeneralDetails.tsx index 43e60d6138f..c3b2bbe89d4 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/PolicyForm/GeneralDetails.tsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/PolicyForm/GeneralDetails.tsx @@ -55,7 +55,7 @@ interface GeneralDetailsProps { version: string | null; description: string; applicableFlows: string[]; - supportedApiTypes: string[]; + supportedApiTypes: string[] | Map[]; dispatch?: React.Dispatch; isViewMode: boolean; } @@ -374,9 +374,11 @@ const GeneralDetails: FC = ({ typeof item === 'string') && + supportedApiTypes.includes('HTTP') + } id='http-select-check-box' onChange={handleApiTypeChange} /> @@ -389,9 +391,11 @@ const GeneralDetails: FC = ({ typeof item === 'string') && + supportedApiTypes.includes('SOAP') + } id='soap-select-check-box' onChange={handleApiTypeChange} /> @@ -404,9 +408,11 @@ const GeneralDetails: FC = ({ typeof item === 'string') && + supportedApiTypes.includes('SOAPTOREST') + } id='soaptorest-select-check-box' onChange={handleApiTypeChange} /> diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Types.d.ts b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Types.d.ts index 2f802adc12b..56edb1a1a74 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Types.d.ts +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Types.d.ts @@ -23,7 +23,7 @@ export type Policy = { displayName: string; applicableFlows: string[]; supportedGateways: string[]; - supportedApiTypes: string[]; + supportedApiTypes: string[] | Map[]; isAPISpecific: boolean; supportedGateways: string[]; }; @@ -60,7 +60,7 @@ export type PolicySpec = { description: string; applicableFlows: string[]; supportedGateways: string[]; - supportedApiTypes: string[]; + supportedApiTypes: string[] | Map[]; policyAttributes: PolicySpecAttribute[]; isAPISpecific?: boolean; md5?: string; diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Shared/PoliciesUI/Types.d.ts b/portals/publisher/src/main/webapp/source/src/app/components/Shared/PoliciesUI/Types.d.ts index 91bfd0ee553..062e0ed4df7 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Shared/PoliciesUI/Types.d.ts +++ b/portals/publisher/src/main/webapp/source/src/app/components/Shared/PoliciesUI/Types.d.ts @@ -23,7 +23,7 @@ export type Policy = { displayName: string; applicableFlows: string[]; supportedGateways: string[]; - supportedApiTypes: string[]; + supportedApiTypes: string[] | Map[]; isAPISpecific: boolean; supportedGateways: string[]; }; @@ -60,7 +60,7 @@ export type PolicySpec = { description: string; applicableFlows: string[]; supportedGateways: string[]; - supportedApiTypes: string[]; + supportedApiTypes: string[] | Map[]; policyAttributes: PolicySpecAttribute[]; isAPISpecific?: boolean; md5?: string; diff --git a/portals/publisher/src/main/webapp/source/src/app/data/Constants.js b/portals/publisher/src/main/webapp/source/src/app/data/Constants.js index 9339855971c..826510e63f1 100644 --- a/portals/publisher/src/main/webapp/source/src/app/data/Constants.js +++ b/portals/publisher/src/main/webapp/source/src/app/data/Constants.js @@ -68,7 +68,9 @@ const CONSTS = { id: null, name: '', environment: '', - endpointConfig: {}, + endpointConfig: { + endpoint_type: 'http', + }, }, ENVIRONMENTS: { production: 'PRODUCTION',