mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 20:01:06 +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 testing = false;
|
||||||
@state() private failed = false;
|
@state() private failed = false;
|
||||||
@state() private hasKey = false;
|
@state() private hasKey = false;
|
||||||
|
@state() private inputChanged = false;
|
||||||
|
|
||||||
protected createRenderRoot() {
|
protected createRenderRoot() {
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -89,7 +90,7 @@ export class ProviderKeyInput extends LitElement {
|
||||||
try {
|
try {
|
||||||
await getAppStorage().providerKeys.set(this.provider, this.keyInput);
|
await getAppStorage().providerKeys.set(this.provider, this.keyInput);
|
||||||
this.hasKey = true;
|
this.hasKey = true;
|
||||||
this.keyInput = "";
|
this.inputChanged = false;
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to save API key:", 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() {
|
render() {
|
||||||
return html`
|
return html`
|
||||||
<div class="space-y-3">
|
<div class="space-y-3">
|
||||||
|
|
@ -140,27 +130,18 @@ export class ProviderKeyInput extends LitElement {
|
||||||
value: this.keyInput,
|
value: this.keyInput,
|
||||||
onInput: (e: Event) => {
|
onInput: (e: Event) => {
|
||||||
this.keyInput = (e.target as HTMLInputElement).value;
|
this.keyInput = (e.target as HTMLInputElement).value;
|
||||||
|
this.inputChanged = true;
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
},
|
},
|
||||||
className: "flex-1",
|
className: "flex-1",
|
||||||
})}
|
})}
|
||||||
${
|
${Button({
|
||||||
this.hasKey
|
|
||||||
? Button({
|
|
||||||
onClick: () => this.removeKey(),
|
|
||||||
variant: "ghost",
|
|
||||||
size: "sm",
|
|
||||||
children: i18n("Clear"),
|
|
||||||
className: "!text-destructive",
|
|
||||||
})
|
|
||||||
: Button({
|
|
||||||
onClick: () => this.saveKey(),
|
onClick: () => this.saveKey(),
|
||||||
variant: "default",
|
variant: "default",
|
||||||
size: "sm",
|
size: "sm",
|
||||||
disabled: !this.keyInput || this.testing,
|
disabled: !this.keyInput || this.testing || (this.hasKey && !this.inputChanged),
|
||||||
children: i18n("Save"),
|
children: i18n("Save"),
|
||||||
})
|
})}
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue