mirror of
https://github.com/getredash/redash.git
synced 2026-03-21 16:00:09 -04:00
* Fix query based param with no results crashing page * Add message for empty dropdown parameters * Handle 500 no results case with empty result set * Cypress: Make sure it shows the message * Use .ant-select-selection to open dropdown
80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
import { isNull, isUndefined, isArray, isEmpty, get, map, join, has } from "lodash";
|
|
import { Query } from "@/services/query";
|
|
import Parameter from "./Parameter";
|
|
|
|
class QueryBasedDropdownParameter extends Parameter {
|
|
constructor(parameter, parentQueryId) {
|
|
super(parameter, parentQueryId);
|
|
this.queryId = parameter.queryId;
|
|
this.multiValuesOptions = parameter.multiValuesOptions;
|
|
this.setValue(parameter.value);
|
|
}
|
|
|
|
normalizeValue(value) {
|
|
if (isUndefined(value) || isNull(value) || (isArray(value) && isEmpty(value))) {
|
|
return null;
|
|
}
|
|
|
|
if (this.multiValuesOptions) {
|
|
value = isArray(value) ? value : [value];
|
|
} else {
|
|
value = isArray(value) ? value[0] : value;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
getExecutionValue(extra = {}) {
|
|
const { joinListValues } = extra;
|
|
if (joinListValues && isArray(this.value)) {
|
|
const separator = get(this.multiValuesOptions, "separator", ",");
|
|
const prefix = get(this.multiValuesOptions, "prefix", "");
|
|
const suffix = get(this.multiValuesOptions, "suffix", "");
|
|
const parameterValues = map(this.value, v => `${prefix}${v}${suffix}`);
|
|
return join(parameterValues, separator);
|
|
}
|
|
return this.value;
|
|
}
|
|
|
|
toUrlParams() {
|
|
const prefix = this.urlPrefix;
|
|
|
|
let urlParam = this.value;
|
|
if (this.multiValuesOptions && isArray(this.value)) {
|
|
urlParam = JSON.stringify(this.value);
|
|
}
|
|
|
|
return {
|
|
[`${prefix}${this.name}`]: !this.isEmpty ? urlParam : null,
|
|
};
|
|
}
|
|
|
|
fromUrlParams(query) {
|
|
const prefix = this.urlPrefix;
|
|
const key = `${prefix}${this.name}`;
|
|
if (has(query, key)) {
|
|
if (this.multiValuesOptions) {
|
|
try {
|
|
const valueFromJson = JSON.parse(query[key]);
|
|
this.setValue(isArray(valueFromJson) ? valueFromJson : query[key]);
|
|
} catch (e) {
|
|
this.setValue(query[key]);
|
|
}
|
|
} else {
|
|
this.setValue(query[key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
loadDropdownValues() {
|
|
if (this.parentQueryId) {
|
|
return Query.associatedDropdown({ queryId: this.parentQueryId, dropdownQueryId: this.queryId }).catch(() =>
|
|
Promise.resolve([])
|
|
);
|
|
}
|
|
|
|
return Query.asDropdown({ id: this.queryId }).catch(Promise.resolve([]));
|
|
}
|
|
}
|
|
|
|
export default QueryBasedDropdownParameter;
|