(currentApp, path, prependMountPath = false)
| 1 | const MOUNT_PATH = window.PARSE_DASHBOARD_PATH; |
| 2 | |
| 3 | export default function generatePath(currentApp, path, prependMountPath = false) { |
| 4 | |
| 5 | const urlObj = new URL(path, window.location.origin); |
| 6 | const params = new URLSearchParams(urlObj.search); |
| 7 | |
| 8 | const filters = JSON.parse(params.get('filters')) |
| 9 | |
| 10 | if (filters) { |
| 11 | for (let i = 0; i < filters.length; i++) { |
| 12 | const filter = filters[i]; |
| 13 | if (filter.compareTo?.__type === 'RelativeDate') { |
| 14 | const date = new Date(); |
| 15 | date.setTime(date.getTime() + filter.compareTo.value * 1000); |
| 16 | filter.compareTo = { |
| 17 | __type: 'Date', |
| 18 | iso: date.toISOString(), |
| 19 | } |
| 20 | filters[i] = filter; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | params.set('filters', JSON.stringify(filters)); |
| 25 | urlObj.search = params.toString(); |
| 26 | |
| 27 | path = urlObj.toString().split(window.location.origin)[1].substring(1); |
| 28 | } |
| 29 | |
| 30 | if (prependMountPath && MOUNT_PATH) { |
| 31 | return `${MOUNT_PATH}apps/${currentApp.slug}/${path}`; |
| 32 | } |
| 33 | return `/apps/${currentApp.slug}/${path}`; |
| 34 | } |
no test coverage detected