-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathObjectTree.tsx
More file actions
59 lines (50 loc) · 1.88 KB
/
ObjectTree.tsx
File metadata and controls
59 lines (50 loc) · 1.88 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
import {StringParam, useQueryParam} from 'use-query-params';
import {Loader} from '../../../components/Loader';
import {useGetSchemaQuery} from '../../../store/reducers/schema/schema';
import {SchemaTree} from './SchemaTree/SchemaTree';
import i18n from './i18n';
import {b} from './shared';
interface ObjectTreeProps {
tenantName: string;
path?: string;
}
function prepareSchemaRootName(name: string | undefined, fallback: string): string {
if (name) {
return name.startsWith('/') ? name : `/${name}`;
}
return fallback.startsWith('/') ? fallback : `/${fallback}`;
}
export function ObjectTree({tenantName, path}: ObjectTreeProps) {
const {data: tenantData = {}, isLoading} = useGetSchemaQuery({
path: tenantName,
database: tenantName,
});
const pathData = tenantData?.PathDescription?.Self;
const [, setCurrentPath] = useQueryParam('schema', StringParam);
if (!pathData && isLoading) {
// If Loader isn't wrapped with div, SplitPane doesn't calculate panes height correctly
return (
<div>
<Loader />
</div>
);
}
return (
<div className={b('tree-wrapper')}>
<div className={b('tree-header')}>{i18n('title_navigation')}</div>
<div className={b('tree')}>
{pathData ? (
<SchemaTree
rootPath={tenantName}
// for the root pathData.Name contains the same string as tenantName,
// ensure it has the leading slash
rootName={prepareSchemaRootName(pathData.Name, tenantName)}
rootType={pathData.PathType}
currentPath={path}
onActivePathUpdate={setCurrentPath}
/>
) : null}
</div>
</div>
);
}