Skip to content

Commit

Permalink
Add filtering logic to only show AI policies within AI APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 committed Feb 12, 2025
1 parent 8309a06 commit 87eb439
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface GeneralDetailsProps {
version: string | null;
description: string;
applicableFlows: string[];
supportedApiTypes: string[];
supportedApiTypes: string[] | Map<string, string>[];
dispatch?: React.Dispatch<any>;
isViewMode: boolean;
}
Expand Down Expand Up @@ -374,9 +374,11 @@ const GeneralDetails: FC<GeneralDetailsProps> = ({
<Checkbox
name='HTTP'
color='primary'
checked={supportedApiTypes.includes(
'HTTP',
)}
checked={
Array.isArray(supportedApiTypes) &&
supportedApiTypes.every(item => typeof item === 'string') &&
supportedApiTypes.includes('HTTP')
}
id='http-select-check-box'
onChange={handleApiTypeChange}
/>
Expand All @@ -389,9 +391,11 @@ const GeneralDetails: FC<GeneralDetailsProps> = ({
<Checkbox
name='SOAP'
color='primary'
checked={supportedApiTypes.includes(
'SOAP',
)}
checked={
Array.isArray(supportedApiTypes) &&
supportedApiTypes.every(item => typeof item === 'string') &&
supportedApiTypes.includes('SOAP')
}
id='soap-select-check-box'
onChange={handleApiTypeChange}
/>
Expand All @@ -404,9 +408,11 @@ const GeneralDetails: FC<GeneralDetailsProps> = ({
<Checkbox
name='SOAPTOREST'
color='primary'
checked={supportedApiTypes.includes(
'SOAPTOREST',
)}
checked={
Array.isArray(supportedApiTypes) &&
supportedApiTypes.every(item => typeof item === 'string') &&
supportedApiTypes.includes('SOAPTOREST')
}
id='soaptorest-select-check-box'
onChange={handleApiTypeChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Policy = {
displayName: string;
applicableFlows: string[];
supportedGateways: string[];
supportedApiTypes: string[];
supportedApiTypes: string[] | Map<string, string>[];
isAPISpecific: boolean;
supportedGateways: string[];
};
Expand Down Expand Up @@ -60,7 +60,7 @@ export type PolicySpec = {
description: string;
applicableFlows: string[];
supportedGateways: string[];
supportedApiTypes: string[];
supportedApiTypes: string[] | Map<string, string>[];
policyAttributes: PolicySpecAttribute[];
isAPISpecific?: boolean;
md5?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Policy = {
displayName: string;
applicableFlows: string[];
supportedGateways: string[];
supportedApiTypes: string[];
supportedApiTypes: string[] | Map<string, string>[];
isAPISpecific: boolean;
supportedGateways: string[];
};
Expand Down Expand Up @@ -60,7 +60,7 @@ export type PolicySpec = {
description: string;
applicableFlows: string[];
supportedGateways: string[];
supportedApiTypes: string[];
supportedApiTypes: string[] | Map<string, string>[];
policyAttributes: PolicySpecAttribute[];
isAPISpecific?: boolean;
md5?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ const CONSTS = {
id: null,
name: '',
environment: '',
endpointConfig: {},
endpointConfig: {
endpoint_type: 'http',
},
},
ENVIRONMENTS: {
production: 'PRODUCTION',
Expand Down

0 comments on commit 87eb439

Please sign in to comment.