Skip to content

Commit

Permalink
Fixed scroll to operation (#2200)
Browse files Browse the repository at this point in the history
* Fixed scroll to operation in operation details

* use id instead of class; fixed for graphql
  • Loading branch information
malincrist authored Jun 5, 2023
1 parent 435f7b8 commit 53bfff2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="animation-fade-in">
<div class="row flex flex-row">
<div class="col-md-11 text-wrap">
<h2 class="operation-name">
<h2 id="operation-name">
<span data-bind="text: operation().displayName"></span>
</h2>
</div>
Expand Down Expand Up @@ -294,7 +294,7 @@ <h3>Definitions</h3>
<!-- ko if: operation -->
<div class="animation-fade-in row flex flex-row">
<div class="col-md-11 text-wrap">
<h2 class="operation-name">
<h2 id="operation-name">
<span data-bind="text: operation().displayName"></span>
</h2>
</div>
Expand Down Expand Up @@ -335,7 +335,7 @@ <h3>Protocol</h3>
<div class="animation-fade-in">
<div class="row flex flex-row">
<div class="col-md-11 text-wrap">
<h2>GraphQL endpoint</h2>
<h2 id="operation-name">GraphQL endpoint</h2>
<span class="monospace" data-bind="text: $component.requestUrlSample"></span>
</div>
<!-- ko if: $component.enableConsole -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class OperationDetails {
public async initialize(): Promise<void> {
const apiName = this.routeHelper.getApiName();
const operationName = this.routeHelper.getOperationName();
const graphName = this.routeHelper.getGraphName();

this.selectedApiName(apiName);
this.selectedOperationName(operationName);
Expand All @@ -158,11 +159,20 @@ export class OperationDetails {
if (operationName) {
await this.loadOperation(apiName, operationName);
}

if (this.enableScrollTo && (operationName || graphName)) {
this.scrollToOperation();
}
}

private async onRouteChange(): Promise<void> {
const apiName = this.routeHelper.getApiName();
const operationName = this.routeHelper.getOperationName();
const graphName = this.routeHelper.getGraphName();

if (this.enableScrollTo && (operationName || graphName)) {
this.scrollToOperation();
}

if (apiName && apiName !== this.selectedApiName()) {
this.selectedApiName(apiName);
Expand Down Expand Up @@ -232,11 +242,6 @@ export class OperationDetails {
this.tags(operationTags.map(tag => tag.name));

this.working(false);

if (this.enableScrollTo) {
const headerElement = document.querySelector(".operation-header");
headerElement && headerElement.scrollIntoView({ behavior: "smooth", block: "start", inline: "start" });
}
}

public async loadDefinitions(operation: Operation): Promise<void> {
Expand Down Expand Up @@ -423,6 +428,11 @@ export class OperationDetails {
return this.routeHelper.getDefinitionAnchor(apiName, operationName, definition.name);
}

private scrollToOperation() {
const headerElement = document.getElementById("operation-name");
headerElement && headerElement.scrollIntoView({ behavior: "smooth", block: "start", inline: "start" });
}

@OnDestroyed()
public dispose(): void {
this.router.removeRouteChangeListener(this.onRouteChange);
Expand Down

0 comments on commit 53bfff2

Please sign in to comment.