Skip to content

Commit 61c41b4

Browse files
committed
main - added project view command
1 parent fa1f26a commit 61c41b4

File tree

4 files changed

+207
-10
lines changed

4 files changed

+207
-10
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,44 @@ Allows adding updates to the projects owned by the users
1111
- Valid Commit account, as this is needed to get Authenticated
1212
- Already existing projects.
1313

14-
## Extension Settings
14+
## Installing
1515

16-
TBD
16+
As this extension is private, you need to install it from the VSIX file using the command line as follows:
17+
18+
```bash
19+
code --install-extension commit-extension-<VERSION NUMBER>.vsix
20+
```
21+
22+
## Getting Started
23+
24+
Once the extension is installed, you need to authenticate with you Commit account. Follow the steps below to Authenticate:
25+
26+
- Authenticate with your Commit account. You can do this by clicking on the User icon on the left side and then clicking on option `Sign in with Commit to use Commit Extension`.
27+
- This will show one-time code as a popup in the bottom right corner. Copy this code by click on `Copy` button.
28+
- Extension will prompt you to open the Commit authentication page in the browser. Click on `Open` button.
29+
- Paste the code in the browser and click on `Sign in` button.
30+
- Once the authentication is successful, close the browser tab and go back to VS Code.
31+
- You will see a message `Welcome <YOUR NAME> to Commit` in the bottom right corner.
32+
33+
Follow the steps below to add an update to your project:
34+
35+
- Press `Ctrl+Shift+P` to open the command palette.
36+
- Type `Commit: Add Project Update` and press `Enter`.
37+
- Select the project for which you want to add an update.
38+
- Type the update message and press `Enter`.
39+
- You will see a message `Update added successfully` in the bottom right corner.
1740

1841
## Known Issues
42+
Following are the known issues with the extension:
43+
44+
- Currently the project structure is not optimized as current version is a POC.
45+
- There is no testing reports for the extension, thus no CI/CD jobs for that as well.
46+
47+
## Feature Roadmap
48+
Following are the features that are planned to be added in the future:
49+
50+
- Add ability to link single project to given workspace.
51+
- Add ability to make other updats such as adding a new project, adding a comment, etc.
52+
- Update Project View to replicate information from Commit Porject page.
53+
- Add ability to connect Github repository to the project, in order to pull information from Github repo such as code type, language, etc.
1954

20-
TBD

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"displayName": "Commit Extension",
1212
"description": "Allow developers to log work on Commit Projects as Latest Updates",
13-
"version": "0.0.1",
13+
"version": "0.0.2",
1414
"engines": {
1515
"vscode": "^1.73.0"
1616
},
@@ -19,14 +19,19 @@
1919
],
2020
"activationEvents": [
2121
"onStartupFinished",
22-
"onCommand:commit-extension.addProjectUpdates"
22+
"onCommand:commit-extension.addProjectUpdates",
23+
"onCommand:commit-extension.viewProjects"
2324
],
2425
"main": "./dist/extension.js",
2526
"contributes": {
2627
"commands": [
2728
{
2829
"command": "commit-extension.addProjectUpdates",
2930
"title": "Commit: Add Project Updates"
31+
},
32+
{
33+
"command": "commit-extension.viewProjects",
34+
"title": "Commit: View Projects"
3035
}
3136
]
3237
},

src/extension.ts

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import {
22
ApolloClient,
33
createHttpLink,
4+
DefaultOptions,
45
InMemoryCache,
56
} from "@apollo/client/core";
67
import { setContext } from "@apollo/client/link/context";
8+
import * as fs from "fs";
79
import fetch from "node-fetch";
810
import * as vscode from "vscode";
911
import { API, Project } from "./api";
1012
import { Auth0AuthenticationProvider, AUTH_TYPE } from "./auth0AuthProvider";
13+
import path = require("path");
1114

1215
const COMMIT_GRAPHQL_API_URL = "https://api.commit-staging.dev/graphql";
1316
const COMMIT_API_BASE_URL = "https://app.commit-staging.dev/";
1417

1518
export async function activate(context: vscode.ExtensionContext) {
16-
console.log(
17-
'Congratulations, your extension "Commit Extension" is now active!'
18-
);
19-
2019
const subscriptions = context.subscriptions;
2120

2221
subscriptions.push(new Auth0AuthenticationProvider(context));
@@ -50,9 +49,22 @@ export async function activate(context: vscode.ExtensionContext) {
5049
};
5150
});
5251

52+
// default options for the apollo client
53+
const defaultOptions: DefaultOptions = {
54+
watchQuery: {
55+
fetchPolicy: "no-cache",
56+
errorPolicy: "ignore",
57+
},
58+
query: {
59+
fetchPolicy: "no-cache",
60+
errorPolicy: "all",
61+
},
62+
};
63+
5364
const client = new ApolloClient({
5465
link: authLink.concat(link),
5566
cache: new InMemoryCache(),
67+
defaultOptions,
5668
});
5769

5870
const api = new API(client);
@@ -116,8 +128,73 @@ export async function activate(context: vscode.ExtensionContext) {
116128
);
117129

