Skip to content
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 support for stringSearch to Table Widget #902

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix HistogramWidget with one non-zero bucket [#901](https://github.com/CartoDB/carto-react/pull/901)
- Spatial Index Sources use remote widgets calculation [#898](https://github.com/CartoDB/carto-react/pull/898)
- Support for `hiddenColumnFields` parameter and `onRowClick` handler for Table Widget [#900](https://github.com/CartoDB/carto-react/pull/900)
- Support for `searchText` and `searchColumn` for Table Widget [#900](https://github.com/CartoDB/carto-react/pull/902)

## 3.0.0

Expand Down
2 changes: 1 addition & 1 deletion packages/react-api/src/api/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function executeModel(props) {
source: data,
params: JSON.stringify(params),
queryParameters,
filters: JSON.stringify(filters),
filters: JSON.stringify({ ...filters, ...props.searchFilter }),
filtersLogicalOperator
};

Expand Down
3 changes: 2 additions & 1 deletion packages/react-widgets/src/models/TableModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ function formatResult(res) {

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

return _executeModel({
model: 'table',
source,
spatialFilter,
searchFilter,
params: {
column: columns,
sortBy,
Expand Down
10 changes: 10 additions & 0 deletions packages/react-widgets/src/widgets/TableWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { _FeatureFlags, _hasFeatureFlag } from '@carto/react-core';
* @param {boolean=} [props.stableHeight] - If specified, error and no-data state will maintain same height as normal widget in loading/loaded state.
* @param {boolean} [props.dense] - Whether the table should use a compact layout with smaller cell paddings.
* @param {number} [props.pageSize] - Number of rows per page. This is used to manage internal state externally.
* @param {string} [props.searchText] - Text to search in the table
* @param {string} [props.searchColumn] - Column used to perform the search, using the searchText property

*/
function TableWidget({
Expand All @@ -46,6 +48,8 @@ function TableWidget({
height,
stableHeight,
dense,
searchText,
searchColumn,
// Internal state
pageSize
}) {
Expand All @@ -55,6 +59,7 @@ function TableWidget({
const [sortBy, setSortBy] = useState(undefined);
const [sortByColumnType, setSortByColumnType] = useState(undefined);
const [sortDirection, setSortDirection] = useState('asc');
const containsStringSearchFilter = searchColumn && searchText;

const {
data = { rows: [], totalCount: 0, hasData: false },
Expand All @@ -65,6 +70,9 @@ function TableWidget({
dataSource,
params: {
columns: [...columns.map((c) => c.field), ...hiddenColumnFields],
searchFilter: containsStringSearchFilter && {
[searchColumn]: { stringSearch: { values: [searchText] } }
},
sortBy,
sortDirection,
sortByColumnType,
Expand Down Expand Up @@ -153,6 +161,8 @@ TableWidget.propTypes = {
height: PropTypes.string,
stableHeight: PropTypes.bool,
dense: PropTypes.bool,
searchText: PropTypes.string,
searchColumn: PropTypes.string,
// Internal state
pageSize: PropTypes.number
};
Expand Down
Loading