Skip to content

Commit

Permalink
Remove manual wait for search button
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 13, 2021
1 parent 1499be0 commit 307906e
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 7,867 deletions.
7,906 changes: 56 additions & 7,850 deletions js/package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@babel/runtime": "^7.14.0",
"column-resizer": "^1.3.6",
"core-js": "^3.12.1",
"debounce": "^1.2.1",
"locutus": "^2.0.14",
"lodash.throttle": "^4.1.1",
"mitt": "^2.1.0",
Expand Down
81 changes: 73 additions & 8 deletions js/src/agile-toolkit-ui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* eslint-disable */
/* global _ATKVERSION_:true, __webpack_public_path__:true */
__webpack_public_path__ = window.__atkBundlePublicPath === undefined ? '/public/' : window.__atkBundlePublicPath + '/';

import debounce from 'debounce';
import 'core-js/stable';
import atkSemantic from 'atk-semantic-ui';
import date from 'locutus/php/datetime/date';
Expand All @@ -14,6 +9,11 @@ import panelService from './services/panel.service';
import vueService from './services/vue.service';
import popupService from "./services/popup.service";

/* eslint-disable */
/* global _ATKVERSION_:true, __webpack_public_path__:true */
__webpack_public_path__ = window.__atkBundlePublicPath === undefined ? '/public/' : window.__atkBundlePublicPath + '/';
/* eslint-enable */

const atk = { ...atkSemantic };

// add version function to atk.
Expand All @@ -22,10 +22,75 @@ atk.options = atkOptions;
atk.eventBus = atkEventBus;
atk.utils = atkUtils;

atk.debounce = (fn, value, immediate = false) => {
const timeOut = atk.options.get('debounceTimeout');
return debounce(fn, timeOut !== null ? timeOut : value, immediate);
/* eslint-disable */
/**
* Returns a function, that, as long as it continues to be invoked, will not
* be triggered. The function will be called after it stops being called for
* N milliseconds. If `immediate` is passed, trigger the function on the
* leading edge, instead of the trailing. The function also has a property 'clear'
* that is a function which will clear the timer to prevent previously scheduled executions.
*
* Based on https://github.com/component/debounce/blob/1.2.1/index.js
*
* @param {function} func function to wrap
* @param {number} [wait=100] timeout in ms
* @param {boolean} [immediate=false] whether to execute at the beginning
*/
atk.debounce = function(func, wait, immediate = false){
var timeout, args, context, timestamp, result;
if (null == wait) {
wait = 100;
}

function later() {
var last = Date.now() - timestamp;

if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
context = args = null;
}
}
};

var debounced = function(){
context = this;
args = arguments;
timestamp = Date.now();
var callNow = immediate && !timeout;
if (!timeout) {
timeout = setTimeout(later, wait);
}
if (callNow) {
result = func.apply(context, args);
context = args = null;
}

return result;
};

debounced.clear = function() {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};

debounced.flush = function() {
if (timeout) {
result = func.apply(context, args);
context = args = null;

debounced.clear();
}
};

return debounced;
};
/* eslint-enable */

// Allow to register a plugin with jQuery;
atk.registerPlugin = plugin;
Expand Down
3 changes: 1 addition & 2 deletions js/src/plugins/scroll.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ export default class scroll extends atkPlugin {
*/
addLoader() {
const $parent = this.$inner.parent().hasClass('atk-overflow-auto') ? this.$inner.parent().parent() : this.$inner.parent();
/* eslint-disable */
// eslint-disable-next-line
$parent.append($('<div id="atkScrollLoader"><div class="ui section hidden divider"></div><div class="ui active centered inline loader basic segment"></div></div>'));
/* eslint-enable */
}

/**
Expand Down
2 changes: 1 addition & 1 deletion public/atkjs-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Behat/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function assertNoException(): void

protected function disableDebounce(): void
{
$this->getSession()->executeScript('atk.options.set("debounceTimeout", 20)');
$this->getSession()->executeScript('atk.options.set("debounceTimeout", 2)');
}

/**
Expand Down
5 changes: 2 additions & 3 deletions tests-behat/crud.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ Feature: Crud

Scenario: search
Then I search grid for "united kingdom"
# make sure auto query trigger
And I wait for loading to start in "button.atk-search-button"
# make sure auto query trigger
Then I should see "United Kingdom"

Scenario: edit
Then I press button "Edit"
Then Modal is open with text "Edit Country"
Then I press Modal button "Save"
Then Toast display should contains text "Form Submit"
# make sure search query stick
# make sure search query stick
Then I should see "United Kingdom"

Scenario: delete
Expand Down
1 change: 0 additions & 1 deletion tests-behat/grid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Feature: Grid
Given I am on "collection/grid.php"
Then I search grid for "kingdom"
# make sure auto query trigger
And I wait for loading to start in "button.atk-search-button"
Then I should see "United Kingdom"
Then I press button "Test"
Then Toast display should contains text "United Kingdom"
Expand Down

0 comments on commit 307906e

Please sign in to comment.