mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Misc changes to codebase back ported from internal fork - part 2 (#5130)
* Auth: make login url configurable. * More portable image url. * durationHumanize: support for milliseconds. * Sorter: support for custom sort.
This commit is contained in:
@@ -24,6 +24,8 @@ export default class Sorter {
|
||||
|
||||
reverse = false;
|
||||
|
||||
sortByIteratees = null;
|
||||
|
||||
get compiled() {
|
||||
return compile(this.field, this.reverse);
|
||||
}
|
||||
@@ -42,9 +44,10 @@ export default class Sorter {
|
||||
this.reverse = !!value; // cast to boolean
|
||||
}
|
||||
|
||||
constructor({ orderByField, orderByReverse } = {}) {
|
||||
constructor({ orderByField, orderByReverse } = {}, sortByIteratees = undefined) {
|
||||
this.setField(orderByField);
|
||||
this.setReverse(orderByReverse);
|
||||
this.sortByIteratees = sortByIteratees;
|
||||
}
|
||||
|
||||
toggleField(field) {
|
||||
@@ -61,7 +64,8 @@ export default class Sorter {
|
||||
|
||||
sort(items) {
|
||||
if (this.field) {
|
||||
items = sortBy(items, this.field);
|
||||
const customIteratee = this.sortByIteratees && this.sortByIteratees[this.field];
|
||||
items = sortBy(items, customIteratee ? [customIteratee] : this.field);
|
||||
if (this.reverse) {
|
||||
items.reverse();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export const IntervalEnum = {
|
||||
HOURS: "hour",
|
||||
DAYS: "day",
|
||||
WEEKS: "week",
|
||||
MILLISECONDS: "millisecond",
|
||||
};
|
||||
|
||||
export function formatDateTime(value) {
|
||||
@@ -76,12 +77,12 @@ export function pluralize(text, count) {
|
||||
return text + (should ? "s" : "");
|
||||
}
|
||||
|
||||
export function durationHumanize(duration, options = {}) {
|
||||
if (!duration) {
|
||||
export function durationHumanize(durationInSeconds, options = {}) {
|
||||
if (!durationInSeconds) {
|
||||
return "-";
|
||||
}
|
||||
let ret = "";
|
||||
const { interval, count } = secondsToInterval(duration);
|
||||
const { interval, count } = secondsToInterval(durationInSeconds);
|
||||
const rounded = Math.round(count);
|
||||
if (rounded !== 1 || !options.omitSingleValueNumber) {
|
||||
ret = `${rounded} `;
|
||||
|
||||
@@ -213,7 +213,7 @@ function QuerySource(props) {
|
||||
value={ds.id}
|
||||
data-name={ds.name}
|
||||
data-test={`SelectDataSource${ds.id}`}>
|
||||
<img src={`/static/images/db-logos/${ds.type}.png`} width="20" alt={ds.name} />
|
||||
<img src={`static/images/db-logos/${ds.type}.png`} width="20" alt={ds.name} />
|
||||
<span>{ds.name}</span>
|
||||
</Select.Option>
|
||||
))}
|
||||
|
||||
@@ -30,6 +30,10 @@ export const messages = [];
|
||||
const logger = debug("redash:auth");
|
||||
const session = { loaded: false };
|
||||
|
||||
const AuthUrls = {
|
||||
Login: "login",
|
||||
};
|
||||
|
||||
function updateSession(sessionData) {
|
||||
logger("Updating session to be:", sessionData);
|
||||
extend(session, sessionData, { loaded: true });
|
||||
@@ -42,10 +46,13 @@ export const Auth = {
|
||||
isAuthenticated() {
|
||||
return session.loaded && session.user.id;
|
||||
},
|
||||
setLoginUrl(loginUrl) {
|
||||
AuthUrls.Login = loginUrl;
|
||||
},
|
||||
login() {
|
||||
const next = encodeURI(location.url);
|
||||
logger("Calling login with next = %s", next);
|
||||
window.location.href = `login?next=${next}`;
|
||||
window.location.href = `${AuthUrls.Login}?next=${next}`;
|
||||
},
|
||||
logout() {
|
||||
logger("Logout.");
|
||||
|
||||
Reference in New Issue
Block a user