Skip to content

Commit 46afcfc

Browse files
committed
refactor: remove header filter
1 parent 1690dbb commit 46afcfc

File tree

7 files changed

+360
-193
lines changed

7 files changed

+360
-193
lines changed

packages/pluggableWidgets/datagrid-web/src/Datagrid.xml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,6 @@
121121
<returnType type="Boolean" />
122122
</property>
123123
</propertyGroup>
124-
<propertyGroup caption="Drop-down filter settings">
125-
<property key="filterAssociation" type="association" selectableObjects="filterAssociationOptions" required="false" dataSource="../datasource">
126-
<caption>Entity</caption>
127-
<description>Set the entity to enable filtering over association with the Drop-down filter widget.</description>
128-
<associationTypes>
129-
<associationType name="Reference" />
130-
<associationType name="ReferenceSet" />
131-
</associationTypes>
132-
</property>
133-
<property key="filterAssociationOptions" type="datasource" isList="true" required="false">
134-
<caption>Selectable objects</caption>
135-
<description>The options to show in the Drop-down filter widget.</description>
136-
</property>
137-
<property key="fetchOptionsLazy" type="boolean" defaultValue="true">
138-
<caption>Use lazy load</caption>
139-
<description>Lazy loading enables faster data grid loading, but with personalization enabled, value restoration will be limited.</description>
140-
</property>
141-
<property key="filterCaptionType" type="enumeration" defaultValue="expression">
142-
<caption>Option caption type</caption>
143-
<description />
144-
<enumerationValues>
145-
<enumerationValue key="attribute">Attribute</enumerationValue>
146-
<enumerationValue key="expression">Expression</enumerationValue>
147-
</enumerationValues>
148-
</property>
149-
<property key="filterAssociationOptionLabel" type="expression" dataSource="filterAssociationOptions" required="false">
150-
<caption>Option caption</caption>
151-
<description />
152-
<returnType type="String" />
153-
</property>
154-
<property key="filterAssociationOptionLabelAttr" type="attribute" dataSource="filterAssociationOptions" required="false">
155-
<caption>Option caption</caption>
156-
<description />
157-
<attributeTypes>
158-
<attributeType name="String" />
159-
</attributeTypes>
160-
</property>
161-
</propertyGroup>
162124
<propertyGroup caption="Column capabilities">
163125
<property key="sortable" type="boolean" defaultValue="true">
164126
<caption>Can sort</caption>

packages/pluggableWidgets/datagrid-web/src/components/WidgetHeaderContext.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
import { getGlobalFilterContextObject } from "@mendix/widget-plugin-filtering/context";
2-
import { HeaderFiltersStore } from "@mendix/widget-plugin-filtering/stores/generic/HeaderFiltersStore";
32
import {
43
getGlobalSelectionContext,
54
SelectionHelper,
65
useCreateSelectionContextValue
76
} from "@mendix/widget-plugin-grid/selection";
87
import { createElement, memo, ReactElement, ReactNode } from "react";
8+
import { RootGridStore } from "../helpers/state/RootGridStore";
99

1010
interface WidgetHeaderContextProps {
1111
children?: ReactNode;
12-
filtersStore: HeaderFiltersStore;
1312
selectionHelper?: SelectionHelper;
13+
rootStore: RootGridStore;
1414
}
1515

1616
const SelectionContext = getGlobalSelectionContext();
1717
const FilterContext = getGlobalFilterContextObject();
1818

19-
function FilterAPIProvider(props: { filtersStore: HeaderFiltersStore; children?: ReactNode }): ReactElement {
20-
return <FilterContext.Provider value={props.filtersStore.context}>{props.children}</FilterContext.Provider>;
21-
}
22-
2319
function SelectionStatusProvider(props: { selectionHelper?: SelectionHelper; children?: ReactNode }): ReactElement {
2420
const value = useCreateSelectionContextValue(props.selectionHelper);
2521
return <SelectionContext.Provider value={value}>{props.children}</SelectionContext.Provider>;
2622
}
2723

2824
function HeaderContainer(props: WidgetHeaderContextProps): ReactElement {
2925
return (
30-
<FilterAPIProvider filtersStore={props.filtersStore}>
26+
<FilterContext.Provider value={null}>
3127
<SelectionStatusProvider selectionHelper={props.selectionHelper}>{props.children}</SelectionStatusProvider>
32-
</FilterAPIProvider>
28+
</FilterContext.Provider>
3329
);
3430
}
3531

packages/pluggableWidgets/datagrid-web/src/helpers/state/RootGridStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CustomFilterHost } from "@mendix/widget-plugin-filtering/stores/generic/CustomFilterHost";
2+
import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver";
23
import { BaseControllerHost } from "@mendix/widget-plugin-mobx-kit/BaseControllerHost";
34
import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch";
45
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate";
@@ -29,6 +30,7 @@ export class RootGridStore extends BaseControllerHost {
2930
exportProgressCtrl: ProgressStore;
3031
loaderCtrl: DerivedLoaderController;
3132
paginationCtrl: PaginationController;
33+
customFilters: FilterObserver;
3234

3335
private gate: Gate;
3436

@@ -44,6 +46,7 @@ export class RootGridStore extends BaseControllerHost {
4446
filtersChannelName: `datagrid/${generateUUID()}`
4547
};
4648
const customFilterHost = new CustomFilterHost();
49+
this.customFilters = customFilterHost;
4750
const query = new DatasourceController(this, { gate });
4851
const columns = (this.columnsStore = new ColumnGroupStore(props, this.staticInfo, columnsInitFilter, {
4952
customFilterHost,

packages/pluggableWidgets/datagrid-web/src/helpers/state/column/ColumnFilterStore.tsx

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import { FilterAPI, getGlobalFilterContextObject } from "@mendix/widget-plugin-filtering/context";
2-
import { RefFilterStore, RefFilterStoreProps } from "@mendix/widget-plugin-filtering/stores/picker/RefFilterStore";
3-
import { StaticSelectFilterStore } from "@mendix/widget-plugin-filtering/stores/picker/StaticSelectFilterStore";
2+
import { StaticSelectFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/StaticSelectFilterStore";
43
import { InputFilterStore, attrgroupFilterStore } from "@mendix/widget-plugin-filtering/stores/input/store-utils";
5-
import { ensure } from "@mendix/widget-plugin-platform/utils/ensure";
4+
import { FilterData } from "@mendix/filter-commons/typings/settings";
5+
import { value } from "@mendix/widget-plugin-filtering/result-meta";
6+
import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver";
7+
import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch";
8+
import { ListAttributeListValue, ListAttributeValue } from "mendix";
69
import { FilterCondition } from "mendix/filters";
7-
import { ListAttributeValue, ListAttributeListValue } from "mendix";
8-
import { action, computed, makeObservable } from "mobx";
10+
import { computed, makeObservable } from "mobx";
911
import { ReactNode, createElement } from "react";
1012
import { ColumnsType } from "../../../../typings/DatagridProps";
1113
import { StaticInfo } from "../../../typings/static-info";
12-
import { FilterData } from "@mendix/widget-plugin-filtering/typings/settings";
13-
import { value } from "@mendix/widget-plugin-filtering/result-meta";
14-
import { disposeFx } from "@mendix/widget-plugin-filtering/mobx-utils";
15-
import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver";
14+
1615
export interface IColumnFilterStore {
1716
renderFilterWidgets(): ReactNode;
1817
}
1918

20-
type FilterStore = InputFilterStore | StaticSelectFilterStore | RefFilterStore;
19+
type FilterStore = InputFilterStore | StaticSelectFilterStore;
2120

2221
const { Provider } = getGlobalFilterContextObject();
2322

@@ -33,61 +32,20 @@ export class ColumnFilterStore implements IColumnFilterStore {
3332
this._filterStore = this.createFilterStore(props, dsViewState);
3433
this._context = this.createContext(this._filterStore, info);
3534

36-
makeObservable<this, "_updateStore">(this, {
37-
_updateStore: action,
38-
condition2: computed,
39-
updateProps: action
35+
makeObservable<this>(this, {
36+
condition: computed
4037
});
4138
}
4239

4340
setup(): () => void {
44-
const [disposers, dispose] = disposeFx();
41+
const [add, disposeAll] = disposeBatch();
4542
if (this._filterStore && "setup" in this._filterStore) {
46-
disposers.push(this._filterStore.setup());
47-
}
48-
return dispose;
49-
}
50-
51-
updateProps(props: ColumnsType): void {
52-
this._widget = props.filter;
53-
this._updateStore(props);
54-
}
55-
56-
private _updateStore(props: ColumnsType): void {
57-
const store = this._filterStore;
58-
59-
if (store === null) {
60-
return;
61-
}
62-
63-
if (store.storeType === "refselect") {
64-
store.updateProps(this.toRefselectProps(props));
65-
} else if (isListAttributeValue(props.attribute)) {
66-
store.updateProps([props.attribute]);
43+
add(this._filterStore.setup());
6744
}
68-
}
69-
70-
private toRefselectProps(props: ColumnsType): RefFilterStoreProps {
71-
const searchAttrId = props.filterAssociationOptionLabelAttr?.id;
72-
const caption =
73-
props.filterCaptionType === "expression"
74-
? ensure(props.filterAssociationOptionLabel, errorMessage("filterAssociationOptionLabel"))
75-
: ensure(props.filterAssociationOptionLabelAttr, errorMessage("filterAssociationOptionLabelAttr"));
76-
77-
return {
78-
ref: ensure(props.filterAssociation, errorMessage("filterAssociation")),
79-
datasource: ensure(props.filterAssociationOptions, errorMessage("filterAssociationOptions")),
80-
searchAttrId,
81-
fetchOptionsLazy: props.fetchOptionsLazy,
82-
caption
83-
};
45+
return disposeAll;
8446
}
8547

8648
private createFilterStore(props: ColumnsType, dsViewState: FilterCondition | null): FilterStore | null {
87-
if (props.filterAssociation) {
88-
return new RefFilterStore(this.toRefselectProps(props), dsViewState);
89-
}
90-
9149
if (isListAttributeValue(props.attribute)) {
9250
return attrgroupFilterStore(props.attribute.type, [props.attribute], dsViewState);
9351
}
@@ -112,7 +70,7 @@ export class ColumnFilterStore implements IColumnFilterStore {
11270
return <Provider value={this._context}>{this._widget}</Provider>;
11371
}
11472

115-
get condition2(): FilterCondition | undefined {
73+
get condition(): FilterCondition | undefined {
11674
return this._filterStore ? this._filterStore.condition : undefined;
11775
}
11876

@@ -135,9 +93,6 @@ const isListAttributeValue = (
13593
return !!(attribute && attribute.isList === false);
13694
};
13795

138-
const errorMessage = (propName: string): string =>
139-
`Can't map ColumnsType to AssociationProperties: ${propName} is undefined`;
140-
14196
export interface ObserverBag {
14297
customFilterHost: FilterObserver;
14398
sharedInitFilter: Array<FilterCondition | undefined>;

packages/pluggableWidgets/datagrid-web/typings/DatagridProps.d.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Mendix Widgets Framework Team
55
*/
66
import { ComponentType, CSSProperties, ReactNode } from "react";
7-
import { ActionValue, DynamicValue, EditableValue, ListValue, ListActionValue, ListAttributeValue, ListAttributeListValue, ListExpressionValue, ListReferenceValue, ListReferenceSetValue, ListWidgetValue, SelectionSingleValue, SelectionMultiValue } from "mendix";
7+
import { ActionValue, DynamicValue, EditableValue, ListValue, ListActionValue, ListAttributeValue, ListAttributeListValue, ListExpressionValue, ListWidgetValue, SelectionSingleValue, SelectionMultiValue } from "mendix";
88
import { Big } from "big.js";
99

1010
export type ItemSelectionMethodEnum = "checkbox" | "rowClick";
@@ -15,8 +15,6 @@ export type LoadingTypeEnum = "spinner" | "skeleton";
1515

1616
export type ShowContentAsEnum = "attribute" | "dynamicText" | "customContent";
1717

18-
export type FilterCaptionTypeEnum = "attribute" | "expression";
19-
2018
export type HidableEnum = "yes" | "hidden" | "no";
2119

2220
export type WidthEnum = "autoFill" | "autoFit" | "manual";
@@ -35,12 +33,6 @@ export interface ColumnsType {
3533
tooltip?: ListExpressionValue<string>;
3634
filter?: ReactNode;
3735
visible: DynamicValue<boolean>;
38-
filterAssociation?: ListReferenceValue | ListReferenceSetValue;
39-
filterAssociationOptions?: ListValue;
40-
fetchOptionsLazy: boolean;
41-
filterCaptionType: FilterCaptionTypeEnum;
42-
filterAssociationOptionLabel?: ListExpressionValue<string>;
43-
filterAssociationOptionLabelAttr?: ListAttributeValue<string>;
4436
sortable: boolean;
4537
resizable: boolean;
4638
draggable: boolean;
@@ -81,12 +73,6 @@ export interface ColumnsPreviewType {
8173
tooltip: string;
8274
filter: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };
8375
visible: string;
84-
filterAssociation: string;
85-
filterAssociationOptions: {} | { caption: string } | { type: string } | null;
86-
fetchOptionsLazy: boolean;
87-
filterCaptionType: FilterCaptionTypeEnum;
88-
filterAssociationOptionLabel: string;
89-
filterAssociationOptionLabelAttr: string;
9076
sortable: boolean;
9177
resizable: boolean;
9278
draggable: boolean;

packages/shared/filter-commons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test": "jest"
3333
},
3434
"dependencies": {
35-
"mendix": "^10.16.49747"
35+
"mendix": "^10.21.64362"
3636
},
3737
"peerDependencies": {
3838
"mobx": "6.12.3",

0 commit comments

Comments
 (0)