Skip to content

Dashboard frontend uses old controller endpoint not the actual DashboardWidget implementation #1885

Description

@joshtrichards

Was about to do some performance optimization of the hot paths in the item querying logic in the widget then I noticed something:

export const getDashboardData = () => {
return axios
.get(url('/notes/dashboard'))
.then(response => {
return response.data
})
.catch(err => {
console.error(err)
handleSyncError(t('notes', 'Fetching notes for dashboard has failed.'), err)
throw err
})
}

The dashboard widget is registered through DashboardWidget, but the rendered frontend still uses the old controller endpoint via the JS dashboard app. So DashboardWidget is not the sole implementation; it is the integration point, while NotesController::dashboard() is the data backend for the actual dashboard UI.

So we have two divergent implementations:

#[NoAdminRequired]
public function dashboard() : JSONResponse {
return $this->helper->handleErrorResponse(function () {
$maxItems = 6;
$userId = $this->helper->getUID();
$notes = $this->notesService->getTopNotes($userId);
$hasMoreNotes = count($notes) > $maxItems;
$notes = array_slice($notes, 0, $maxItems);
$items = array_map(function ($note) {
$excerpt = '';
try {
$excerpt = $note->getExcerpt();
} catch (\Throwable $e) {
}
return [
'id' => $note->getId(),
'title' => $note->getTitle(),
'category' => $note->getCategory(),
'favorite' => $note->getFavorite(),
'excerpt' => $excerpt,
];
}, $notes);
return [
'items' => $items,
'hasMoreItems' => $hasMoreNotes,
];
});
}

public function getWidgetButtons(string $userId): array {
$buttons = [
new WidgetButton(
WidgetButton::TYPE_NEW,
$this->url->linkToRouteAbsolute('notes.page.createGet'),
$this->l10n->t('Create new note')
)
];
if ($this->notesService->countNotes($userId) > 7) {
$buttons[] = new WidgetButton(
WidgetButton::TYPE_MORE,
$this->url->linkToRouteAbsolute('notes.page.index'),
$this->l10n->t('More notes')
);
}
return $buttons;
}
public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
$notes = $this->notesService->getTopNotes($userId);
$notes = array_slice($notes, 0, $limit);
return array_values(array_map(function (Note $note): WidgetItem {
$excerpt = '';
try {
$excerpt = $note->getExcerpt();
} catch (\Throwable $e) {
}
$link = $this->url->linkToRouteAbsolute('notes.page.indexnote', ['id' => $note->getId()]);
$icon = $note->getFavorite()
? $this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))
: $this->getIconUrl();
return new WidgetItem($note->getTitle(), $excerpt, $link, $icon, (string)$note->getModified());
}, $notes));
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions