Skip to content

Commit 9040afd

Browse files
committed
reset function added
1 parent 8ad29fe commit 9040afd

File tree

2 files changed

+89
-24
lines changed

2 files changed

+89
-24
lines changed

src/scripts/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ document.addEventListener('DOMContentLoaded', function () {
400400
if (oldToast) oldToast.parentNode.removeChild(oldToast);
401401
console.log('[Org Check] Organisation exists on GitHub:', org);
402402
// Valid org: update storage and fetch data
403-
chrome.storage.local.set({ orgName: org, githubCache: null }, function () {
403+
chrome.storage.local.set({ orgName: org, githubCache: null }, function () {
404404
const scrumReport = document.getElementById('scrumReport');
405405
if (scrumReport) {
406406
scrumReport.innerHTML = '<p style="text-align: center; color: #666; padding: 20px;">Organisation changed. Click "Generate Report" to fetch new data.</p>';

src/scripts/scrumHelper.js

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ let refreshButton_Placed = false;
33
let enableToggle = true;
44
let hasInjectedContent = false;
55
let orgName = 'fossasia'; // default
6+
7+
// Global cache object
8+
let githubCache = {
9+
data: null,
10+
cacheKey: null,
11+
timestamp: null,
12+
ttl: null,
13+
fetching: false,
14+
queue: [],
15+
subject: null
16+
};
17+
618
function allIncluded(outputTarget = 'email') {
719
console.log('allIncluded called with outputTarget:', outputTarget);
820
console.log('Current window context:', window.location.href);
@@ -38,7 +50,71 @@ function allIncluded(outputTarget = 'email') {
3850
let issue_opened_button =
3951
'<div style="vertical-align:middle;display: inline-block;padding: 0px 4px;font-size:9px;font-weight: 600;color: #fff;text-align: center;background-color: #2cbe4e;border-radius: 3px;line-height: 12px;margin-bottom: 2px;" class="State State--green">open</div>';
4052

41-
// let linkStyle = '';
53+
/**
54+
* Resets all report processing flags and state, then optionally regenerates the report
55+
* @param {boolean} regenerateReport - Whether to regenerate the report after reset
56+
* @param {string} outputTarget - The output target ('popup' or 'email')
57+
*/
58+
function resetReportState(regenerateReport = false, outputTarget = 'popup') {
59+
log('Resetting report state');
60+
61+
// Reset all processing flags
62+
issuesDataProcessed = false;
63+
prsReviewDataProcessed = false;
64+
hasInjectedContent = false;
65+
66+
// Reset data arrays
67+
lastWeekArray = [];
68+
nextWeekArray = [];
69+
reviewedPrsArray = [];
70+
githubPrsReviewDataProcessed = {};
71+
72+
// Clear cached data
73+
githubCache.data = null;
74+
githubCache.cacheKey = null;
75+
githubCache.timestamp = null;
76+
githubCache.subject = null;
77+
78+
log('Report state reset complete');
79+
80+
// Regenerate report if requested
81+
if (regenerateReport) {
82+
log('Regenerating report after reset');
83+
if (outputTarget === 'popup') {
84+
writeGithubIssuesPrs();
85+
writeGithubPrsReviews();
86+
} else {
87+
// For email context, trigger a fresh data fetch
88+
fetchGithubData();
89+
}
90+
}
91+
}
92+
93+
/**
94+
* Forces a refresh of GitHub data by clearing cache and fetching new data
95+
* @returns {Promise} Promise that resolves when refresh is complete
96+
*/
97+
async function forceGithubDataRefresh() {
98+
log('Force refreshing GitHub data');
99+
100+
// Clear cache from storage
101+
await new Promise(resolve => {
102+
chrome.storage.local.remove('githubCache', resolve);
103+
});
104+
105+
// Reset report state
106+
resetReportState(false);
107+
108+
// Fetch fresh data
109+
try {
110+
await fetchGithubData();
111+
return { success: true, message: 'Data refreshed successfully' };
112+
} catch (error) {
113+
logError('Force refresh failed:', error);
114+
return { success: false, error: error.message };
115+
}
116+
}
117+
42118
function getChromeData() {
43119
console.log("Getting Chrome data for context:", outputTarget);
44120
chrome.storage.local.get(
@@ -205,18 +281,6 @@ function allIncluded(outputTarget = 'email') {
205281
console.error('[SCRUM-HELPER]:', ...args);
206282
}
207283
}
208-
// Global cache object
209-
let githubCache = {
210-
data: null,
211-
cacheKey: null,
212-
timestamp: 0,
213-
ttl: 10 * 60 * 1000, // cache valid for 10 mins
214-
fetching: false,
215-
queue: [],
216-
errors: {},
217-
errorTTL: 60 * 1000, // 1 min error cache
218-
subject: null,
219-
};
220284

221285
async function getCacheTTL() {
222286
return new Promise((resolve) => {
@@ -400,12 +464,9 @@ function allIncluded(outputTarget = 'email') {
400464

401465
await saveToStorage(githubCache.data);
402466
processGithubData(githubCache.data);
403-
467+
404468
if (outputTarget === 'popup') {
405-
issuesDataProcessed = false;
406-
prsReviewDataProcessed = false;
407-
writeGithubIssuesPrs();
408-
writeGithubPrsReviews();
469+
resetReportState(true, 'popup');
409470
}
410471

411472
// Resolve queued calls
@@ -480,10 +541,8 @@ function allIncluded(outputTarget = 'email') {
480541
user: githubUserData?.login
481542
});
482543

483-
lastWeekArray = [];
484-
nextWeekArray = [];
485-
reviewedPrsArray = [];
486-
githubPrsReviewDataProcessed = {};
544+
// Reset data arrays and processing state
545+
resetReportState(false);
487546

488547
// Update subject
489548
if (!githubCache.subject && scrumSubject) {
@@ -619,8 +678,11 @@ ${userReason}`;
619678
logError('No Github PR review data available');
620679
return;
621680
}
681+
682+
// Reset arrays for fresh processing
622683
reviewedPrsArray = [];
623684
githubPrsReviewDataProcessed = {};
685+
624686
let i;
625687
for (i = 0; i < items.length; i++) {
626688
let item = items[i];
@@ -707,8 +769,11 @@ ${userReason}`;
707769

708770
function writeGithubIssuesPrs() {
709771
let items = githubIssuesData.items;
772+
773+
// Reset arrays for fresh processing
710774
lastWeekArray = [];
711775
nextWeekArray = [];
776+
712777
if (!items) {
713778
logError('No Github issues data available');
714779
return;
@@ -846,7 +911,7 @@ ${userReason}`;
846911
}, 1000);
847912
}
848913
function handleRefresh() {
849-
hasInjectedContent = false; // Reset the flag before refresh
914+
resetReportState(false, 'email');
850915
allIncluded();
851916
}
852917
}

0 commit comments

Comments
 (0)