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
2 changes: 2 additions & 0 deletions packages/pluggableWidgets/dropdown-sort-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- We fixed an issue with Gallery widget causing errors when Mendix app is being used in an iframe.

- We fixed an issue with Dropdown sort widget not showing attribute captions correctly.

## [1.2.2] - 2025-03-31

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { AttributeMetaData, DynamicValue } from "mendix";
import { SortOrderStore } from "../stores/SortOrderStore";
import { SortStoreHost } from "../stores/SortStoreHost";
import { SortInstruction } from "../types/store";

interface SortStoreProviderSpec {
host: SortStoreHost;
initSortOrder?: SortInstruction[];
attributes: Array<{
attribute: AttributeMetaData;
caption?: DynamicValue<string>;
}>;
}

export class SortStoreProvider {
Expand All @@ -18,11 +13,7 @@ export class SortStoreProvider {

constructor(spec: SortStoreProviderSpec) {
this._host = spec.host;
const options = spec.attributes.map(item => ({
value: item.attribute.id,
caption: item.caption?.value ?? "empty"
}));
this.store = new SortOrderStore({ options, initSortOrder: spec.initSortOrder });
this.store = new SortOrderStore({ initSortOrder: spec.initSortOrder });
}

setup(): () => void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
import { AttributeMetaData, DynamicValue } from "mendix";
import { createElement, FC } from "react";
import { createElement, FC, useEffect } from "react";
import { SortStoreProvider } from "../../helpers/SortStoreProvider";
import { BasicSortStore } from "../../types/store";
import { SortAPI } from "../context";
Expand All @@ -20,11 +20,14 @@ export function withLinkedSortStore<P extends RequiredProps>(
() =>
new SortStoreProvider({
host: props.sortAPI.host,
initSortOrder: props.sortAPI.host.sortOrder,
attributes: props.attributes
initSortOrder: props.sortAPI.host.sortOrder
})
);

useEffect(() => {
store.setProps({ attributes: props.attributes });
}, [store, props.attributes]);

return <Component {...props} sortStore={store} />;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,51 @@ import { PlainJs, Serializable } from "@mendix/filter-commons/typings/settings";
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
import { action, computed, makeObservable, observable } from "mobx";
import { BasicSortStore, Option, SortInstruction } from "../types/store";
import { AttributeMetaData, DynamicValue } from "mendix";

type StorableState = Array<[number, "asc" | "desc"]>;

type Props = {
attributes: Array<{
attribute: AttributeMetaData;
caption?: DynamicValue<string>;
}>;
};

export class SortOrderStore implements BasicSortStore, Serializable {
private readonly _sortOrder: SortInstruction[] = [];

readonly id = `SortOrderStore@${generateUUID()}`;
readonly options: Option[];
readonly idToIndex: Map<string, number>;

constructor(spec: { options?: Option[]; initSortOrder?: SortInstruction[] } = {}) {
const { options = [], initSortOrder = [] } = spec;
options: Option[] = [];
readonly idToIndex: Map<string, number> = new Map();

this.options = [...options];
this.idToIndex = new Map(options.map((option, index) => [option.value, index]));
constructor(spec: { initSortOrder?: SortInstruction[] }) {
const { initSortOrder = [] } = spec;
this._sortOrder = [...initSortOrder];

makeObservable<this, "_sortOrder">(this, {
_sortOrder: observable,
options: observable.struct,
sortOrder: computed,
setSortOrder: action,
setProps: action,
push: action,
remove: action
});
}

setProps(props: Props): void {
this.options = props.attributes.map(item => ({
value: item.attribute.id,
caption: item.caption?.value ?? "<empty>"
}));

this.idToIndex.clear();
this.options.forEach((option, index) => {
this.idToIndex.set(option.value, index);
});
}

get sortOrder(): SortInstruction[] {
return [...this._sortOrder];
}
Expand Down
Loading