forked from VisActor/VChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoption.tsx
More file actions
73 lines (68 loc) · 2.44 KB
/
Copy pathoption.tsx
File metadata and controls
73 lines (68 loc) · 2.44 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
import { Layout } from '@arco-design/web-react';
import { useLocation } from 'react-router-dom';
import { Header } from './header';
import { useContext, useEffect, useRef, useState } from 'react';
import { LanguageContext } from './i18n';
import { OptionDocument } from './option/index';
import { parseOutline } from './option/outline';
import { parseDescription } from './option/description';
import menu from '../menu.json';
export function Option() {
const { language, setLanguage } = useContext(LanguageContext);
const location = useLocation();
const { pathname: pathName } = location;
const assetDirectory = pathName.split('/')[2];
const menuConfig = menu.find(menuItem => menuItem.menu === assetDirectory);
const getOutline = async () => {
try {
const response = await fetch(`/documents/${assetDirectory}/${language}/outline.json`);
const json = await response.json();
return parseOutline(json, {}, [
{ from: 'Chart.axes$', to: 'Chart-axes' },
{ from: 'Chart.legends$', to: 'Chart-legends' },
{ from: 'Chart.extensionMark$', to: 'Chart-extensionMark' },
{ from: 'Chart.customMark$', to: 'Chart-customMark' },
{ from: 'Chart.series$', to: 'Chart-series' },
{ from: 'Chart.total$', to: 'Chart-total' }
]);
} catch (e) {
console.log(e);
}
return null;
};
const getDescription = async (pathName: string) => {
try {
const optionPath = pathName.split(`/${assetDirectory}/`)[1];
if (!optionPath) {
return [];
}
const basePath = optionPath.split('.')[0];
const response = await fetch(
!basePath || basePath === ''
? `/documents/${assetDirectory}/${language}/${assetDirectory}.json`
: `/documents/${assetDirectory}/${language}/${assetDirectory}.${basePath}.json`
);
const json = await response.json();
return parseDescription(json, basePath) ?? [];
} catch (e) {
console.log(e);
}
return '';
};
return (
<Layout>
<Layout.Header>
<Header />
</Layout.Header>
<Layout style={{ height: 'calc(100vh - 48px)', marginTop: '48px' }}>
<OptionDocument
baseUrl={`/vchart/${assetDirectory}`}
getOutline={getOutline}
getDescription={getDescription}
outlineStyle={{ maxHeight: 'calc(100vh - 48px)' }}
descriptionStyle={{ maxHeight: 'calc(100vh - 48px)' }}
/>
</Layout>
</Layout>
);
}