Skip to content

Commit e745a56

Browse files
authored
Merge pull request wso2#939 from msm1992/main-gateway-ui
Populate custom GW default hostname template by default
2 parents add7107 + 1a81c77 commit e745a56

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditGWEnvironment.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,14 @@ function AddEditGWEnvironment(props) {
185185
}, [permissions]);
186186

187187
useEffect(() => {
188-
setGatewayConfiguration(
189-
settings.gatewayConfiguration.filter((t) => t.type === gatewayType)[0].configurations,
190-
);
188+
const config = settings.gatewayConfiguration.filter((t) => t.type === gatewayType)[0];
189+
if (gatewayType === 'other') {
190+
setGatewayConfiguration([]);
191+
} else {
192+
setGatewayConfiguration(
193+
config.configurations,
194+
);
195+
}
191196
}, [gatewayType]);
192197

193198
let permissionType = '';
@@ -1023,6 +1028,7 @@ function AddEditGWEnvironment(props) {
10231028
initialVhosts={vhosts}
10241029
onVhostChange={onChange}
10251030
gatewayType={gatewayType}
1031+
isEditMode={editMode}
10261032
/>
10271033
</Box>
10281034
</Grid>

portals/admin/src/main/webapp/source/src/app/components/GatewayEnvironments/AddEditVhost.jsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* under the License.
1717
*/
1818

19-
import React, { useEffect, useState } from 'react';
19+
import React, { useEffect, useRef, useState } from 'react';
20+
import { useAppContext } from 'AppComponents/Shared/AppContext';
2021
import { styled } from '@mui/material/styles';
2122
import PropTypes from 'prop-types';
2223
import TextField from '@mui/material/TextField';
@@ -42,13 +43,15 @@ const StyledSpan = styled('span')(({ theme }) => ({ color: theme.palette.error.d
4243
function AddEditVhost(props) {
4344
const intl = useIntl();
4445
const {
45-
onVhostChange, initialVhosts, gatewayType,
46+
onVhostChange, initialVhosts, gatewayType, isEditMode,
4647
} = props;
4748
const [userVhosts, setUserVhosts] = useState([]);
4849
const [id, setId] = useState(0);
4950
const defaultVhost = {
5051
host: '', httpContext: '', httpsPort: 8243, httpPort: 8280, wssPort: 8099, wsPort: 9099, isNew: true,
5152
};
53+
const prevRef = useRef();
54+
const { settings } = useAppContext();
5255

5356
// change handlers
5457
const updateChanges = (key, field, newValue) => {
@@ -142,7 +145,38 @@ function AddEditVhost(props) {
142145
};
143146

144147
useEffect(() => {
145-
if (!isUserVhostsUpdated(userVhosts) && initialVhosts && initialVhosts.length > 0) {
148+
if (prevRef.gatewayType !== gatewayType) {
149+
const config = settings.gatewayConfiguration.filter((t) => t.type === gatewayType)[0];
150+
if (initialVhosts && initialVhosts.length > 0) {
151+
let i = 0;
152+
if (config && !isEditMode) {
153+
const defaultHostnameTemplate = config.defaultHostnameTemplate
154+
? config.defaultHostnameTemplate : '';
155+
setUserVhosts(initialVhosts.map((vhost) => {
156+
const keyedVhost = vhost;
157+
keyedVhost.key = '' + i++;
158+
keyedVhost.host = defaultHostnameTemplate;
159+
return keyedVhost;
160+
}));
161+
} else {
162+
setUserVhosts(initialVhosts.map((vhost) => {
163+
const keyedVhost = vhost;
164+
keyedVhost.key = '' + i++;
165+
return keyedVhost;
166+
}));
167+
}
168+
setId(i);
169+
} else {
170+
setId(id + 1);
171+
const vhost = defaultVhost;
172+
vhost.key = '' + id;
173+
if (config && config.defaultHostnameTemplate) {
174+
vhost.host = config.defaultHostnameTemplate;
175+
}
176+
setUserVhosts([vhost]);
177+
}
178+
prevRef.gatewayType = gatewayType;
179+
} else if (!isUserVhostsUpdated(userVhosts) && initialVhosts && initialVhosts.length > 0) {
146180
let i = 0;
147181
setUserVhosts(initialVhosts.map((vhost) => {
148182
const keyedVhost = vhost;
@@ -151,7 +185,7 @@ function AddEditVhost(props) {
151185
}));
152186
setId(i);
153187
}
154-
}, [initialVhosts]);
188+
}, [initialVhosts, gatewayType]);
155189

156190
let vhostCounter = 1;
157191
return (

0 commit comments

Comments
 (0)