Skip to content

Commit 5a9beb2

Browse files
authored
Bugfixes (#21)
1 parent a732abf commit 5a9beb2

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mxtreetable",
33
"widgetName": "MxTreeTable",
4-
"version": "2.0.6",
4+
"version": "2.0.7",
55
"description": "TreeTable widget",
66
"copyright": "Mendix 2019",
77
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",

src/MxTreeTable.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,14 @@ Your context object is of type "${contextEntity}". Please check the configuratio
773773
const {
774774
stateManagementType,
775775
stateLocalStorageKey,
776+
stateLocalStorageKeyIncludeGUID,
776777
stateExecuteSelectActionOnRestore,
777778
stateLocalStorageType
778779
} = this.props;
779-
const key = stateLocalStorageKey !== "" ? `TreeTableState-${stateLocalStorageKey}` : `TreeTableState-${guid}`;
780+
const key =
781+
stateLocalStorageKey !== ""
782+
? `TreeTableState-${stateLocalStorageKey}${stateLocalStorageKeyIncludeGUID ? `-${guid}` : ""}`
783+
: `TreeTableState-${guid}`;
780784
const currentDateTime = +new Date();
781785
const emptyState: TableState = {
782786
context: guid,
@@ -819,14 +823,21 @@ Your context object is of type "${contextEntity}". Please check the configuratio
819823
private _writeTableState(state: TableState): void {
820824
// We're doing this the dirty way instead of Object.assign because IE11 sucks
821825
const writeState = JSON.parse(JSON.stringify(state)) as TableState;
822-
const { stateManagementType, stateLocalStorageKey, stateLocalStorageType } = this.props;
826+
const {
827+
stateManagementType,
828+
stateLocalStorageKey,
829+
stateLocalStorageKeyIncludeGUID,
830+
stateLocalStorageType
831+
} = this.props;
823832
if (stateManagementType === "disabled" /* || stateManagementType === "mendix"*/) {
824833
return;
825834
}
826835
this.debug("writeTableState", writeState);
827836
const key =
828837
stateLocalStorageKey !== ""
829-
? `TreeTableState-${stateLocalStorageKey}`
838+
? `TreeTableState-${stateLocalStorageKey}${
839+
stateLocalStorageKeyIncludeGUID ? `-${writeState.context}` : ""
840+
}`
830841
: `TreeTableState-${writeState.context}`;
831842
writeState.lastUpdate = +new Date();
832843
if (stateLocalStorageType === "session") {

src/MxTreeTable.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,10 @@ Note: State management (currently) ONLY works when you load a whole tree (see Da
557557
<caption>Key</caption>
558558
<description>When storing the state in local storage, it will choose a specific key, based on the the GUID of your context. If you happen to use a non-persistent context, this will change every time. In that case you can set a key here (make it unique for your current view). Otherwise, leave it empty.</description>
559559
</property>
560+
<property key="stateLocalStorageKeyIncludeGUID" type="boolean" defaultValue="false">
561+
<caption>Include guid</caption>
562+
<description>When you set a key you can still add the GUID if needed. This is not useful when using non-persistent objects</description>
563+
</property>
560564
<property key="stateExecuteSelectActionOnRestore" type="boolean" defaultValue="true">
561565
<caption>Restore selection action</caption>
562566
<description>When you restore your state, and you have an On Change action defined for your selection (see Selection tab), you can execute this. This is enabled by default.</description>

src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="MxTreeTable" version="2.0.6" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="MxTreeTable" version="2.0.7" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="MxTreeTable.xml"/>
66
</widgetFiles>

src/store/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface NodeStoreConstructorOptions {
5959
convertMxObjectToRow: (mxObject: mendix.lib.MxObject, parentKey?: string | null) => Promise<TreeRowObject>;
6060
getInitialTableState: (guid: string) => TableState;
6161
writeTableState: (state: TableState) => void;
62-
onSelect: (ids: string[]) => void;
62+
onSelect: (ids?: string[]) => void;
6363
resetColumns: (col: string) => void;
6464
reset: () => void;
6565
debug: (...args: unknown[]) => void;
@@ -89,7 +89,7 @@ export class NodeStore {
8989
private convertMxObjectToRow: (mxObject: mendix.lib.MxObject, parentKey?: string | null) => Promise<TreeRowObject>;
9090
private getInitialTableState: (guid: string) => TableState;
9191
private writeTableState: (state: TableState) => void;
92-
private onSelect: (ids: string[]) => void;
92+
private onSelect: (ids?: string[]) => void;
9393

9494
private selectionMode: SelectionMode;
9595
private dataResetOnContextChange: boolean;
@@ -526,13 +526,15 @@ export class NodeStore {
526526
return this.rowObjects.filter(findRow => findRow._parent && findRow._parent === row.key).length > 0;
527527
}
528528

529-
private _setSelectedFromExternal(guids: string | string[]): void {
529+
private _setSelectedFromExternal(guids?: null | string | string[]): void {
530530
if (this.selectionMode === "none") {
531531
return;
532532
}
533533

534534
let selected: RowObject[] = [];
535-
if (Array.isArray(guids)) {
535+
if (typeof guids === "undefined" || guids === null) {
536+
selected = [];
537+
} else if (Array.isArray(guids)) {
536538
selected = guids.map(guid => this.findRowObject(guid)).filter(obj => obj !== null) as RowObject[];
537539
} else {
538540
const object = this.findRowObject(guids);
@@ -561,6 +563,9 @@ export class NodeStore {
561563
this.setSelected(selectedGuids);
562564
this.setExpanded(parentGuids);
563565
this.onSelect(selectedGuids);
566+
} else if (selected.length === 0) {
567+
this.setSelected();
568+
this.onSelect();
564569
}
565570
}
566571

typings/MxTreeTableProps.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export interface MxTreeTableContainerProps extends CommonProps {
116116
stateLocalStorageTime: number;
117117
stateLocalStorageType: StateManagementStorage;
118118
stateLocalStorageKey: string;
119+
stateLocalStorageKeyIncludeGUID: boolean;
119120
stateExecuteSelectActionOnRestore: boolean;
120121
// stateEntity: string;
121122
// getStateObjectMicroflow: string;

0 commit comments

Comments
 (0)