-
Notifications
You must be signed in to change notification settings - Fork 201
[Test PR] Implemented API Key For Federated APIs #1338
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
Open
dpiyumal2319
wants to merge
12
commits into
wso2:main
Choose a base branch
from
dpiyumal2319:dasunw-federated-gateway-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff20eb6
- Added plan mapping to the gateway onboarding
dpiyumal2319 0560586
Remove redundant flags
dpiyumal2319 eceff25
Clenup diffs
dpiyumal2319 47430e6
Extracted plan mapping to a separate component
dpiyumal2319 4ecf5c7
Added table for plan mapping
dpiyumal2319 8fb755f
Added missing locale
dpiyumal2319 55fdd19
Removed unrelated ReadOnly flag
dpiyumal2319 5f49924
Removed unrelted change
dpiyumal2319 b76b9a9
Added error signaling for the external plan mapping errors
dpiyumal2319 2f087e8
Removed unrelted change
dpiyumal2319 f95e5f0
Made the gateway plan mapping to look like claim mapping.
dpiyumal2319 ff42c63
Added plan mapping key name derived from the settings
dpiyumal2319 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 hidden or 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 hidden or 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
224 changes: 224 additions & 0 deletions
224
...dmin/src/main/webapp/source/src/app/components/GatewayEnvironments/GatewayPlanMapping.jsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import Box from '@mui/material/Box'; | ||
| import Stack from '@mui/material/Stack'; | ||
| import Table from '@mui/material/Table'; | ||
| import TableBody from '@mui/material/TableBody'; | ||
| import TableCell from '@mui/material/TableCell'; | ||
| import TableContainer from '@mui/material/TableContainer'; | ||
| import TableHead from '@mui/material/TableHead'; | ||
| import TableRow from '@mui/material/TableRow'; | ||
| import TextField from '@mui/material/TextField'; | ||
| import FormLabel from '@mui/material/FormLabel'; | ||
| import FormHelperText from '@mui/material/FormHelperText'; | ||
| import Tooltip from '@mui/material/Tooltip'; | ||
| import HelpOutline from '@mui/icons-material/HelpOutline'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import { FormattedMessage } from 'react-intl'; | ||
|
|
||
| const PLAN_MAPPING_PROPERTY_PREFIX = 'plan_mapping.'; | ||
|
|
||
| /** | ||
| * Gateway plan mapping configuration. | ||
| * @param {Object} props component props. | ||
| * @returns {JSX.Element} rendered gateway plan mapping section. | ||
| */ | ||
| export default function GatewayPlanMapping(props) { | ||
| const { | ||
| gatewayConfiguration, | ||
| additionalProperties = {}, | ||
| setAdditionalProperties = () => {}, | ||
| } = props; | ||
|
|
||
| const leftLabel = gatewayConfiguration?.labels?.left || 'Key'; | ||
| const rightLabel = gatewayConfiguration?.labels?.right || gatewayConfiguration.label || 'Value'; | ||
| const values = Array.isArray(gatewayConfiguration.values) ? gatewayConfiguration.values : []; | ||
| const groupedValues = values.reduce((groups, mappingValue) => { | ||
| if (!mappingValue || typeof mappingValue !== 'object' || !mappingValue.id) { | ||
| return groups; | ||
| } | ||
| const apiType = mappingValue.apiType || 'other'; | ||
| return { | ||
| ...groups, | ||
| [apiType]: [...(groups[apiType] || []), mappingValue], | ||
| }; | ||
| }, {}); | ||
| const groupedValuesForDisplay = { | ||
| ...groupedValues, | ||
| ...(!groupedValues.async && groupedValues.rest ? { async: groupedValues.rest } : {}), | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| const apiTypeOrder = ['rest', 'async', 'ai-api', 'other']; | ||
| const apiTypeLabels = { | ||
| rest: ( | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.apiType.rest' | ||
| defaultMessage='REST APIs' | ||
| /> | ||
| ), | ||
| async: ( | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.apiType.async' | ||
| defaultMessage='Async APIs' | ||
| /> | ||
| ), | ||
| 'ai-api': ( | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.apiType.ai' | ||
| defaultMessage='AI APIs' | ||
| /> | ||
| ), | ||
| other: ( | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.apiType.other' | ||
| defaultMessage='Other APIs' | ||
| /> | ||
| ), | ||
| }; | ||
| const orderedApiTypes = [ | ||
| ...apiTypeOrder.filter((apiType) => groupedValuesForDisplay[apiType]?.length > 0), | ||
| ...Object.keys(groupedValuesForDisplay).filter((apiType) => !apiTypeOrder.includes(apiType)), | ||
| ]; | ||
|
|
||
| const getPlanMappingValue = (localPolicyId) => { | ||
| return additionalProperties[`${PLAN_MAPPING_PROPERTY_PREFIX}${localPolicyId}`] || ''; | ||
| }; | ||
| const tableStyles = { | ||
| '& .MuiTableCell-head': { | ||
| fontWeight: 500, | ||
| color: '#8A94A6', | ||
| fontSize: '0.8rem', | ||
| borderBottom: '1px solid #EEF1F6', | ||
| px: 2, | ||
| py: 1, | ||
| }, | ||
| '& .MuiTableCell-body': { | ||
| fontSize: '0.75rem', | ||
| borderBottom: '1px solid #EEF1F6', | ||
| color: '#2F3441', | ||
| px: 2, | ||
| py: 1.5, | ||
| verticalAlign: 'middle', | ||
| }, | ||
| '& .MuiTableRow-root:last-of-type .MuiTableCell-body': { | ||
| borderBottom: 'none', | ||
| }, | ||
| }; | ||
|
|
||
| return ( | ||
| <Box mt={1}> | ||
| <Stack direction='row' spacing={1} alignItems='center' mb={0.75}> | ||
| {gatewayConfiguration.label && ( | ||
| <FormLabel component='legend'>{gatewayConfiguration.label}</FormLabel> | ||
| )} | ||
| {gatewayConfiguration.tooltip && ( | ||
| <Tooltip title={gatewayConfiguration.tooltip} placement='right-end' interactive> | ||
| <HelpOutline fontSize='small' color='action' /> | ||
| </Tooltip> | ||
| )} | ||
| </Stack> | ||
| <Typography variant='body2' color='text.secondary' sx={{ mb: 2 }}> | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.helper' | ||
| defaultMessage='Map each local subscription plan to the corresponding gateway plan identifier.' | ||
| /> | ||
| </Typography> | ||
| {orderedApiTypes.length === 0 ? ( | ||
| <FormHelperText> | ||
| <FormattedMessage | ||
| id='GatewayEnvironments.PlanMapping.noCompatibleLocalPlans' | ||
| defaultMessage='No local subscription plans match the supported API types of this gateway.' | ||
| /> | ||
| </FormHelperText> | ||
| ) : orderedApiTypes.map((apiType) => ( | ||
| <Box | ||
| key={apiType} | ||
| mb={2} | ||
| sx={{ | ||
| border: (theme) => `1px solid ${theme.palette.divider}`, | ||
| borderRadius: 1, | ||
| overflow: 'hidden', | ||
| backgroundColor: 'background.paper', | ||
| }} | ||
| > | ||
| <Box | ||
| display='flex' | ||
| alignItems='center' | ||
| px={2} | ||
| py={1.25} | ||
| sx={{ backgroundColor: 'action.hover' }} | ||
| > | ||
| <Typography variant='subtitle2'> | ||
| {apiTypeLabels[apiType] || apiType} | ||
| </Typography> | ||
| </Box> | ||
| <TableContainer> | ||
| <Table size='small' sx={tableStyles}> | ||
| <TableHead> | ||
| <TableRow> | ||
| <TableCell>{leftLabel}</TableCell> | ||
| <TableCell>{rightLabel}</TableCell> | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {groupedValuesForDisplay[apiType].map((mappingValue) => ( | ||
| <TableRow key={`${apiType}.${mappingValue.id}`}> | ||
| <TableCell component='th' scope='row'> | ||
| <Typography variant='body2' fontWeight={500}> | ||
| {mappingValue.label || mappingValue.id} | ||
| </Typography> | ||
| </TableCell> | ||
| <TableCell> | ||
| <TextField | ||
| id={`${gatewayConfiguration.name}.${mappingValue.id}`} | ||
| margin='dense' | ||
| name={mappingValue.id} | ||
| fullWidth | ||
| variant='outlined' | ||
| value={getPlanMappingValue(mappingValue.id)} | ||
| onChange={(event) => setAdditionalProperties( | ||
| `${PLAN_MAPPING_PROPERTY_PREFIX}${mappingValue.id}`, | ||
| event.target.value || undefined, | ||
| )} | ||
| placeholder={mappingValue.label || mappingValue.id} | ||
| /> | ||
| </TableCell> | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </TableContainer> | ||
| </Box> | ||
| ))} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| GatewayPlanMapping.propTypes = { | ||
| gatewayConfiguration: PropTypes.shape({ | ||
| name: PropTypes.string, | ||
| label: PropTypes.string, | ||
| tooltip: PropTypes.string, | ||
| labels: PropTypes.shape({ | ||
| left: PropTypes.string, | ||
| right: PropTypes.string, | ||
| }), | ||
| values: PropTypes.arrayOf(PropTypes.oneOfType([ | ||
| PropTypes.string, | ||
| PropTypes.shape({ | ||
| id: PropTypes.string, | ||
| label: PropTypes.string, | ||
| apiType: PropTypes.string, | ||
| }), | ||
| ])), | ||
| }).isRequired, | ||
| additionalProperties: PropTypes.objectOf(PropTypes.oneOfType([ | ||
| PropTypes.string, | ||
| PropTypes.arrayOf(PropTypes.string), | ||
| ])), | ||
| setAdditionalProperties: PropTypes.func, | ||
| }; | ||
|
|
||
| GatewayPlanMapping.defaultProps = { | ||
| additionalProperties: {}, | ||
| setAdditionalProperties: () => {}, | ||
| }; | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.