Skip to content

Commit

Permalink
Merge pull request #95 from mendix/feat/lvc-searchbox-state
Browse files Browse the repository at this point in the history
[WC-509] Construct internal constraints list view widget separately
  • Loading branch information
Keraito committed May 27, 2021
2 parents 1f3cef0 + e0710e5 commit c2721f1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 74 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this tool will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## 1.3.12 - 2021-05-27

### Fixed

- Fixed an issue introduced in v1.3.11 where using a list view control widget multiple times would accumulate its constraints instead of replacing them.
- Fixed an issue where the list view control widgets constraints are combined incorrectly with the integrated list view search's constraints, losing context in-between.

## 1.3.11 - 2021-05-10 [YANKED]

### Fixed

- Fixed an issue where combining list view filtering with pagination sort would reset all the filters. (Fixes Ticket #119143)
72 changes: 1 addition & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "list-view-controls",
"widgetName": "ListViewControls",
"version": "1.3.11",
"version": "1.3.12",
"description": "Search and filter Mendix list views",
"copyright": "Mendix BV",
"scripts": {
Expand Down
20 changes: 19 additions & 1 deletion src/Shared/DataSourceHelper/DataSourceHelper.ts
Expand Up @@ -25,6 +25,7 @@ export interface DataSourceHelperListView extends mxui.widget.ListView {
__lvcPrototypeUpdated: boolean;
__customWidgetPagingLoading: boolean;
__customWidgetPagingOffset: number;
_getSearchText?: () => string;
}

export class DataSourceHelper {
Expand Down Expand Up @@ -179,7 +180,24 @@ export class DataSourceHelper {
.join("")
.replace(/\[]/g, ""); // Remove empty string "[]"

constraints = this.widget._datasource._constraints + unGroupedConstraints + groupedConstraints;
// @ts-ignore This is a subclass property, but we also handle it gracefully if not present.
const searchPaths: string[] | undefined = this.widget._datasource._searchPaths;
const searchText: string | undefined = this.widget._getSearchText?.();

// Unfortunately the listview datasource object does not have a `_getSearchConstraints()` function of some kind,
// but rather builds it on the fly in `setSearchText(string)`. To not affect the ListView widget, we copy that part
// out of the function and paste it here. Specifically it is in `QuerySource.setSearchText`.
const getListViewSearchConstraints = (paths: string[] | undefined, text: string | undefined): string => {
if (paths && text && text.trim() !== "") {
const searchConstraints = paths.map(path => `contains(${path},'${searchText}')`);
return `[${searchConstraints.join(" or ")}]`;
}
return "";
};

const listViewSearchConstraints = getListViewSearchConstraints(searchPaths, searchText);

constraints = listViewSearchConstraints + unGroupedConstraints + groupedConstraints;
// if (!restoreState) {
// this.widget._datasource._sorting = sorting;
// }
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="ListViewControls" version="1.3.11" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="ListViewControls" version="1.3.12" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="CheckBoxFilter/CheckBoxFilter.xml"/>
<widgetFile path="DropDownFilter/DropDownFilter.xml"/>
Expand Down

0 comments on commit c2721f1

Please sign in to comment.