Skip to content

Commit

Permalink
[IMP] web: HOOT - disable stop button temporarily
Browse files Browse the repository at this point in the history
This commit temporarily disables the "Stop" button in the UI after
clicking on it to avoid immediatly re-running the test runner right
after stopping it.

Part-of: #158916
  • Loading branch information
Arcasias committed Mar 28, 2024
1 parent dcb5ed7 commit b77e3d9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion addons/web/static/lib/hoot/ui/hoot_buttons.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @odoo-module */

import { Component, useState, xml } from "@odoo/owl";
import { Test } from "../core/test";
import { refresh, subscribeToURLParams } from "../core/url";
import { HootLink } from "./hoot_link";
import { Test } from "../core/test";

/**
* @typedef {{
Expand All @@ -15,13 +15,21 @@ import { Test } from "../core/test";
//-----------------------------------------------------------------------------

const {
clearTimeout,
Object: { keys: $keys },
setTimeout,
} = globalThis;

//-----------------------------------------------------------------------------
// Internal
//-----------------------------------------------------------------------------

const DISABLE_TIMEOUT = 500;

//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------

/** @extends {Component<HootButtonsProps, import("../hoot").Environment>} */
export class HootButtons extends Component {
static components = { HootLink };
Expand All @@ -35,6 +43,7 @@ export class HootButtons extends Component {
class="flex items-center bg-btn gap-2 px-2 py-1 transition-colors"
t-on-click="onRunClick"
t-att-title="isRunning ? 'Stop (Esc)' : 'Run'"
t-att-disabled="state.disable"
>
<i t-attf-class="fa fa-{{ isRunning ? 'stop' : 'play' }}" />
<span class="hidden sm:inline" t-esc="isRunning ? 'Stop' : 'Run'" />
Expand All @@ -60,9 +69,11 @@ export class HootButtons extends Component {
setup() {
const { runner } = this.env;
this.state = useState({
disable: false,
failed: [],
});
this.runnerState = useState(runner.state);
this.disableTimeout = 0;

runner.__afterPostTest(({ id, status }) => {
if (status === Test.FAILED) {
Expand Down Expand Up @@ -90,6 +101,14 @@ export class HootButtons extends Component {
}
case "running": {
runner.stop();
if (this.disableTimeout) {
clearTimeout(this.disableTimeout);
}
this.state.disable = true;
this.disableTimeout = setTimeout(
() => (this.state.disable = false),
DISABLE_TIMEOUT
);
break;
}
}
Expand Down

0 comments on commit b77e3d9

Please sign in to comment.