Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

disable create service token button while one is being created #1197

Merged
merged 1 commit into from
Jan 28, 2025
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
14 changes: 13 additions & 1 deletion src/main/webapp/app/pages/AccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import client from 'app/shared/api/clientInstance';
import { Token } from 'app/shared/api/generated/API';
import ButtonWithTooltip from 'app/shared/button/ButtonWithTooltip';
import { LoadingButton } from 'app/shared/button/LoadingButton';
import InfoIcon from 'app/shared/icons/InfoIcon';
import { ContactLink } from 'app/shared/links/ContactLink';
import { SimpleConfirmModal } from 'app/shared/modal/SimpleConfirmModal';
Expand Down Expand Up @@ -67,6 +68,7 @@ export class AccountPage extends React.Component<IRegisterProps> {
@observable apiAccessRequested =
this.account?.additionalInfo?.apiAccessRequest?.requested || false;
@observable showCreateServiceAccountTokenModal = false;
@observable isCreatingServiceAccountToken = false;
@observable serviceAccountTokens: Token[] = [];

constructor(props: Readonly<IRegisterProps>) {
Expand Down Expand Up @@ -126,13 +128,18 @@ export class AccountPage extends React.Component<IRegisterProps> {

@action.bound
async addServiceAccountToken(name: string) {
this.isCreatingServiceAccountToken = true;
try {
await client.createServiceAccountTokenUsingPOST({ name });
await this.getServiceAccountTokens();
this.hideCreateServiceAccountTokenModal();
notifySuccess('Service account token is added');
} catch (e) {
notifyError(e);
} finally {
setTimeout(() => {
this.isCreatingServiceAccountToken = false;
}, 100);
Comment on lines +140 to +142
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for adding a small delay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a brief flicker where the button re-enables before the modal closes. This small delay mitigates that

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good, thanks!

}
}

Expand Down Expand Up @@ -458,7 +465,12 @@ export class AccountPage extends React.Component<IRegisterProps> {
>
Cancel
</Button>
<Button type="submit">Create Token</Button>
<Button
type="submit"
disabled={this.isCreatingServiceAccountToken}
>
Create Token
</Button>
</Modal.Footer>
</AvForm>
</Modal>
Expand Down
Loading