Skip to content

Commit 428503d

Browse files
committed
fix: make use of "store" flags
1 parent cb0d5af commit 428503d

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export function getProperties(values: GalleryPreviewProps, defaultProperties: Pr
1818
hidePropertiesIn(defaultProperties, values, ["onSelectionChange", "itemSelectionMode"]);
1919
}
2020

21-
if (values.stateStorageType === "localStorage") {
21+
const usePersonalization = values.storeFilters || values.storeSort;
22+
if (!usePersonalization) {
23+
hidePropertiesIn(defaultProperties, values, ["stateStorageType", "stateStorageAttr", "onConfigurationChange"]);
24+
} else if (values.stateStorageType === "localStorage") {
2225
hidePropertyIn(defaultProperties, values, "stateStorageAttr");
2326
hidePropertyIn(defaultProperties, values, "onConfigurationChange");
2427
}

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ interface GalleryPersistentStateControllerSpec {
88
filtersHost: Serializable;
99
sortHost: Serializable;
1010
storage: ObservableStorage;
11+
storeFilters: boolean;
12+
storeSort: boolean;
1113
}
1214

1315
export class GalleryPersistentStateController {
1416
private readonly _storage: ObservableStorage;
1517
private readonly _filtersHost: Serializable;
1618
private readonly _sortHost: Serializable;
19+
readonly storeFilters: boolean;
20+
readonly storeSort: boolean;
1721

1822
readonly schemaVersion: number = 1;
1923

@@ -22,6 +26,8 @@ export class GalleryPersistentStateController {
2226
this._storage = spec.storage;
2327
this._filtersHost = spec.filtersHost;
2428
this._sortHost = spec.sortHost;
29+
this.storeFilters = spec.storeFilters;
30+
this.storeSort = spec.storeSort;
2531

2632
makeObservable<this, "_persistentState">(this, {
2733
_persistentState: computed,
@@ -77,15 +83,22 @@ export class GalleryPersistentStateController {
7783
if (!this._validate(data)) {
7884
return;
7985
}
80-
this._filtersHost.fromJSON(data.filters);
81-
this._sortHost.fromJSON(data.sort);
86+
if (this.storeFilters) {
87+
this._filtersHost.fromJSON(data.filters);
88+
}
89+
if (this.storeSort) {
90+
this._sortHost.fromJSON(data.sort);
91+
}
8292
}
8393

8494
toJSON(): PlainJs {
85-
return {
86-
version: 1,
87-
filters: this._filtersHost.toJSON(),
88-
sort: this._sortHost.toJSON()
89-
};
95+
const data: PlainJs = { version: 1 };
96+
if (this.storeFilters) {
97+
data.filters = this._filtersHost.toJSON();
98+
}
99+
if (this.storeSort) {
100+
data.sort = this._sortHost.toJSON();
101+
}
102+
return data;
90103
}
91104
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ export class GalleryStore extends BaseControllerHost {
8787
query: this._query.derivedQuery
8888
});
8989

90-
this.initStateController(spec, spec.gate);
90+
const useStorage = spec.storeFilters || spec.storeSort;
91+
if (useStorage) {
92+
this.initPersistentStorage(spec, spec.gate);
93+
}
9194
}
9295

93-
initStateController(props: StaticProps, gate: GalleryPropsGate): void {
96+
initPersistentStorage(props: StaticProps, gate: GalleryPropsGate): void {
9497
if (props.stateStorageType === "localStorage") {
9598
this._storage = new BrowserStorage(this.name);
9699
} else if (gate.props.stateStorageAttr) {
@@ -107,7 +110,9 @@ export class GalleryStore extends BaseControllerHost {
107110
new GalleryPersistentStateController(this, {
108111
storage: this._storage,
109112
filtersHost: this._filtersHost,
110-
sortHost: this._sortHost
113+
sortHost: this._sortHost,
114+
storeFilters: props.storeFilters,
115+
storeSort: props.storeSort
111116
});
112117
}
113118
}

0 commit comments

Comments
 (0)