-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Global mode to CategoryWidget & PieWidget #370
Changes from 4 commits
1003151
6918c7c
f3772ce
82ada84
cf9cac9
e907327
a7018ff
a8a5c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,55 @@ | ||
import { executeSQL } from '@carto/react-api/'; | ||
import { AggregationTypes } from '@carto/react-core/'; | ||
import { Methods, executeTask } from '@carto/react-workers'; | ||
import { | ||
formatOperationColumn, | ||
formatTableNameWithFilters, | ||
wrapModelCall | ||
} from './utils'; | ||
|
||
export const getCategories = async (props) => { | ||
const { | ||
column, | ||
operationColumn, | ||
operation, | ||
joinOperation, | ||
filters, | ||
filtersLogicalOperator, | ||
dataSource | ||
} = props; | ||
|
||
return executeTask(dataSource, Methods.FEATURES_CATEGORY, { | ||
filters, | ||
filtersLogicalOperator, | ||
export function getCategories(props) { | ||
return wrapModelCall(props, fromLocal, fromRemote); | ||
} | ||
|
||
// From local | ||
function fromLocal(props) { | ||
const { source, column, operationColumn, operation, joinOperation } = props; | ||
|
||
return executeTask(source.id, Methods.FEATURES_CATEGORY, { | ||
filters: source.filters, | ||
filtersLogicalOperator: source.filtersLogicalOperator, | ||
operation, | ||
joinOperation, | ||
column, | ||
operationColumn: operationColumn || column | ||
}); | ||
}; | ||
} | ||
|
||
// From remote | ||
function fromRemote(props) { | ||
const { source, abortController } = props; | ||
const { credentials, connection } = source; | ||
|
||
const query = buildSqlQueryToGetCategories(props); | ||
|
||
return executeSQL({ | ||
credentials, | ||
query, | ||
connection, | ||
opts: { abortController } | ||
}); | ||
} | ||
|
||
function buildSqlQueryToGetCategories(props) { | ||
const { column, operation, operationColumn, joinOperation } = props; | ||
|
||
const selectValueClause = `${operation}(${ | ||
operation === AggregationTypes.COUNT | ||
? '*' | ||
: formatOperationColumn(operationColumn || column, joinOperation) | ||
}) as value`; | ||
|
||
return `SELECT COALESCE(${column}, 'null') as name, ${selectValueClause} FROM ${formatTableNameWithFilters( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, what databases should support this feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any of them. Do you know any incompatibility here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop, but it would be nice to involve Data team in these queries verification. Can you gather them (not just this one) and pass them to @Jesus89 please? |
||
props | ||
)} GROUP BY ${column}`.trim(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change here Sergio?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/CartoDB/carto-react/pull/370/files#diff-b6744b2ddd16d9987012b38f43d5800cd351e453fd471af46f6dbb649801e738R59
As you can see in that line, we define a default value. A default value can only be assigned in destructuring when it's undefined, not null.