fix(khira): fix text circle icon glitch and implement typing-first app autocomplete with role-based filtering
This commit is contained in:
@@ -101,8 +101,9 @@ func (s *Server) RegisterRoutes(r chi.Router) {
|
||||
api.Put("/auth/profile", s.handleUpdateProfile)
|
||||
api.Post("/auth/profile", s.handleUpdateProfile)
|
||||
|
||||
// Users
|
||||
// Users & Apps
|
||||
api.Get("/users", s.handleListUsers)
|
||||
api.Get("/apps", s.handleListApps)
|
||||
|
||||
// Tickets
|
||||
api.Get("/tickets", s.handleListTickets)
|
||||
@@ -315,6 +316,25 @@ func (s *Server) handleListUsers(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleListApps(w http.ResponseWriter, r *http.Request) {
|
||||
assignee := r.URL.Query().Get("assignee")
|
||||
role := r.URL.Query().Get("role")
|
||||
q := r.URL.Query().Get("q")
|
||||
|
||||
if role == "" && assignee != "" {
|
||||
if u, err := s.Store.GetUser(assignee); err == nil && u != nil {
|
||||
role = u.Role
|
||||
}
|
||||
}
|
||||
|
||||
apps := s.Store.ListApps(role, q)
|
||||
s.writeJSON(w, http.StatusOK, map[string]any{
|
||||
"status": "ok",
|
||||
"apps": apps,
|
||||
"count": len(apps),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleListTickets(w http.ResponseWriter, r *http.Request) {
|
||||
status := r.URL.Query().Get("status")
|
||||
priority := r.URL.Query().Get("priority")
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -500,6 +501,156 @@ func (s *Store) DeleteTicket(ticketID string, actor *User) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
type AppMeta struct {
|
||||
Name string `json:"name"`
|
||||
Roles []string `json:"roles"`
|
||||
TicketCount int `json:"ticket_count"`
|
||||
}
|
||||
|
||||
func (s *Store) ListApps(targetRole, query string) []AppMeta {
|
||||
appMap := make(map[string]*AppMeta)
|
||||
|
||||
// 1. Query distinct app_name from tickets with associated user roles
|
||||
rows, err := s.primaryDB.Query(`
|
||||
SELECT t.app_name, COALESCE(u.role, ''), COUNT(*)
|
||||
FROM tickets t
|
||||
LEFT JOIN users u ON LOWER(t.assigned_to) = LOWER(u.username)
|
||||
WHERE t.app_name IS NOT NULL AND t.app_name != ''
|
||||
GROUP BY t.app_name, COALESCE(u.role, '')
|
||||
`)
|
||||
if err == nil {
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var appName, role string
|
||||
var cnt int
|
||||
if err := rows.Scan(&appName, &role, &cnt); err == nil {
|
||||
appName = strings.TrimSpace(appName)
|
||||
if appName == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := appMap[appName]; !ok {
|
||||
appMap[appName] = &AppMeta{
|
||||
Name: appName,
|
||||
Roles: []string{},
|
||||
}
|
||||
}
|
||||
appMap[appName].TicketCount += cnt
|
||||
if role != "" {
|
||||
hasRole := false
|
||||
for _, r := range appMap[appName].Roles {
|
||||
if strings.EqualFold(r, role) {
|
||||
hasRole = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasRole {
|
||||
appMap[appName].Roles = append(appMap[appName].Roles, role)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Also check errors table for distinct app_name
|
||||
errRows, err := s.primaryDB.Query(`
|
||||
SELECT DISTINCT app_name FROM errors WHERE app_name IS NOT NULL AND app_name != ''
|
||||
`)
|
||||
if err == nil {
|
||||
defer errRows.Close()
|
||||
for errRows.Next() {
|
||||
var appName string
|
||||
if err := errRows.Scan(&appName); err == nil {
|
||||
appName = strings.TrimSpace(appName)
|
||||
if appName != "" && appMap[appName] == nil {
|
||||
appMap[appName] = &AppMeta{
|
||||
Name: appName,
|
||||
Roles: []string{},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Fallback standard applications if not present in DB
|
||||
defaults := []string{
|
||||
"Creator Suite Web",
|
||||
"Creator Suite iOS",
|
||||
"Creator Suite Android",
|
||||
"FastAPI Backend",
|
||||
"Image Manipulator Pro",
|
||||
"Unified Dashboard Client",
|
||||
"Unified Dashboard iOS",
|
||||
"Unified Dashboard Android",
|
||||
"Batch Inpaint Service",
|
||||
"Nexus Gateway",
|
||||
}
|
||||
for _, defApp := range defaults {
|
||||
if appMap[defApp] == nil {
|
||||
roles := []string{}
|
||||
nameLower := strings.ToLower(defApp)
|
||||
if strings.Contains(nameLower, "android") {
|
||||
roles = append(roles, "android_dev")
|
||||
}
|
||||
if strings.Contains(nameLower, "ios") {
|
||||
roles = append(roles, "ios_dev")
|
||||
}
|
||||
if strings.Contains(nameLower, "backend") || strings.Contains(nameLower, "service") || strings.Contains(nameLower, "gateway") {
|
||||
roles = append(roles, "backend_dev")
|
||||
}
|
||||
appMap[defApp] = &AppMeta{
|
||||
Name: defApp,
|
||||
Roles: roles,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Role-based filtering:
|
||||
// "suppose the assignee is from iOS developer then no apps which is associated to an android developer should be shown,
|
||||
// if assignee is backend developer then every app should be shown as suggestion while typing"
|
||||
var result []AppMeta
|
||||
qLower := strings.ToLower(strings.TrimSpace(query))
|
||||
targetRole = strings.ToLower(strings.TrimSpace(targetRole))
|
||||
|
||||
for _, meta := range appMap {
|
||||
if qLower != "" && !strings.Contains(strings.ToLower(meta.Name), qLower) {
|
||||
continue
|
||||
}
|
||||
|
||||
nameLower := strings.ToLower(meta.Name)
|
||||
isAndroidApp := strings.Contains(nameLower, "android")
|
||||
isIOSApp := strings.Contains(nameLower, "ios")
|
||||
for _, r := range meta.Roles {
|
||||
if strings.EqualFold(r, "android_dev") {
|
||||
isAndroidApp = true
|
||||
}
|
||||
if strings.EqualFold(r, "ios_dev") {
|
||||
isIOSApp = true
|
||||
}
|
||||
}
|
||||
|
||||
if targetRole == "ios_dev" {
|
||||
// No apps associated to an android developer should be shown
|
||||
if isAndroidApp {
|
||||
continue
|
||||
}
|
||||
} else if targetRole == "android_dev" {
|
||||
// No apps associated to an iOS developer should be shown
|
||||
if isIOSApp {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// if backend_dev (or any other), every app is included!
|
||||
|
||||
result = append(result, *meta)
|
||||
}
|
||||
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].Name < result[j].Name
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *Store) ListTickets(status, priority, app, assignee, reporter, query, ticketType string) []*Ticket {
|
||||
|
||||
var conds []string
|
||||
|
||||
+146
-6
@@ -116,7 +116,7 @@ const greet=()=>{const h=new Date().getHours();return h<5?'Working late':h<12?'G
|
||||
const put=(sel,html)=>{const el=typeof sel==='string'?$(sel):sel;if(el&&el._h!==html){el.innerHTML=html;el._h=html}return el};
|
||||
let tt;function toast(m,t){const s=$('#snack');s.textContent=m;s.style.background=t==='err'?'var(--err)':'';s.classList.add('on');clearTimeout(tt);tt=setTimeout(()=>s.classList.remove('on'),3500)}
|
||||
const busy=async(b,fn)=>{b.disabled=true;try{return await fn()}finally{b.disabled=false}};
|
||||
const chk=f=>{f.querySelectorAll('.bad').forEach(x=>x.classList.remove('bad'));const bad=[...f.querySelectorAll('[required]:not(:disabled)')].filter(x=>!x.value.trim());bad.forEach(x=>x.closest('.fld').classList.add('bad'));if(bad.length){bad[0].focus();toast('Fill in the required fields','err')}return!bad.length};
|
||||
const chk=f=>{f.querySelectorAll('.bad').forEach(x=>x.classList.remove('bad'));const bad=[...f.querySelectorAll('[required]:not(:disabled)')].filter(x=>!x.disabled&&!x.closest('[hidden]')&&!x.closest('fieldset:disabled')&&!x.value.trim());bad.forEach(x=>x.closest('.fld').classList.add('bad'));if(bad.length){bad[0].focus();toast('Fill in the required fields','err')}return!bad.length};
|
||||
|
||||
/* ── form builders ── */
|
||||
function fld(n,l,o={}){
|
||||
@@ -378,8 +378,6 @@ function deleteTicketD(id){
|
||||
|
||||
/* ── create ticket ── */
|
||||
function newTicket(){
|
||||
const appOpts=[['','Select application'],...Array.from(new Set([...APPS,...(S.t||[]).map(t=>t.app||t.app_name),...(S.e||[]).map(e=>e.app||e.app_name)].filter(Boolean)))];
|
||||
|
||||
dlg({wide:1,title:'New ticket',sub:`Reporting as ${esc(S.u.name)}`,ok:'Create ticket',
|
||||
body:`${rad('type',[['general','General'],['application','Application']],'general')}
|
||||
<fieldset class="grp" data-g="general">
|
||||
@@ -388,8 +386,20 @@ function newTicket(){
|
||||
${fld('description','Description',{t:'area',rows:5,req:1})}
|
||||
</fieldset>
|
||||
<fieldset class="grp" data-g="application" hidden disabled>
|
||||
${fld('assignee_username','Developer account',{t:'select',opts:usOpts(1),req:1})}
|
||||
${fld('app','App name',{t:'select',opts:appOpts,req:1})}
|
||||
<label class="fld sel">
|
||||
<select name="assignee_username" id="appDevSelect" required>
|
||||
${usOpts(1).map(([v,l])=>`<option value="${esc(v)}">${esc(l)}</option>`).join('')}
|
||||
</select>
|
||||
<span>Developer account *</span>
|
||||
</label>
|
||||
<div class="app-ac-wrap">
|
||||
<label class="fld">
|
||||
<input name="app" id="appInput" placeholder=" " autocomplete="off" required>
|
||||
<span>App name *</span>
|
||||
</label>
|
||||
<div class="app-ac-menu" id="appSugMenu" hidden></div>
|
||||
<div id="appConflictWarn" class="app-ac-conflict" style="display:none"></div>
|
||||
</div>
|
||||
${fld('version','Version',{req:1})}
|
||||
${fld('feature','Feature name')}
|
||||
${fld('api_key','API key')}
|
||||
@@ -415,11 +425,141 @@ function newTicket(){
|
||||
const on=x.dataset.g===g;
|
||||
x.hidden=!on;
|
||||
x.disabled=!on;
|
||||
x.querySelectorAll('input, select, textarea').forEach(inp=>{
|
||||
inp.disabled=!on;
|
||||
});
|
||||
});
|
||||
};
|
||||
f.querySelectorAll('[name=type]').forEach(r=>r.onchange=sw);
|
||||
sw();
|
||||
|
||||
// App Autocomplete & dynamic role-based app suggestions
|
||||
const devSel=f.querySelector('#appDevSelect');
|
||||
const appInp=f.querySelector('#appInput');
|
||||
const sugMenu=f.querySelector('#appSugMenu');
|
||||
const conflictWarn=f.querySelector('#appConflictWarn');
|
||||
|
||||
let allApps=[];
|
||||
const loadApps=async()=>{
|
||||
try{
|
||||
const res=await api('/khira/api/apps');
|
||||
if(res.apps&&Array.isArray(res.apps)){
|
||||
allApps=res.apps;
|
||||
}
|
||||
}catch(err){
|
||||
console.error('Failed to load apps list',err);
|
||||
}
|
||||
};
|
||||
loadApps();
|
||||
|
||||
const getDevRole=()=>{
|
||||
const uName=devSel?devSel.value:'';
|
||||
if(!uName)return'';
|
||||
const u=(S.us||[]).find(x=>x.username.toLowerCase()===uName.toLowerCase());
|
||||
return u?(u.role||''):'';
|
||||
};
|
||||
|
||||
const renderSuggestions=()=>{
|
||||
if(!sugMenu||!appInp)return;
|
||||
const role=getDevRole();
|
||||
const q=(appInp.value||'').trim().toLowerCase();
|
||||
|
||||
// Role-based filtering:
|
||||
// iOS dev -> no apps associated to android developer
|
||||
// Android dev -> no apps associated to iOS developer
|
||||
// Backend dev (or others) -> every app is shown
|
||||
const filtered=allApps.filter(app=>{
|
||||
const appNameLower=(app.name||'').toLowerCase();
|
||||
const roles=(app.roles||[]).map(r=>r.toLowerCase());
|
||||
const isAndroidApp=roles.includes('android_dev')||appNameLower.includes('android');
|
||||
const isIOSApp=roles.includes('ios_dev')||appNameLower.includes('ios');
|
||||
|
||||
if(role==='ios_dev'&&isAndroidApp)return false;
|
||||
if(role==='android_dev'&&isIOSApp)return false;
|
||||
|
||||
if(q&&!appNameLower.includes(q))return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
if(!filtered.length){
|
||||
sugMenu.innerHTML=`<div class="app-ac-empty">No existing app matching "<b>${esc(q||'role filter')}</b>".<br>You can keep typing to use a custom app name.</div>`;
|
||||
}else{
|
||||
sugMenu.innerHTML=filtered.map(app=>{
|
||||
let badge='';
|
||||
const nameLower=app.name.toLowerCase();
|
||||
const roles=(app.roles||[]).map(r=>r.toLowerCase());
|
||||
if(roles.includes('ios_dev')||nameLower.includes('ios')){
|
||||
badge='<span class="app-ac-badge ios">iOS</span>';
|
||||
}else if(roles.includes('android_dev')||nameLower.includes('android')){
|
||||
badge='<span class="app-ac-badge android">Android</span>';
|
||||
}else if(roles.includes('backend_dev')||nameLower.includes('backend')||nameLower.includes('service')){
|
||||
badge='<span class="app-ac-badge backend">Backend</span>';
|
||||
}
|
||||
return`<div class="app-ac-item" data-app="${esc(app.name)}">
|
||||
<span class="app-name">${esc(app.name)}</span>
|
||||
<span class="app-meta">${badge}</span>
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
sugMenu.querySelectorAll('.app-ac-item').forEach(it=>{
|
||||
it.onmousedown=e=>{
|
||||
e.preventDefault();
|
||||
appInp.value=it.dataset.app;
|
||||
sugMenu.hidden=true;
|
||||
checkConflict();
|
||||
};
|
||||
});
|
||||
}
|
||||
sugMenu.hidden=false;
|
||||
};
|
||||
|
||||
const checkConflict=()=>{
|
||||
if(!conflictWarn||!appInp)return;
|
||||
const role=getDevRole();
|
||||
const val=(appInp.value||'').trim();
|
||||
if(!val){
|
||||
conflictWarn.style.display='none';
|
||||
return;
|
||||
}
|
||||
const valLower=val.toLowerCase();
|
||||
const matchedApp=allApps.find(a=>a.name.toLowerCase()===valLower);
|
||||
const roles=matchedApp?(matchedApp.roles||[]).map(r=>r.toLowerCase()):[];
|
||||
const isAndroid=roles.includes('android_dev')||valLower.includes('android');
|
||||
const isIOS=roles.includes('ios_dev')||valLower.includes('ios');
|
||||
|
||||
if(role==='ios_dev'&&isAndroid){
|
||||
conflictWarn.innerHTML=`<span class="ms" style="font-size:16px">warning</span> <span>Selected developer is iOS Dev, but "${esc(val)}" is an Android application.</span>`;
|
||||
conflictWarn.style.display='flex';
|
||||
}else if(role==='android_dev'&&isIOS){
|
||||
conflictWarn.innerHTML=`<span class="ms" style="font-size:16px">warning</span> <span>Selected developer is Android Dev, but "${esc(val)}" is an iOS application.</span>`;
|
||||
conflictWarn.style.display='flex';
|
||||
}else{
|
||||
conflictWarn.style.display='none';
|
||||
}
|
||||
};
|
||||
|
||||
if(appInp){
|
||||
appInp.addEventListener('focus',()=>{
|
||||
renderSuggestions();
|
||||
});
|
||||
appInp.addEventListener('input',()=>{
|
||||
renderSuggestions();
|
||||
checkConflict();
|
||||
});
|
||||
appInp.addEventListener('blur',()=>{
|
||||
setTimeout(()=>{if(sugMenu)sugMenu.hidden=true;},180);
|
||||
});
|
||||
}
|
||||
|
||||
if(devSel){
|
||||
devSel.addEventListener('change',()=>{
|
||||
checkConflict();
|
||||
if(appInp&&!sugMenu.hidden){
|
||||
renderSuggestions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const imgInput=f.querySelector('#appImgInput');
|
||||
const previewWrap=f.querySelector('#imgPreviewWrap');
|
||||
const previewImg=f.querySelector('#imgPreview');
|
||||
@@ -513,7 +653,7 @@ function errD(id){
|
||||
const isArch=!!e.archived;
|
||||
dlg({wide:1,title:esc(e.exception_type),sub:esc(`${e.id} · ${appName}${e.environment?' · '+e.environment:''}`),
|
||||
body:`<div class="r"><span class="sv ${(e.severity||'').toUpperCase()}">${esc(e.severity)}</span><span class="stt ${isArch?'archived':k}">${isArch?'Archived':EL[k]}</span><span class="id">${e.events||e.occurrences||1} events · ${ago(e.last_seen)}</span></div>
|
||||
${appName?`<div style="margin:10px 0"><button type="button" class="chip" id="btnLogMoreForApp" style="background:var(--sec-c);font-weight:500"><span class="ms">add_circle</span>Log another error for ${esc(appName)}</button></div>`:''}
|
||||
${appName?`<div style="margin:10px 0"><button type="button" class="chip" id="btnLogMoreForApp" style="background:var(--sec-c);font-weight:500"><svg class="btn-ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:6px"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>Log another error for ${esc(appName)}</button></div>`:''}
|
||||
<p>${esc(e.message)}</p>${blk('Endpoint',e.endpoint)}${blk('Stack trace',e.stack_trace)}${blk('Payload',e.payload||e.request_payload)}${e.escalated_ticket_id||e.linked_ticket_id?`<p class="sub">Escalated as ${esc(e.escalated_ticket_id||e.linked_ticket_id)}</p>`:''}${e.resolution_notes?`<p class="sub">Resolution: ${esc(e.resolution_notes)}</p>`:''}`,
|
||||
ok:k==='resolved'?'Close':'Escalate to ticket',
|
||||
alt:k==='unresolved'?['Resolve',()=>resolveD(id)]:(k==='resolved'?[(isArch?'Restore':'Archive'),async()=>{
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
<div class="tools">
|
||||
<div class="chips" id="eChips"></div>
|
||||
<div class="tr">
|
||||
<button class="chip" id="btnLogAppErr" title="Log and continue assigning errors for an application"><span class="ms">add_circle</span><span>Testing Phase: Log Errors</span></button>
|
||||
<button class="chip" id="btnLogAppErr" title="Log and continue assigning errors for an application"><svg class="btn-ic" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:6px"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg><span>Testing Phase: Log Errors</span></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="elist" class="list"></div>
|
||||
|
||||
@@ -376,6 +376,21 @@ dt{font-size:12px;color:var(--on-sv)}dd{word-break:break-word}
|
||||
.att-thumb:hover{transform:scale(1.03)}
|
||||
.att-card .ell{font-size:12px;color:var(--on-sv)}
|
||||
|
||||
/* Application autocomplete typing-first dropdown */
|
||||
.app-ac-wrap{position:relative;width:100%}
|
||||
.app-ac-menu{position:absolute;top:calc(100% + 4px);left:0;right:0;background:var(--sc-hi);border:1px solid var(--out-v);border-radius:12px;max-height:220px;overflow-y:auto;z-index:60;box-shadow:0 8px 24px rgb(0 0 0/.35);padding:6px;display:grid;gap:2px}
|
||||
.app-ac-item{padding:8px 12px;border-radius:8px;cursor:pointer;display:flex;align-items:center;justify-content:space-between;font-size:13px;color:var(--on-s);transition:background .15s}
|
||||
.app-ac-item:hover,.app-ac-item.highlighted{background:var(--sec-c)}
|
||||
.app-ac-item .app-name{font-weight:500;display:flex;align-items:center;gap:8px}
|
||||
.app-ac-item .app-meta{font-size:11px;color:var(--on-sv);display:flex;gap:6px;align-items:center}
|
||||
.app-ac-badge{padding:2px 8px;border-radius:8px;font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.3px}
|
||||
.app-ac-badge.ios{background:rgb(34 197 94/.18);color:#4ade80}
|
||||
.app-ac-badge.android{background:rgb(56 189 248/.18);color:#38bdf8}
|
||||
.app-ac-badge.backend{background:rgb(234 179 8/.18);color:#facc15}
|
||||
.app-ac-empty{padding:12px;font-size:12px;color:var(--on-sv);text-align:center;line-height:1.4}
|
||||
.app-ac-conflict{margin-top:6px;font-size:12px;color:var(--err);display:flex;align-items:center;gap:6px}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user