A nice CacheLabel React component (#2628)

Introducing a nice component as a label that show when data was
loaded from cache, when the cache was taken (in humanize duration as in
`a few minutes ago`) in a tooltip, and it can act as a button that
can trigger a force-refresh.

While working on it, it became clear that it was going to be hard to
use this component in the Dashboard view since it's not pure React.
I'm planning on refactoring the dashboard view with proper React/Redux
and introducing the CachedLabel component at that point.

While digging around in the Dashboard view I realized that there was a
bunch on unused code around managing timers that was used in explorev1
and decided to rip it out.
This commit is contained in:
Maxime Beauchemin
2017-04-17 09:06:56 -07:00
committed by GitHub
parent 23aeee5a9c
commit 787daf6005
6 changed files with 108 additions and 34 deletions

View File

@@ -56,19 +56,12 @@ const px = function () {
.tooltip();
}
const Slice = function (data, datasource, controller) {
let timer;
const token = $('#token_' + data.slice_id);
const containerId = 'con_' + data.slice_id;
const selector = '#' + containerId;
const container = $(selector);
const sliceId = data.slice_id;
const formData = applyDefaultFormData(data.form_data);
let dttm = 0;
const stopwatch = function () {
dttm += 10;
const num = dttm / 1000;
$('#timer').text(num.toFixed(2) + ' sec');
};
slice = {
data,
formData,
@@ -114,8 +107,6 @@ const px = function () {
},
/* eslint no-shadow: 0 */
always(data) {
clearInterval(timer);
$('#timer').removeClass('btn-warning');
if (data && data.query) {
slice.viewSqlQuery = data.query;
}
@@ -123,13 +114,10 @@ const px = function () {
done(payload) {
Object.assign(data, payload);
clearInterval(timer);
token.find('img.loading').hide();
container.fadeTo(0.5, 1);
container.show();
$('#timer').addClass('label-success');
$('#timer').removeClass('label-warning label-danger');
$('.query-and-save button').removeAttr('disabled');
this.always(data);
controller.done(this);
@@ -173,7 +161,6 @@ const px = function () {
container.html(errHtml);
container.show();
$('span.query').removeClass('disabled');
$('#timer').addClass('btn-danger');
$('.query-and-save button').removeAttr('disabled');
this.always(o);
controller.error(this);
@@ -213,10 +200,6 @@ const px = function () {
token.find('img.loading').show();
container.fadeTo(0.5, 0.25);
container.css('height', this.height());
dttm = 0;
timer = setInterval(stopwatch, 10);
$('#timer').removeClass('label-danger label-success');
$('#timer').addClass('label-warning');
$.getJSON(this.jsonEndpoint(), (queryResponse) => {
try {
vizMap[formData.viz_type](this, queryResponse);