Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use alias names #530

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/layer-table/layer-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,8 @@ export class LayerTable {
false, // formatUsingLayerPopup
false, // removeDuplicates
true, // addColumnTitle
fields
fields,
true
);
}

Expand Down
24 changes: 16 additions & 8 deletions src/utils/downloadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ export async function consolidateLabels(
formatUsingLayerPopup = true,
includeHeaderNames = false,
isCSVExport = false,
fields = []
fields = [],
useFieldAliasNames = false
): Promise<string[][]> {
const labelRequests = [];

Object.keys(exportInfos).forEach(k => {
const labelInfo: IExportInfo = exportInfos[k];
labelRequests.push(
_prepareLabels(webmap, labelInfo.layerView?.layer || labelInfo.layer, labelInfo.ids, formatUsingLayerPopup, includeHeaderNames, fields)
_prepareLabels(webmap, labelInfo.layerView?.layer || labelInfo.layer, labelInfo.ids, formatUsingLayerPopup, includeHeaderNames, fields, useFieldAliasNames)
);
if (isCSVExport) {
// add the layer id as a temp value separator that we can use to split values for CSV export
Expand Down Expand Up @@ -162,9 +163,10 @@ export async function downloadCSV(
formatUsingLayerPopup: boolean,
removeDuplicates = false,
addColumnTitle = false,
fields = []
fields = [],
useFieldAliasNames = false
): Promise<void> {
let labels = await consolidateLabels(webmap, exportInfos, formatUsingLayerPopup, addColumnTitle, true, fields);
let labels = await consolidateLabels(webmap, exportInfos, formatUsingLayerPopup, addColumnTitle, true, fields, useFieldAliasNames);
labels = removeDuplicates ? removeDuplicateLabels(labels) : labels;

const layerIds = Object.keys(exportInfos);
Expand Down Expand Up @@ -841,7 +843,8 @@ export async function _prepareLabels(
ids: number[],
formatUsingLayerPopup = true,
includeHeaderNames = false,
fields = []
fields = [],
useFieldAliasNames = false
): Promise<string[][]> {
// Get the label formatting, if any
const labelFormatProps: ILabelFormatProps = await _getLabelFormat(webmap, layer, formatUsingLayerPopup);
Expand Down Expand Up @@ -957,7 +960,7 @@ export async function _prepareLabels(

:
// Export all attributes
await _prepareLabelsFromAll(featureSet, attributeTypes, attributeDomains, includeHeaderNames);
await _prepareLabelsFromAll(featureSet, attributeTypes, attributeDomains, includeHeaderNames, useFieldAliasNames);

return Promise.resolve(labels);
}
Expand All @@ -975,7 +978,8 @@ export async function _prepareLabelsFromAll(
featureSet: __esri.Graphic[],
attributeTypes: IAttributeTypes,
attributeDomains: IAttributeDomains,
includeHeaderNames = false
includeHeaderNames = false,
useFieldAliasNames = false
): Promise<string[][]> {
const [intl] = await loadModules(["esri/intl"]);

Expand All @@ -997,8 +1001,12 @@ export async function _prepareLabelsFromAll(
if (includeHeaderNames) {
const headerNames = [];
const featuresAttrs = featureSet[0].attributes;
const fieldHash = (featureSet[0]?.layer as __esri.FeatureLayer)?.fields.reduce((prev, cur) => {
prev[cur.name] = cur.alias;
return prev;
}, {});
Object.keys(featuresAttrs).forEach(k => {
headerNames.push(k);
headerNames.push(useFieldAliasNames && fieldHash ? fieldHash[k] : k);
});
labels.unshift(headerNames);
}
Expand Down
Loading