Skip to content

Commit

Permalink
Merge branch 'feature/search-by-coordinates' of https://github.com/Ca…
Browse files Browse the repository at this point in the history
…rtoDB/carto-react into feature/search-by-coordinates
  • Loading branch information
eamador committed Jul 5, 2023
2 parents aeeb418 + b3b92e9 commit db541c7
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

## 2.1

### 2.1.5 (2023-07-05)

- Supporting for `client` parameter for Widgets API calls without passing client as component attribute [#729](https://github.com/CartoDB/carto-react/pull/729)

### 2.1.4 (2023-06-29)

- Add TableCell styles for padding prop [#725](https://github.com/CartoDB/carto-react/pull/725)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "2.1.4"
"version": "2.1.5"
}
23 changes: 11 additions & 12 deletions packages/react-api/__tests__/api/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ describe('model', () => {
expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=table&source=cartobq.public_account.seattle_collisions&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=&filters=%7B%7D&filtersLogicalOperator=AND'
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=table&client=c4react&source=cartobq.public_account.seattle_collisions&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=&filters=%7B%7D&filtersLogicalOperator=AND'
});
});

test('works correctly with a query source that fits GET url length', () => {
const longButStillFittingGetSource = {
...QUERY_SOURCE,
data: 'a'.repeat(1819)
data: 'a'.repeat(1804)
};
executeModel({
model: 'formula',
Expand All @@ -49,14 +49,14 @@ describe('model', () => {
expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: `https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&source=${longButStillFittingGetSource.data}&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=&filters=%7B%7D&filtersLogicalOperator=AND`
url: `https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&client=c4react&source=${longButStillFittingGetSource.data}&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=&filters=%7B%7D&filtersLogicalOperator=AND`
});
});

test('uses POST for when URL length exceeds limit', () => {
const longQuerySource = {
...QUERY_SOURCE,
data: 'a'.repeat(1820)
data: 'a'.repeat(1805)
};

executeModel({ model: 'formula', source: longQuerySource, params: DEFAULT_PARAMS });
Expand All @@ -67,6 +67,7 @@ describe('model', () => {
method: 'POST',
body: JSON.stringify({
type: 'query',
client: 'c4react',
source: longQuerySource.data,
params: DEFAULT_PARAMS,
filters: longQuerySource.filters,
Expand All @@ -87,7 +88,7 @@ describe('model', () => {
expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND'
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&client=c4react&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND'
});
});

Expand All @@ -107,7 +108,7 @@ describe('model', () => {
expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND'
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&client=c4react&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND'
});
});

Expand All @@ -116,14 +117,13 @@ describe('model', () => {
model: 'formula',
source: QUERY_PARAMS_SOURCE,
params: DEFAULT_PARAMS,
spatialFilter: SPATIAL_FILTER,
client: 'unit-test'
spatialFilter: SPATIAL_FILTER
});

expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND&spatialFilters=%7B%22geom%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-84.40640911186557%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C31.358634554371573%5D%5D%5D%7D%7D&client=unit-test'
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&client=c4react&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND&spatialFilters=%7B%22geom%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-84.40640911186557%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C31.358634554371573%5D%5D%5D%7D%7D'
});
});

Expand All @@ -132,14 +132,13 @@ describe('model', () => {
model: 'formula',
source: { ...QUERY_PARAMS_SOURCE, geoColumn: 'abc' },
params: DEFAULT_PARAMS,
spatialFilter: SPATIAL_FILTER,
client: 'unit-test'
spatialFilter: SPATIAL_FILTER
});

