-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiagram.js
51 lines (44 loc) · 1.47 KB
/
diagram.js
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
import {h} from 'https://esm.sh/preact';
import htm from 'https://esm.sh/htm';
import {useEffect} from 'https://esm.sh/preact/hooks';
const html = htm.bind(h);
export function Diagram({document, onOpenFrame, mcAccessToken}) {
let image = '';
if (document.documentID) {
image = html`
<div class="image">
<img src="data:image/x-png;base64, ${document.diagramImage}" alt="${document.title}"/>
</div>`;
}
const buildUrl = (pathname) => {
return `${MC_BASE_URL}/oauth/frame/?token=${mcAccessToken}&redirect=${pathname}`;
};
const onEdit = () => {
onOpenFrame(buildUrl(
`/app/projects/${document.projectID}/diagrams/${document.documentID}/version/v${document.major}.${document.minor}/edit`));
return false;
};
const onSelect = () => {
onOpenFrame(buildUrl(
`/app/plugins/confluence/select`))
return false;
};
useEffect(() => {
if (!document.documentID) {
onSelect();
}
}, [document])
return html`
<div id="diagram-container">
<div class="diagram">
${image}
</div>
<div class="select-buttons">
<button type="button" onClick="${onEdit}">Edit current diagram</button>
<button type="button" onClick="${onSelect}">
Select different diagram
</button>
</div>
</div>
`;
}