Skip to content

Commit

Permalink
Merge pull request #483 from Esri/f/dataset-requestOptions
Browse files Browse the repository at this point in the history
pass dataset request options to queryFeatures()
  • Loading branch information
tomwayson authored Jan 5, 2021
2 parents c1d4136 + d28433c commit 98ae133
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cedar-amcharts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
## 1.0.0
- Add tabindex properties to fillInSpec

## 1.0.0-rc.1
Expand Down
8 changes: 7 additions & 1 deletion packages/cedar/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- pass dataset request options to `queryFeatures()`

## [1.0.1]

### Fixed
- make @esri/arcis-rest-* `peerDependencies` of @esri/cedar
### Changed
Expand Down Expand Up @@ -282,7 +287,8 @@ Baseline version.
- Basic interaction events: on, off, clicked
- Map to Chart interaction demos

[Unreleased]: https://github.com/Esri/cedar/compare/v1.0.0...master
[Unreleased]: https://github.com/Esri/cedar/compare/v1.0.1...master
[1.0.1]: https://github.com/Esri/cedar/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/Esri/cedar/compare/v1.0.0-rc.1...v1.0.0
[1.0.0-rc.1]: https://github.com/Esri/cedar/compare/v1.0.0-beta.9...v1.0.0-rc.1
[1.0.0-beta.9]: https://github.com/Esri/cedar/compare/v1.0.0-beta.8...v1.0.0-beta.9
Expand Down
5 changes: 5 additions & 0 deletions packages/cedar/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IRequestOptions } from '@esri/arcgis-rest-request'
import { IFeatureSet } from '@esri/arcgis-rest-types'

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

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/cedar/src/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export function queryDatasets(datasets: IDataset[]) {
datasets.forEach((dataset, i) => {
// only query datasets that don't have inline data
if (dataset.url) {
const { url, name, query, requestOptions } = dataset
// TODO: make name required on datasets, or required if > 1 dataset?
names.push(dataset.name || `dataset${i}`)
names.push(name || `dataset${i}`)

const queryParams = createQueryParams(dataset.query)
const params = { ...(requestOptions && requestOptions.params), ...createQueryParams(query) }
const options: IQueryFeaturesOptions = {
url: dataset.url,
params: queryParams
...requestOptions,
url,
params,
}
if (config.fetch && typeof config.fetch === 'function') {
// we are configured to use a custom fetch implementation
Expand Down
28 changes: 28 additions & 0 deletions packages/cedar/test/query/query.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// NOTE: this is auto-mocked in __mocks__
import { queryFeatures, decodeValues } from '@esri/arcgis-rest-feature-layer'
import {} from 'jest'
import { IDataset } from '../../src/common'
import config from '../../src/config'
import { queryDatasets } from '../../src/query/query'
import { createQueryParams } from '../../src/query/url'
Expand Down Expand Up @@ -88,6 +89,33 @@ describe('when querying datasets', () => {
})
})
})
describe('when that dataset has requestOptions', () => {
const datasets = definitions.bar.datasets
it('should merge them into those passed to queryFeatures', () => {
const httpMethod = 'POST'
const dataset: IDataset = {
...datasets[0],
requestOptions: {
// override default HTTP method
httpMethod,
params: {
// invalid param should NOT be used
f: 'html'
}
}
}
return queryDatasets([ dataset ]).then((datasetsData) => {
// verify that it called queryFeatures once w/ the right parameters
expect(mockQueryFeatures.mock.calls.length).toEqual(1)
const requestOptions = mockQueryFeatures.mock.calls[0][0]
verifyRequestOptions(dataset, requestOptions)
expect(requestOptions.httpMethod).toEqual(httpMethod)
expect(datasetsData).toEqual({
Number_of_SUM: mockQueryResponse
})
})
})
})
})
describe('when multiple datasets', () => {
beforeEach(() => {
Expand Down

0 comments on commit 98ae133

Please sign in to comment.