expect(mockedMakeCall).toHaveBeenCalledWith({
credentials: TABLE_SOURCE.credentials,
opts: { method: 'GET' },
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND&spatialFilters=%7B%22abc%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-84.40640911186557%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C31.358634554371573%5D%5D%5D%7D%7D&client=unit-test'
url: 'https://gcp-us-east1.api.carto.com/v3/sql/carto-ps-bq-developers/model/formula?type=query&client=c4react&source=SELECT+*+FROM+%60cartobq.public_account.seattle_collisions%60+WHERE+time_column+%3E+%40start+AND+time_column+%3C+%40end&params=%7B%22column%22%3A%22__test__%22%2C%22operation%22%3A%22avg%22%7D&queryParameters=%7B%22start%22%3A%222019-01-01%22%2C%22end%22%3A%222019-01-02%22%7D&filters=%7B%7D&filtersLogicalOperator=AND&spatialFilters=%7B%22abc%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B%5B-84.40640911186557%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C23.809680634191537%5D%2C%5B-78.72111096471372%2C31.358634554371573%5D%2C%5B-84.40640911186557%2C31.358634554371573%5D%5D%5D%7D%7D'
});
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/react-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-api",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Api",
"author": "CARTO Dev Team",
"keywords": [
Expand Down Expand Up @@ -64,9 +64,9 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-core": "^2.1.4",
"@carto/react-redux": "^2.1.4",
"@carto/react-workers": "^2.1.4",
"@carto/react-core": "^2.1.5",
"@carto/react-redux": "^2.1.5",
"@carto/react-workers": "^2.1.5",
"@deck.gl/carto": "^8.9.18",
"@deck.gl/core": "^8.9.18",
"@deck.gl/extensions": "^8.9.18",
Expand Down
10 changes: 3 additions & 7 deletions packages/react-api/src/api/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { checkCredentials, makeCall } from './common';
import { MAP_TYPES, API_VERSIONS } from '@deck.gl/carto/typed';
import { _assert as assert } from '@carto/react-core/';

import { REQUEST_GET_MAX_URL_LENGTH } from '@carto/react-core';
import { REQUEST_GET_MAX_URL_LENGTH, _getClient } from '@carto/react-core';

const AVAILABLE_MODELS = [
'category',
Expand All @@ -26,7 +26,6 @@ const DEFAULT_GEO_COLUMN = 'geom';
* @param { object } props.params - widget's props
* @param { SpatialFilter= } props.spatialFilter - restrict widget calculation to an area
* @param { object= } props.opts - Additional options for the HTTP request
* @param { string } [props.client] - (Optional) Client for metrics
*/
export function executeModel(props) {
assert(props.source, 'executeModel: missing source');
Expand All @@ -40,7 +39,7 @@ export function executeModel(props) {
)}`
);

const { source, model, params, spatialFilter, client, opts } = props;
const { source, model, params, spatialFilter, opts } = props;

checkCredentials(source.credentials);

Expand All @@ -58,6 +57,7 @@ export function executeModel(props) {
: '';
let queryParams = {
type,
client: _getClient(),
source: data,
params: JSON.stringify(params),
queryParameters,
Expand All @@ -76,10 +76,6 @@ export function executeModel(props) {
queryParams.spatialFilters = JSON.stringify(spatialFilters);
}

if (client) {
queryParams.client = client;
}

const urlWithSearchParams = url + '?' + new URLSearchParams(queryParams).toString();
const isGet = urlWithSearchParams.length <= REQUEST_GET_MAX_URL_LENGTH;
if (isGet) {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-auth",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Auth",
"author": "CARTO Dev Team",
"keywords": [
Expand Down Expand Up @@ -64,7 +64,7 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-core": "^2.1.4",
"@carto/react-core": "^2.1.5",
"react": "17.x || 18.x",
"react-dom": "17.x || 18.x"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-basemaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-basemaps",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Basemaps",
"keywords": [
"carto",
Expand Down Expand Up @@ -64,7 +64,7 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-core": "^2.1.4",
"@carto/react-core": "^2.1.5",
"@deck.gl/google-maps": "^8.9.18",
"react": "17.x || 18.x",
"react-dom": "17.x || 18.x"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-core",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Core",
"author": "CARTO Dev Team",
"keywords": [
Expand Down
5 changes: 5 additions & 0 deletions packages/react-core/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ export {
setFlags as _setFeatureFlags,
clearFlags as _clearFeatureFlags
} from './utils/featureFlags';

export {
setClient as _setClient,
getClient as _getClient
} from './utils/clientParameter';
5 changes: 5 additions & 0 deletions packages/react-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ export {
setFlags as _setFeatureFlags,
clearFlags as _clearFeatureFlags
} from './utils/featureFlags';

export {
setClient as _setClient,
getClient as _getClient
} from './utils/clientParameter';
2 changes: 2 additions & 0 deletions packages/react-core/src/utils/clientParameter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export function getClient(): string
export function setClient(c: string): void
10 changes: 10 additions & 0 deletions packages/react-core/src/utils/clientParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Default client
let client = 'c4react';

export function getClient() {
return client;
}

export function setClient(c) {
client = c;
}
6 changes: 3 additions & 3 deletions packages/react-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-redux",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Redux",
"author": "CARTO Dev Team",
"keywords": [
Expand Down Expand Up @@ -63,8 +63,8 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-core": "^2.1.4",
"@carto/react-workers": "^2.1.4",
"@carto/react-core": "^2.1.5",
"@carto/react-workers": "^2.1.5",
"@deck.gl/carto": "^8.9.18",
"@deck.gl/core": "^8.9.18",
"@reduxjs/toolkit": "^1.5.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-ui",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - UI",
"author": "CARTO Dev Team",
"keywords": [
Expand Down Expand Up @@ -78,7 +78,7 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-core": "^2.1.4",
"@carto/react-core": "^2.1.5",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mui/icons-material": "^5.11.16",
Expand Down
12 changes: 6 additions & 6 deletions packages/react-widgets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/react-widgets",
"version": "2.1.4",
"version": "2.1.5",
"description": "CARTO for React - Widgets",
"author": "CARTO Dev Team",
"keywords": [
Expand Down Expand Up @@ -65,11 +65,11 @@
"@babel/runtime": "^7.13.9"
},
"peerDependencies": {
"@carto/react-api": "^2.1.4",
"@carto/react-core": "^2.1.4",
"@carto/react-redux": "^2.1.4",
"@carto/react-ui": "^2.1.4",
"@carto/react-workers": "^2.1.4",
"@carto/react-api": "^2.1.5",
"@carto/react-core": "^2.1.5",
"@carto/react-redux": "^2.1.5",
"@carto/react-ui": "^2.1.5",
"@carto/react-workers": "^2.1.5",
"@deck.gl/core": "^8.9.18",
"@deck.gl/layers": "^8.9.18",
"@emotion/react": "^11.10.6",
Expand Down
3 changes: 1 addition & 2 deletions packages/react-widgets/src/models/CategoryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ function fromLocal(props) {

// From remote
function fromRemote(props) {
const { source, spatialFilter, abortController, client, ...params } = props;
const { source, spatialFilter, abortController, ...params } = props;
const { column, operation, operationColumn } = params;

return _executeModel({
model: 'category',
source,
spatialFilter,
client,
params: {
column,
operation,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-widgets/src/models/FormulaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ function fromLocal(props) {

// From remote
function fromRemote(props) {
const { source, spatialFilter, abortController, client, operationExp, ...params } = props;
const { source, spatialFilter, abortController, operationExp, ...params } = props;
const { column, operation } = params;

return _executeModel({
model: 'formula',
source,
spatialFilter,
client,
params: { column: column ?? '*', operation, operationExp },
opts: { abortController }
}).then((res) => normalizeObjectKeys(res.rows[0]));
Expand Down
3 changes: 1 addition & 2 deletions packages/react-widgets/src/models/RangeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ function fromLocal(props) {

// From remote
function fromRemote(props) {
const { source, abortController, client, ...params } = props;
const { source, abortController, ...params } = props;
const { column } = params;

return _executeModel({
model: 'range',
source,
client,
params: { column },
opts: { abortController }
}).then((res) => normalizeObjectKeys(res.rows[0]));
Expand Down
3 changes: 1 addition & 2 deletions packages/react-widgets/src/models/TableModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ function formatResult(res) {

// From remote
function fromRemote(props) {
const { source, spatialFilter, abortController, client, ...params } = props;
const { source, spatialFilter, abortController, ...params } = props;
const { columns, sortBy, sortDirection } = params;

return _executeModel({
model: 'table',
source,
spatialFilter,
client,
params: { column: columns, sortBy, sortDirection, limit: HARD_LIMIT + 1 },
opts: { abortController }
})
Expand Down
3 changes: 1 addition & 2 deletions packages/react-widgets/src/models/TimeSeriesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ function fromLocal({

// From remote
function fromRemote(props) {
const { source, abortController, spatialFilter, client, ...params } = props;
const { source, abortController, spatialFilter, ...params } = props;
const { column, operationColumn, joinOperation, operation, stepSize } = params;

return _executeModel({
model: 'timeseries',
source,
spatialFilter,
client,
params: {
column,
stepSize,
Expand Down
Loading

0 comments on commit db541c7

Please sign in to comment.