Skip to content

Commit

Permalink
domains is a hash, not an array
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwayson committed Nov 27, 2018
1 parent e44b54c commit 7915607
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
43 changes: 20 additions & 23 deletions docs/examples/bar-domain.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
21 changes: 19 additions & 2 deletions packages/cedar/src/dataset.ts
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
7 changes: 5 additions & 2 deletions packages/cedar/src/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7915607

Please sign in to comment.