Skip to content

Commit 08478ad

Browse files
authored
Feature/refresh on context change (#18)
1 parent bf82fb8 commit 08478ad

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
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.3",
4+
"version": "2.0.4",
55
"description": "TreeTable widget",
66
"copyright": "Mendix 2019",
77
"author": "Jelte Lagendijk <jelte.lagendijk@mendix.com>",

src/MxTreeTable.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
122122

123123
// Create store
124124
const storeOpts: NodeStoreConstructorOptions = {
125+
dataResetOnContextChange: this.props.dataResetOnContextChange,
125126
calculateInitialParents: this.props.loadScenario === "all",
126127
rowObjectMxProperties: {
127128
nodeChildReference: this.referenceAttr,
@@ -202,6 +203,10 @@ class MxTreeTable extends Component<MxTreeTableContainerProps> {
202203
}
203204
}
204205

206+
componentWillUnmount(): void {
207+
this.store.clearSubscriptions();
208+
}
209+
205210
render(): ReactNode {
206211
const {
207212
uiShowHeader,

src/MxTreeTable.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
</attributeTypes>
6565
</property>
6666
</propertyGroup>
67+
<propertyGroup caption="Reset">
68+
<property key="dataResetOnContextChange" type="boolean" defaultValue="false">
69+
<caption>Reset on context change</caption>
70+
<description>This should be false by default, because you only want to reload the whole table when the context object is switched (new object guid). If for some reason you need to reset the table whenever the context object changes, set this to true. Use this combined with the 'Whole Tree' scenario and state management.</description>
71+
</property>
72+
</propertyGroup>
6773
</propertyGroup>
6874

6975
<!-- ****************

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.3" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="MxTreeTable" version="2.0.4" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="MxTreeTable.xml"/>
66
</widgetFiles>

src/store/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface RowObjectMxProperties {
4343

4444
export interface NodeStoreConstructorOptions {
4545
contextObject?: mendix.lib.MxObject;
46+
dataResetOnContextChange?: boolean;
4647
columns: TreeColumnProps[];
4748
validColumns: boolean;
4849
selectFirstOnSingle: boolean;
@@ -87,6 +88,7 @@ export class NodeStore {
8788
private writeTableState: (state: TableState) => void;
8889
private onSelect: (ids: string[]) => void;
8990

91+
private dataResetOnContextChange: boolean;
9092
private needToCalculateInitialParents: boolean;
9193
private needToRestoreStateOnContextChange: boolean;
9294
private needToRestoreSelectFirst: boolean;
@@ -96,6 +98,7 @@ export class NodeStore {
9698

9799
constructor({
98100
contextObject,
101+
dataResetOnContextChange,
99102
columns,
100103
validColumns,
101104
selectFirstOnSingle,
@@ -113,6 +116,7 @@ export class NodeStore {
113116
debug
114117
}: NodeStoreConstructorOptions) {
115118
this.contextObject = contextObject || null;
119+
this.dataResetOnContextChange = typeof dataResetOnContextChange !== 'undefined' ? dataResetOnContextChange : false;
116120
this.columns = columns;
117121
this.validColumns = validColumns;
118122
this.selectFirstOnSingle = selectFirstOnSingle;
@@ -140,7 +144,7 @@ export class NodeStore {
140144
@action
141145
setContext(obj?: mendix.lib.MxObject): void {
142146
this.debug("Store: setContext", obj);
143-
if (this.contextObject !== null && obj && this.contextObject.getGuid() !== obj.getGuid()) {
147+
if (this.contextObject !== null && obj && (this.contextObject.getGuid() !== obj.getGuid() || this.dataResetOnContextChange)) {
144148
if (this.needToCalculateInitialParents) {
145149
this.calculateInitialParents = true;
146150
if (this.needToRestoreStateOnContextChange) {
@@ -385,7 +389,7 @@ export class NodeStore {
385389

386390
const { subscribe } = window.mx.data;
387391

388-
if (this.contextObject && this.contextObject.getGuid) {
392+
if (this.contextObject && this.contextObject.getGuid && !this.dataResetOnContextChange) {
389393
const guid = this.contextObject.getGuid();
390394
this.subscriptionHandles.push(
391395
subscribe({

typings/MxTreeTableProps.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface MxTreeTableContainerProps extends CommonProps {
6464
getDataMf: string;
6565
getDataNf: Nanoflow;
6666
nodeIsRootAttr: string;
67+
dataResetOnContextChange: boolean;
6768

6869
childMethod: ChildDataSource;
6970
childReference: string;

0 commit comments

Comments
 (0)