Commit 650ab72c by Torkel Ödegaard Committed by GitHub

Panel: Cancel panel query via loading spinner (#25954)

* Panel: Cancel panel query via loading spinne

* Removed unused icon
parent 83df83fa
......@@ -87,10 +87,16 @@ export class PanelHeader extends Component<Props, State> {
});
};
onCancelQuery = () => {
this.props.panel.getQueryRunner().cancelQuery();
};
private renderLoadingState(): JSX.Element {
return (
<div className="panel-loading">
<Icon className="fa-spin" name="fa fa-spinner" />
<div className="panel-loading" onClick={this.onCancelQuery}>
<Tooltip content="Cancel query">
<Icon className="panel-loading__spinner spin-counter-clock" name="sync" />
</Tooltip>
</div>
);
}
......
......@@ -25,6 +25,7 @@ import {
applyFieldOverrides,
DataConfigSource,
TimeZone,
LoadingState,
} from '@grafana/data';
export interface QueryRunnerOptions<
......@@ -198,6 +199,22 @@ export class PanelQueryRunner {
});
}
cancelQuery() {
if (!this.subscription) {
return;
}
this.subscription.unsubscribe();
// If we have an old result with loading state, send it with done state
if (this.lastResult && this.lastResult.state === LoadingState.Loading) {
this.subject.next({
...this.lastResult,
state: LoadingState.Done,
});
}
}
resendLastResult = () => {
if (this.lastResult) {
this.subject.next(this.lastResult);
......
......@@ -78,6 +78,10 @@ $panel-header-no-title-zindex: 1;
z-index: $panel-header-z-index + 1;
font-size: $font-size-lg;
color: $text-color-weak;
&:hover {
cursor: pointer;
}
}
.panel-empty {
......
......@@ -34,3 +34,16 @@
transition: max-height 250ms ease-in-out;
}
}
@keyframes spin-counter-clock {
0% {
transform: rotate(359deg);
}
100% {
transform: rotate(0deg);
}
}
.spin-counter-clock {
animation: spin-counter-clock 3s infinite linear;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment