Skip to content

Commit

Permalink
Fix styling errors reportered by restyled
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshiokatsuneo committed Feb 10, 2025
1 parent 3f7b779 commit 2b19010
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions client/app/services/query-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const logger = debug("redash:services:QueryResult");
const filterTypes = ["filter", "multi-filter", "multiFilter"];

function defer() {
const result = { onStatusChange: status => {} };
const result = { onStatusChange: (status) => {} };
result.promise = new Promise((resolve, reject) => {
result.resolve = resolve;
result.reject = reject;
Expand Down Expand Up @@ -40,13 +40,13 @@ function getColumnNameWithoutType(column) {
}

function getColumnFriendlyName(column) {
return getColumnNameWithoutType(column).replace(/(?:^|\s)\S/g, a => a.toUpperCase());
return getColumnNameWithoutType(column).replace(/(?:^|\s)\S/g, (a) => a.toUpperCase());
}

const createOrSaveUrl = data => (data.id ? `api/query_results/${data.id}` : "api/query_results");
const createOrSaveUrl = (data) => (data.id ? `api/query_results/${data.id}` : "api/query_results");
const QueryResultResource = {
get: ({ id }) => axios.get(`api/query_results/${id}`),
post: data => axios.post(createOrSaveUrl(data), data),
post: (data) => axios.post(createOrSaveUrl(data), data),
};

export const ExecutionStatus = {
Expand Down Expand Up @@ -97,11 +97,11 @@ function handleErrorResponse(queryResult, error) {
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}

export function fetchDataFromJob(jobId, interval = 1000) {
return axios.get(`api/jobs/${jobId}`).then(data => {
return axios.get(`api/jobs/${jobId}`).then((data) => {
const status = statuses[data.job.status];
if (status === ExecutionStatus.WAITING || status === ExecutionStatus.PROCESSING) {
return sleep(interval).then(() => fetchDataFromJob(data.job.id));
Expand Down Expand Up @@ -146,7 +146,7 @@ class QueryResult {
// TODO: we should stop manipulating incoming data, and switch to relaying
// on the column type set by the backend. This logic is prone to errors,
// and better be removed. Kept for now, for backward compatability.
each(this.query_result.data.rows, row => {
each(this.query_result.data.rows, (row) => {
forOwn(row, (v, k) => {
let newType = null;
if (isNumber(v)) {
Expand All @@ -173,7 +173,7 @@ class QueryResult {
});
});

each(this.query_result.data.columns, column => {
each(this.query_result.data.columns, (column) => {
column.name = "" + column.name;
if (columnTypes[column.name]) {
if (column.type == null || column.type === "string") {
Expand Down Expand Up @@ -265,14 +265,14 @@ class QueryResult {

getColumnNames() {
if (this.columnNames === undefined && this.query_result.data) {
this.columnNames = this.query_result.data.columns.map(v => v.name);
this.columnNames = this.query_result.data.columns.map((v) => v.name);
}

return this.columnNames;
}

getColumnFriendlyNames() {
return this.getColumnNames().map(col => getColumnFriendlyName(col));
return this.getColumnNames().map((col) => getColumnFriendlyName(col));
}

getTruncated() {
Expand All @@ -286,7 +286,7 @@ class QueryResult {

const filters = [];

this.getColumns().forEach(col => {
this.getColumns().forEach((col) => {
const name = col.name;
const type = name.split("::")[1] || name.split("__")[1];
if (includes(filterTypes, type)) {
Expand All @@ -302,8 +302,8 @@ class QueryResult {
}
}, this);

this.getRawData().forEach(row => {
filters.forEach(filter => {
this.getRawData().forEach((row) => {
filters.forEach((filter) => {
filter.values.push(row[filter.name]);
if (filter.values.length === 1) {
if (filter.multiple) {
Expand All @@ -315,8 +315,8 @@ class QueryResult {
});
});

filters.forEach(filter => {
filter.values = uniqBy(filter.values, v => {
filters.forEach((filter) => {
filter.values = uniqBy(filter.values, (v) => {
if (moment.isMoment(v)) {
return v.unix();
}
Expand Down Expand Up @@ -345,12 +345,12 @@ class QueryResult {

axios
.get(`api/queries/${queryId}/results/${id}.json`)
.then(response => {
.then((response) => {
// Success handler
queryResult.isLoadingResult = false;
queryResult.update(response);
})
.catch(error => {
.catch((error) => {
// Error handler
queryResult.isLoadingResult = false;
handleErrorResponse(queryResult, error);
Expand All @@ -362,10 +362,10 @@ class QueryResult {
loadLatestCachedResult(queryId, parameters) {
axios
.post(`api/queries/${queryId}/results`, { queryId, parameters })
.then(response => {
.then((response) => {
this.update(response);
})
.catch(error => {
.catch((error) => {
handleErrorResponse(this, error);
});
}
Expand All @@ -375,11 +375,11 @@ class QueryResult {
this.deferred.onStatusChange(ExecutionStatus.LOADING_RESULT);

QueryResultResource.get({ id: this.job.query_result_id })
.then(response => {
.then((response) => {
this.update(response);
this.isLoadingResult = false;
})
.catch(error => {
.catch((error) => {
if (tryCount === undefined) {
tryCount = 0;
}
Expand All @@ -394,9 +394,12 @@ class QueryResult {
});
this.isLoadingResult = false;
} else {
setTimeout(() => {
this.loadResult(tryCount + 1);
}, 1000 * Math.pow(2, tryCount));
setTimeout(
() => {
this.loadResult(tryCount + 1);
},
1000 * Math.pow(2, tryCount)
);
}
});
}
Expand All @@ -410,7 +413,7 @@ class QueryResult {
: axios.get(`api/queries/${query}/jobs/${this.job.id}`);

request
.then(jobResponse => {
.then((jobResponse) => {
this.update(jobResponse);

if (this.getStatus() === "processing" && this.job.query_result_id && this.job.query_result_id !== "None") {
Expand All @@ -429,7 +432,7 @@ class QueryResult {
}, waitTime);
}
})
.catch(error => {
.catch((error) => {
logger("Connection error", error);
// TODO: use QueryResultError, or better yet: exception/reject of promise.
this.update({
Expand Down Expand Up @@ -458,14 +461,14 @@ class QueryResult {

axios
.post(`api/queries/${id}/results`, { id, parameters, apply_auto_limit: applyAutoLimit, max_age: maxAge })
.then(response => {
.then((response) => {
queryResult.update(response);

if ("job" in response) {
queryResult.refreshStatus(id, parameters);
}
})
.catch(error => {
.catch((error) => {
handleErrorResponse(queryResult, error);
});

Expand All @@ -488,14 +491,14 @@ class QueryResult {
}

QueryResultResource.post(params)
.then(response => {
.then((response) => {
queryResult.update(response);

if ("job" in response) {
queryResult.refreshStatus(query, parameters);
}
})
.catch(error => {
.catch((error) => {
handleErrorResponse(queryResult, error);
});

Expand Down

0 comments on commit 2b19010

Please sign in to comment.