-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
104 lines (86 loc) · 2.64 KB
/
index.jsx
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
import ForgeUI, {
render,
useState,
useProductContext,
Text,
TextField,
InlineDialog,
ContentBylineItem,
Form,
Select,
Option,
Button,
} from "@forge/ui";
import { properties, storage, startsWith } from "@forge/api";
const App = () => {
const { contentId } = useProductContext();
const [getLabels, setLabels] = useState(async () => {
let result = await storage.get('classificationLabels');
if (typeof result === "undefined" || result === null) return [];
result = JSON.parse(result);
return result;
});
const [getClassState, setClassState] = useState(async () => {
let result = await properties.onConfluencePage(contentId).get("pageclassification");
if (typeof result == "undefined" || result === null) result = "not set";
return result;
});
const saveLabel = async (formData) => {
if (formData) {
let currentLabels = await getLabels;
currentLabels.push(
{ label: formData.label, value: formData.label }
);
await storage
.set('classificationLabels', JSON.stringify(currentLabels))
.then(() => setLabels(currentLabels));
}
};
const saveClassification = async (formData) => {
await properties
.onConfluencePage(contentId)
.set("pageclassification", formData.selection)
.then(() => setClassState(formData.selection));
};
const emptyLabels = async () => {
await storage
.set('classificationLabels', "")
.then(() => setLabels([]));
}
const emptyButton = [
<Button text="Clear saved labels" onClick={emptyLabels} />
];
return (
<InlineDialog>
<Text>{`Classification: ${getClassState}`}</Text>
<Form onSubmit={saveClassification} submitButtonText="Save">
<Select label="Pick a saved label" name="selection">
{getLabels.map(option => <Option {...option} />)}
</Select>
</Form>
<Form onSubmit={saveLabel} submitButtonText="Add" actionButtons={emptyButton}>
<TextField name="label" label="Custom label" />
</Form>
</InlineDialog>
);
};
export const run = render(
<ContentBylineItem>
<App />
</ContentBylineItem>
);
export const getDP = async (contextPayload) => {
const useValidIcon = true;
const {
extension: {
content: { id: contentId },
},
} = contextPayload;
let getClassState = await properties.onConfluencePage(contentId).get("pageclassification");
if (typeof getClassState == "undefined") getClassState = "Not set";
return {
title: `Classification: ${getClassState}`,
icon: "https://chapter8.com/assets/images/2023-logo-8.svg",
tooltip: `Click to change the document classification`,
};
};