Skip to content
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

Favorite feature #117

Open
wants to merge 31 commits into
base: viewmodes
Choose a base branch
from
Open

Favorite feature #117

wants to merge 31 commits into from

Conversation

jrauh01
Copy link
Collaborator

@jrauh01 jrauh01 commented Jan 3, 2025

This PR introduces the ability to mark resources as favorites in the resource lists. A star icon appears when hovering over a list item, allowing users to toggle resources as favorites. Once a favorite is added, a new list with the favorites is displayed above the main resource list, with the star icon permanently visible for these items. Favorites are stored per user. Additionally to resource uuid and username the resource's kind is stored to optimize database queries.

Planned features:

  • A list summarizing all favorites across all resource types
  • Customizable order of the favorites via drag & drop

Closes #107

@jrauh01 jrauh01 self-assigned this Jan 3, 2025
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jan 3, 2025
@jrauh01 jrauh01 changed the base branch from main to viewmodes January 3, 2025 13:25
@jrauh01 jrauh01 changed the title Favorites Add favorite feature Jan 3, 2025
@jrauh01 jrauh01 force-pushed the favorites branch 3 times, most recently from 19dfc74 to 942c6cd Compare January 7, 2025 15:40
@jrauh01 jrauh01 changed the title Add favorite feature Favorite feature Jan 8, 2025
@jrauh01 jrauh01 requested a review from lippserd January 8, 2025 08:09
@lippserd lippserd requested a review from jhoxhaa January 13, 2025 07:18
@jrauh01 jrauh01 force-pushed the viewmodes branch 2 times, most recently from ea8dcfc to 3f467af Compare January 15, 2025 14:22
@jrauh01 jrauh01 force-pushed the favorites branch 2 times, most recently from af500ea to 570585b Compare January 15, 2025 14:36
library/Kubernetes/Model/Favorite.php Outdated Show resolved Hide resolved
library/Kubernetes/Common/Links.php Outdated Show resolved Hide resolved
application/controllers/FavoriteController.php Outdated Show resolved Hide resolved
@jrauh01 jrauh01 force-pushed the favorites branch 2 times, most recently from f56cd0b to f0d7090 Compare January 16, 2025 13:06
]
);
}
} catch (\Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always catch Throwable and import it.

);
}
} catch (\Exception $e) {
die($e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log and rethrow.

} catch (\Exception $e) {
die($e->getMessage());
}
$this->getResponse()->setHeader('X-Icinga-Container', 'ignore', true)->sendResponse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why sendResponse()? A little comment block about the 3 lines explaining their purpose would be great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed superfluous sendResponse() and disableLayout().

]));
}

public function createRelations(Relations $relations)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed as it's empty.

@@ -110,6 +114,28 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall('none', StateBall::SIZE_MEDIUM));
$size = match ($this->getViewMode()) {
ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON => 'sm',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split the lines here.


protected $tag = 'span';

public function __construct(string $state)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constructor property promotion everywhere.

@@ -94,8 +97,42 @@ public function indexAction(): void
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);

$favorites = Favorite::on(Database::connection())->execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to call execute(). Also for the other places in this file. Do you know why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also loads every favorite for every resource type. This is not good. The implementation should be changed so that the favorites can be differentiated per resource type. This would allow favorites to be loaded as follows:

SELECT * FROM pod WHERE pod.uuid IN (SELECT resource_uuid FROM favorite WHERE kind = "pod") AND ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute() is not necessary because ::on() returns a Query which implements IteratorAggregate. The implemented method getIterator() executes the query.

Copy link
Collaborator Author

@jrauh01 jrauh01 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the sql statement, I think we could also do it as follows, so we don't have to change the schema and save the kind:
SELECT * FROM favorite WHERE favorite.reference_uuid IN (SELECT uuid FROM pod) AND ...

Would like to hear your opinion.

$favoriteResources = $modelClass::on(Database::connection())
->filter(
Filter::all(
$filter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter for username missing, right?

->execute();
} else {
// Get empty ResultSet, otherwise all resources would be displayed as favorites
$favoriteResources = $modelClass::on(Database::connection())->filter(Filter::equal('uuid', 0))->execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you add the favorites HTML if there are no favorites?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants