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> { ...@@ -87,10 +87,16 @@ export class PanelHeader extends Component<Props, State> {
}); });
}; };
onCancelQuery = () => {
this.props.panel.getQueryRunner().cancelQuery();
};
private renderLoadingState(): JSX.Element { private renderLoadingState(): JSX.Element {
return ( return (
<div className="panel-loading"> <div className="panel-loading" onClick={this.onCancelQuery}>
<Icon className="fa-spin" name="fa fa-spinner" /> <Tooltip content="Cancel query">
<Icon className="panel-loading__spinner spin-counter-clock" name="sync" />
</Tooltip>
</div> </div>
); );
} }
......
...@@ -25,6 +25,7 @@ import { ...@@ -25,6 +25,7 @@ import {
applyFieldOverrides, applyFieldOverrides,
DataConfigSource, DataConfigSource,
TimeZone, TimeZone,
LoadingState,
} from '@grafana/data'; } from '@grafana/data';
export interface QueryRunnerOptions< export interface QueryRunnerOptions<
...@@ -198,6 +199,22 @@ export class PanelQueryRunner { ...@@ -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 = () => { resendLastResult = () => {
if (this.lastResult) { if (this.lastResult) {
this.subject.next(this.lastResult); this.subject.next(this.lastResult);
......
...@@ -78,6 +78,10 @@ $panel-header-no-title-zindex: 1; ...@@ -78,6 +78,10 @@ $panel-header-no-title-zindex: 1;
z-index: $panel-header-z-index + 1; z-index: $panel-header-z-index + 1;
font-size: $font-size-lg; font-size: $font-size-lg;
color: $text-color-weak; color: $text-color-weak;
&:hover {
cursor: pointer;
}
} }
.panel-empty { .panel-empty {
......
...@@ -34,3 +34,16 @@ ...@@ -34,3 +34,16 @@
transition: max-height 250ms ease-in-out; 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