Skip to content

Commit 98ae133

Browse files
authored
Merge pull request #483 from Esri/f/dataset-requestOptions
pass dataset request options to queryFeatures()
2 parents c1d4136 + d28433c commit 98ae133

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

packages/cedar-amcharts/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6-
## Unreleased
6+
## 1.0.0
77
- Add tabindex properties to fillInSpec
88

99
## 1.0.0-rc.1

packages/cedar/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Added
9+
- pass dataset request options to `queryFeatures()`
10+
11+
## [1.0.1]
12+
813
### Fixed
914
- make @esri/arcis-rest-* `peerDependencies` of @esri/cedar
1015
### Changed
@@ -282,7 +287,8 @@ Baseline version.
282287
- Basic interaction events: on, off, clicked
283288
- Map to Chart interaction demos
284289

285-
[Unreleased]: https://github.com/Esri/cedar/compare/v1.0.0...master
290+
[Unreleased]: https://github.com/Esri/cedar/compare/v1.0.1...master
291+
[1.0.1]: https://github.com/Esri/cedar/compare/v1.0.0...v1.0.1
286292
[1.0.0]: https://github.com/Esri/cedar/compare/v1.0.0-rc.1...v1.0.0
287293
[1.0.0-rc.1]: https://github.com/Esri/cedar/compare/v1.0.0-beta.9...v1.0.0-rc.1
288294
[1.0.0-beta.9]: https://github.com/Esri/cedar/compare/v1.0.0-beta.8...v1.0.0-beta.9

packages/cedar/src/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IRequestOptions } from '@esri/arcgis-rest-request'
12
import { IFeatureSet } from '@esri/arcgis-rest-types'
23

34
export interface IField {
@@ -72,6 +73,10 @@ export interface IDataset {
7273
* Values in these fields will be decoded using the coded value domain specified.
7374
*/
7475
domains?: IDomains
76+
/**
77+
* Options to use for requests to this dataset. See: https://esri.github.io/arcgis-rest-js/api/request/IRequestOptions/
78+
*/
79+
requestOptions?: IRequestOptions
7580
}
7681

7782
/**

packages/cedar/src/query/query.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ export function queryDatasets(datasets: IDataset[]) {
1717
datasets.forEach((dataset, i) => {
1818
// only query datasets that don't have inline data
1919
if (dataset.url) {
20+
const { url, name, query, requestOptions } = dataset
2021
// TODO: make name required on datasets, or required if > 1 dataset?
21-
names.push(dataset.name || `dataset${i}`)
22+
names.push(name || `dataset${i}`)
2223

23-
const queryParams = createQueryParams(dataset.query)
24+
const params = { ...(requestOptions && requestOptions.params), ...createQueryParams(query) }
2425
const options: IQueryFeaturesOptions = {
25-
url: dataset.url,
26-
params: queryParams
26+
...requestOptions,
27+
url,
28+
params,
2729
}
2830
if (config.fetch && typeof config.fetch === 'function') {
2931
// we are configured to use a custom fetch implementation

packages/cedar/test/query/query.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// NOTE: this is auto-mocked in __mocks__
22
import { queryFeatures, decodeValues } from '@esri/arcgis-rest-feature-layer'
33
import {} from 'jest'
4+
import { IDataset } from '../../src/common'
45
import config from '../../src/config'
56
import { queryDatasets } from '../../src/query/query'
67
import { createQueryParams } from '../../src/query/url'
@@ -88,6 +89,33 @@ describe('when querying datasets', () => {
8889
})
8990
})
9091
})
92+
describe('when that dataset has requestOptions', () => {
93+
const datasets = definitions.bar.datasets
94+
it('should merge them into those passed to queryFeatures', () => {
95+
const httpMethod = 'POST'
96+
const dataset: IDataset = {
97+
...datasets[0],
98+
requestOptions: {
99+
// override default HTTP method
100+
httpMethod,
101+
params: {
102+
// invalid param should NOT be used
103+
f: 'html'
104+
}
105+
}
106+
}
107+
return queryDatasets([ dataset ]).then((datasetsData) => {
108+
// verify that it called queryFeatures once w/ the right parameters
109+
expect(mockQueryFeatures.mock.calls.length).toEqual(1)
110+
const requestOptions = mockQueryFeatures.mock.calls[0][0]
111+
verifyRequestOptions(dataset, requestOptions)
112+
expect(requestOptions.httpMethod).toEqual(httpMethod)
113+
expect(datasetsData).toEqual({
114+
Number_of_SUM: mockQueryResponse
115+
})
116+
})
117+
})
118+
})
91119
})
92120
describe('when multiple datasets', () => {
93121
beforeEach(() => {

0 commit comments

Comments
 (0)