mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 22:03:45 +00:00
Fix ProviderKeyInput UX: improve save button state and remove clear button
- Add inputChanged state to track when user modifies input after save - Remove Clear button and removeKey() method entirely - Save button now disables after successful save until input changes - Save button stays enabled on test failure (allows immediate retry) - Keep input field showing stars (••••) after successful save instead of clearing This provides clearer feedback and prevents accidental key deletion.
This commit is contained in:
parent
1726c1e3af
commit
9e50bb2c37
1 changed files with 10 additions and 29 deletions
|
|
@ -24,6 +24,7 @@ export class ProviderKeyInput extends LitElement {
|
|||
@state() private testing = false;
|
||||
@state() private failed = false;
|
||||
@state() private hasKey = false;
|
||||
@state() private inputChanged = false;
|
||||
|
||||
protected createRenderRoot() {
|
||||
return this;
|
||||
|
|
@ -89,7 +90,7 @@ export class ProviderKeyInput extends LitElement {
|
|||
try {
|
||||
await getAppStorage().providerKeys.set(this.provider, this.keyInput);
|
||||
this.hasKey = true;
|
||||
this.keyInput = "";
|
||||
this.inputChanged = false;
|
||||
this.requestUpdate();
|
||||
} catch (error) {
|
||||
console.error("Failed to save API key:", error);
|
||||
|
|
@ -108,17 +109,6 @@ export class ProviderKeyInput extends LitElement {
|
|||
}
|
||||
}
|
||||
|
||||
private async removeKey() {
|
||||
try {
|
||||
await getAppStorage().providerKeys.delete(this.provider);
|
||||
this.hasKey = false;
|
||||
this.keyInput = "";
|
||||
this.requestUpdate();
|
||||
} catch (error) {
|
||||
console.error("Failed to remove API key:", error);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<div class="space-y-3">
|
||||
|
|
@ -140,27 +130,18 @@ export class ProviderKeyInput extends LitElement {
|
|||
value: this.keyInput,
|
||||
onInput: (e: Event) => {
|
||||
this.keyInput = (e.target as HTMLInputElement).value;
|
||||
this.inputChanged = true;
|
||||
this.requestUpdate();
|
||||
},
|
||||
className: "flex-1",
|
||||
})}
|
||||
${
|
||||
this.hasKey
|
||||
? Button({
|
||||
onClick: () => this.removeKey(),
|
||||
variant: "ghost",
|
||||
size: "sm",
|
||||
children: i18n("Clear"),
|
||||
className: "!text-destructive",
|
||||
})
|
||||
: Button({
|
||||
onClick: () => this.saveKey(),
|
||||
variant: "default",
|
||||
size: "sm",
|
||||
disabled: !this.keyInput || this.testing,
|
||||
children: i18n("Save"),
|
||||
})
|
||||
}
|
||||
${Button({
|
||||
onClick: () => this.saveKey(),
|
||||
variant: "default",
|
||||
size: "sm",
|
||||
disabled: !this.keyInput || this.testing || (this.hasKey && !this.inputChanged),
|
||||
children: i18n("Save"),
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue