Hi Team,
The second resolver function defined in the index.js
file is not being invoked. I’m unsure what’s causing the issue.
Please find the code snippet below for reference(using forge issue_panel custom UI).
index.js file
import Resolver from "@forge/resolver";
import api, { route } from "@forge/api";
const resolver = new Resolver();
resolver.define("fetchLabels", async (req) => {
console.log("fetchLabels fun trigged in resolver");
const key = req.context.extension.issue.key;
const res = await api
.asUser()
.requestJira(route`/rest/api/3/issue/${key}?fields=labels`);
const data = await res.json();
const label = data.fields.labels;
if (label == undefined) {
console.warn(`${key}: Failed to find labels`);
return [];
}
return label;
});
resolver.define("getProjects", async (req) => {
console.log("requeste received at resolvers index.js file", req);
const result = await fetch(
"https://dev.azure.com/abcd/_apis/projects?api-version=7.0",
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization:
"Basic asdaskjdhaskfhksjdhfksdfhkjsdhfksdhfkjsdf",
},
}
);
const projects = result;
console.log("fetched projects", projects);
return projects;
});
export const handler = resolver.getDefinitions();
App.js
import React, { useEffect, useState } from "react";
import { events, invoke } from "@forge/bridge";
function App() {
const [data, setData] = useState(null);
const handleFetchSuccess = (data) => {
setData(data);
if (data.length === 0) {
throw new Error("No labels returned");
}
};
const handleFetchError = () => {
console.error("Failed to get label");
};
useEffect(async () => {
(async function () {
const fetchLabels = async () => await invoke("fetchLabels");
fetchLabels().then(handleFetchSuccess).catch(handleFetchError);
const projects = await invoke("getProjects");
console.log("projects", projects);
const subscribeForIssueChangedEvent = () =>
events.on("JIRA_ISSUE_CHANGED", () => {
fetchLabels().then(handleFetchSuccess).catch(handleFetchError);
});
const subscription = subscribeForIssueChangedEvent();
return () => {
subscription.then((subscription) => subscription.unsubscribe());
};
})();
}, []);
if (!data) {
return <div>Loading...</div>;
}
const labels = data.map((label) => <div>{label}</div>);
return (
<div>
<span>Issue labels:</span>
<div>{labels}</div>
</div>
);
}
export default App;