Review main Merged

84535[TASK] Introduce Alert web component

Marcin Sągol CR +2 V +2 Normal +157 −0 updated 07/10/24, 07:39

Commit message

A new web component called `<typo3-backend-alert>`,
which is based on the Bootstrap alert component,
is introduced. It will be used to streamline the
use of this component through backend code.

The web component can therefore be used in
any JavaScript module or directly in HTML markup.

This is the first step towards unifying the alert,
notification, and callout components in the backend.
These components share a lot of common logic and
should therefore have a common ancestor.

Note: The new component might receive further
changes in the future and is therefore introduced
as internal for now.

Review

  • Code review CR +2 Done
    • Andreas Kienast +2
    • Oli Bartsch +1
  • Verified V +2 Done
    • Andreas Kienast +2
    • Oli Bartsch +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 5876

Show 3851 earlier messages
  1. Marcin Sągol uploaded patch set 1 06/08/24, 21:08

  2. core-ci voted on patch set 1 V +1 06/08/24, 21:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58931

  3. Ayke Halder commented on patch set 1 06/11/24, 14:32

    Maybe combine the inline/non-inline rendering? And some idea for the property `iconIdentifier`.

    alert.ts:32

    Does it work to set the value of `iconIdentifier` here instead of using the constructor? ``` @property({ type: String }) iconIdentifier: string = this.getIconIdentifier(); [OR static method] @property({ type: String }) iconIdentifier: string = Alert.getIconIdentifier(this.severity); ``` May we actually expect `severity` to change after object-initialization? Then we might need to manage on-change `severity` to also update `iconIdentifier`. ---- Do we expect a custom `icon-identifier` to be set via attribute? Then rename the attribute from default `iconidentifier` to `icon-identifier`: `@property({ type: String, attribute: 'icon-identifier' }) iconIdentifier…` If not - maybe bind directly to method `getIconIdentifier()` ``` export class Alert extends LitElement { private static getIconIdentifier(severity: SeverityEnum): string { const icons = { [SeverityEnum.notice]: 'actions-lightbulb', [SeverityEnum.ok]: 'actions-check', [SeverityEnum.warning]: 'actions-exclamation', [SeverityEnum.error]: 'actions-close', [SeverityEnum.info]: 'actions-info', }; return icons[severity] || 'actions-info'; } @property(…)… … @property({ attribute: false }) iconIdentifier = () => { return Alert.getIconIdentifier(this.severity) }; public async … ```

    alert.ts:55

    May we combine inline/non-inline like this? * This adds some `div`-tags without `class`-attribute to the inline HTML. * Non-inline HTML does not change (mind `p`-/`div`-tag for `alert-body`). ```ts import { ifDefined } from 'lit/directives/if-defined'; […] return html` <div class=${classMap(classes)} role="alert"> <div class="${ifDefined(this.inline ? null : 'media')}"> ${this.showIcon ? html` <div class="${ifDefined(this.inline ? null : 'media-left')}"> <span class="${this.emphasizedIcon ? 'icon-emphasized' : nothing}"> <typo3-backend-icon identifier="${this.iconIdentifier}" size="small"></typo3-backend-icon> </span> </div> ` : nothing} <div class="${ifDefined(this.inline ? null : 'media-body')}"> ${this.heading ? html`<h4 class="alert-title">${this.heading}</h4>` : nothing} <p class="alert-body">${unsafeHTML(this.message)}</p> </div> </div> ${this.dismissible ? this.renderDismissButton() : nothing} </div> `; ``` To remove the `class`-attribute completely in case of inline: Instead of `<tag class="${ifDefined(this.inline ? null : 'media-body')}">` this might also work `<tag class="${this.inline ? nothing : 'media-body'}">`

    alert.ts:84

    Is a `div`-tag needed or can this be a `p`-tag like for the inline-version?

    alert.ts:92

    Can this become a static method? Also see comment about constructor above.
  4. Marcin Sągol uploaded patch set 2 V +1 06/16/24, 17:29

  5. Marcin Sągol commented on patch set 2 06/16/24, 17:30

    alert.ts:32 Reply

    Probably for now I would avoid custom icons, just to make sure that we have the same styles/views across the whole app. Later, when/if we make a common abstract class for notifications/callouts/alerts etc. we can think about giving an option for custom icons. Looking at Notification component, there is no option to set a custom icon - let's make here the same, then it will be easier to make a common ground for both. The iconIdentifier will be just a private property, which might change when severity changes, i have added update() method for this.

    alert.ts:55 Reply

    For now I have removed the inline `property`. This was for special cases when i was testing this component in various code parts (when i replaced static HTML with this component). But since the unification of all those alert-like components will take place later (needs to be discussed with UI/UX team), so the code also will be updated later. So for now i do not implemet any variants (block or inline) of this component (I do not want to add now something that might change soon and wont be use dnow).

    alert.ts:84 Reply

    For now, there won't be an inline version.

    alert.ts:92 Reply

    It is now a static method.
  6. Marcin Sągol updated the commit message in patch set 3 06/16/24, 17:30

  7. core-ci voted on patch set 3 V +1 06/16/24, 17:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59681

  8. core-ci voted on patch set 2 V +1 06/16/24, 17:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59680

  9. Georg Ringer voted on patch set 3 CR +1 V +1 06/17/24, 07:51

  10. Andreas Kienast commented on patch set 3 CR -1 06/17/24, 13:03

    Temp -1, will review thoroughly
  11. Marcin Sągol commented on patch set 3 06/18/24, 07:10

    Reply

    Hi Andreas, i would like to have some feedback here as this task blocks my other task :)
  12. Andreas Kienast commented on patch set 3 06/18/24, 10:37

    alert.ts:22

    Please use proper naming here: `typo3-backend-alert`. Also, please move the module into the `elements` directory.

    alert.ts:31

    Why is this configurable at all?

    alert.ts:38

    The property is superfluous. It's better to call the method directly in the rendering, this would also make the `updated()` callback obsolete.

    alert.ts:52

    Why does `close` need to be async? All actions within a synchronous.

    alert.ts:53

    Can be shortened to `this.parentNode?.removeChild(this);`

    alert.ts:85

    I'm nor sure if I really like this...
  13. Andreas Kienast commented on patch set 3 06/18/24, 10:39

    Also, this is a feature, but misses the feature.rst file. I'm not sure whether it's smart to propagate this as a general feature (for now).
  14. Andreas Kienast commented on patch set 3 06/18/24, 10:41

    alert.ts:25

    This should also not be configurable (it's not used at all anyway).
  15. Benjamin Franzke commented on patch set 3 CR -1 06/18/24, 10:42

    In general this needs to be compared with the similar patch https://review.typo3.org/c/Packages/TYPO3.CMS/+/84707 I'd like to see a list of usages where this component is planed to be integrated.

    alert.ts:85 Reply

    ack, this is not a good idea for new API. This needs to render a `<slot></slot>`, to ensure that this API can be used in a safe way and doesn't introduce security issues.
  16. Marcin Sągol commented on patch set 3 06/18/24, 13:38

    Reply

    @ben@bnf.dev I was explaining it a bit on the core devs channel, in the patch commit message, and in the issue on Forge. There are multiple elements that serve very similar roles: Notifications, Alerts, Callouts, and Infoboxes. The alert, for example, is used in many places in the code by using plain static HTML to define it (you can search the code by alert classes). I was suggesting introducing the Alert Web Component (I want to use it in my different task: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83637) and then, as a separate patch, it could be used in the code instead of inlined HTML. Next, it should be discussed if all those components: Notifications, Alerts, Callouts, and Infoboxes are needed. If they are, we could create an abstract class for all of them, as they share a lot of common logic, and the concrete implementations could provide just small enhancements.
  17. Georg Ringer commented on patch set 3 CR 0 06/19/24, 08:03

    rst is missing
  18. Jasmina Ließmann wrote 06/19/24, 13:07

    Removed cc Jasmina Ließmann.
  19. Marcin Sągol uploaded patch set 4 CR -1 V +1 06/24/24, 14:06

  20. Marcin Sągol commented on patch set 4 06/24/24, 14:11

    alert.ts:22 Reply

    Done

    alert.ts:31 Reply

    The icon can be rendered in 2 styles: the default one (just an icon) and emphasized, then it is rendered inside circle with colored background. There is a style for it in the backend.css and for example such class is used in `TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer`.

    alert.ts:38 Reply

    Done

    alert.ts:52 Reply

    Done

    alert.ts:53 Reply

    Done
  21. core-ci voted on patch set 4 V +1 06/24/24, 14:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60180

  22. Marcin Sągol uploaded patch set 5 V +1 06/24/24, 14:17

  23. Marcin Sągol commented on patch set 5 06/24/24, 14:17

    alert.ts:31 Reply

    As discussed on Slack, i have removed this attribute and the icon is always emphasized.
  24. core-ci voted on patch set 5 V +1 06/24/24, 14:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60186

  25. Marcin Sągol uploaded patch set 6 V +1 06/24/24, 15:02

  26. core-ci voted on patch set 6 V +1 06/24/24, 15:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60191

  27. Marcin Sągol commented on patch set 6 06/24/24, 15:49

    alert.ts:85 Reply

    @ben@bnf.dev how the slot could be implemented here without loosing bootstrap styles?
  28. Marcin Sągol updated the commit message in patch set 7 V +1 06/24/24, 15:55

  29. Marcin Sągol uploaded patch set 8 06/24/24, 15:58

  30. core-ci voted on patch set 8 V +1 06/24/24, 16:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60196

  31. core-ci voted on patch set 7 V +1 06/24/24, 16:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60195

  32. Marcin Sągol updated the commit message in patch set 9 V +1 06/24/24, 17:32

  33. core-ci voted on patch set 9 V +1 06/24/24, 17:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60201

  34. Marcin Sągol uploaded patch set 10 V +1 06/25/24, 07:27

  35. Marcin Sągol commented on patch set 9 06/25/24, 07:29

    alert.ts:25 Reply

    Done

    alert.ts:85 Reply

    For now i have removed the `unsafeHTML()` usage.
  36. core-ci voted on patch set 10 V +1 06/25/24, 07:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60267

  37. Marcin Sągol rebased onto patch set 11 V +1 06/30/24, 10:49

  38. core-ci voted on patch set 11 V +1 06/30/24, 10:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60663

  39. Andreas Kienast commented on patch set 11 CR -1 07/05/24, 09:58

    Will review asap One thing beforehand: the rst file must be moved to 13.3
  40. Marcin Sągol uploaded patch set 12 CR -1 V +1 07/05/24, 10:43

  41. Marcin Sągol commented on patch set 12 07/05/24, 10:44

    Reply

    Rst moved into 13.3.
  42. core-ci voted on patch set 12 V +1 07/05/24, 10:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61040

  43. Andreas Kienast commented on patch set 12 CR -1 07/05/24, 11:18

    on it
  44. Andreas Kienast uploaded patch set 13 CR -1 V +1 07/05/24, 11:56

  45. core-ci voted on patch set 13 V +1 07/05/24, 12:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61046

  46. Andreas Kienast voted on patch set 13 CR +1 V +1 07/05/24, 12:06

  47. Andreas Kienast commented on patch set 13 07/05/24, 12:06

    Reply

    Done

    Reply

    Done

    alert.ts:85 Reply

    Done
  48. Marcin Sągol voted on patch set 13 CR +1 V +1 07/05/24, 12:57

  49. Mathias Brodala commented on patch set 13 07/05/24, 13:05

    alert-element.ts:36

    It would be nice if this was a String instead with a suitable conversion. This would make it easier to understand the severity just from reading the source.

    alert-element.ts:40

    As mentioned on Slack: could this be passed as element content instead?
  50. Marcin Sągol commented on patch set 13 07/05/24, 13:13

    alert-element.ts:36 Reply

    Could be, but i thought for example if used in PHP, we we would use `ContextualFeedbackSeverity` to pass the severity like `ContextualFeedbackSeverity::OK`, `ContextualFeedbackSeverity::NOTICE` so ve have numbers here, and for JS core we have the `SeverityEnum` like `SeverityEnum.info.info`.
  51. Mathias Brodala commented on patch set 13 07/05/24, 13:17

    alert-element.ts:36 Reply

    Could you then use this in your commit description and in the RST? This way we have good examples to avoid magic numbers from the start.
  1. Philipp Kuhlmay commented on patch set 13 07/05/24, 13:22

    alert-element.ts:23

    Shouldn't this be something like 'alert-element' instead of 'immediate-action-element'? Module: @typo3/backend/element/alert-element

    alert-element.ts:28

    I suggest to change the following to lines to "Alert heading" and "Alert message" like used inside the commit message, as this is an alert and not a modal.
  2. Andreas Kienast voted on patch set 13 CR 0 V 0 07/05/24, 13:24

  3. Marcin Sągol uploaded patch set 14 CR +1 V +1 07/05/24, 13:53

  4. Marcin Sągol commented on patch set 14 07/05/24, 13:53

    alert-element.ts:23 Reply

    Done

    alert-element.ts:28 Reply

    Done

    alert-element.ts:36 Reply

    Done
  5. Andreas Kienast commented on patch set 14 07/05/24, 13:54

    @marcin@soee.pl your latest push reverted all the changes I did today.
  6. core-ci voted on patch set 14 V +1 07/05/24, 14:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61057

  7. Marcin Sągol commented on patch set 14 07/05/24, 14:09

    Reply

    Do you still have them locally and can push?
  8. Marcin Sągol uploaded patch set 15 V +1 07/05/24, 14:17

  9. Marcin Sągol commented on patch set 15 07/05/24, 14:19

    Reply

    Ok, they should be back again.
  10. Marcin Sągol updated the commit message in patch set 16 07/05/24, 14:19

  11. core-ci voted on patch set 15 V +1 07/05/24, 14:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61059

  12. core-ci voted on patch set 16 V +1 07/05/24, 14:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61060

  13. Andreas Kienast voted on patch set 16 CR +1 V +1 07/08/24, 06:05

  14. Oli Bartsch commented on patch set 16 CR -1 07/08/24, 07:17

    commit message and rst need some cleanup. Will try to do today.
    is
    does not exist anymore
    does not exist anymore
  15. Marcin Sągol commented on patch set 16 07/08/24, 11:21

    Reply

    Right, and this is desired from my perspective, as there are nested places where the alert should be condensed, so icon is not needed and rendered without icon atm.
  16. Oli Bartsch uploaded patch set 17 CR +1 V +1 07/09/24, 14:54

  17. core-ci voted on patch set 17 V +1 07/09/24, 14:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61247

  18. Oli Bartsch commented on patch set 17 CR +1 V +1 07/09/24, 14:59

    Reply

    Done

    Reply

    Done

    Reply

    Done

    Reply

    Done

    alert-element.ts:40 Reply

    As discussed in slack due to the need of shadow dom and the drawbacks (encapsulated styles, etc.) we will go with the current solution for now.
  19. Benjamin Franzke commented on patch set 17 07/09/24, 15:16

    Reply

    fine by me

    alert-element.ts:40 Reply

    I'm also not happy with this, as already mentioned in https://review.typo3.org/c/Packages/TYPO3.CMS/+/84535/13#message-9fc00fe5d0fd4447c270f998d9ac903177218883 But that means this component needs to use shadow-dom in order to use `<slot>` and therefore needs to avoid bootstrap classes. We'll need some more preparatory refactorings first, like: > 85132: [TASK] Introduce CSS Color Tokens | https://review.typo3.org/c/Packages/TYPO3.CMS/+/85132 ..and patches that will follow. if this patch is urgently needed it can go in, otherwise I'd love if someone would implement proper shadow DOM directly..
  20. Andreas Kienast commented on patch set 17 07/10/24, 07:20

    alert-element.ts:40 Reply

    Compromise: let's merge this patch as a [TASK]. This way the component isn't documented and we're fine changing this again at a later point without being breaking.
  21. Oli Bartsch uploaded patch set 18 CR +1 V +1 07/10/24, 07:29

  22. Oli Bartsch commented on patch set 18 CR +1 V +1 07/10/24, 07:29

    alert-element.ts:40 Reply

    Acknowledged
  23. core-ci voted on patch set 18 V +1 07/10/24, 07:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61289

  24. Andreas Kienast voted on patch set 18 CR +2 V +2 07/10/24, 07:39

  25. Andreas Kienast merged patch set 19 07/10/24, 07:39