Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed

- We fixed an issue where pages with many drop-down filters became slow to scroll.
- We fixed an issue where, with lazy loading turned off, the drop-down filter loaded only part of the options after the user returned to the page. Because of this, a selected option could lose its caption and the filter was no longer applied to the data grid.

## [3.11.3] - 2026-07-27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export interface ColumnsType {
hidable: HidableEnum;
allowEventPropagation: boolean;
width: WidthEnum;
size: number;
Comment thread
gjulivan marked this conversation as resolved.
Resolved
minWidth: MinWidthEnum;
minWidthLimit: number;
size: number;
alignment: AlignmentEnum;
columnClass?: ListExpressionValue<string>;
wrapText: boolean;
Expand Down Expand Up @@ -99,9 +99,9 @@ export interface ColumnsPreviewType {
hidable: HidableEnum;
allowEventPropagation: boolean;
width: WidthEnum;
size: number | null;
minWidth: MinWidthEnum;
minWidthLimit: number | null;
size: number | null;
alignment: AlignmentEnum;
columnClass: string;
wrapText: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
jest.mock(
"mendix/filters/builders",
() => {
const node =
(type: string) =>
(...args: unknown[]) => ({ type, args });
return {
association: node("association"),
attribute: node("attribute"),
contains: node("contains"),
equals: node("equals"),
literal: node("literal"),
or: node("or"),
and: node("and"),
notEqual: node("notEqual")
};
},
{ virtual: true }
);

import { AssociationMetaData, AttributeMetaData, ListValue, ObjectItem } from "mendix";
import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
import { RefFilterStore, RefFilterStoreProps } from "../stores/RefFilterStore";

// describe("RefFilterStore", () => {

Check warning on line 25 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// afterEach(() => _resetGlobalState());

// describe("get options()", () => {

Check warning on line 28 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// let items: ObjectItem[];
// let mapItem: (item: ObjectItem) => string;
// let store: RefFilterStore;
Expand All @@ -19,7 +43,7 @@
// );
// });

// it("returns array of options", () => {

Check warning on line 46 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// expect(store.options).toMatchInlineSnapshot(`
// [
// {
Expand All @@ -42,11 +66,11 @@
// });
// });

// describe("get condition()", () => {

Check warning on line 69 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// it.todo("return filter condition using equals");

Check warning on line 70 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// });

// describe("toJSON()", () => {

Check warning on line 73 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// let store: RefFilterStore;
// beforeEach(() => {
// store = new RefFilterStore(
Expand All @@ -59,17 +83,17 @@
// );
// });

// it("returns state as JS array", () => {

Check warning on line 86 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// expect(store.toJSON()).toEqual([]);
// });

// it("save state with one item", () => {

Check warning on line 90 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// const guid = store.options[0].value;
// store.toggle(guid);
// expect(store.toJSON()).toEqual([guid]);
// });

// it("save state with multiple items", () => {

Check warning on line 96 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// const [guid1, guid2] = [store.options[0].value, store.options[1].value];
// store.toggle(guid1);
// store.toggle(guid2);
Expand All @@ -81,7 +105,7 @@
// });
// });

// describe("fromJSON()", () => {

Check warning on line 108 in packages/shared/widget-plugin-dropdown-filter/src/__tests__/RefFilterStore.spec.ts

View workflow job for this annotation

GitHub Actions / Run code quality check

Do not comment out tests
// let store: RefFilterStore;
// beforeEach(() => {
// store = new RefFilterStore(
Expand Down Expand Up @@ -249,5 +273,118 @@
// });

describe("RefFilterStore", () => {
it.todo("should be implemented");
describe("options datasource limit", () => {
beforeEach(() => jest.useFakeTimers());
afterEach(() => jest.useRealTimers());

it("does not change the limit in the constructor when lazy loading is off", () => {
const { datasource } = setupStore({ fetchOptionsLazy: false }, { run: false });
expect(datasource.setLimit).not.toHaveBeenCalled();
});

it("resets a restored limit to the default on setup when lazy loading is off", () => {
Comment thread
gjulivan marked this conversation as resolved.
Resolved
// The runtime restores the last used limit when the user returns to the page.
const { datasource } = setupStore({ fetchOptionsLazy: false }, { limit: 100 });
expect(datasource.setLimit).toHaveBeenCalledTimes(1);
expect(datasource.setLimit).toHaveBeenLastCalledWith(undefined);
});

it("does not limit options on search or search clear when lazy loading is off", () => {
const { store, datasource } = setupStore({ fetchOptionsLazy: false });
datasource.setLimit.mockClear();

store.search.setBuffer("ZZAccount");
jest.advanceTimersByTime(SEARCH_DELAY);
expect(datasource.setFilter).toHaveBeenCalledTimes(1);

store.search.clear();
jest.advanceTimersByTime(SEARCH_DELAY);
expect(datasource.setFilter).toHaveBeenCalledTimes(2);
expect(datasource.setFilter).toHaveBeenLastCalledWith(undefined);

expect(datasource.setLimit).not.toHaveBeenCalled();
});

it("sets limit to 0 in the constructor when lazy loading is on", () => {
const { datasource } = setupStore({ fetchOptionsLazy: true }, { run: false });
expect(datasource.setLimit).toHaveBeenLastCalledWith(0);
});

it("limits options on search when lazy loading is on", () => {
const { store, datasource } = setupStore({ fetchOptionsLazy: true });
datasource.setLimit.mockClear();

store.search.setBuffer("ZZAccount");
jest.advanceTimersByTime(SEARCH_DELAY);

expect(datasource.setLimit).toHaveBeenLastCalledWith(100);
});
});

describe("selected options", () => {
it("shows the caption of a restored selection outside the first 100 options", () => {
const items = Array.from({ length: 150 }, (_, i) => item(`obj_${i}`));
const { store } = setupStore({ fetchOptionsLazy: false }, { items });

store.fromJSON(["obj_149"]);

expect(store.selectedOptions).toEqual([{ caption: "Caption obj_149", value: "obj_149", selected: true }]);
});
});
});

const SEARCH_DELAY = 300;

type MockListValue = ListValue & { setLimit: jest.Mock; setFilter: jest.Mock };

function item(id: string): ObjectItem {
return { id } as ObjectItem;
}

function mockList({
items = [],
limit = Number.POSITIVE_INFINITY
}: {
items?: ObjectItem[];
limit?: number;
}): MockListValue {
const list = {
status: "available",
items,
limit,
offset: 0,
hasMoreItems: false,
filter: undefined,
setFilter: jest.fn(),
setOffset: jest.fn(),
setSortOrder: jest.fn(),
requestTotalCount: jest.fn(),
reload: jest.fn()
} as unknown as MockListValue;
list.setLimit = jest.fn((next?: number) => {
(list as { limit: number }).limit = next ?? Number.POSITIVE_INFINITY;
});
return list;
}

function setupStore(
props: Pick<RefFilterStoreProps, "fetchOptionsLazy">,
{ items, limit, run = true }: { items?: ObjectItem[]; limit?: number; run?: boolean } = {}
): { store: RefFilterStore; datasource: MockListValue } {
const datasource = mockList({ items, limit });
const gateProvider = new GateProvider<RefFilterStoreProps>({
...props,
refEntity: { id: "Module.Task_Account" } as unknown as AssociationMetaData,
refCaption: { get: (obj: ObjectItem) => ({ value: `Caption ${obj.id}` }) },
refOptions: datasource,
searchAttrId: "Module.Account.Name" as AttributeMetaData["id"]
});
const store = new RefFilterStore({ gate: gateProvider.gate, initCond: null });
if (run) {
disposers.push(store.setup());
}
return { store, datasource };
}

const disposers: Array<() => void> = [];
afterEach(() => disposers.splice(0).forEach(dispose => dispose()));
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ export class RefFilterStore extends BaseSelectStore {
);
} else {
this.setFetchReady(true);
this.loadMore();
// The runtime restores the last used limit when the user returns to the page,
// so reset it to the default (no limit) to load all options.
this.datasource.setLimit(undefined);
}

return dispose;
Expand All @@ -184,7 +186,9 @@ export class RefFilterStore extends BaseSelectStore {
? contains(attribute(this.searchAttrId), literal(search))
: undefined;
this.datasource.setFilter(cond);
this.datasource.setLimit(this.searchSize);
if (this.lazyMode) {
this.datasource.setLimit(this.searchSize);
}
};

return [data, effect, { delay: 300 }];
Expand Down
Loading