-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsimple-table.component.js
More file actions
103 lines (89 loc) · 3.39 KB
/
simple-table.component.js
File metadata and controls
103 lines (89 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Utils } from "../../../helpers/utils.js";
import { BaseComponent } from "../../base.component.js";
const TAG = "[SimpleTableComponent]";
export class SimpleTableComponent extends BaseComponent {
jsComponentPConnectData = {};
childComponent;
props = {
child: undefined,
};
constructor(componentsManager, pConn) {
super(componentsManager, pConn);
this.type = "SimpleTable";
this.utils = new Utils();
}
init() {
this.jsComponentPConnectData = this.jsComponentPConnect.registerAndSubscribeComponent(
this,
this.checkAndUpdate
);
this.componentsManager.onComponentAdded(this);
this.checkAndUpdate();
}
destroy() {
super.destroy();
this.jsComponentPConnectData.unsubscribeFn?.();
this.childComponent?.destroy?.();
this.childComponent = null
this.#sendPropsUpdate();
this.componentsManager.onComponentRemoved(this);
}
update(pConn) {
if (this.pConn !== pConn) {
this.pConn = pConn;
this.checkAndUpdate();
}
}
checkAndUpdate() {
if (this.jsComponentPConnect.shouldComponentUpdate(this)) {
this.#updateSelf();
}
}
#updateSelf() {
const configProps = this.pConn.resolveConfigProps(this.pConn.getConfigProps());
this.props.label = configProps.label;
if (configProps.value !== undefined) {
this.props.value = configProps.value;
}
if (configProps.visibility != null) {
this.props.visible = this.utils.getBooleanValue(configProps.visibility);
}
const { multiRecordDisplayAs, fieldMetadata } = configProps;
let { contextClass } = configProps;
if (!contextClass) {
let listName = this.pConn.getComponentConfig().referenceList;
listName = PCore.getAnnotationUtils().getPropertyName(listName);
contextClass = this.pConn.getFieldMetadata(listName)?.pageClass;
}
if (multiRecordDisplayAs === "fieldGroup") {
const fieldGroupProps = { ...configProps, contextClass };
if (this.childComponent) {
this.childComponent.update(this.pConn, fieldGroupProps)
} else {
this.childComponent = this.componentsManager.create("FieldGroupTemplate", [this.pConn, fieldGroupProps]);
this.childComponent.init();
}
this.#sendPropsUpdate();
} else if (fieldMetadata && fieldMetadata.type === 'Page List' && fieldMetadata.dataRetrievalType === 'refer') {
console.warn(TAG, 'Displaying ListView in SimpleTable is not supported yet.');
} else {
if (this.childComponent) {
this.childComponent.update(this.pConn);
} else {
this.childComponent = this.componentsManager.create("SimpleTableManual", [this.pConn]);
this.childComponent.init();
}
this.#sendPropsUpdate();
}
}
onEvent(event) {
// TODO: remove optional call when all other modes are implemented so that child component is always defined
this.childComponent?.onEvent(event);
}
#sendPropsUpdate() {
this.props = {
child: this.childComponent?.compId ?? "-1",
};
this.componentsManager.onComponentPropsUpdate(this);
}
}