-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix(Issue#202): counts in one request #225
base: master
Are you sure you want to change the base?
Changes from 2 commits
bdb189c
80d96b7
49f7ffc
e822f51
6624565
cd53a4b
2d27842
99b959c
046d508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,6 @@ | |
p.router.Use(p.withRecovery) | ||
|
||
p.router.HandleFunc("/add", p.checkAuth(p.handleAdd)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/list", p.checkAuth(p.handleList)).Methods(http.MethodGet) | ||
p.router.HandleFunc("/lists", p.checkAuth(p.handleLists)).Methods(http.MethodGet) | ||
p.router.HandleFunc("/remove", p.checkAuth(p.handleRemove)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/complete", p.checkAuth(p.handleComplete)).Methods(http.MethodPost) | ||
|
@@ -208,7 +207,7 @@ | |
if addRequest.SendTo == "" { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
msg := "Unable to add issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
|
@@ -227,7 +226,7 @@ | |
receiver, appErr := p.API.GetUserByUsername(addRequest.SendTo) | ||
if appErr != nil { | ||
msg := "Unable to find user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
@@ -290,27 +289,18 @@ | |
} | ||
} | ||
|
||
func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | ||
func (p *Plugin) handleLists(w http.ResponseWriter, r *http.Request) { | ||
userID := r.Header.Get("Mattermost-User-ID") | ||
|
||
listInput := r.URL.Query().Get("list") | ||
listID := MyListKey | ||
switch listInput { | ||
case OutFlag: | ||
listID = OutListKey | ||
case InFlag: | ||
listID = InListKey | ||
} | ||
|
||
issues, err := p.listManager.GetIssueList(userID, listID) | ||
allListIssue, err := p.listManager.GetAllList(userID) | ||
if err != nil { | ||
msg := "Unable to get issues for user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
if len(issues) > 0 && r.URL.Query().Get("reminder") == "true" && p.getReminderPreference(userID) { | ||
if allListIssue != nil && len(allListIssue.My) > 0 && r.URL.Query().Get("reminder") == "true" && p.getReminderPreference(userID) { | ||
var lastReminderAt int64 | ||
lastReminderAt, err = p.getLastReminderTimeForUser(userID) | ||
if err != nil { | ||
|
@@ -329,7 +319,7 @@ | |
nt := time.Unix(now/1000, 0).In(timezone) | ||
lt := time.Unix(lastReminderAt/1000, 0).In(timezone) | ||
if nt.Sub(lt).Hours() >= 1 && (nt.Day() != lt.Day() || nt.Month() != lt.Month() || nt.Year() != lt.Year()) { | ||
p.PostBotDM(userID, "Daily Reminder:\n\n"+issuesListToString(issues)) | ||
p.PostBotDM(userID, "Daily Reminder:\n\n"+issuesListToString(allListIssue.My)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is a good bug fix here too. Nice work 👍 |
||
p.trackDailySummary(userID) | ||
err = p.saveLastReminderTimeForUser(userID) | ||
if err != nil { | ||
|
@@ -338,31 +328,6 @@ | |
} | ||
} | ||
|
||
issuesJSON, err := json.Marshal(issues) | ||
if err != nil { | ||
msg := "Unable marhsal count issue list to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
_, err = w.Write(issuesJSON) | ||
if err != nil { | ||
p.API.LogError("Unable to write json response err=" + err.Error()) | ||
} | ||
} | ||
|
||
func (p *Plugin) handleLists(w http.ResponseWriter, r *http.Request) { | ||
userID := r.Header.Get("Mattermost-User-ID") | ||
|
||
allListIssue, err := p.listManager.GetAllList(userID) | ||
if err != nil { | ||
msg := "Unable to get issues for user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
allListIssueJSON, err := json.Marshal(allListIssue) | ||
if err != nil { | ||
msg := "Unable marhsal all lists issues to json" | ||
|
@@ -438,7 +403,7 @@ | |
receiver, appErr := p.API.GetUserByUsername(changeRequest.SendTo) | ||
if appErr != nil { | ||
msg := "username not valid" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, msg, err) | ||
return | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,9 @@ export default class SidebarButtons extends React.PureComponent { | |||||
theme: PropTypes.object.isRequired, | ||||||
isTeamSidebar: PropTypes.bool, | ||||||
showRHSPlugin: PropTypes.func.isRequired, | ||||||
allIssues: PropTypes.object, | ||||||
myIssues: PropTypes.array, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here
Suggested change
|
||||||
inIssues: PropTypes.array, | ||||||
outIssues: PropTypes.array, | ||||||
actions: PropTypes.shape({ | ||||||
updateRhsState: PropTypes.func.isRequired, | ||||||
telemetry: PropTypes.func.isRequired, | ||||||
|
@@ -46,7 +48,9 @@ export default class SidebarButtons extends React.PureComponent { | |||||
container = style.containerTeam; | ||||||
} | ||||||
|
||||||
const allIssues = this.props.allIssues; | ||||||
const myIssues = this.props.myIssues; | ||||||
const inIssues = this.props.inIssues; | ||||||
const outIssues = this.props.outIssues; | ||||||
|
||||||
return ( | ||||||
<div style={container}> | ||||||
|
@@ -63,7 +67,7 @@ export default class SidebarButtons extends React.PureComponent { | |||||
}} | ||||||
> | ||||||
<i className='icon icon-check'/> | ||||||
{' ' + allIssues && allIssues.my ? allIssues.my.length : 0} | ||||||
{' ' + myIssues ? myIssues.length : 0} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||||||
</a> | ||||||
</OverlayTrigger> | ||||||
<OverlayTrigger | ||||||
|
@@ -79,7 +83,7 @@ export default class SidebarButtons extends React.PureComponent { | |||||
style={button} | ||||||
> | ||||||
<i className='icon icon-arrow-down'/> | ||||||
{' ' + allIssues && allIssues.in ? allIssues.in.length : 0} | ||||||
{' ' + inIssues ? inIssues.length : 0} | ||||||
</a> | ||||||
</OverlayTrigger> | ||||||
<OverlayTrigger | ||||||
|
@@ -95,7 +99,7 @@ export default class SidebarButtons extends React.PureComponent { | |||||
style={button} | ||||||
> | ||||||
<i className='icon icon-arrow-up'/> | ||||||
{' ' + allIssues && allIssues.out ? allIssues.out.length : 0} | ||||||
{' ' + outIssues ? outIssues.length : 0} | ||||||
</a> | ||||||
</OverlayTrigger> | ||||||
</div> | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,7 +51,9 @@ const InListName = 'in'; | |||||
|
||||||
export default class SidebarRight extends React.PureComponent { | ||||||
static propTypes = { | ||||||
allIssues: PropTypes.arrayOf(PropTypes.object), | ||||||
myIssues: PropTypes.array, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
inIssues: PropTypes.array, | ||||||
outIssues: PropTypes.array, | ||||||
todoToast: PropTypes.object, | ||||||
theme: PropTypes.object.isRequired, | ||||||
siteURL: PropTypes.string.isRequired, | ||||||
|
@@ -61,7 +63,7 @@ export default class SidebarRight extends React.PureComponent { | |||||
complete: PropTypes.func.isRequired, | ||||||
accept: PropTypes.func.isRequired, | ||||||
bump: PropTypes.func.isRequired, | ||||||
fetchAllIssue: PropTypes.func.isRequired, | ||||||
fetchAllIssueLists: PropTypes.func.isRequired, | ||||||
openAddCard: PropTypes.func.isRequired, | ||||||
closeAddCard: PropTypes.func.isRequired, | ||||||
openAssigneeModal: PropTypes.func.isRequired, | ||||||
|
@@ -99,7 +101,7 @@ export default class SidebarRight extends React.PureComponent { | |||||
|
||||||
componentDidMount() { | ||||||
document.addEventListener('keydown', this.handleKeypress); | ||||||
this.props.actions.fetchAllIssue(); | ||||||
this.props.actions.fetchAllIssueLists(); | ||||||
this.props.actions.setVisible(true); | ||||||
} | ||||||
|
||||||
|
@@ -122,15 +124,15 @@ export default class SidebarRight extends React.PureComponent { | |||||
} | ||||||
|
||||||
getInIssues() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It looks like these 3 functions aren't actually called though. I think we can just remove them |
||||||
return this.props.allIssues.in.length; | ||||||
return this.props.inIssues.length; | ||||||
} | ||||||
|
||||||
getOutIssues() { | ||||||
return this.props.allIssues.out.length; | ||||||
return this.props.outIssues.length; | ||||||
} | ||||||
|
||||||
getMyIssues() { | ||||||
return this.props.allIssues.my.length; | ||||||
return this.props.myIssues.length; | ||||||
} | ||||||
|
||||||
addTodoItem() { | ||||||
|
@@ -150,12 +152,12 @@ export default class SidebarRight extends React.PureComponent { | |||||
|
||||||
switch (this.state.list) { | ||||||
case MyListName: | ||||||
todos = this.props.allIssues.my || []; | ||||||
todos = this.props.myIssues || []; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These empty arrays are going to cause re-renders. But |
||||||
addButton = 'Add Todo'; | ||||||
inboxList = this.props.allIssues.in || []; | ||||||
inboxList = this.props.inIssues || []; | ||||||
break; | ||||||
case OutListName: | ||||||
todos = this.props.allIssues.out || []; | ||||||
todos = this.props.outIssues || []; | ||||||
listHeading = 'Sent Todos'; | ||||||
addButton = 'Request a Todo from someone'; | ||||||
break; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I think we are changing the logic here, but I think we are actually fixing a bug. LGTM 👍