-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathcontainer.tsx
More file actions
97 lines (84 loc) · 2.85 KB
/
container.tsx
File metadata and controls
97 lines (84 loc) · 2.85 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
import { createRef, h } from 'preact';
import { classJoin, className } from '../util/className';
import { Status } from '../types';
import { Table } from './table/table';
import { HeaderContainer } from './headerContainer';
import { FooterContainer } from './footerContainer';
import log from '../util/log';
import { useEffect } from 'preact/hooks';
import * as actions from './actions';
import { useStore } from '../hooks/useStore';
import useSelector from '../../src/hooks/useSelector';
import { useConfig } from '../../src/hooks/useConfig';
import { SearchConfig } from '../../src/view/plugin/search/search';
export function Container() {
const config = useConfig();
const { dispatch } = useStore();
const status = useSelector((state) => state.status);
const data = useSelector((state) => state.data);
const tableRef = useSelector((state) => state.tableRef);
const tempRef = createRef();
useEffect(() => {
// set the initial header object
// we update the header width later when "data"
// is available in the state
dispatch(actions.SetHeader(config.header));
if ((config.search as SearchConfig)?.keyword) {
//skipping initial pipeline as search keyword is present and search plugin will handle the initial data laod
} else {
processPipeline();
}
config.pipeline.on('updated', processPipeline);
return () => config.pipeline.off('updated', processPipeline);
}, []);
useEffect(() => {
if (config.header && status === Status.Loaded && data?.length) {
// now that we have the data, let's adjust columns width
// NOTE: that we only calculate the columns width once
dispatch(
actions.SetHeader(config.header.adjustWidth(config, tableRef, tempRef)),
);
}
}, [data, config, tempRef]);
const processPipeline = async () => {
dispatch(actions.SetLoadingData());
try {
const data = await config.pipeline.process();
dispatch(actions.SetData(data));
// TODO: do we need this setTimemout?
setTimeout(() => {
dispatch(actions.SetStatusToRendered());
}, 0);
} catch (e) {
log.error(e);
dispatch(actions.SetDataErrored());
}
};
return (
<div
role="complementary"
className={classJoin(
'gridjs',
className('container'),
status === Status.Loading ? className('loading') : null,
config.className.container,
)}
style={{
...config.style.container,
...{
width: config.width,
},
}}
>
{status === Status.Loading && (
<div className={className('loading-bar')} />
)}
<HeaderContainer />
<div className={className('wrapper')} style={{ height: config.height }}>
<Table />
</div>
<FooterContainer />
<div ref={tempRef} id="gridjs-temp" className={className('temp')} />
</div>
);
}