118130
subscriptions.push(addProjectUpdateDisposable);
131+
132+
// Register a Webview
133+
let webviewDisposable = vscode.commands.registerCommand(
134+
"commit-extension.viewProjects",
135+
async () => {
136+
const panel = vscode.window.createWebviewPanel(
137+
"commitExtension", // Identifies the type of the webview. Used internally
138+
"Commit Projects", // Title
139+
vscode.ViewColumn.One,
140+
{
141+
enableScripts: true, // Enable javascript in the webview
142+
}
143+
);
144+
145+
// Send message to webview
146+
const sendMessage = (type: string, message: any) => {
147+
panel.webview.postMessage({
148+
command: type,
149+
data: message,
150+
});
151+
};
152+
153+
// Handle messages from the webview
154+
panel.webview.onDidReceiveMessage(
155+
async (message) => {
156+
switch (message.command) {
157+
case "updateProjects":
158+
try {
159+
const projects = await api.getUserProjects();
160+
sendMessage("projects", JSON.stringify(projects));
161+
162+
// Show the success message
163+
vscode.window.showInformationMessage("Projects Updated");
164+
} catch (error: any) {
165+
vscode.window.showErrorMessage(error.message);
166+
}
167+
break;
168+
case "showMessage":
169+
vscode.window.showInformationMessage(message.data);
170+
break;
171+
}
172+
},
173+
undefined,
174+
context.subscriptions
175+
);
176+
177+
// Set the webview's content using vsocde-resource URI
178+
panel.webview.html = getWebviewContent(context);
179+
180+
// sendMessage("update", JSON.stringify(await api.getUserProjects()));
181+
}
182+
);
183+
184+
subscriptions.push(webviewDisposable);
119185
}
120186

187+
const getWebviewContent = (context: vscode.ExtensionContext) => {
188+
// Read the HTML file
189+
const htmlPath = vscode.Uri.file(
190+
path.join(context.extensionPath, "src", "webview", "index.html")
191+
);
192+
193+
const html = htmlPath.with({ scheme: "vscode-resource" });
194+
195+
return fs.readFileSync(html.fsPath, "utf8");
196+
};
197+
121198
const getAuth0Sessions = async () => {
122199
const session = await vscode.authentication.getSession(AUTH_TYPE, [], {
123200
createIfNone: false,
@@ -134,5 +211,5 @@ const getAuth0Sessions = async () => {
134211

135212
// This method is called when your extension is deactivated
136213
export function deactivate() {
137-
console.log("Commit Extension deactivated");
214+
// Remove the AUTH_TYPE session
138215
}

src/webview/index.html

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<script src="https://cdn.tailwindcss.com"></script>
7+
</head>
8+
<body class="m-5">
9+
<div class="">
10+
<h1 class="text-3xl font-bold">
11+
Your Projects
12+
</h1>
13+
</div>
14+
15+
<!-- Button to refresh projects -->
16+
<div class="mt-4">
17+
<btn id="update-projects" class="bg-blue-500 hover:bg-blue-700 cursor-pointer text-white font-bold py-2 px-4 rounded">
18+
Refresh Projects
19+
</btn>
20+
</div>
21+
<!-- Project List table -->
22+
<div class="my-2">
23+
<table id="projects-table" class="shadow-lg bg-slate-800 border-separate">
24+
<thead>
25+
<tr>
26+
<th class="bg-blue-300 border text-left px-8 py-4">Title</th>
27+
<th class="bg-blue-300 border text-left px-8 py-4">Porject ID</th>
28+
</tr>
29+
</thead>
30+
<tbody id="projects-table-body">
31+
</tbody>
32+
</table>
33+
</div>
34+
<script>
35+
// Import the API, Keyring and some utility functions
36+
const vscode = acquireVsCodeApi();
37+
38+
// Create onload function
39+
window.onload = function() {
40+
vscode.postMessage({
41+
command: 'updateProjects'
42+
});
43+
};
44+
45+
// Button to refresh projects
46+
const updateProjects = document.getElementById('update-projects');
47+
// Add onclick listener to button
48+
updateProjects.addEventListener('click', () => {
49+
// Send a message back to the extension
50+
vscode.postMessage({
51+
command: 'updateProjects'
52+
});
53+
});
54+
55+
// Handle messages sent from the extension to the webview
56+
window.addEventListener('message', event => {
57+
const message = event.data; // The JSON data our extension sent
58+
switch (message.command) {
59+
case 'projects':
60+
// Update the projects list
61+
const projectsElm = document.getElementById('projects-table-body');
62+
projectsElm.innerHTML = '';
63+
64+
// Load Message JSON String data into an array
65+
const projects = JSON.parse(message.data);
66+
projects.forEach(project => {
67+
const row = document.createElement('tr');
68+
row.innerHTML = `
69+
<td class="border px-8 py-4">${project.title}</td>
70+
<td class="border px-8 py-4">${project.id}</td>
71+
`;
72+
// Add classes to the row
73+
row.classList.add('hover:bg-gray-500', 'cursor-pointer');
74+
projectsElm.appendChild(row);
75+
});
76+
break;
77+
}
78+
});
79+
</script>
80+
</body>
81+
</html>

0 commit comments

Comments
 (0)