-
Notifications
You must be signed in to change notification settings - Fork 8
Enhance SSH dialog user experience #4260
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
base: development
Are you sure you want to change the base?
Conversation
- prevent empty key name - disable close the dialog while generating or saving the key
…into development_ssh_UX
await sshKeysManagement.update(newKeys); | ||
createCustomToast("SSH keys have been recovered successfully.", ToastType.success); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys will be renamed, this is to make the user aware of what happened to the keys
…into development_ssh_UX
assignDefaultNames(keys?: SSHKeyData[]): SSHKeyData[] { | ||
if (!keys) { | ||
keys = this.oldKeys as SSHKeyData[]; | ||
} | ||
const existingNames = new Set(keys.map(k => k.name).filter(Boolean)); | ||
for (const key of keys) { | ||
if (isAlphanumericWithSpace("Invalid name")(key.name) !== true) { | ||
key.name = this.getUniqueName(existingNames, false); | ||
} | ||
} | ||
return keys; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assignDefaultNames(keys?: SSHKeyData[]): SSHKeyData[] { | |
if (!keys) { | |
keys = this.oldKeys as SSHKeyData[]; | |
} | |
const existingNames = new Set(keys.map(k => k.name).filter(Boolean)); | |
for (const key of keys) { | |
if (isAlphanumericWithSpace("Invalid name")(key.name) !== true) { | |
key.name = this.getUniqueName(existingNames, false); | |
} | |
} | |
return keys; | |
} | |
assignDefaultNames(keys?: SSHKeyData[]): SSHKeyData[] { | |
if (!keys) { | |
keys = this.oldKeys as SSHKeyData[]; | |
} | |
// Collect existing names, filtering out empty or falsy names | |
const existingNames = new Set( | |
keys | |
.map(k => k.name) | |
.filter(name => name && isAlphanumericWithSpace("Invalid name")(name) === true) | |
); | |
for (const key of keys) { | |
// Check if name is invalid or empty | |
if (!key.name || isAlphanumericWithSpace("Invalid name")(key.name) !== true) { | |
// Assign a unique default name | |
key.name = this.getUniqueName(existingNames, false); | |
} else { | |
// Add valid existing name to the set to prevent duplicates | |
existingNames.add(key.name); | |
} | |
} | |
return keys; | |
} |
export function isAlphanumericWithSpace(msg: string) { | ||
return (value: string) => { | ||
if (value.endsWith(" ")) { | ||
return msg; | ||
} | ||
value = value.trimEnd(); | ||
if (!/^[a-zA-Z0-9]+( [a-zA-Z0-9]+)*$/.test(value)) { | ||
return msg; | ||
} | ||
return true; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function isAlphanumericWithSpace(msg: string) { | |
return (value: string) => { | |
if (value.endsWith(" ")) { | |
return msg; | |
} | |
value = value.trimEnd(); | |
if (!/^[a-zA-Z0-9]+( [a-zA-Z0-9]+)*$/.test(value)) { | |
return msg; | |
} | |
return true; | |
}; | |
} | |
export function isAlphanumericWithSpace(msg: string) { | |
return (value: string) => { | |
if (value.endsWith(" ") || !/^[a-zA-Z0-9]+( [a-zA-Z0-9]+)*$/.test(value.trimEnd())) { | |
return msg; | |
} | |
return true; | |
}; | |
} |
|
||
it("should not allow empty string", () => { | ||
expect(validator("")).toBe("Invalid input"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add this
it("should not allow a string with only spaces", () => { expect(validator(" ")).toBe("Invalid input"); expect(validator(" ")).toBe("Invalid input"); });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this it("should allow a single character", () => { expect(validator("A")).toBe(true); expect(validator("z")).toBe(true); expect(validator("1")).toBe(true); });
Description
Related Issues
Tested Scenarios
Documentation PR
For UI changes, Please provide the Documentation PR on info_grid
To consider
Preliminary Checks:
UI Checks:
Code Quality Checks:
Testing Checklist
General Checklist