Skip to content

Generate user images from initials and user views refinements - #722

Merged
giuscris merged 5 commits into
2.xfrom
feature/user-views-improvements
Jul 2, 2025
Merged

Generate user images from initials and user views refinements#722
giuscris merged 5 commits into
2.xfrom
feature/user-views-improvements

Conversation

@giuscris

@giuscris giuscris commented Jul 2, 2025

Copy link
Copy Markdown
Member

No description provided.

@giuscris giuscris added this to the 2.0.0 milestone Jul 2, 2025
@giuscris giuscris self-assigned this Jul 2, 2025
@giuscris giuscris added the enhancement New feature or request label Jul 2, 2025
@giuscris
giuscris requested a review from Copilot July 2, 2025 20:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a shared _user-image partial to render either an uploaded profile image or a generated SVG of user initials, updates the User model and controller to support nullable images, and refines related views and CSS for a consistent layout.

  • Added InitialsImageGenerator to produce SVG data URIs for initials-based fallback images.
  • Refactored profile.php, index.php, and sidebar.php to use the new _user-image partial.
  • Updated the User model, panel controllers, and SCSS to handle nullable images and adjust flex layouts.

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
panel/views/users/profile.php Replaced inline <img> with _user-image partial and updated the image-action permission check
panel/views/users/index.php Added user count badge, reordered columns, and swapped inline image for full name cell using _user-image partial
panel/views/partials/user-image.php Introduced new _user-image partial that selects either the uploaded image URI or an initials SVG data URI
panel/views/partials/sidebar.php Replaced sidebar user image <img> with the _user-image partial
panel/src/scss/components/_users.scss Adjusted flex properties and layout for .user-fullname, .user-username, and sizing for .user-image
formwork/src/Users/User.php Made $image nullable, updated image() to return ?Image, and removed hasDefaultImage()
formwork/src/Users/InitialsImageGenerator.php Added InitialsImageGenerator class to generate and cache initials-based SVG URIs
formwork/src/Panel/Controllers/UsersController.php Updated controller checks to use image() !== null instead of hasDefaultImage() and adjusted deletion logic
Comments suppressed due to low confidence (1)

formwork/src/Users/InitialsImageGenerator.php:21

  • This new InitialsImageGenerator contains public logic that would benefit from unit tests to ensure SVG generation, caching, and color contrast behave as expected.
    public static function generate(string $name): string

@@ -0,0 +1,5 @@
<img <?= $this->attr([
'class' => $class ?? null,

Copilot AI Jul 2, 2025

Copy link

Choose a reason for hiding this comment

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

The partial does not provide a default CSS class for the <img> element, which may break existing styling. Consider defaulting to 'user-image' when no class is provided.

Suggested change
'class' => $class ?? null,
'class' => $class ?? 'user-image',

Copilot uses AI. Check for mistakes.
<div class="user-summary-image">
<img src="<?= $user->image()->uri() ?>" alt="<?= $panel->user()->username() ?>">
<?php if ($panel->user()->canChangeOptionsOf($user) && !$user->hasDefaultImage()) : ?>
<?= $this->insert('_user-image', ['user' => $user]) ?>

Copilot AI Jul 2, 2025

Copy link

Choose a reason for hiding this comment

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

When inserting the image partial here, you may need to pass a CSS class (e.g., 'user-image') to maintain consistent styling with your existing SCSS rules.

Copilot uses AI. Check for mistakes.
<div class="panel-user-card">
<div class="panel-user-image">
<img src="<?= $panel->user()->image()->uri() ?>" alt="<?= $panel->user()->username() ?>">
<?= $this->insert('_user-image', ['user' => $panel->user()]) ?>

Copilot AI Jul 2, 2025

Copy link

Choose a reason for hiding this comment

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

Same as above: pass a default class to the image partial here so the sidebar avatar matches your .user-image styling.

Suggested change
<?= $this->insert('_user-image', ['user' => $panel->user()]) ?>
<?= $this->insert('_user-image', ['user' => $panel->user(), 'class' => 'user-image']) ?>

Copilot uses AI. Check for mistakes.
@giuscris
giuscris merged commit 74d63c4 into 2.x Jul 2, 2025
2 checks passed
@giuscris
giuscris deleted the feature/user-views-improvements branch July 2, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants