From 76667f910ba01bdbf7cda732e98a995979c2d50a Mon Sep 17 00:00:00 2001 From: hiranyakavishani Date: Thu, 28 Sep 2023 00:17:02 +0530 Subject: [PATCH 1/3] UI fixes for versioning support of API Products --- .../main/webapp/site/public/locales/en.json | 20 ++++- .../webapp/site/public/locales/raw.en.json | 11 ++- .../APIProduct/APIProductCreateWrapper.jsx | 5 +- .../Apis/Create/Components/DefaultAPIForm.jsx | 38 +++++++- .../Configuration/DesignConfigurations.jsx | 11 ++- .../Details/LifeCycle/LifeCycleUpdate.jsx | 9 +- .../Apis/Details/NewVersion/NewVersion.jsx | 88 ++++++++++++------- .../Apis/Details/TryOut/TryOutConsole.jsx | 30 +++---- .../Details/components/APIDetailsTopMenu.jsx | 12 +-- .../components/CreateNewVersionButton.jsx | 8 +- .../src/app/components/Apis/Details/index.jsx | 5 ++ .../APICards/ApiThumbClassic.jsx | 20 ++--- .../source/src/app/data/ScopeValidation.jsx | 1 + .../main/webapp/source/src/app/data/api.js | 36 ++++++-- 14 files changed, 205 insertions(+), 89 deletions(-) diff --git a/portals/publisher/src/main/webapp/site/public/locales/en.json b/portals/publisher/src/main/webapp/site/public/locales/en.json index 0c6833b14dc..93d80e57c01 100644 --- a/portals/publisher/src/main/webapp/site/public/locales/en.json +++ b/portals/publisher/src/main/webapp/site/public/locales/en.json @@ -104,7 +104,7 @@ "Apis.Create.APIProduct.APIProductCreateWrapper.sub.heading": [ { "type": 0, - "value": "Create an API Product by providing a Name, a Context, Resources, and Business Plans (optional)." + "value": "Create an API Product by providing a Name, a Context, a Version, Resources, and Business Plans (optional)." } ], "Apis.Create.AsyncAPI.ApiCreateAsyncAPI.advertiseOnly.warning": [ @@ -225,6 +225,12 @@ "value": "Version" } ], + "Apis.Create.Components.DefaultAPIForm.api.product.version": [ + { + "type": 0, + "value": "Version" + } + ], "Apis.Create.Components.NewTopic.topic.name": [ { "type": 0, @@ -1359,6 +1365,18 @@ "value": "Selected Rate Limiting Policy will be applied to all the requests of this API." } ], + "Apis.Details.APIProduct.NewVersion.NewVersion.error": [ + { + "type": 0, + "value": "Something went wrong while creating a new version!. Error:" + } + ], + "Apis.Details.APIProduct.NewVersion.NewVersion.success": [ + { + "type": 0, + "value": "Successfully created new version" + } + ], "Apis.Details.AccessControl.roles.help": [ { "type": 0, diff --git a/portals/publisher/src/main/webapp/site/public/locales/raw.en.json b/portals/publisher/src/main/webapp/site/public/locales/raw.en.json index aaf9f58c97f..05a50132584 100644 --- a/portals/publisher/src/main/webapp/site/public/locales/raw.en.json +++ b/portals/publisher/src/main/webapp/site/public/locales/raw.en.json @@ -51,7 +51,7 @@ "defaultMessage": "Add Resources" }, "Apis.Create.APIProduct.APIProductCreateWrapper.sub.heading": { - "defaultMessage": "Create an API Product by providing a Name, a Context, Resources, and Business Plans (optional)." + "defaultMessage": "Create an API Product by providing a Name, a Context, a Version, Resources, and Business Plans (optional)." }, "Apis.Create.AsyncAPI.ApiCreateAsyncAPI.advertiseOnly.warning": { "defaultMessage": "API Manager only supports the streaming APIs of types WebSocket, SSE and WebSub. Please create one of the supported types if you want to deploy it in the gateway." @@ -98,6 +98,9 @@ "Apis.Create.Components.DefaultAPIForm.api.product.context": { "defaultMessage": "Context" }, + "Apis.Create.Components.DefaultAPIForm.api.product.version": { + "defaultMessage": "Version" + }, "Apis.Create.Components.DefaultAPIForm.name": { "defaultMessage": "Name" }, @@ -582,6 +585,12 @@ "Apis.Details.APILevelRateLimitingPolicies.components.Configuration.tooltip": { "defaultMessage": "Selected Rate Limiting Policy will be applied to all the requests of this API." }, + "Apis.Details.APIProduct.NewVersion.NewVersion.error": { + "defaultMessage": "Something went wrong while creating a new version!. Error:" + }, + "Apis.Details.APIProduct.NewVersion.NewVersion.success": { + "defaultMessage": "Successfully created new version" + }, "Apis.Details.AccessControl.roles.help": { "defaultMessage": "Enter valid role and press enter" }, diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/APIProduct/APIProductCreateWrapper.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/APIProduct/APIProductCreateWrapper.jsx index 43dae82e9cf..557f5e6d099 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/APIProduct/APIProductCreateWrapper.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/APIProduct/APIProductCreateWrapper.jsx @@ -105,7 +105,7 @@ export default function ApiProductCreateWrapper(props) { @@ -190,11 +190,12 @@ export default function ApiProductCreateWrapper(props) { const createAPIProduct = () => { setCreating(true); const { - name, context, + name, context, version, } = apiInputs; const apiData = { name, context, + version, policies, apis: apiResources, }; diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Components/DefaultAPIForm.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Components/DefaultAPIForm.jsx index 661fdf64f88..1a2a1ed6f3e 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Components/DefaultAPIForm.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Create/Components/DefaultAPIForm.jsx @@ -143,7 +143,7 @@ export default function DefaultAPIForm(props) { // Check the provided API validity on mount, TODO: Better to use Joi schema here ~tmkb useEffect(() => { onValidate(Boolean(api.name) - && (isAPIProduct || Boolean(api.version)) + && (Boolean(api.version)) && Boolean(api.context)); }, []); @@ -154,10 +154,9 @@ export default function DefaultAPIForm(props) { .reduce((acc, cVal) => acc && cVal); // Aggregate the individual validation states // TODO: refactor following redundant validation. // The valid state should available in the above reduced state ~tmkb - // if isAPIProduct gets true version validation has been skipped isFormValid = isFormValid && Boolean(api.name) - && (isAPIProduct || Boolean(api.version)) + && Boolean(api.version) && Boolean(api.context); onValidate(isFormValid, validity); setValidity(newState); @@ -430,7 +429,7 @@ export default function DefaultAPIForm(props) { ) : ( <> - + + + + + * + + )} + name='version' + value={api.version} + onChange={onChange} + InputProps={{ + id: 'itest-id-apiversion-input', + onBlur: ({ target: { value } }) => { + validate('version', value); + }, + }} + InputLabelProps={{ + for: 'itest-id-apiversion-input', + }} + helperText={validity.version && validity.version.message} + margin='normal' + variant='outlined' + /> + )} diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/DesignConfigurations.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/DesignConfigurations.jsx index ce558acbed1..668cf3472ad 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/DesignConfigurations.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/DesignConfigurations.jsx @@ -136,6 +136,11 @@ const useStyles = makeStyles((theme) => ({ * @returns {Object} Deep copy of an object */ function copyAPIConfig(api) { + let isDefaultVersion = false; + // to set isDefaultVersion of migrated APIProducts as true + if (api.apiType === API.CONSTS.APIProduct && api.isDefaultVersion == null) { + isDefaultVersion = true; + } const copiedConfig = { id: api.id, name: api.name, @@ -146,7 +151,7 @@ function copyAPIConfig(api) { responseCachingEnabled: api.responseCachingEnabled, cacheTimeout: api.cacheTimeout, visibility: api.visibility, - isDefaultVersion: api.isDefaultVersion, + isDefaultVersion: api.isDefaultVersion || isDefaultVersion, enableSchemaValidation: api.enableSchemaValidation, accessControlRoles: [...api.accessControlRoles], visibleRoles: [...api.visibleRoles], @@ -562,9 +567,7 @@ export default function DesignConfigurations() { )} - {api.apiType !== API.CONSTS.APIProduct && ( - - )} +