-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDashContainerPanel.tsx
More file actions
197 lines (190 loc) · 6.29 KB
/
Copy pathDashContainerPanel.tsx
File metadata and controls
197 lines (190 loc) · 6.29 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import {switchInput} from '@xh/hoist/desktop/cmp/input';
import {toolbar} from '@xh/hoist/desktop/cmp/toolbar';
import React from 'react';
import {creates, hoistCmp, HoistModel, managed, XH} from '@xh/hoist/core';
import {bindable, makeObservable} from '@xh/hoist/mobx';
import {Icon} from '@xh/hoist/icon';
import {filler, frame} from '@xh/hoist/cmp/layout';
import {panel} from '@xh/hoist/desktop/cmp/panel';
import {button, refreshButton} from '@xh/hoist/desktop/cmp/button';
import {dashContainer, DashContainerModel} from '@xh/hoist/desktop/cmp/dash';
import {
buttonWidget,
chartWidget,
gridWidget,
panelWidget,
treeGridWidget,
errorWidget
} from '../widgets';
import {wrapper} from '../../../common';
export const dashContainerPanel = hoistCmp.factory({
model: creates(() => DashContainerPanelModel),
render({model}) {
return wrapper({
description: [
<p>
<code>DashContainer</code> is configured and managed via a{' '}
<code>DashContainerModel</code>
and allows the user to drag-and-drop content into various tab, and split-pane
layouts. This component also supports publishing observable state, managed
mounting/unmounting of inactive tabs, and lazy refreshing of its active view.
</p>
],
item: panel({
title: 'Layout › Dash Container',
icon: Icon.layout(),
headerItems: [refreshButton({minimal: true, intent: null})],
height: '80%',
width: '80%',
item: model.renderDashboard
? dashContainer({testId: 'dash-container'})
: frame({
item: 'The Dashboard is not rendered now and has been unmounted. When rendered again, its previous state will be restored.',
padding: 10
}),
bbar: bbar()
}),
links: [
{
url: '$TB/client-app/src/desktop/tabs/layout/dashContainer/DashContainerPanel.tsx',
notes: 'This example.'
},
{
url: '$HR/desktop/cmp/dash/container/DashContainer.ts',
notes: 'Hoist container component.'
},
{
url: '$HR/desktop/cmp/dash/container/DashContainerModel.ts',
notes: 'Hoist container model - primary API.'
},
{
url: '$HR/desktop/cmp/dash/DashViewSpec.ts',
notes: 'Configuration template for contained views.'
},
{
url: '$HR/desktop/cmp/dash/DashViewModel.ts',
notes: 'Model for contained view instances. '
}
]
});
}
});
const bbar = hoistCmp.factory<DashContainerPanelModel>(({model}) =>
toolbar(
switchInput({
label: 'Render Dashboard',
bind: 'renderDashboard',
labelSide: 'left'
}),
'-',
switchInput({
label: 'Layout Locked',
bind: 'layoutLocked',
labelSide: 'left',
model: model.dashContainerModel
}),
'-',
switchInput({
label: 'Content Locked',
bind: 'contentLocked',
labelSide: 'left',
model: model.dashContainerModel
}),
'-',
switchInput({
label: 'Rename Locked',
bind: 'renameLocked',
labelSide: 'left',
model: model.dashContainerModel
}),
filler(),
button({
text: 'Reset & Clear State',
icon: Icon.reset(),
onClick: () => model.resetState()
})
)
);
class DashContainerPanelModel extends HoistModel {
@bindable renderDashboard = true;
@managed
dashContainerModel = new DashContainerModel({
persistWith: {localStorageKey: 'dashContainerExampleState'},
showMenuButton: true,
initialState: [
{
type: 'row',
content: [
{
type: 'stack',
width: 60,
content: [
{type: 'view', id: 'grid'},
{type: 'view', id: 'treeGrid'},
{type: 'view', id: 'error'}
]
},
{
type: 'column',
width: 40,
content: [
{type: 'view', id: 'chart'},
{type: 'view', id: 'buttons', height: '200px'}
]
}
]
}
],
viewSpecDefaults: {
icon: Icon.grid()
},
viewSpecs: [
{
id: 'grid',
title: 'Grid',
unique: true,
content: gridWidget
},
{
id: 'buttons',
title: 'Buttons',
icon: Icon.stop(),
content: buttonWidget
},
{
id: 'chart',
title: 'Chart',
icon: Icon.chartLine(),
unique: true,
refreshMode: 'onShowAlways',
content: chartWidget
},
{
id: 'panel',
title: 'Panel',
icon: Icon.window(),
renderMode: 'always',
content: panelWidget
},
{
id: 'treeGrid',
title: 'Tree Grid',
content: treeGridWidget
},
{
id: 'error',
title: 'Error Example',
content: errorWidget({componentName: 'DashContainer'})
}
]
});
constructor() {
super();
makeObservable(this);
}
resetState() {
this.dashContainerModel
.restoreDefaultsAsync()
.then(() => XH.toast({message: 'Dash state reset to default'}));
}
}