Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 5 commits into from
Mar 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions framework/core/js/src/forum/components/UserSecurityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down