-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Heatmap days clickable #13935
Heatmap days clickable #13935
Conversation
Could you provide a screenshot/gif of this PR in action? |
Codecov Report
@@ Coverage Diff @@
## master #13935 +/- ##
==========================================
- Coverage 42.21% 42.20% -0.01%
==========================================
Files 767 771 +4
Lines 81624 82078 +454
==========================================
+ Hits 34458 34644 +186
- Misses 41531 41784 +253
- Partials 5635 5650 +15
Continue to review full report at Codecov.
|
Can you make it clear the filter when clicking the same date again? |
models/action.go
Outdated
var dateLow time.Time | ||
var dateHigh time.Time | ||
|
||
dateLow, _ = time.Parse("2006-1-2", opts.Date) |
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.
Shouldn't ignore the error.
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.
dateLow, _ = time.Parse("2006-1-2", opts.Date) | |
var err error | |
dateLow, err = time.Parse("2006-1-2", opts.Date) | |
if err != nil { | |
return fmt.Errorf("Unable to parse %s: %v", opts.Date, err) | |
} |
should do it.
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.
I think we have two ways to handle the error. The way @zeripath suggested or by just logging the error. Returning the error will cause a 500 error code. Logging the error seems to be closer to the behavior on other parts of gitea. For example if I use invalid parameters for sorting the issue list it just don't sort instead of throwing an error.
I'm not sure which way is better. What do you think?
dateLow, err := time.Parse("2006-1-2", opts.Date)
if err != nil {
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
} else {
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
}
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.
I like yours because if we fail to parse the date, there is no reason to continue as the functions below would fail as well (would that be a panic?).
I'll do a gif, filter clearing by clicking again, and error checking as soon as possible :) |
Please apply this diff for more robust JS: diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue
index c06fd8799..b9a3aa3a6 100644
--- a/web_src/js/components/ActivityHeatmap.vue
+++ b/web_src/js/components/ActivityHeatmap.vue
@@ -41,21 +41,22 @@ export default {
no_contributions: 'No contributions',
},
}),
methods: {
- handleDayClick(event) {
+ handleDayClick(e) {
// Reset filter if same date is clicked
- const day = window.location.search.match(/\?date=(\d{4})-(\d{1,2})-(\d{1,2})/);
- if (day !== null) {
- if (day.length === 4) {
- if ((parseInt(day[1]) === event.date.getFullYear()) && (parseInt(day[2]) === (event.date.getMonth() + 1)) && (parseInt(day[3]) === event.date.getDate())) {
- window.location.search = '';
- return;
- }
- }
+ const params = new URLSearchParams(document.location.search);
+ const queryDate = params.get('date');
+ const clickedDate = e.date.toISOString().substring(0, 10);
+ if (queryDate && queryDate === clickedDate) {
+ params.delete('date');
+ } else {
+ params.set('date', clickedDate);
}
- window.location.search = `?date=${event.date.getFullYear()}-${event.date.getMonth() + 1}-${event.date.getDate()}`;
+ const newSearch = params.toString();
+ window.location.search = newSearch.length ? `?${newSearch}` : '';
}
},
};
</script> |
Honestly I didn't knew the URLSearchParams object, thats the better solution of course. Your date comparison trades 2020-2-1 and 2020-02-01 as different dates, thats fine as long as nobody tries to edit the url by hand. The regex approach handles that case (on purpose). So I think we should combine both to something like this: handleDayClick(e) {
// Reset filter if same date is clicked
const params = new URLSearchParams(document.location.search);
const queryDate = params.get('date');
let sameDate = false;
if (queryDate !== null) {
const day = queryDate.match(/(\d{4})-(\d{1,2})-(\d{1,2})/);
if (day !== null) {
if (day.length === 4) {
if ((parseInt(day[1]) === e.date.getFullYear()) && (parseInt(day[2]) === (e.date.getMonth() + 1)) && (parseInt(day[3]) === e.date.getDate())) {
sameDate = true;
}
}
}
}
if (sameDate) {
params.delete('date');
} else {
params.set('date', `${e.date.getFullYear()}-${e.date.getMonth() + 1}-${e.date.getDate()}`);
}
const newSearch = params.toString();
window.location.search = newSearch.length ? `?${newSearch}` : '';
} Do you agree? |
No, I'd enforce |
Okay, I pushed your version but with a small correction. Timezone is substracted from the date because at least in Germany (UTC+2) it returns one day off since toISOString() formats the date to UTC+0. |
@@ -159,6 +159,7 @@ func Dashboard(ctx *context.Context) { | |||
IncludePrivate: true, | |||
OnlyPerformedBy: false, | |||
IncludeDeleted: false, | |||
Date: ctx.Query("date"), |
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.
You're missing this parameter in routers/user/profile.go
.
models/action.go
Outdated
IncludePrivate bool // include private actions | ||
OnlyPerformedBy bool // only actions performed by requested user | ||
IncludeDeleted bool // include deleted actions | ||
Date string // the day we want activity for: YYYY-M-D |
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.
Would you mind changing the signature of GetFeedsOptions
to not specify a single date, but to contain a time range (i.e. after, before time.Time
, populate these values in home.go
/profile.go
)? In #14080 I'm making this struct reusable for the heatmap, and a time-range filter would be welcome for the heatmap too (for #5439).
@LFriede would be nice if you can resolve conflicts :) |
Sorry for the late reply.
|
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.
looks good, please merge current master
Hi,
I filed an issue (#10843) about making the days in the heatmap clickable like here on github to display the actions on a specific day. I've implemented it with this PR.