Admin: User list tweaks (#38750)
* Setup filter * Enable filtering users by active in last 30 days * Add loading state * Update last active age strings * Tweak user list * Use theme spacing * Improve table's accessibility * Add more aria-labels
This commit is contained in:
+32
-7
@@ -48,24 +48,49 @@ func GetAgeString(t time.Time) string {
|
||||
months := int(math.Floor(minutes / 43800))
|
||||
days := int(math.Floor(minutes / 1440))
|
||||
hours := int(math.Floor(minutes / 60))
|
||||
|
||||
var amount string
|
||||
if years > 0 {
|
||||
return fmt.Sprintf("%dy", years)
|
||||
if years == 1 {
|
||||
amount = "year"
|
||||
} else {
|
||||
amount = "years"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", years, amount)
|
||||
}
|
||||
if months > 0 {
|
||||
return fmt.Sprintf("%dM", months)
|
||||
if months == 1 {
|
||||
amount = "month"
|
||||
} else {
|
||||
amount = "months"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", months, amount)
|
||||
}
|
||||
if days > 0 {
|
||||
return fmt.Sprintf("%dd", days)
|
||||
if days == 1 {
|
||||
amount = "day"
|
||||
} else {
|
||||
amount = "days"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", days, amount)
|
||||
}
|
||||
if hours > 0 {
|
||||
return fmt.Sprintf("%dh", hours)
|
||||
if hours == 1 {
|
||||
amount = "hour"
|
||||
} else {
|
||||
amount = "hours"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", hours, amount)
|
||||
}
|
||||
if int(minutes) > 0 {
|
||||
return fmt.Sprintf("%dm", int(minutes))
|
||||
if int(minutes) == 1 {
|
||||
amount = "minute"
|
||||
} else {
|
||||
amount = "minutes"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", int(minutes), amount)
|
||||
}
|
||||
|
||||
return "< 1m"
|
||||
return "< 1 minute"
|
||||
}
|
||||
|
||||
// ToCamelCase changes kebab case, snake case or mixed strings to camel case. See unit test for examples.
|
||||
|
||||
@@ -62,14 +62,14 @@ func TestDateAge(t *testing.T) {
|
||||
assert.Equal(t, "?", GetAgeString(time.Time{})) // base case
|
||||
|
||||
tests := map[time.Duration]string{
|
||||
-1 * time.Hour: "< 1m", // one hour in the future
|
||||
0: "< 1m",
|
||||
2 * time.Second: "< 1m",
|
||||
2 * time.Minute: "2m",
|
||||
2 * time.Hour: "2h",
|
||||
3 * 24 * time.Hour: "3d",
|
||||
67 * 24 * time.Hour: "2M",
|
||||
409 * 24 * time.Hour: "1y",
|
||||
-1 * time.Hour: "< 1 minute", // one hour in the future
|
||||
0: "< 1 minute",
|
||||
2 * time.Second: "< 1 minute",
|
||||
2 * time.Minute: "2 minutes",
|
||||
2 * time.Hour: "2 hours",
|
||||
3 * 24 * time.Hour: "3 days",
|
||||
67 * 24 * time.Hour: "2 months",
|
||||
409 * 24 * time.Hour: "1 year",
|
||||
}
|
||||
for elapsed, expected := range tests {
|
||||
assert.Equalf(
|
||||
|
||||
Reference in New Issue
Block a user