Skip to content

Commit 5c26a7f

Browse files
committed
feat: convert gallery and fix tests
1 parent 0818cfc commit 5c26a7f

File tree

5 files changed

+32
-45
lines changed

5 files changed

+32
-45
lines changed

packages/pluggableWidgets/datagrid-date-filter-web/src/components/__tests__/DatagridDateFilter.spec.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ describe("Date Filter", () => {
7373
hasError: false,
7474
value: { type: "direct", store: dateFilterStore }
7575
},
76-
filterObserver: {} as ObservableFilterHost,
77-
sharedInitFilter: []
76+
filterObserver: {} as ObservableFilterHost
7877
};
7978

8079
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI | null>(
@@ -168,8 +167,7 @@ describe("Date Filter", () => {
168167
hasError: false,
169168
value: { type: "direct", store: dateFilterStore }
170169
},
171-
filterObserver: {} as ObservableFilterHost,
172-
sharedInitFilter: []
170+
filterObserver: {} as ObservableFilterHost
173171
};
174172

175173
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI | null>(
@@ -223,8 +221,7 @@ describe("Date Filter", () => {
223221
hasError: false,
224222
value: { type: "direct", store: dateFilterStore }
225223
},
226-
filterObserver: {} as ObservableFilterHost,
227-
sharedInitFilter: []
224+
filterObserver: {} as ObservableFilterHost
228225
};
229226

230227
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI | null>(
@@ -264,8 +261,7 @@ describe("Date Filter", () => {
264261
hasError: false,
265262
value: { type: "direct", store: dateFilterStore }
266263
},
267-
filterObserver: {} as ObservableFilterHost,
268-
sharedInitFilter: []
264+
filterObserver: {} as ObservableFilterHost
269265
};
270266

271267
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI | null>(

packages/pluggableWidgets/datagrid-number-filter-web/src/components/__tests__/DatagridNumberFilter.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ const setContext = (store: NumberInputFilterStore) => {
5353
hasError: false,
5454
value: { type: "direct", store }
5555
},
56-
filterObserver: {} as ObservableFilterHost,
57-
sharedInitFilter: []
56+
filterObserver: {} as ObservableFilterHost
5857
};
5958
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI>(filterAPI);
6059
};

packages/pluggableWidgets/datagrid-text-filter-web/src/components/__tests__/DatagridTextFilter.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ const setContext = (store: StringInputFilterStore) => {
5050
hasError: false,
5151
value: { type: "direct", store }
5252
},
53-
filterObserver: {} as ObservableFilterHost,
54-
sharedInitFilter: []
53+
filterObserver: {} as ObservableFilterHost
5554
};
5655
(window as any)["com.mendix.widgets.web.filterable.filterContext.v2"] = createContext<FilterAPI>(filterAPI);
5756
};
Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,54 @@
1-
import { compactArray, fromCompactArray, isAnd } from "@mendix/filter-commons/condition-utils";
2-
import { CustomFilterHost } from "@mendix/widget-plugin-filtering/stores/generic/CustomFilterHost";
31
import { DatasourceController } from "@mendix/widget-plugin-grid/query/DatasourceController";
42
import { disposeBatch } from "@mendix/widget-plugin-mobx-kit/disposeBatch";
53
import { ReactiveController, ReactiveControllerHost } from "@mendix/widget-plugin-mobx-kit/reactive-controller";
6-
import { SortStoreHost } from "@mendix/widget-plugin-sorting/stores/SortStoreHost";
7-
import { ListValue } from "mendix";
4+
import { SortInstruction } from "@mendix/widget-plugin-sorting/types/store";
5+
86
import { FilterCondition } from "mendix/filters";
9-
import { makeAutoObservable, reaction } from "mobx";
7+
import { reaction } from "mobx";
8+
9+
interface ObservableFilterStore {
10+
filter: FilterCondition | undefined;
11+
}
12+
13+
interface ObservableSortStore {
14+
sortOrder: SortInstruction[] | undefined;
15+
}
1016

