Skip to content

Commit 755e575

Browse files
authored
Added an input field for a hostname if it was not specified (#1666)
1 parent f214b57 commit 755e575

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/components/operations/operation-details/ko/runtime/operation-console.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
<div class="text-monospace" data-bind="text: urlTemplate, attr: { 'data-method': method }"></div>
3636
<!-- /ko -->
3737

38-
39-
<!-- ko if: $component.hostnameSelectionEnabled -->
38+
<!-- ko if: $component.hostnameSelectionEnabled() || $component.showHostnameInput() -->
4039
<h3>Host</h3>
4140

4241
<div class="row flex flex-row">
@@ -47,11 +46,18 @@ <h3>Host</h3>
4746
</div>
4847
<div class="col-6">
4948
<div class="form-group">
49+
<!-- ko if: $component.hostnameSelectionEnabled -->
5050
<select id="hostname" class="form-control" data-bind="value: $component.selectedHostname">
5151
<!-- ko foreach: { data: $component.hostnames, as: 'hostname' } -->
5252
<option data-bind="value: hostname, text: hostname"></option>
5353
<!-- /ko -->
5454
</select>
55+
<!-- /ko -->
56+
<!-- ko if: $component.showHostnameInput -->
57+
<input id="hostname" type="text" autocomplete="off" class="form-control form-control-sm"
58+
placeholder="hostname" spellcheck="false"
59+
data-bind="event: { keyup: $component.updateRequestSummary }, textInput: $component.selectedHostname">
60+
<!-- /ko -->
5561
</div>
5662
</div>
5763
</div>

src/components/operations/operation-details/ko/runtime/operation-console.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class OperationConsole {
4343
public readonly selectedRepresentation: ko.Observable<ConsoleRepresentation>;
4444
public readonly requestError: ko.Observable<string>;
4545
public readonly codeSample: ko.Observable<string>;
46+
public readonly showHostnameInput: ko.Observable<boolean>;
4647
public readonly selectedHostname: ko.Observable<string>;
4748
public readonly isHostnameWildcarded: ko.Computed<boolean>;
4849
public readonly hostnameSelectionEnabled: ko.Observable<boolean>;
@@ -89,6 +90,7 @@ export class OperationConsole {
8990
this.sendingRequest = ko.observable(false);
9091
this.codeSample = ko.observable();
9192
this.onFileSelect = this.onFileSelect.bind(this);
93+
this.showHostnameInput = ko.observable(false);
9294
this.selectedHostname = ko.observable("");
9395
this.hostnameSelectionEnabled = ko.observable();
9496
this.isHostnameWildcarded = ko.computed(() => this.selectedHostname().includes("*"));
@@ -192,8 +194,14 @@ export class OperationConsole {
192194
const hostnames = this.hostnames();
193195
this.hostnameSelectionEnabled(this.hostnames()?.length > 1);
194196

195-
const hostname = hostnames[0];
196-
this.selectedHostname(hostname);
197+
let hostname = "";
198+
199+
if (hostnames) {
200+
hostname = hostnames[0];
201+
this.selectedHostname(hostname);
202+
} else {
203+
this.showHostnameInput(true);
204+
}
197205

198206
this.hostnameSelectionEnabled(this.hostnames()?.length > 1);
199207
consoleOperation.host.hostname(hostname);

src/components/operations/operation-details/ko/runtime/operation-details.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class OperationDetails {
6767
this.requestUrlSample = ko.computed(() => {
6868

6969
const api = this.api();
70-
const hostname = this.sampleHostname();
70+
const hostname = this.sampleHostname() ?? null;
7171

7272
if ((!this.api() || !this.operation()) && api?.type !== TypeOfApi.graphQL) {
7373
return null;
@@ -83,12 +83,14 @@ export class OperationDetails {
8383

8484
let requestUrl = "";
8585

86-
if (api.type === TypeOfApi.webSocket) {
87-
requestUrl = `${hostname}${Utils.ensureLeadingSlash(operationPath)}`;
88-
} else {
89-
requestUrl = `https://${hostname}${Utils.ensureLeadingSlash(operationPath)}`;
86+
if (hostname && api.type !== TypeOfApi.webSocket) {
87+
requestUrl = 'https://';
9088
}
9189

90+
if (hostname) requestUrl += hostname;
91+
92+
requestUrl += Utils.ensureLeadingSlash(operationPath);
93+
9294
if (api.apiVersion && api.apiVersionSet?.versioningScheme === "Query") {
9395
return Utils.addQueryParameter(requestUrl, api.apiVersionSet.versionQueryName, api.apiVersion);
9496
}
@@ -284,12 +286,10 @@ export class OperationDetails {
284286
public async loadGatewayInfo(apiName: string): Promise<void> {
285287
const hostnames = await this.apiService.getApiHostnames(apiName);
286288

287-
if (hostnames.length === 0) {
288-
throw new Error(`Unable to fetch gateway hostnames.`);
289+
if (hostnames.length !== 0) {
290+
this.sampleHostname(hostnames[0]);
291+
this.hostnames(hostnames);
289292
}
290-
291-
this.sampleHostname(hostnames[0]);
292-
this.hostnames(hostnames);
293293
}
294294

295295
private cleanSelection(): void {

src/models/console/consoleOperation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export class ConsoleOperation {
4545
this.requestUrl = ko.computed(() => {
4646
const protocol = this.api.protocols.indexOf("https") !== -1 ? "https" : "http";
4747
const urlTemplate = this.getRequestPath();
48-
const result = `${protocol}://${this.host.hostname()}${Utils.ensureLeadingSlash(urlTemplate)}`;
48+
let result = this.host.hostname() ? `${protocol}://${this.host.hostname()}` : '';
49+
result += Utils.ensureLeadingSlash(urlTemplate);
4950

5051
return result;
5152
});

0 commit comments

Comments
 (0)