Skip to content

Commit

Permalink
feat(TestRun): show loading idicator only after 150ms
Browse files Browse the repository at this point in the history
  • Loading branch information
harunbleech committed Sep 27, 2024
1 parent 043e2c0 commit 0b1d063
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
6 changes: 2 additions & 4 deletions assets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@

&__icon {
display: flex;
transition: opacity 0.3s, transform 0.3s;
transition: opacity 0.3s;
grid-row: 1 / 1;
grid-column: 1 / 1;
}
Expand All @@ -253,7 +253,7 @@
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, calc(-50% + 5px));
transform: translate(-50%, -50%);
z-index: 1;
visibility: hidden;
opacity: 0;
Expand All @@ -280,13 +280,11 @@

.vrts-action-button__icon {
opacity: 0;
transform: translateY(5px);
}

.vrts-action-button__spinner {
visibility: visible;
opacity: 1;
transform: translate(-50%, -50%);

path {
animation-play-state: running;
Expand Down
8 changes: 6 additions & 2 deletions components/alert-actions/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ class VrtsAlertActions extends window.HTMLElement {
return;
}

$el.setAttribute( 'data-vrts-loading', 'true' );

const action = $el.getAttribute( 'data-vrts-alert-action' );
const id = $el.getAttribute( 'data-vrts-alert-id' );

Expand All @@ -91,6 +89,10 @@ class VrtsAlertActions extends window.HTMLElement {
const restEndpoint = `${ window.vrts_admin_vars.rest_url }/alerts/${ id }/${ action }`;
const method = shouldSetAction ? 'POST' : 'DELETE';

const timeout = setTimeout( () => {
$el.setAttribute( 'data-vrts-loading', 'true' );
}, 150 );

fetch( restEndpoint, {
method,
headers: {
Expand Down Expand Up @@ -126,6 +128,8 @@ class VrtsAlertActions extends window.HTMLElement {
);
}
}

clearTimeout( timeout );
} );
}

Expand Down
19 changes: 14 additions & 5 deletions components/test-run-alerts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ class VrtsTestRunAlerts extends window.HTMLElement {
} );

$el.setAttribute( 'data-vrts-current', 'true' );
$comparisons.setAttribute( 'data-vrts-loading', 'true' );

const timeout = setTimeout( () => {
$comparisons.setAttribute( 'data-vrts-loading', 'true' );
}, 150 );

fetch( href )
.then( ( response ) => {
Expand Down Expand Up @@ -159,6 +162,8 @@ class VrtsTestRunAlerts extends window.HTMLElement {
if ( $newPagination ) {
$pagination.replaceWith( $newPagination );
}

clearTimeout( timeout );
} );
}

Expand All @@ -172,8 +177,6 @@ class VrtsTestRunAlerts extends window.HTMLElement {
return;
}

$el.setAttribute( 'data-vrts-loading', 'true' );

const action = $el.getAttribute( 'data-vrts-test-run-action' );
const id = $el.getAttribute( 'data-vrts-test-run-id' );

Expand All @@ -184,6 +187,10 @@ class VrtsTestRunAlerts extends window.HTMLElement {
const restEndpoint = `${ window.vrts_admin_vars.rest_url }/test-runs/${ id }/${ action }`;
const method = shouldSetAction ? 'POST' : 'DELETE';

const timeout = setTimeout( () => {
$el.setAttribute( 'data-vrts-loading', 'true' );
}, 150 );

fetch( restEndpoint, {
method,
headers: {
Expand All @@ -202,16 +209,18 @@ class VrtsTestRunAlerts extends window.HTMLElement {
shouldSetAction ? 'secondary' : 'primary'
);

const $alert = document.querySelectorAll(
const $alerts = document.querySelectorAll(
'.vrts-test-run-alerts__card'
);

$alert.forEach( ( item ) => {
$alerts.forEach( ( item ) => {
item.setAttribute(
'data-vrts-state',
shouldSetAction ? 'read' : 'unread'
);
} );

clearTimeout( timeout );
} );
}

Expand Down
7 changes: 6 additions & 1 deletion components/test-run-pagination/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class VrtsTestRunPagination extends window.HTMLElement {
} );

$nextAlert.setAttribute( 'data-vrts-current', 'true' );
$comparisons.setAttribute( 'data-vrts-loading', 'true' );

const timeout = setTimeout( () => {
$comparisons.setAttribute( 'data-vrts-loading', 'true' );
}, 150 );

$sidebar.scrollTo( {
top: $nextAlert.offsetTop - 100,
Expand Down Expand Up @@ -86,6 +89,8 @@ class VrtsTestRunPagination extends window.HTMLElement {
if ( $newPagination ) {
this.replaceWith( $newPagination );
}

clearTimeout( timeout );
} );
}

Expand Down

0 comments on commit 0b1d063

Please sign in to comment.