Manier om een themacomponent te beperken tot alleen moderators?

AI-generated summary

pangbo developed a theme component for moderators that adds a modal to remind them to consider suspending a user after handling a flag. The component is located in javascripts/discourse/admin/components/modal/remove-post.gjs and imports AdminUser from the admin namespace. While it functions correctly for moderators, regular users encounter an error because they cannot load the admin/models/admin-user module. pangbo is seeking a supported way to restrict the component (or its admin-specific import) to only moderators and admins, preventing the error for regular users.

david suggests using optionalRequire as a current best practice, referencing an example implementation in discourse/app/components/modal/tag-upload.gjs. However, david notes that the JavaScript build systems are undergoing changes, and this approach may require updates in the future with accompanying deprecation messages and instructions.

Ik heb een themacomponent ontwikkeld speciaal voor onze moderators. Deze component voegt een modaal venster toe dat moderators eraan herinnert een gebruiker te schorsen na het afhandelen van een vlag. Ik heb deze component geplaatst op javascripts/discourse/admin/components/modal/remove-post.gjs, en bovenaan importeert het AdminUser met import AdminUser from \"admin/models/admin-user\";.

Voor moderators werkt alles perfect. Echter, gewone gebruikers ervaren problemen. Discourse probeert deze component nog steeds te laden voor alle gebruikers, en aangezien gewone gebruikers geen admin/** modules laden, resulteert dit in de volgende foutmelding:

Error: Could not find module `admin/models/admin-user`

Idealiter wil ik dat deze subcomponent (of zelfs maar deze import) alleen wordt geladen voor moderators en beheerders. Is er een officieel ondersteunde manier om ervoor te zorgen dat een Glimmer-component binnen een themacomponent alleen wordt geladen voor personeel (moderators/beheerders) in Discourse, zodat gewone gebruikers nooit foutmeldingen over ontbrekende modules voor admin-specifieke imports tegenkomen?

Right now, the best strategy is to use optionalRequire like this:

We’re doing a lot of work on our JS build systems right now, so there’s a change this will need change in future. If it does, there will be a deprecation message with instructions to upgrade.