Skip to content

Commit

Permalink
adding errors and logout for #28
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Oct 24, 2023
1 parent 77e5935 commit 9a57a7f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 51 deletions.
11 changes: 10 additions & 1 deletion pages/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,24 @@ module.exports = function (env) {
<li>
<a href="https://github.com/bitovi/jira-timeline-report" class="color-gray-900 text-2xl underline-on-hover">Jira Timeline Report</a>
</li>
<li>
<a href="https://www.bitovi.com/services/agile-project-management-consulting" class="by-bitovi">Bitovi</a>
</li>
</ul>
<div>
<a href="https://www.bitovi.com/services/agile-project-management-consulting" class="by-bitovi">Bitovi</a>
<button id="logout" class="p-2 block color-gray-900 underline-on-hover pointer">Log out</button>
</div>
</div>
</nav>
</div>
<div id="mainElement" class='place-center w-1280'>Loading ... </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.1.2/axios.min.js"></script>
<script>
logout.onclick = function(){
localStorage.clear();
window.location.reload();
}
</script>
<script type="module">
import JiraOIDCHelpers from "./jira-oidc-helpers.js";
import main from "./main.js";
Expand Down
38 changes: 25 additions & 13 deletions public/jira-oidc-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
const CACHE_FETCH = false;

function responseToJSON(response) {
if(!response.ok) {
return response.json().then((payload) => {
const err = new Error("HTTP status code: " + response.status);
Object.assign(err, payload);
Object.assign(err, response);
throw err;
})
}
return response.json();
}

Expand Down Expand Up @@ -223,27 +231,31 @@ export default function JiraOIDCHelpers({
return response;
})
},
fetchAllJiraIssuesWithJQLAndFetchAllChangelog: async function (params) {
fetchAllJiraIssuesWithJQLAndFetchAllChangelog: function (params) {
function getRemainingChangeLogsForIssues(response) {
return jiraHelpers.fetchRemainingChangelogsForIssues(response.issues)
}

const firstRequest = jiraHelpers.fetchJiraIssuesWithJQL({ maxResults: 100, expand: ["changelog"], ...params });

const { issues, maxResults, total, startAt } = await firstRequest;
const requests = [firstRequest.then(getRemainingChangeLogsForIssues)];
return firstRequest.then( ({ issues, maxResults, total, startAt }) => {

for (let i = startAt + maxResults; i < total; i += maxResults) {
requests.push(
jiraHelpers.fetchJiraIssuesWithJQL({ maxResults: maxResults, startAt: i, ...params })
.then(getRemainingChangeLogsForIssues)
);
}
return Promise.all(requests).then(
(responses) => {
return responses.flat();
const requests = [firstRequest.then(getRemainingChangeLogsForIssues)];

for (let i = startAt + maxResults; i < total; i += maxResults) {
requests.push(
jiraHelpers.fetchJiraIssuesWithJQL({ maxResults: maxResults, startAt: i, ...params })
.then(getRemainingChangeLogsForIssues)
);
}
)
return Promise.all(requests).then(
(responses) => {
return responses.flat();
}
)
});


},
// this could do each response incrementally, but I'm being lazy
fetchAllJiraIssuesWithJQLAndFetchAllChangelogUsingNamedFields: async function (params) {
Expand Down
90 changes: 53 additions & 37 deletions public/timeline-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,29 @@ export class TimelineReport extends StacheElement {
</details>
{{# if( not(this.jql) ) }}
<div class="my-2 p-2 h-780 border-solid-1px-slate-900 border-box block overflow-hidden color-bg-white drop-shadow-md">Enter a JQL above.</div>
{{ /if }}
{{# if(this.releases) }}
{{# if(this.rawIssuesPromise.value) }}
<steerco-timeline
class='my-2 border-solid-1px-slate-900 border-box block overflow-hidden color-bg-white drop-shadow-md'
releases:from="this.releases"
initiatives:from="this.initiativesWithAStartAndEndDate"
breakOutTimings:from="this.breakOutTimings"
showReleasesInTimeline:from="this.showReleasesInTimeline"
/>
{{ else }}
{{# if(this.jql) }}
<div class="my-2 p-2 h-780 border-solid-1px-slate-900 border-box block overflow-hidden color-bg-white drop-shadow-md">Loading ...</div>
{{/ if }}
{{/ if}}
{{/ if }}
{{# if(this.rawIssuesPromise.isPending) }}
<div class="my-2 p-2 h-780 border-solid-1px-slate-900 border-box block overflow-hidden color-bg-white drop-shadow-md">Loading ...</div>
{{/ if }}
{{# if(this.rawIssuesPromise.isRejected) }}
<div class="my-2 p-2 h-780 border-solid-1px-slate-900 border-box block overflow-hidden color-text-and-bg-blocked drop-shadow-md">
<p>There was an error loading from Jira!</p>
<p>Error message: {{this.rawIssuesPromise.reason.errorMessages[0]}}</p>
<p>Please check your JQL is correct!</p>
</div>
{{/ if }}
`;
static props = {
Expand Down Expand Up @@ -217,41 +222,52 @@ export class TimelineReport extends StacheElement {
default: function (issue) {
return issue?.[FIX_VERSIONS_KEY]?.[0]?.name;
}
},
rawIssues: {
async(resolve) {
console.log("checking for promise")
if(!this.rawIssuesPromise) {
console.log("no promise");
resolve(null)
} else {
console.log("have a promise")
this.rawIssuesPromise.then(resolve);
}
}
}
};
// hooks
async connected() {

this.jiraHelpers.getServerInfo().then((serverInfo) => {
this.serverInfo = serverInfo;
}
get serverInfoPromise(){
return this.jiraHelpers.getServerInfo();
}
get rawIssuesPromise(){
if (this.jql) {
const serverInfoPromise = this.serverInfoPromise;

const issuesPromise = this.jiraHelpers.fetchAllJiraIssuesWithJQLAndFetchAllChangelogUsingNamedFields({
jql: this.jql,
fields: ["summary",
"Rank",
"Start date",
"Due date",
"Issue Type",
"Fix versions",
"Story Points",
"Confidence",
"Product Target Release", PARENT_LINK_KEY, LABELS_KEY, STATUS_KEY, "Sprint", "Epic Link", "Created"],
expand: ["changelog"]
});

if (this.jql) {
const serverInfoPromise = this.jiraHelpers.getServerInfo();

const issuesPromise = this.jiraHelpers.fetchAllJiraIssuesWithJQLAndFetchAllChangelogUsingNamedFields({
jql: this.jql,
fields: ["summary",
"Rank",
"Start date",
"Due date",
"Issue Type",
"Fix versions",
"Story Points",
"Confidence",
"Product Target Release", PARENT_LINK_KEY, LABELS_KEY, STATUS_KEY, "Sprint", "Epic Link", "Created"],
expand: ["changelog"]
});

Promise.all([
issuesPromise, serverInfoPromise
]).then(([issues, serverInfo]) => {
this.rawIssues = rawIssuesToBaseIssueFormat(issues, serverInfo);
})


}
return Promise.all([
issuesPromise, serverInfoPromise
]).then(([issues, serverInfo]) => {
return rawIssuesToBaseIssueFormat(issues, serverInfo);

})
}
}
get teams() {
if (!this.rawIssues) {
Expand Down

0 comments on commit 9a57a7f

Please sign in to comment.