UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.55 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{isSome as e}from"../../../core/arrayUtils.js";import{createFieldInfos as i}from"../../../support/popupUtils.js";import t from"../../../tables/AttributeTableTemplate.js";import l from"../../../tables/elements/AttributeTableAttachmentElement.js";import r from"../../../tables/elements/AttributeTableFieldElement.js";import n from"../../../tables/elements/AttributeTableGroupElement.js";import o from"../../../tables/elements/AttributeTableRelationshipElement.js";import s from"../../../tables/support/FieldOrder.js";import a from"./AttachmentsColumnTemplate.js";import{isGroupColumn as d,isFieldColumn as m,isRelationshipColumn as p,isAttachmentsColumn as f}from"./columnUtils.js";import c from"./FieldColumnTemplate.js";import u from"./GroupColumnTemplate.js";import h from"./RelationshipColumnTemplate.js";import b from"./TableTemplate.js";import{isIFeatureTableSupportedLayer as w,isIFeatureTableSupportedLayerWithAttachments as y,isIFeatureTableSupportedLayerWithRelationships as T,hasTemplateForField as j}from"./tableUtils.js";function v(i,t){const l=[];return i?.forEach((i=>{const{description:r,label:n,type:o}=i;if("group"===o){const o=i.elements.map((e=>E(e,t))).filter(e);if(!o?.length)return;l.push(new u({description:r,columnTemplates:o,label:n}))}else{const e=E(i,t);if(!e)return;l.push(e)}})),l}function E(e,i){const{description:t,label:l,type:r}=e;if("field"===r){const r=e.fieldName??void 0,n=i.findIndex((e=>e.field&&e.field===r)),o=n>-1?i.at(n)?.order:void 0;return new c({description:t,direction:o,fieldName:r,initialSortPriority:n,label:l})}return"attachment"===r?new a({description:t,label:l}):"relationship"===r?new h({description:t,label:l,relationshipId:e.relationshipId}):void 0}function F(i){const t=[];return i.forEach((i=>{const{hidden:l}=i;if(d(i)){if(l)return;const r=i.columns?.map((e=>N(e))).filter(e);if(!r?.length)return;t.push(new n({elements:r}))}else{const e=N(i);if(!e)return;t.push(e)}})),t}function N(e){const{fieldName:i,hidden:t}=e;if(m(e)){if(!t)return new r({fieldName:i})}else if(p(e)){if(!t)return new o({relationshipId:e.relationshipId})}else if(f(e)&&!t)return new l}async function x({layer:e,excludeAttachments:n,excludeRelationships:s,excludedFieldTypesOverride:a}){const d=[],m=[];if(!e||!w(e))return new t;await e.load();const p=i(e,{...a&&{ignoreFieldTypes:a},sortDisabled:!0});for(const{visible:i,fieldName:t}of p)i&&d.push(new r({fieldName:t}));return y(e)&&!0!==n&&d.push(new l),T(e)&&!0!==s&&e.relationships?.forEach((e=>{d.push(new o({relationshipId:e.id}))})),new t({elements:d,orderByFields:m})}async function A(e){const{excludeAttachments:t,excludeRelationships:l,layer:r,excludedFieldTypesOverride:n}=e,o=[];await r.load();return i(r,{...n&&{ignoreFieldTypes:n},sortDisabled:!0}).forEach((({fieldName:e,format:i,label:t,visible:l})=>{null!=e&&o.push(new c({fieldName:e,format:i,label:t,visible:l}))})),y(r)&&!0!==t&&o.push(new a),T(r)&&!0!==l&&r.relationships?.forEach((({id:e})=>{o.push(new h({relationshipId:e}))})),new b({columnTemplates:o})}async function I(e){const{layer:t,template:l,includeHiddenFields:r,excludedFieldTypesOverride:n}=e,o=l.orderByFields??[],s=v(l.elements,o);if(r){await t.load();i(t,{...n&&{ignoreFieldTypes:n},sortDisabled:!0}).forEach((e=>{if(!e.fieldName)return;const{fieldName:i,label:t}=e;if(!j(i,s)){const e=o.findIndex((e=>e.field&&e.field===i)),l=e>-1?o.at(e)?.order:void 0;s.push(new c({direction:l,fieldName:i,initialSortPriority:e,label:t,visible:!1}))}})),y(t)&&!s.some((e=>"attachment"===e.type))&&s.push(new a({visible:!1})),T(t)&&t.relationships?.forEach((({id:e})=>{s.some((i=>"relationship"===i.type&&i.relationshipId===e))||s.push(new h({relationshipId:e,visible:!1}))}))}return new b({columnTemplates:s})}function g(e,i,t=!0){const{allColumns:l,columns:r}=e,n=[],o=F(r.toArray());e.activeSortOrders.forEach((({fieldName:e,direction:i})=>{e&&i&&n.push(new s({field:e,order:i}))}));return l.filter((e=>null!=e.direction&&(!e.hidden||t))).forEach((({fieldName:e,direction:i})=>{const t=n.find((i=>i.field===e));i&&!t&&n.push(new s({field:e,order:i}))})),i.elements=o,i.orderByFields=n,i}export{F as createAttributeTableElements,x as createAttributeTableTemplateFromLayer,v as createColumnTemplates,N as createNestedAttributeTableElement,E as createNestedColumnTemplate,I as createTableTemplateFromAttributeTableTemplate,A as createTableTemplateFromLayer,g as syncAttributeTableTemplateWithTable};