-
Notifications
You must be signed in to change notification settings - Fork 167
/
code-hub-group.tsx
67 lines (54 loc) · 2.12 KB
/
code-hub-group.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
import * as React from "react";
import * as SDK from "azure-devops-extension-sdk";
import "./code-hub-group.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 ICodeHubGroup {
projectContext: any;
}
class CodeHubGroup extends React.Component<{}, ICodeHubGroup> {
constructor(props: {}) {
super(props);
this.state = { projectContext: undefined };
}
public componentDidMount() {
try {
console.log("Component did mount, 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">
<Header title="Custom Code Hub" />
<div className="page-content">
<div className="webcontext-section">
<h2>Project Context:</h2>
<pre>{JSON.stringify(this.state.projectContext, 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(<CodeHubGroup />);