Skip to content

Commit 07f6a07

Browse files
sbenodizclaude
andcommitted
Fix UI: Clear Chat button overlap and add local testing
- Replace ha-button with native button element to fix z-index issues - Add proper positioning and z-index to header and clear button - Improve button styling with native CSS properties - Add local frontend testing environment - tests/frontend/test_panel.html for standalone testing - tests/frontend/serve.py as simple HTTP server - Update README with local testing instructions This fixes the issue where the Clear Chat button was overlapping with other UI elements in the header. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fabe1b5 commit 07f6a07

File tree

5 files changed

+143
-11
lines changed

5 files changed

+143
-11
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,32 @@ Please check out our [contribution guidelines](CONTRIBUTING.md) for detailed inf
229229

230230
For security issues, please review our [security policy](SECURITY.md).
231231

232+
### Local Frontend Testing
233+
234+
You can test the frontend UI locally without deploying to Home Assistant:
235+
236+
1. **Start the local test server:**
237+
```bash
238+
cd tests/frontend
239+
python3 serve.py
240+
```
241+
242+
2. **Open your browser:**
243+
Navigate to `http://localhost:8000/test_panel.html`
244+
245+
3. **Test the interface:**
246+
The test page provides a mock Home Assistant environment where you can test UI changes, styling, and component behavior without needing a full Home Assistant installation.
247+
248+
**Test files location:**
249+
- `tests/frontend/test_panel.html` - Standalone test page
250+
- `tests/frontend/serve.py` - Simple HTTP server for testing
251+
252+
This is particularly useful for:
253+
- Testing CSS changes and styling
254+
- Verifying UI layout and responsiveness
255+
- Debugging frontend JavaScript issues
256+
- Quick iteration on visual changes
257+
232258
### CI/CD Workflows
233259

234260
This project uses GitHub Actions to ensure code quality and reliability:

custom_components/ai_agent_ha/frontend/ai_agent_ha-panel.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,31 @@ class AiAgentHaPanel extends LitElement {
5454
font-size: 20px;
5555
font-weight: 500;
5656
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
57+
position: relative;
58+
z-index: 100;
5759
}
5860
.clear-button {
5961
margin-left: auto;
60-
--mdc-theme-primary: var(--error-color);
61-
--mdc-theme-on-primary: #fff;
62-
--mdc-typography-button-font-size: 13px;
63-
--mdc-button-height: 32px;
64-
--mdc-button-padding: 0 12px;
62+
border: none;
6563
border-radius: 16px;
6664
background: var(--error-color);
6765
color: #fff;
66+
cursor: pointer;
6867
transition: all 0.2s ease;
6968
display: flex;
7069
align-items: center;
7170
gap: 6px;
72-
padding: 0 12px;
71+
padding: 8px 16px;
7372
font-weight: 500;
73+
font-size: 13px;
7474
box-shadow: 0 1px 2px rgba(0,0,0,0.08);
7575
min-width: unset;
7676
width: auto;
77-
height: 32px;
77+
height: 36px;
78+
flex-shrink: 0;
79+
position: relative;
80+
z-index: 101;
81+
font-family: inherit;
7882
}
7983
.clear-button:hover {
8084
background: var(--error-color);
@@ -882,14 +886,14 @@ class AiAgentHaPanel extends LitElement {
882886
<div class="header">
883887
<ha-icon icon="mdi:robot"></ha-icon>
884888
AI Agent HA
885-
<ha-button
889+
<button
886890
class="clear-button"
887891
@click=${this._clearChat}
888-
.disabled=${this._isLoading}
892+
?disabled=${this._isLoading}
889893
>
890894
<ha-icon icon="mdi:delete-sweep"></ha-icon>
891895
<span>Clear Chat</span>
892-
</ha-button>
896+
</button>
893897
</div>
894898
<div class="content">
895899
<div class="chat-container">

custom_components/ai_agent_ha/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"requirements": [
2222
"aiohttp>=3.8.0"
2323
],
24-
"version": "0.99.5"
24+
"version": "0.99.6"
2525
}

tests/frontend/serve.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
"""Simple HTTP server for testing the AI Agent HA panel locally."""
3+
import http.server
4+
import socketserver
5+
import os
6+
7+
PORT = 8000
8+
9+
# Change to the project directory
10+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
11+
12+
class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
13+
def end_headers(self):
14+
# Add CORS headers for local testing
15+
self.send_header('Access-Control-Allow-Origin', '*')
16+
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
17+
self.send_header('Access-Control-Allow-Headers', '*')
18+
super().end_headers()
19+
20+
def do_OPTIONS(self):
21+
self.send_response(200)
22+
self.end_headers()
23+
24+
Handler = MyHTTPRequestHandler
25+
26+
with socketserver.TCPServer(("", PORT), Handler) as httpd:
27+
print(f"Server running at http://localhost:{PORT}/")
28+
print(f"Open http://localhost:{PORT}/test_panel.html to test the panel")
29+
print("Press Ctrl+C to stop the server")
30+
try:
31+
httpd.serve_forever()
32+
except KeyboardInterrupt:
33+
print("\nServer stopped.")

tests/frontend/test_panel.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>AI Agent HA Panel Test</title>
7+
<style>
8+
:root {
9+
--primary-background-color: #fafafa;
10+
--secondary-background-color: #e5e5e5;
11+
--card-background-color: #ffffff;
12+
--primary-color: #03a9f4;
13+
--primary-text-color: #212121;
14+
--secondary-text-color: #727272;
15+
--text-primary-color: #ffffff;
16+
--divider-color: #e0e0e0;
17+
--error-color: #db4437;
18+
--error-background-color: #fce4ec;
19+
--app-header-background-color: #03a9f4;
20+
--app-header-text-color: #ffffff;
21+
--accent-color: #ff9800;
22+
--info-color: #2196f3;
23+
--success-color: #4caf50;
24+
}
25+
body {
26+
margin: 0;
27+
padding: 0;
28+
font-family: "Roboto", "Noto", sans-serif;
29+
}
30+
</style>
31+
<script type="module" src="../../custom_components/ai_agent_ha/frontend/ai_agent_ha-panel.js"></script>
32+
</head>
33+
<body>
34+
<ai_agent_ha-panel id="panel"></ai_agent_ha-panel>
35+
36+
<script>
37+
// Mock hass object for testing
38+
const mockHass = {
39+
callService: async (domain, service, data) => {
40+
console.log('Mock service call:', domain, service, data);
41+
return { success: true };
42+
},
43+
callWS: async (data) => {
44+
console.log('Mock WebSocket call:', data);
45+
if (data.type === 'config_entries/get') {
46+
return [
47+
{
48+
domain: 'ai_agent_ha',
49+
title: 'AI Agent HA (Llama)',
50+
data: { ai_provider: 'llama' }
51+
}
52+
];
53+
}
54+
return {};
55+
},
56+
connection: {
57+
subscribeEvents: (callback, eventType) => {
58+
console.log('Mock event subscription:', eventType);
59+
return () => {};
60+
}
61+
}
62+
};
63+
64+
// Set the mock hass object on the panel
65+
const panel = document.getElementById('panel');
66+
panel.hass = mockHass;
67+
</script>
68+
</body>
69+
</html>

0 commit comments

Comments
 (0)