Skip to content

Commit 9670a44

Browse files
committed
chore: fixes in editor conifg and stored json
1 parent b7ab767 commit 9670a44

File tree

8 files changed

+51
-13
lines changed

8 files changed

+51
-13
lines changed

packages/pluggableWidgets/gallery-web/src/Gallery.editorConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export function getProperties(values: GalleryPreviewProps, defaultProperties: Pr
2222
hidePropertiesIn(defaultProperties, values, ["onSelectionChange", "itemSelectionMode"]);
2323
}
2424

25+
if (values.stateStorageType === "localStorage") {
26+
hidePropertyIn(defaultProperties, values, "stateStorageAttr");
27+
hidePropertyIn(defaultProperties, values, "onConfigurationChange");
28+
}
29+
2530
// Hide scrolling settings for now.
2631
hidePropertiesIn(defaultProperties, values, ["showPagingButtons", "showTotalCount"]);
2732

packages/pluggableWidgets/gallery-web/src/Gallery.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@
139139
<attributeType name="String" />
140140
</attributeTypes>
141141
</property>
142+
<property key="onConfigurationChange" type="action" required="false">
143+
<caption>On change</caption>
144+
<description />
145+
</property>
142146
<property key="storeFilters" type="boolean" defaultValue="true">
143147
<caption>Store filters</caption>
144148
<description />
@@ -147,10 +151,6 @@
147151
<caption>Store sort</caption>
148152
<description />
149153
</property>
150-
<property key="onConfigurationChange" type="action" required="false">
151-
<caption>On change</caption>
152-
<description />
153-
</property>
154154
</propertyGroup>
155155
</propertyGroup>
156156
<propertyGroup caption="Accessibility">

packages/pluggableWidgets/gallery-web/typings/GalleryProps.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ export interface GalleryPreviewProps {
8686
onSelectionChange: {} | null;
8787
stateStorageType: StateStorageTypeEnum;
8888
stateStorageAttr: string;
89+
onConfigurationChange: {} | null;
8990
storeFilters: boolean;
9091
storeSort: boolean;
91-
onConfigurationChange: {} | null;
9292
filterSectionTitle: string;
9393
emptyMessageTitle: string;
9494
ariaLabelListBox: string;

packages/shared/widget-plugin-sorting/src/__tests__/SortStoreHost.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ describe("SortStoreHost", () => {
1313
[attrId("attr1"), "asc"],
1414
[attrId("attr2"), "desc"]
1515
] as SortInstruction[],
16-
setSortOrder: jest.fn()
16+
setSortOrder: jest.fn(),
17+
toJSON: jest.fn(),
18+
fromJSON: jest.fn()
1719
};
1820
});
1921

@@ -60,7 +62,9 @@ describe("SortStoreHost", () => {
6062
it("should replace previously observed store", () => {
6163
const anotherMockStore: ObservableSortStore = {
6264
sortOrder: [[attrId("attr3"), "asc"]] as SortInstruction[],
63-
setSortOrder: jest.fn()
65+
setSortOrder: jest.fn(),
66+
toJSON: jest.fn(),
67+
fromJSON: jest.fn()
6468
};
6569

6670
sortStoreHost.observe(mockStore);
@@ -206,7 +210,9 @@ describe("SortStoreHost", () => {
206210
it("should handle store changes after observation", () => {
207211
const mutableStore = {
208212
sortOrder: [[attrId("attr1"), "asc"]] as SortInstruction[],
209-
setSortOrder: jest.fn()
213+
setSortOrder: jest.fn(),
214+
toJSON: jest.fn(),
215+
fromJSON: jest.fn()
210216
};
211217

212218
sortStoreHost.observe(mutableStore);

packages/shared/widget-plugin-sorting/src/stores/SortOrderStore.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
import { PlainJs, Serializable } from "@mendix/filter-commons/typings/settings";
12
import { generateUUID } from "@mendix/widget-plugin-platform/framework/generate-uuid";
23
import { action, computed, makeObservable, observable } from "mobx";
34
import { BasicSortStore, Option, SortInstruction } from "../types/store";
45

5-
export class SortOrderStore implements BasicSortStore {
6+
type StorableState = Array<[number, "asc" | "desc"]>;
7+
8+
export class SortOrderStore implements BasicSortStore, Serializable {
69
private readonly _sortOrder: SortInstruction[] = [];
710

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

1115
constructor(spec: { options?: Option[]; initSortOrder?: SortInstruction[] } = {}) {
1216
const { options = [], initSortOrder = [] } = spec;
1317

1418
this.options = [...options];
19+
this.idToIndex = new Map(options.map((option, index) => [option.value, index]));
1520
this._sortOrder = [...initSortOrder];
1621

1722
makeObservable<this, "_sortOrder">(this, {
@@ -40,4 +45,25 @@ export class SortOrderStore implements BasicSortStore {
4045
this._sortOrder.splice(index, 1);
4146
}
4247
}
48+
49+
toJSON(): PlainJs {
50+
const data: StorableState = this.sortOrder.map(inst => {
51+
const index = this.idToIndex.get(inst[0])!;
52+
return [index, inst[1]];
53+
});
54+
55+
return data;
56+
}
57+
58+
fromJSON(data: PlainJs): void {
59+
if (!Array.isArray(data)) {
60+
return;
61+
}
62+
const sortOrder = (data as StorableState).flatMap<SortInstruction>(([index, direction]) => {
63+
const value = this.options[index]?.value;
64+
return value ? [[value, direction]] : [];
65+
});
66+
67+
this.setSortOrder(...sortOrder);
68+
}
4369
}

packages/shared/widget-plugin-sorting/src/stores/SortStoreHost.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ export class SortStoreHost implements Serializable {
5454
}
5555

5656
toJSON(): PlainJs {
57-
return this.sortOrder.map(arr => arr.slice());
57+
return this._store ? this._store.toJSON() : null;
5858
}
5959

6060
fromJSON(data: PlainJs): void {
6161
if (data == null || !Array.isArray(data)) {
6262
return;
6363
}
6464
if (this._store) {
65-
this._store.setSortOrder(...(data as SortInstruction[]));
65+
this._store.fromJSON(data);
6666
}
6767
}
6868
}

packages/shared/widget-plugin-sorting/src/types/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Serializable } from "@mendix/filter-commons/typings/settings";
12
import type { ListAttributeValue } from "mendix";
23

34
export type SortDirection = "asc" | "desc";
@@ -11,7 +12,7 @@ export type Option = {
1112
value: ListAttributeId;
1213
};
1314

14-
export interface ObservableSortStore {
15+
export interface ObservableSortStore extends Serializable {
1516
sortOrder: SortInstruction[];
1617
setSortOrder(...item: SortInstruction[]): void;
1718
}

turbo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://turborepo.org/schema.json",
3-
"globalPassThroughEnv": ["GITHUB_TOKEN", "GH_PAT", "GH_USERNAME", "GH_EMAIL", "GH_NAME", "CPAPI_PASS", "CPAPI_URL", "CPAPI_USER", "CPAPI_USER_OPENID"],
3+
"globalPassThroughEnv": ["GITHUB_TOKEN", "GH_PAT", "GH_USERNAME", "GH_EMAIL", "GH_NAME", "CPAPI_PASS", "CPAPI_URL", "CPAPI_USER", "CPAPI_USER_OPENID", "MX_PROJECT_PATH"],
44
"globalDependencies": [
55
"automation/**",
66
".npmrc",

0 commit comments

Comments
 (0)