chore: hide developer tokens section in if there is nothing to display or create (#3753)

This commit is contained in:
Robert Korulczyk 2023-03-12 12:37:49 +01:00 committed by GitHub
parent b7498d6cb1
commit 661b9d7d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,17 +51,27 @@ export default class UserSecurityPage<CustomAttrs extends IUserPageAttrs = IUser
settingsItems() {
const items = new ItemList<Mithril.Children>();
['developerTokens', 'sessions'].forEach((section) => {
const sectionName = `${section}Items` as 'developerTokensItems' | 'sessionsItems';
const sectionLocale = camelCaseToSnakeCase(section);
if (
app.forum.attribute('canCreateAccessToken') ||
app.forum.attribute('canModerateAccessTokens') ||
(this.state.hasLoadedTokens() && this.state.getDeveloperTokens()?.length)
) {
items.add(
section,
<FieldSet className={`UserSecurityPage-${section}`} label={app.translator.trans(`core.forum.security.${sectionLocale}_heading`)}>
{this[sectionName]().toArray()}
'developerTokens',
<FieldSet className="UserSecurityPage-developerTokens" label={app.translator.trans(`core.forum.security.developer_tokens_heading`)}>
{this.developerTokensItems().toArray()}
</FieldSet>
);
});
} else if (!this.state.hasLoadedTokens()) {
items.add('developerTokens', <LoadingIndicator />);
}
items.add(
'sessions',
<FieldSet className="UserSecurityPage-sessions" label={app.translator.trans(`core.forum.security.sessions_heading`)}>
{this.sessionsItems().toArray()}
</FieldSet>
);
if (this.user!.id() === app.session.user!.id()) {
items.add(