diff --git a/docs/examples/bar-domain.json b/docs/examples/bar-domain.json index fb9d318d..c44ef0c9 100644 --- a/docs/examples/bar-domain.json +++ b/docs/examples/bar-domain.json @@ -7,30 +7,27 @@ "query": { "where": "facname = 'WHITE EAGLE ELEMENTARY' OR facname = 'FRY ELEMENTARY SCHOOL'" }, - "domains": [ - { - "name": "sheltstat", - "domain": { - "type": "codedValue", - "name": "ShelterCode", - "description": "Shelter Codes", - "codedValues": [ - { - "name": "Open", - "code": 1 - }, - { - "name": "Closed", - "code": 2 - }, - { - "name": "Full", - "code": 3 - } - ] - } + "domains": { + "sheltstat": { + "type": "codedValue", + "name": "ShelterCode", + "description": "Shelter Codes", + "codedValues": [ + { + "name": "Open", + "code": 1 + }, + { + "name": "Closed", + "code": 2 + }, + { + "name": "Full", + "code": 3 + } + ] } - ] + } } ], "series": [ diff --git a/packages/cedar/src/dataset.ts b/packages/cedar/src/dataset.ts index b2ea6862..a61f2127 100644 --- a/packages/cedar/src/dataset.ts +++ b/packages/cedar/src/dataset.ts @@ -1,17 +1,34 @@ -import { IFeature, IFeatureSet, IField as IRestField } from '@esri/arcgis-rest-common-types' +import { IFeature, IFeatureSet } from '@esri/arcgis-rest-common-types' export interface IField { field: string, label?: string } +// TODO: move this and IDomain(s) to rest-js +export interface ICodedValue { + name: string, + code: string | number +} + +export interface IDomain { + type: string, + name: string, + description?: string, + codedValues?: ICodedValue[] +} + +export interface IDomains { + [index: string]: IDomain +} + export interface IDataset { name: string, url?: string, data?: IFeatureSet | Array<{}>, query?: {}, join?: string, - domains?: IRestField[] + domains?: IDomains } // TODO: move to series.ts? diff --git a/packages/cedar/src/query/query.ts b/packages/cedar/src/query/query.ts index 9a09add6..f286c653 100644 --- a/packages/cedar/src/query/query.ts +++ b/packages/cedar/src/query/query.ts @@ -33,12 +33,15 @@ export function queryDatasets(datasets: IDataset[]) { requests.push( queryFeatures(options) .then((queryResponse: IQueryFeaturesResponse) => { + const { domains } = dataset + const fields: any[] = domains && Object.keys(domains).map((name) => ({ name, domain: domains[name]})) // for now, we only decode CVDs when an array of fields is passed describing codes and names - if (dataset.domains && dataset.domains.length > 0) { + if (fields && fields.length > 0) { const decodeOptions: IDecodeValuesRequestOptions = { url: options.url, queryResponse, - fields: dataset.domains, + // TODO: decodeValues() should take `domains?: IDomains` as an alternative to `fields?: IField[]` + fields, fetch: config.fetch } return decodeValues(decodeOptions)