-
Notifications
You must be signed in to change notification settings - Fork 3
/
excel-export.ts
25 lines (23 loc) · 1.38 KB
/
excel-export.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type Graphic from 'esri/Graphic'
import { AbstractDataAction, MutableStoreManager, type DataRecordSet, type DataLevel, type DataRecord } from 'jimu-core'
export default class ExportJson extends AbstractDataAction {
// changed according to breaking changes in ExB 1.13: https://developers.arcgis.com/experience-builder/guide/whats-new/#data-action [2024-01-23]
async isSupported (dataSets: DataRecordSet[], dataLevel: DataLevel, widgetId: string): Promise<boolean> {
console.log('ExportJson.isSupported', dataSets, dataLevel, widgetId)
return dataSets[0]?.records.length > 0
}
// TODO: Hidden columns are exported as well. Can we see which ones are hidden in the datasource?
async onExecute (dataSets: DataRecordSet[], dataLevel: DataLevel, widgetId: string): Promise<boolean> {
console.log('ExportJson.onExecute', dataSets, dataLevel, widgetId)
if (dataSets[0]?.records.length > 0) {
// TODO: The following "as any" casts are due to insufficient typings in ExB 1.13. Re-check in future versions.
const features = dataSets.map((drs: DataRecordSet) => drs.records.map((r: DataRecord) => (r as any).feature as Graphic)).flat()
MutableStoreManager.getInstance().updateStateValue(this.widgetId, 'results', {
features: features,
label: (dataSets[0].dataSource as any)?.fetchedSchema?.label
})
return true
}
return false
}
}