(asset: TriggerExportProps)
| 36 | !!(context && 'localData' in context) |
| 37 | |
| 38 | export async function triggerExport(asset: TriggerExportProps): Promise<void> { |
| 39 | if (isLocalExport(asset.export_context)) { |
| 40 | try { |
| 41 | downloadBlob( |
| 42 | new Blob([asset.export_context.localData], { type: asset.export_context.mediaType }), |
| 43 | asset.export_context.filename |
| 44 | ) |
| 45 | lemonToast.success('Export complete!') |
| 46 | } catch (e) { |
| 47 | lemonToast.error('Export failed!') |
| 48 | } |
| 49 | } else { |
| 50 | const poller = new Promise(async (resolve, reject) => { |
| 51 | const trackingProperties = { |
| 52 | export_format: asset.export_format, |
| 53 | dashboard: asset.dashboard, |
| 54 | insight: asset.insight, |
| 55 | export_context: asset.export_context, |
| 56 | total_time_ms: 0, |
| 57 | } |
| 58 | const startTime = performance.now() |
| 59 | |
| 60 | try { |
| 61 | let exportedAsset = await api.exports.create({ |
| 62 | export_format: asset.export_format, |
| 63 | dashboard: asset.dashboard, |
| 64 | insight: asset.insight, |
| 65 | export_context: asset.export_context, |
| 66 | }) |
| 67 | |
| 68 | if (!exportedAsset.id) { |
| 69 | reject('Missing export_id from response') |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | let attempts = 0 |
| 74 | |
| 75 | const maxPoll = asset.export_format === ExporterFormat.CSV ? MAX_CSV_POLL : MAX_PNG_POLL |
| 76 | while (attempts < maxPoll) { |
| 77 | attempts++ |
| 78 | |
| 79 | if (exportedAsset.has_content) { |
| 80 | await downloadExportedAsset(exportedAsset) |
| 81 | |
| 82 | trackingProperties.total_time_ms = performance.now() - startTime |
| 83 | posthog.capture('export succeeded', trackingProperties) |
| 84 | |
| 85 | resolve('Export complete') |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | await delay(POLL_DELAY_MS) |
| 90 | |
| 91 | exportedAsset = await api.exports.get(exportedAsset.id) |
| 92 | } |
| 93 | |
| 94 | reject('Content not loaded in time...') |
| 95 | } catch (e: any) { |
no test coverage detected
searching dependent graphs…