Created
July 31, 2018 21:10
-
-
Save asprouse/7201e5391bae0e595c7671a64a2980dd to your computer and use it in GitHub Desktop.
Timber Link Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import queryString from 'query-string'; | |
import {timberAppId, timberConsoleUrl} from '../../config'; | |
function formatDateParam(params) { | |
return name => { | |
let date = params[name]; | |
if (date) { | |
if (!(date instanceof Date)) { | |
date = new Date(date); | |
} | |
params[name] = date.toISOString(); | |
} | |
}; | |
} | |
const dateParams = ['start', 'end', 'date', 'focus']; | |
export function getUserFilter(userId) { | |
return `context.user.id:${userId}`; | |
} | |
export function getConsoleUrl(params = {}) { | |
if (!params.apps) { | |
params.apps = timberAppId; | |
} | |
dateParams.forEach(formatDateParam(params)); | |
return `${timberConsoleUrl}?${queryString.stringify(params)}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment