Skip to content

Commit 8e9d94e

Browse files
committed
chore: introduce wide filter api
1 parent 46afcfc commit 8e9d94e

File tree

7 files changed

+57
-75
lines changed

7 files changed

+57
-75
lines changed

packages/pluggableWidgets/datagrid-web/src/Datagrid.editorConfig.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ export function getProperties(
7474
"hidable"
7575
]);
7676
}
77-
78-
if (!column.filterAssociation) {
79-
hideNestedPropertiesIn(defaultProperties, values, "columns", index, [
80-
"filterAssociationOptions",
81-
"filterAssociationOptionLabel",
82-
"fetchOptionsLazy",
83-
"filterCaptionType",
84-
"filterAssociationOptionLabelAttr"
85-
]);
86-
}
87-
if (column.filterCaptionType === "attribute") {
88-
hidePropertyIn(defaultProperties, values, "columns", index, "filterAssociationOptionLabel");
89-
} else {
90-
hidePropertyIn(defaultProperties, values, "columns", index, "filterAssociationOptionLabelAttr");
91-
}
9277
});
9378
if (values.pagination === "buttons") {
9479
hidePropertyIn(defaultProperties, values, "showNumberOfRows");
@@ -209,11 +194,6 @@ export const getPreview = (
209194
draggable: false,
210195
dynamicText: "Dynamic text",
211196
filter: { widgetCount: 0, renderer: () => null },
212-
filterAssociation: "",
213-
filterAssociationOptionLabel: "",
214-
filterAssociationOptionLabelAttr: "",
215-
filterAssociationOptions: {},
216-
filterCaptionType: "attribute",
217197
header: "Column",
218198
hidable: "no",
219199
resizable: false,
@@ -227,8 +207,7 @@ export const getPreview = (
227207
minWidth: "auto",
228208
minWidthLimit: 100,
229209
allowEventPropagation: true,
230-
exportValue: "",
231-
fetchOptionsLazy: true
210+
exportValue: ""
232211
}
233212
];
234213
const columns = rowLayout({

packages/pluggableWidgets/datagrid-web/src/Datagrid.editorPreview.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ const initColumns: ColumnsPreviewType[] = [
3535
draggable: false,
3636
dynamicText: "Dynamic Text",
3737
filter: { renderer: () => <div />, widgetCount: 0 },
38-
filterAssociation: "",
39-
filterAssociationOptionLabel: "",
40-
filterAssociationOptionLabelAttr: "",
41-
filterAssociationOptions: {},
42-
filterCaptionType: "expression",
38+
4339
header: "Column",
4440
hidable: "no",
4541
resizable: false,
@@ -53,8 +49,7 @@ const initColumns: ColumnsPreviewType[] = [
5349
minWidth: "auto",
5450
minWidthLimit: 100,
5551
allowEventPropagation: true,
56-
exportValue: "",
57-
fetchOptionsLazy: true
52+
exportValue: ""
5853
}
5954
];
6055

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const Container = observer((props: Props): ReactElement => {
8282
headerTitle={props.filterSectionTitle?.value}
8383
headerContent={
8484
props.filtersPlaceholder && (
85-
<WidgetHeaderContext selectionHelper={selectionHelper} filtersStore={rootStore.headerFiltersStore}>
85+
<WidgetHeaderContext selectionHelper={selectionHelper} rootStore={rootStore}>
8686
{props.filtersPlaceholder}
8787
</WidgetHeaderContext>
8888
)

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ interface WidgetHeaderContextProps {
1616
const SelectionContext = getGlobalSelectionContext();
1717
const FilterContext = getGlobalFilterContextObject();
1818

19-
function SelectionStatusProvider(props: { selectionHelper?: SelectionHelper; children?: ReactNode }): ReactElement {
20-
const value = useCreateSelectionContextValue(props.selectionHelper);
21-
return <SelectionContext.Provider value={value}>{props.children}</SelectionContext.Provider>;
22-
}
23-
2419
function HeaderContainer(props: WidgetHeaderContextProps): ReactElement {
20+
const selectionContext = useCreateSelectionContextValue(props.selectionHelper);
2521
return (
26-
<FilterContext.Provider value={null}>
27-
<SelectionStatusProvider selectionHelper={props.selectionHelper}>{props.children}</SelectionStatusProvider>
22+
<FilterContext.Provider value={props.rootStore.autonomousFilterAPI}>
23+
<SelectionContext.Provider value={selectionContext}>{props.children}</SelectionContext.Provider>
2824
</FilterContext.Provider>
2925
);
3026
}

packages/pluggableWidgets/datagrid-web/src/consistency-check.ts

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import { ColumnsPreviewType, DatagridPreviewProps } from "../typings/DatagridPro
44
export function check(values: DatagridPreviewProps): Problem[] {
55
const errors: Problem[] = [];
66

7-
const columnChecks = [
8-
checkAssociationSettings,
9-
checkFilteringSettings,
10-
checkDisplaySettings,
11-
checkSortingSettings,
12-
checkHidableSettings
13-
];
7+
const columnChecks = [checkFilteringSettings, checkDisplaySettings, checkSortingSettings, checkHidableSettings];
148

159
values.columns.forEach((column: ColumnsPreviewType, index) => {
1610
for (const check of columnChecks) {
@@ -28,33 +22,33 @@ export function check(values: DatagridPreviewProps): Problem[] {
2822

2923
const columnPropPath = (prop: string, index: number): string => `columns/${index + 1}/${prop}`;
3024

31-
const checkAssociationSettings = (
32-
values: DatagridPreviewProps,
33-
column: ColumnsPreviewType,
34-
index: number
35-
): Problem | undefined => {
36-
if (!values.columnsFilterable) {
37-
return;
38-
}
39-
40-
if (!column.filterAssociation) {
41-
return;
42-
}
43-
44-
if (column.filterCaptionType === "expression" && !column.filterAssociationOptionLabel) {
45-
return {
46-
property: columnPropPath("filterAssociationOptionLabel", index),
47-
message: `A caption is required when using associations. Please set 'Option caption' property for column (${column.header})`
48-
};
49-
}
50-
51-
if (column.filterCaptionType === "attribute" && !column.filterAssociationOptionLabelAttr) {
52-
return {
53-
property: columnPropPath("filterAssociationOptionLabelAttr", index),
54-
message: `A caption is required when using associations. Please set 'Option caption' property for column (${column.header})`
55-
};
56-
}
57-
};
25+
// const checkAssociationSettings = (
26+
// values: DatagridPreviewProps,
27+
// column: ColumnsPreviewType,
28+
// index: number
29+
// ): Problem | undefined => {
30+
// if (!values.columnsFilterable) {
31+
// return;
32+
// }
33+
34+
// if (!column.filterAssociation) {
35+
// return;
36+
// }
37+
38+
// if (column.filterCaptionType === "expression" && !column.filterAssociationOptionLabel) {
39+
// return {
40+
// property: columnPropPath("filterAssociationOptionLabel", index),
41+
// message: `A caption is required when using associations. Please set 'Option caption' property for column (${column.header})`
42+
// };
43+
// }
44+
45+
// if (column.filterCaptionType === "attribute" && !column.filterAssociationOptionLabelAttr) {
46+
// return {
47+
// property: columnPropPath("filterAssociationOptionLabelAttr", index),
48+
// message: `A caption is required when using associations. Please set 'Option caption' property for column (${column.header})`
49+
// };
50+
// }
51+
// };
5852

5953
const checkFilteringSettings = (
6054
values: DatagridPreviewProps,
@@ -65,7 +59,7 @@ const checkFilteringSettings = (
6559
return;
6660
}
6761

68-
if (!column.attribute && !column.filterAssociation) {
62+
if (!column.attribute) {
6963
return {
7064
property: columnPropPath("attribute", index),
7165
message: `An attribute or reference is required when filtering is enabled. Please select 'Attribute' or 'Reference' property for column (${column.header})`

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { createContextWithStub, FilterAPI } from "@mendix/widget-plugin-filtering/context";
12
import { CustomFilterHost } from "@mendix/widget-plugin-filtering/stores/generic/CustomFilterHost";
2-
import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver";
33
import { BaseControllerHost } from "@mendix/widget-plugin-mobx-kit/BaseControllerHost";
44
import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch";
55
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate";
@@ -30,7 +30,7 @@ export class RootGridStore extends BaseControllerHost {
3030
exportProgressCtrl: ProgressStore;
3131
loaderCtrl: DerivedLoaderController;
3232
paginationCtrl: PaginationController;
33-
customFilters: FilterObserver;
33+
readonly autonomousFilterAPI: FilterAPI;
3434

3535
private gate: Gate;
3636

@@ -46,8 +46,12 @@ export class RootGridStore extends BaseControllerHost {
4646
filtersChannelName: `datagrid/${generateUUID()}`
4747
};
4848
const customFilterHost = new CustomFilterHost();
49-
this.customFilters = customFilterHost;
5049
const query = new DatasourceController(this, { gate });
50+
this.autonomousFilterAPI = createContextWithStub({
51+
filterObserver: customFilterHost,
52+
sharedInitFilter,
53+
parentChannelName: this.staticInfo.filtersChannelName
54+
});
5155
const columns = (this.columnsStore = new ColumnGroupStore(props, this.staticInfo, columnsInitFilter, {
5256
customFilterHost,
5357
sharedInitFilter

packages/shared/widget-plugin-filtering/src/context.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ export function useFilterAPI(): Result<FilterAPI, APIError> {
5555

5656
/** @deprecated This hook is renamed, use `useFilterAPI` instead. */
5757
export const useFilterContextValue = useFilterAPI;
58+
59+
export function createContextWithStub(options: {
60+
filterObserver: FilterObserver;
61+
parentChannelName: string;
62+
sharedInitFilter: Array<FilterCondition | undefined>;
63+
}): FilterAPI {
64+
return {
65+
version: 3,
66+
parentChannelName: options.parentChannelName,
67+
provider: value(PROVIDER_STUB),
68+
filterObserver: options.filterObserver,
69+
sharedInitFilter: options.sharedInitFilter
70+
};
71+
}

0 commit comments

Comments
 (0)