-
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
Merged
Clebal
merged 8 commits into
feature/sc-219448/formulawidget-remote-mode-for-global
from
feature/sc-219449/categorywidget-piewidget-global-remote-mode
Apr 19, 2022
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1003151
CategoryWidget PieWidget global remote mode [sc-219449]
6918c7c
Fix test name
f3772ce
Fix minor bug when using count operation with a nullable column
82ada84
Fix tests
cf9cac9
Merge branch 'feature/sc-219448/formulawidget-remote-mode-for-global'…
e907327
Merge branch 'feature/sc-219448/formulawidget-remote-mode-for-global'…
a7018ff
Update CHANGELOG.md
a8a5c1b
Add Global mode to HistogramWidget (#371)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 76 additions & 35 deletions
111
packages/react-widgets/__tests__/models/CategoryModel.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,53 @@ | ||
import { executeSQL } from '@carto/react-api/'; | ||
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}(${formatOperationColumn( | ||
operationColumn || column, | ||
joinOperation | ||
)}) as value`; | ||
|
||
return `SELECT ${column} as name, ${selectValueClause} FROM ${formatTableNameWithFilters( | ||
props | ||
)} GROUP BY ${column}`.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.