Skip to content

Commit

Permalink
Merge pull request #549 from Krishanx92/main
Browse files Browse the repository at this point in the history
Fix create and publish issue
  • Loading branch information
Krishanx92 authored Feb 20, 2024
2 parents c6e6344 + 0a0431f commit c5b4a38
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,26 @@ function APICreateDefault(props) {
isWebSocket, isAPIProduct, history, intl, multiGateway
} = props;
const { data: settings, isLoading, error: settingsError } = usePublisherSettings();

const [isAvailbaleGateway, setIsAvailableGateway] = useState(false);
const [pageError, setPageError] = useState(null);
useEffect(() => {
if (settingsError) {
setPageError(settingsError.message);
}
}, [settingsError]);

useEffect(() => {
if (settings != null) {
if (settings.gatewayTypes && settings.gatewayTypes.length === 1) {
for (const env of settings.environment) {
if (env.gatewayType === settings.gatewayTypes[0]) {
setIsAvailableGateway(true);
break;
}
}
}
}
}, [settings]);
const [isCreating, setIsCreating] = useState();
const [isPublishing, setIsPublishing] = useState(false);

Expand Down Expand Up @@ -106,6 +119,23 @@ function APICreateDefault(props) {
function handleOnChange(event) {
const { name: action, value } = event.target;
inputsDispatcher({ action, value });
const settingsEnvList = settings && settings.environment;
if (settings && settings.gatewayTypes.length === 2 && (value === 'wso2/synapse' || value === 'wso2/apk')) {
for (const env of settingsEnvList) {
let tmpEnv = '';
if (env.gatewayType === 'APK') {
tmpEnv = 'wso2/apk';
} else if (env.gatewayType === 'Regular') {
tmpEnv = 'wso2/synapse';
}
if (tmpEnv === value) {
setIsAvailableGateway(true);
break;
} else {
setIsAvailableGateway(false);
}
}
}
}

/**
Expand All @@ -131,7 +161,7 @@ function APICreateDefault(props) {

useEffect(() => {
getDefaultCustomProperties();
}, [settings]);
}, [settings]);

/**
*
Expand Down Expand Up @@ -212,7 +242,7 @@ function APICreateDefault(props) {
promisedCreatedAPI = newAPI
.save();
Alert.loading(promisedCreatedAPI, {
loading: 'Creating API...' + apiData.gatewayType,
loading: 'Creating API...',
success: 'API created successfully',
error: (error) => {
console.error(error);
Expand Down Expand Up @@ -273,20 +303,39 @@ function APICreateDefault(props) {
);
return env && env.vhosts[0].host;
};
if (envList && envList.length > 0) {
if (envList.includes('Default') && getFirstVhost('Default')) {
body1.push({
name: 'Default',
displayOnDevportal: true,
vhost: getFirstVhost('Default'),
});
} else if (getFirstVhost(envList[0])) {
body1.push({
name: envList[0],
displayOnDevportal: true,
vhost: getFirstVhost(envList[0]),
});
if (settings.gatewayTypes && settings.gatewayTypes.length === 1) {
if (envList && envList.length > 0) {
if (envList.includes('Default') && getFirstVhost('Default')) {
body1.push({
name: 'Default',
displayOnDevportal: true,
vhost: getFirstVhost('Default'),
});
} else if (getFirstVhost(envList[0])) {
body1.push({
name: envList[0],
displayOnDevportal: true,
vhost: getFirstVhost(envList[0]),
});
}
}
} else {
const envList1 = settings.environment;
envList1.forEach((env) => {
let tmpEnv = '';
if (env.gatewayType === 'APK') {
tmpEnv = 'wso2/apk';
} else if (env.gatewayType === 'Regular') {
tmpEnv = 'wso2/synapse';
}
if (tmpEnv === apiInputs.gatewayType && getFirstVhost(env.name)) {
body1.push({
name: env.name,
displayOnDevportal: true,
vhost: getFirstVhost(env.name),
});
}
});
}
setIsDeploying(true);
const promisedDeployment = restApi.deployRevision(api.id, revisionId, body1);
Expand Down Expand Up @@ -482,7 +531,7 @@ function APICreateDefault(props) {
id='itest-id-apicreatedefault-createnpublish'
variant='contained'
color='primary'
disabled={isDeploying || isRevisioning || !isPublishable
disabled={!isAvailbaleGateway || isDeploying || isRevisioning || !isPublishable
|| isAPICreateDisabled || !apiInputs.isFormValid}
onClick={createAndPublish}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@ export default function Environments() {
const restApi = new API();
const restProductApi = new APIProduct();
const [selectedRevision, setRevision] = useState([]);
const assignGateway = api.gatewayType === "wso2/synapse" ? "Regular" : "APK";
const externalGateways = settings && settings.environment.filter((p) => !p.provider.toLowerCase().includes('wso2'));
const internalGatewaysFiltered = settings && settings.environment.filter((p) =>
p.provider.toLowerCase().includes('wso2'));
const internalGateways = internalGatewaysFiltered && internalGatewaysFiltered.filter((p) =>
settings.gatewayTypes.some((gateway) => p.gatewayType.toLowerCase().includes(gateway.toLowerCase()))
p.gatewayType.toLowerCase() === assignGateway.toLowerCase()
);
const [selectedVhosts, setVhosts] = useState(null);
const [selectedVhostDeploy, setVhostsDeploy] = useState([]);
Expand Down

0 comments on commit c5b4a38

Please sign in to comment.