1117
export class QueryParamsController implements ReactiveController {
1218
private readonly _query: DatasourceController;
13-
private readonly _filters: CustomFilterHost;
14-
private readonly _sort: SortStoreHost;
19+
private readonly _filtersHost: ObservableFilterStore;
20+
private readonly _sortHost: ObservableSortStore;
1521

1622
constructor(
1723
host: ReactiveControllerHost,
1824
query: DatasourceController,
19-
filters: CustomFilterHost,
20-
sort: SortStoreHost
25+
filters: ObservableFilterStore,
26+
sort: ObservableSortStore
2127
) {
2228
host.addController(this);
2329

2430
this._query = query;
25-
this._filters = filters;
26-
this._sort = sort;
27-
28-
makeAutoObservable(this, { setup: false });
29-
}
30-
31-
private get _derivedSortOrder(): ListValue["sortOrder"] {
32-
return this._sort.sortOrder;
33-
}
34-
35-
private get _derivedFilter(): FilterCondition {
36-
return compactArray(this._filters.conditions);
31+
this._filtersHost = filters;
32+
this._sortHost = sort;
3733
}
3834

3935
setup(): () => void {
4036
const [add, disposeAll] = disposeBatch();
4137
add(
4238
reaction(
43-
() => this._derivedSortOrder,
39+
() => this._sortHost.sortOrder,
4440
sortOrder => this._query.setSortOrder(sortOrder),
4541
{ fireImmediately: true }
4642
)
4743
);
4844
add(
4945
reaction(
50-
() => this._derivedFilter,
46+
() => this._filtersHost.filter,
5147
filter => this._query.setFilter(filter),
5248
{ fireImmediately: true }
5349
)
5450
);
5551

5652
return disposeAll;
5753
}
58-
59-
unzipFilter(filter?: FilterCondition): Array<FilterCondition | undefined> {
60-
if (!filter || !isAnd(filter)) {
61-
return [];
62-
}
63-
return fromCompactArray(filter);
64-
}
6554
}

packages/pluggableWidgets/gallery-web/src/stores/GalleryStore.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createContextWithStub, FilterAPI } from "@mendix/widget-plugin-filtering/context";
2+
import { CombinedFilter } from "@mendix/widget-plugin-filtering/stores/generic/CombinedFilter";
23
import { CustomFilterHost } from "@mendix/widget-plugin-filtering/stores/generic/CustomFilterHost";
34
import { DatasourceController } from "@mendix/widget-plugin-grid/query/DatasourceController";
45
import { PaginationController } from "@mendix/widget-plugin-grid/query/PaginationController";
@@ -67,16 +68,17 @@ export class GalleryStore extends BaseControllerHost {
6768

6869
this._filtersHost = new CustomFilterHost();
6970

71+
const combinedFilter = new CombinedFilter(this, { stableKey: spec.name, inputs: [this._filtersHost] });
72+
7073
this._sortHost = new SortStoreHost({
7174
initSort: spec.gate.props.datasource.sortOrder
7275
});
7376

74-
const paramCtrl = new QueryParamsController(this, this._query, this._filtersHost, this._sortHost);
77+
new QueryParamsController(this, this._query, combinedFilter, this._sortHost);
7578

7679
this.filterAPI = createContextWithStub({
7780
filterObserver: this._filtersHost,
78-
parentChannelName: this.id,
79-
sharedInitFilter: paramCtrl.unzipFilter(spec.gate.props.datasource.filter)
81+
parentChannelName: this.id
8082
});
8183

8284
this.sortAPI = {
@@ -93,6 +95,8 @@ export class GalleryStore extends BaseControllerHost {
9395
if (useStorage) {
9496
this.initPersistentStorage(spec, spec.gate);
9597
}
98+
99+
combinedFilter.hydrate(spec.gate.props.datasource.filter);
96100
}
97101

98102
initPersistentStorage(props: StaticProps, gate: GalleryPropsGate): void {

0 commit comments

Comments
 (0)