-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI implementation for allowing to have api policy and a common policy with same name and same version #809
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a97063f
UI implementation for allowing to have api policy and a common policy…
RusJaI 4fa4dab
Fix compilation errors and missing changes from pulled changes
RusJaI e297577
fix appearance of the policy list
RusJaI 8a9e6ae
Address review comments
RusJaI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,9 @@ const Policies: React.FC = () => { | |
|
||
const [api, updateAPI] = useAPI(); | ||
const [updating, setUpdating] = useState(false); | ||
const [policies, setPolicies] = useState<Policy[] | null>(null); | ||
const [apiPolicies, setApiPolicies] = useState<Policy[] | null>(null); | ||
const [commonPolicies, setCommonPolicies] = useState<Policy[] | null>(null); | ||
const [policies, setPolicies] = useState<Policy[]>([]); | ||
const [allPolicies, setAllPolicies] = useState<PolicySpec[] | null>(null); | ||
const [expandedResource, setExpandedResource] = useState<string | null>(null); | ||
const [isChoreoConnectEnabled, setIsChoreoConnectEnabled] = useState(api.gatewayType === 'wso2/apk'); | ||
|
@@ -175,53 +177,83 @@ const Policies: React.FC = () => { | |
const commonPoliciesPromise = API.getCommonOperationPolicies(); | ||
Promise.all([apiPoliciesPromise, commonPoliciesPromise]).then((response) => { | ||
const [apiPoliciesResponse, commonPoliciesResponse] = response; | ||
const apiSpecificPolicies = apiPoliciesResponse.body.list; | ||
const commonPolicies = commonPoliciesResponse.body.list; | ||
const mergedList = [...commonPolicies, ...apiSpecificPolicies]; | ||
const apiSpecificPoliciesList = apiPoliciesResponse.body.list; | ||
const commonPoliciesList = commonPoliciesResponse.body.list; | ||
const mergedList = [...commonPoliciesList, ...apiSpecificPoliciesList]; | ||
|
||
// Get all common policies and API specific policies | ||
setAllPolicies(mergedList); | ||
|
||
let unionByPolicyDisplayName; | ||
let apiPolicyByPolicyDisplayName; | ||
let commonPolicyByPolicyDisplayName; | ||
if (showMultiVersionPolicies) { | ||
// Get the union of policies depending on the policy display name and version | ||
unionByPolicyDisplayName = [...mergedList | ||
.reduce((map, obj) => map.set(obj.name + obj.version, obj), new Map()).values()]; | ||
// Get the policies depending on the policy display name and version | ||
apiPolicyByPolicyDisplayName = [...apiSpecificPoliciesList | ||
.reduce((map: Map<string, Policy>, obj: Policy) => | ||
map.set(obj.name + obj.version, obj), new Map()).values()]; | ||
commonPolicyByPolicyDisplayName = [...commonPoliciesList | ||
.reduce((map: Map<string, Policy>, obj: Policy) => | ||
map.set(obj.name + obj.version, obj), new Map()).values()]; | ||
} else { | ||
// Get the union of policies depending on the policy display name | ||
unionByPolicyDisplayName = [...mergedList | ||
.reduce((map, obj) => map.set(obj.name, obj), new Map()).values()]; | ||
// Get the policies depending on the policy display name | ||
apiPolicyByPolicyDisplayName = [...apiSpecificPoliciesList | ||
.reduce((map: Map<string, Policy>, obj: Policy) => | ||
map.set(obj.name, obj), new Map()).values()]; | ||
commonPolicyByPolicyDisplayName = [...commonPoliciesList | ||
.reduce((map: Map<string, Policy>, obj: Policy) => | ||
map.set(obj.name, obj), new Map()).values()]; | ||
} | ||
unionByPolicyDisplayName.sort( | ||
apiPolicyByPolicyDisplayName.sort( | ||
(a: Policy, b: Policy) => a.name.localeCompare(b.name)) | ||
commonPolicyByPolicyDisplayName.sort( | ||
(a: Policy, b: Policy) => a.name.localeCompare(b.name)) | ||
|
||
let filteredApiPolicyByGatewayTypeList = null; | ||
let filteredCommonPolicyByGatewayTypeList = null; | ||
|
||
let filteredByGatewayTypeList = null; | ||
if (!isChoreoConnectEnabled) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified as, let gatewayType = isChoreoConnectEnabled ? 'ChoreoConnect' : 'Synapse';
// Get relevant gateway supported policies
filteredApiPolicyByGatewayTypeList = apiPolicyByPolicyDisplayName.filter(
(policy: Policy) => policy.supportedGateways.includes(gatewayType));
filteredCommonPolicyByGatewayTypeList = commonPolicyByPolicyDisplayName.filter(
(policy: Policy) => policy.supportedGateways.includes(gatewayType)); |
||
// Get synpase gateway supported policies | ||
filteredByGatewayTypeList = unionByPolicyDisplayName.filter( | ||
filteredApiPolicyByGatewayTypeList = apiPolicyByPolicyDisplayName.filter( | ||
(policy: Policy) => policy.supportedGateways.includes('Synapse')); | ||
filteredCommonPolicyByGatewayTypeList = commonPolicyByPolicyDisplayName.filter( | ||
(policy: Policy) => policy.supportedGateways.includes('Synapse')); | ||
} else { | ||
// Get CC gateway supported policies | ||
filteredByGatewayTypeList = unionByPolicyDisplayName.filter( | ||
filteredApiPolicyByGatewayTypeList = apiPolicyByPolicyDisplayName.filter( | ||
(policy: Policy) => policy.supportedGateways.includes('ChoreoConnect')); | ||
filteredCommonPolicyByGatewayTypeList = commonPolicyByPolicyDisplayName.filter( | ||
(policy: Policy) => policy.supportedGateways.includes('ChoreoConnect')); | ||
} | ||
|
||
let filteredByAPITypeList = null; | ||
let filteredApiPoliciesByAPITypeList = []; | ||
let filteredCommonPoliciesByAPITypeList = []; | ||
|
||
if (api.type === "HTTP") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplify as, if (api.type === 'HTTP' || api.type === 'SOAP' || api.type === 'SOAPTOREST') {
// Get HTTP, SOAP and SOAP to REST supported policies
filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter(
(policy: Policy) => policy.supportedApiTypes.includes(api.type));
filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter(
(policy: Policy) => policy.supportedApiTypes.includes(api.type));
} |
||
// Get HTTP supported policies | ||
filteredByAPITypeList = filteredByGatewayTypeList.filter( | ||
filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('HTTP')); | ||
filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('HTTP')); | ||
} else if (api.type === "SOAP"){ | ||
// Get SOAP supported policies | ||
filteredByAPITypeList = filteredByGatewayTypeList.filter( | ||
filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('SOAP')); | ||
filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('SOAP')); | ||
} else if (api.type === "SOAPTOREST"){ | ||
// Get SOAP to REST supported policies | ||
filteredByAPITypeList = filteredByGatewayTypeList.filter( | ||
filteredApiPoliciesByAPITypeList = filteredApiPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('SOAPTOREST')); | ||
filteredCommonPoliciesByAPITypeList = filteredCommonPolicyByGatewayTypeList.filter( | ||
(policy: Policy) => policy.supportedApiTypes.includes('SOAPTOREST')); | ||
} | ||
|
||
setPolicies(filteredByAPITypeList); | ||
setApiPolicies(filteredApiPoliciesByAPITypeList); | ||
setCommonPolicies(filteredCommonPoliciesByAPITypeList); | ||
const combinedPolicyList = [...filteredCommonPoliciesByAPITypeList, ...filteredApiPoliciesByAPITypeList]; | ||
combinedPolicyList.sort( | ||
(a: Policy, b: Policy) => a.name.localeCompare(b.name)) | ||
setPolicies(combinedPolicyList); | ||
|
||
}).catch((error) => { | ||
console.error(error); | ||
|
@@ -498,7 +530,7 @@ const Policies: React.FC = () => { | |
], | ||
); | ||
|
||
if (!policies || !openAPISpec || updating) { | ||
if (!apiPolicies || !commonPolicies || !openAPISpec || updating) { | ||
return <Progress per={90} message='Loading Policies ...' /> | ||
} | ||
|
||
|
@@ -597,7 +629,8 @@ const Policies: React.FC = () => { | |
</Box> | ||
<Box width='35%' p={1}> | ||
<PolicyList | ||
policyList={policies} | ||
apiPolicyList={apiPolicies} | ||
commonPolicyList={commonPolicies} | ||
fetchPolicies={fetchPolicies} | ||
isChoreoConnectEnabled={isChoreoConnectEnabled} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as follows.