-
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
Retrieve spatialDataColumn in TableWidget for its future usage #900
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ]; then | ||
echo "Missing target directory. Usage: $0 <target_dir>" | ||
exit 1 | ||
fi | ||
|
||
SOURCE_DIR="packages" | ||
TARGET_DIR="$1" | ||
|
||
for dir in "$SOURCE_DIR"/*; do | ||
if [ -d "$dir" ]; then | ||
DIR_NAME=$(basename "$dir") | ||
|
||
SOURCE_PATH="$dir/dist" | ||
TARGET_PATH="$TARGET_DIR/$DIR_NAME" | ||
|
||
echo "Copying $SOURCE_PATH to $TARGET_PATH" | ||
cp -r "$SOURCE_PATH" "$TARGET_PATH" | ||
fi | ||
done | ||
|
||
echo "All directories copied successfully!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,33 @@ const AVAILABLE_MODELS = [ | |
|
||
const DEFAULT_GEO_COLUMN = 'geom'; | ||
|
||
const extractSpatialDataFromSource = (source) => { | ||
let spatialDataType = source.spatialDataType; | ||
let spatialDataColumn = source.spatialDataColumn; | ||
|
||
if (!spatialDataType || !spatialDataColumn) { | ||
if (source.geoColumn) { | ||
const parsedGeoColumn = source.geoColumn.split(':'); | ||
if (parsedGeoColumn.length === 2) { | ||
spatialDataType = parsedGeoColumn[0]; | ||
spatialDataColumn = parsedGeoColumn[1]; | ||
} else if (parsedGeoColumn.length === 1) { | ||
spatialDataColumn = parsedGeoColumn[0] || DEFAULT_GEO_COLUMN; | ||
spatialDataType = 'geo'; | ||
} | ||
if (spatialDataType === 'geom') { | ||
// fallback if for some reason someone provided old `geom:$column` | ||
spatialDataType = 'geo'; | ||
} | ||
} else { | ||
spatialDataType = 'geo'; | ||
spatialDataColumn = DEFAULT_GEO_COLUMN; | ||
} | ||
} | ||
|
||
return { spatialDataType, spatialDataColumn }; | ||
}; | ||
|
||
/** | ||
* Execute a SQL model request. | ||
* | ||
|
@@ -56,6 +83,7 @@ export function executeModel(props) { | |
const queryParameters = source.queryParameters | ||
? JSON.stringify(source.queryParameters) | ||
: ''; | ||
|
||
let queryParams = { | ||
type, | ||
client: _getClient(), | ||
|
@@ -67,29 +95,8 @@ export function executeModel(props) { | |
}; | ||
|
||
let spatialFilters; | ||
if (spatialFilter) { | ||
let spatialDataType = source.spatialDataType; | ||
let spatialDataColumn = source.spatialDataColumn; | ||
|
||
if (!spatialDataType || !spatialDataColumn) { | ||
if (source.geoColumn) { | ||
const parsedGeoColumn = source.geoColumn.split(':'); | ||
if (parsedGeoColumn.length === 2) { | ||
spatialDataType = parsedGeoColumn[0]; | ||
spatialDataColumn = parsedGeoColumn[1]; | ||
} else if (parsedGeoColumn.length === 1) { | ||
spatialDataColumn = parsedGeoColumn[0] || DEFAULT_GEO_COLUMN; | ||
spatialDataType = 'geo'; | ||
} | ||
if (spatialDataType === 'geom') { | ||
// fallback if for some reason someone provided old `geom:$column` | ||
spatialDataType = 'geo'; | ||
} | ||
} else { | ||
spatialDataType = 'geo'; | ||
spatialDataColumn = DEFAULT_GEO_COLUMN; | ||
} | ||
} | ||
if (spatialFilter || props.model === 'table') { | ||
const { spatialDataType, spatialDataColumn } = extractSpatialDataFromSource(source); | ||
|
||
// API supports multiple filters, we apply it only to geometry column or spatialDataColumn | ||
spatialFilters = spatialFilter | ||
|
@@ -98,8 +105,10 @@ export function executeModel(props) { | |
} | ||
: undefined; | ||
|
||
queryParams.spatialFilters = JSON.stringify(spatialFilters); | ||
queryParams.spatialDataType = spatialDataType; | ||
if (spatialFilters) queryParams.spatialFilters = JSON.stringify(spatialFilters); | ||
if (spatialDataType) queryParams.spatialDataType = spatialDataType; | ||
if (spatialDataColumn) queryParams.spatialDataColumn = spatialDataColumn; | ||
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. This only specifies which is the |
||
|
||
if (spatialDataType !== 'geo') { | ||
if (source.spatialFiltersResolution !== undefined) { | ||
queryParams.spatialFiltersResolution = source.spatialFiltersResolution; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ import { _FeatureFlags, _hasFeatureFlag } from '@carto/react-core'; | |
* @param {string} props.title - Title to show in the widget header. | ||
* @param {string} props.dataSource - ID of the data source to get the data from. | ||
* @param {Column[]} props.columns - List of data columns to display. | ||
* @param {Column[]} props.hiddenColumnFields - List of data columns to be retrieved, but not displayed. | ||
* @param {Function=} props.onRowClick - Function to handle on click events on rows. | ||
* @param {Function=} [props.onError] - Function to handle error messages from the widget. | ||
* @param {Function=} [props.onStateChange] - Callback to handle state updates of widgets | ||
* @param {object} [props.wrapperProps] - Extra props to pass to [WrapperWidgetUI](https://storybook-react.carto.com/?path=/docs/widgets-wrapperwidgetui--default). | ||
|
@@ -32,10 +34,12 @@ function TableWidget({ | |
title, | ||
dataSource, | ||
columns, | ||
hiddenColumnFields = [], | ||
wrapperProps, | ||
noDataAlertProps, | ||
onError, | ||
onStateChange, | ||
onRowClick, | ||
initialPageSize = 10, | ||
onPageSizeChange, | ||
global, | ||
|
@@ -60,7 +64,7 @@ function TableWidget({ | |
id, | ||
dataSource, | ||
params: { | ||
columns: columns.map((c) => c.field), | ||
columns: [...columns.map((c) => c.field), ...hiddenColumnFields], | ||
sortBy, | ||
sortDirection, | ||
sortByColumnType, | ||
|
@@ -121,6 +125,7 @@ function TableWidget({ | |
height={height} | ||
dense={dense} | ||
isLoading={isLoading} | ||
onRowClick={onRowClick} | ||
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. I've added support for the 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. ok but add a new comment in the parm section please |
||
/> | ||
)} | ||
</WidgetWithAlert> | ||
|
@@ -139,6 +144,7 @@ TableWidget.propTypes = { | |
align: PropTypes.oneOf(['left', 'right']) | ||
}) | ||
).isRequired, | ||
hiddenColumnFields: PropTypes.arrayOf(PropTypes.string), | ||
onError: PropTypes.func, | ||
wrapperProps: PropTypes.object, | ||
noDataAlertProps: PropTypes.object, | ||
|
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.
@zbigg I've added this, as we both sometimes copy&paste content for the seek of pragmatism when developing things on Carto4React and testing them on cloud-native 😄