Skip to content

Commit ddda330

Browse files
authored
Bug: Project activity on dashboard sometimes triggers internal error (#1760)
* Ensure PHP activity arrays are translated to JS arrays * Add loading indicator when loading all activity * Fix activity sorting bug (comparing user objects) * Activity: also show time and fix field name column
1 parent 3b0dd5d commit ddda330

5 files changed

Lines changed: 28 additions & 14 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script>
22
export let danger = false
33
export let disabled = false
4+
export let loading = false
45
export {clazz as class}
56
67
let clazz = ''
78
</script>
89

910
<!-- https://daisyui.com/components/button -->
10-
<button on:click class:btn-error={danger} class:btn-disabled={disabled} class='btn btn-primary { clazz }'>
11+
<button on:click class:btn-error={danger} class:btn-disabled={disabled} class:loading={loading} class='btn btn-primary { clazz }'>
1112
<slot />
1213
</button>

next-app/src/routes/projects/[project_code]/+page.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
export let data: DashboardData
1818
1919
let only_showing_subset = true
20+
let loading = false;
2021
2122
$: project = data.project
2223
$: activities = data.activities
@@ -53,8 +54,9 @@
5354
].filter(({ value }) => value !== undefined)
5455
5556
async function load_all_activities() {
57+
loading = true
5658
activities = await GET({url: `/projects/${$page.params.project_code}/activities`})
57-
59+
loading = false
5860
only_showing_subset = false
5961
}
6062
</script>
@@ -80,8 +82,8 @@
8082
<Activity { activities } />
8183

8284
{#if only_showing_subset}
83-
<footer class='flex justify-center mt-2'>
84-
<Button on:click={ load_all_activities } class='btn-outline btn-xs sm:btn-sm'>
85+
<footer class='flex justify-center m-4'>
86+
<Button on:click={ load_all_activities } class='btn-outline btn-xs sm:btn-sm' {loading}>
8587
show all
8688
</Button>
8789
</footer>

next-app/src/routes/projects/[project_code]/Activity.svelte

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
interface AugmentedActivity extends Activity {
77
date_locale: string,
8+
date_time_locale: string,
89
date_iso: string,
910
time: number,
1011
field_names: string,
@@ -36,6 +37,7 @@
3637
return {
3738
...activity,
3839
date_locale: date.toLocaleDateString(),
40+
date_time_locale: date.toLocaleString(),
3941
date_iso: date.toISOString().split('T')[0],
4042
time: date.getTime(),
4143
field_names: to_names(activity.fields),
@@ -44,16 +46,25 @@
4446
}
4547
4648
function byDateThenUser(a: AugmentedActivity, b: AugmentedActivity) {
47-
return a.date_iso === b.date_iso ? a.user === b.user ? des(a.time, b.time)
48-
: asc(a.user.username, b.user.username)
49-
: des(a.date_iso, b.date_iso)
49+
if (a.date_iso !== b.date_iso) {
50+
return des(a.date_iso, b.date_iso);
51+
}
52+
53+
if (a.user.username !== b.user.username) {
54+
return asc(a.user.username, b.user.username);
55+
}
56+
57+
return des(a.time, b.time);
5058
}
5159
5260
const asc = (a: string | number, b: string | number) => a > b ? 1 : -1
5361
const des = (a: string | number, b: string | number) => a < b ? 1 : -1
5462
5563
function to_names(fields: Field[] = []): string {
56-
return fields.map(field => field.name).join(', ')
64+
// This is quite rudimentary, but far better than nothing
65+
return [...new Set(fields.map(field => field.fieldLabel?.label)
66+
.filter(label => !!label))]
67+
.join(', ')
5768
}
5869
</script>
5970

@@ -63,20 +74,20 @@
6374
<thead>
6475
<tr>
6576
<td>user</td>
66-
<th>date</th>
6777
<th>action</th>
6878
<th>entry</th>
6979
<th>fields</th>
80+
<th>date</th>
7081
</tr>
7182
</thead>
7283
<tbody>
7384
{#each sorted_activities as activity}
7485
<tr>
7586
<td>{ activity.user.username }</td>
76-
<td>{ activity.date_locale }</td>
7787
<td>{ action_display[activity.action] || activity.action }</td>
7888
<td>{ activity.entry || '' }</td>
7989
<td>{ activity.field_names || '' }</td>
90+
<td>{ activity.date_time_locale }</td>
8091
</tr>
8192
{:else}
8293
<tr><td>No activity</td></tr>

next-app/src/routes/projects/[project_code]/activities/+server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type LegacyResult = {
1313
}
1414

1515
export type Field = {
16-
name: string,
16+
fieldLabel?: { label: string },
1717
}
1818

1919
type LegacyActivity = {

src/Api/Model/Shared/Dto/ActivityListDto.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function getActivityForUser($userId, $filterParams = [])
104104
$unreadItems = array_merge($unreadItems, self::getUnreadActivityForUserInProject($userId, $project["id"]));
105105
}
106106
$unreadItems = array_merge($unreadItems, self::getGlobalUnreadActivityForUser($userId));
107-
uasort($activity, ["self", "sortActivity"]);
107+
usort($activity, ["self", "sortActivity"]);
108108
$dto = [
109109
"activity" => $activity,
110110
"unread" => $unreadItems,
@@ -124,7 +124,7 @@ public static function getActivityForOneProject($projectModel, $userId, $filterP
124124
{
125125
$activity = self::getActivityForProject($projectModel, $filterParams);
126126
$unreadItems = self::getUnreadActivityForUserInProject($userId, $projectModel->id->asString());
127-
uasort($activity, ["self", "sortActivity"]);
127+
usort($activity, ["self", "sortActivity"]);
128128
$dto = [
129129
"activity" => $activity,
130130
"unread" => $unreadItems,
@@ -146,7 +146,7 @@ public static function getActivityForOneLexEntry($projectModel, $entryId, $filte
146146
// TODO: handle unread items for this activity log type (single-entry). Perhaps the getUnreadActivity() functions should just take a list of items? 2018-02 RM
147147
// $unreadItems = self::getUnreadActivityForUserInProject($userId, $projectModel->id->asString());
148148
$unreadItems = [];
149-
uasort($activity, ["self", "sortActivity"]);
149+
usort($activity, ["self", "sortActivity"]);
150150
$dto = [
151151
"activity" => $activity,
152152
"unread" => $unreadItems,

0 commit comments

Comments
 (0)