-
Notifications
You must be signed in to change notification settings - Fork 167
/
backlog-toolpane.tsx
80 lines (65 loc) · 2.69 KB
/
backlog-toolpane.tsx
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
import * as React from "react";
import * as SDK from "azure-devops-extension-sdk";
import "./backlog-toolpane.scss";
import { Header } from "azure-devops-ui/Header";
import { Page } from "azure-devops-ui/Page";
import { showRootComponent } from "../../Common";
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
interface IBacklogToolPane {
projectContext: any;
selectedWorkItems: any[];
}
class BacklogToolPane extends React.Component<{}, IBacklogToolPane> {
constructor(props: {}) {
super(props);
this.state = { projectContext: undefined, selectedWorkItems: [] };
}
public componentDidMount() {
try {
console.log("Component did mount, register objects...");
SDK.register("backlogPanelObject", {
workItemSelectionChanged: (workItemInfos: any) => {
console.log("workItemSelectionChanged", workItemInfos);
this.setState({ selectedWorkItems: workItemInfos });
}
});
console.log("Initializing SDK...");
SDK.init();
SDK.ready().then(() => {
console.log("SDK is ready, loading project context...");
this.loadProjectContext();
}).catch((error) => {
console.error("SDK ready failed: ", error);
});
} catch (error) {
console.error("Error during SDK initialization or project context loading: ", error);
}
}
public render(): JSX.Element {
return (
<Page className="sample-hub flex-grow">
<div className="page-content sample-margin">
<div className="webcontext-section">
<h2>Project Context:</h2>
<pre>{JSON.stringify(this.state.projectContext, null, 2)}</pre>
</div>
<div>
<h2>Selected Work Items:</h2>
<pre>{JSON.stringify(this.state.selectedWorkItems, null, 2)}</pre>
</div>
</div>
</Page>
);
}
private async loadProjectContext(): Promise<void> {
try {
const client = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const context = await client.getProject();
this.setState({ projectContext: context });
SDK.notifyLoadSucceeded();
} catch (error) {
console.error("Failed to load project context: ", error);
}
}
}
showRootComponent(<BacklogToolPane />);