Remove community workspace dropdown UI
Deploy / deploy (push) Successful in 2m30s
CI / Rust Checks (push) Successful in 5m32s
CI / UI Checks (push) Successful in 5s
CI / Deployment Manifests (push) Successful in 2s
CI / Frontend E2E (push) Failing after 4m46s

This commit is contained in:
github-ops
2026-06-19 17:59:57 +00:00
parent 58cfd86d90
commit 0d8a36e4d4
12 changed files with 52 additions and 337 deletions
+34 -173
View File
@@ -5,22 +5,10 @@ var WS_LIST = [
var workspaceLoadPromise = null;
var workspaceLoadFailed = false;
var lastWorkspaceId = null;
function tKey(key) {
return typeof t === 'function' ? t(key) : key;
}
function tfKey(key, vars) {
return typeof tf === 'function' ? tf(key, vars) : key;
}
function buildIconSvg(href, width, height) {
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', String(width));
svg.setAttribute('height', String(height));
var use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
use.setAttribute('href', href);
svg.appendChild(use);
return svg;
}
function workspaceColor(index) {
return ['#0d9488', '#7c3aed', '#0891b2', '#f59e0b', '#2563eb'][index % 5];
@@ -45,30 +33,6 @@ function mapWorkspace(record, index) {
};
}
function cachedWorkspaceId() {
try {
return localStorage.getItem('crank_workspace_id');
} catch (_error) {
return null;
}
}
function cachedWorkspaceSlug() {
try {
return localStorage.getItem('crank_workspace_slug');
} catch (_error) {
return null;
}
}
function sessionWorkspaceId() {
if (!window.CrankAuth || typeof window.CrankAuth.getCachedSession !== 'function') {
return null;
}
var session = window.CrankAuth.getCachedSession();
return session && session.current_workspace_id ? session.current_workspace_id : null;
}
function cacheCurrentWorkspace(workspace) {
if (!workspace) return;
try {
@@ -78,30 +42,7 @@ function cacheCurrentWorkspace(workspace) {
}
function resolveCurrentWorkspace() {
var workspaceId = sessionWorkspaceId() || cachedWorkspaceId();
var workspaceSlug = cachedWorkspaceSlug();
return WS_LIST.find(function(item) { return item.id === workspaceId; })
|| WS_LIST.find(function(item) { return item.slug === workspaceSlug; })
|| WS_LIST[0]
|| null;
}
function emitWorkspaceChange(workspace) {
if (!workspace) {
return;
}
lastWorkspaceId = workspace.id;
window.dispatchEvent(new CustomEvent('crank:workspacechange', { detail: workspace }));
}
function getCurrentWs() {
var workspace = resolveCurrentWorkspace();
if (workspace) {
cacheCurrentWorkspace(workspace);
}
return workspace;
return WS_LIST[0] || null;
}
function updateWorkspaceHeader(workspace) {
@@ -114,77 +55,24 @@ function updateWorkspaceHeader(workspace) {
}
}
function renderWorkspaceList() {
var current = getCurrentWs();
updateWorkspaceHeader(current);
function emitWorkspaceChange(workspace) {
if (!workspace || workspace.id === lastWorkspaceId) {
return;
}
lastWorkspaceId = workspace.id;
window.dispatchEvent(new CustomEvent('crank:workspacechange', { detail: workspace }));
}
document.querySelectorAll('.ws-dropdown-footer').forEach(function(footer) {
footer.hidden = true;
});
function getCurrentWs() {
var workspace = resolveCurrentWorkspace();
if (workspace) {
cacheCurrentWorkspace(workspace);
}
return workspace;
}
var list = document.getElementById('ws-dropdown-list');
if (!list) return;
window.CrankDom.clear(list);
WS_LIST.forEach(function(workspace) {
var active = current && workspace.id === current.id;
var item = document.createElement('div');
item.className = 'ws-dropdown-item' + (active ? ' active' : '');
item.addEventListener('click', function() {
var dd = document.getElementById('ws-dropdown');
if (dd) dd.hidden = true;
});
var dot = document.createElement('div');
dot.className = 'ws-item-dot';
dot.style.background = workspace.color;
dot.textContent = workspace.letter;
item.appendChild(dot);
var info = document.createElement('div');
info.className = 'ws-item-info';
var name = document.createElement('div');
name.className = 'ws-item-name';
name.textContent = workspace.name;
var role = document.createElement('div');
role.className = 'ws-item-role';
role.textContent = workspace.role;
info.appendChild(name);
info.appendChild(role);
item.appendChild(info);
if (active) {
var check = buildIconSvg(
(window.APP_BASE || '') + 'icons/general/check.svg#icon',
12,
12
);
item.appendChild(check);
}
list.appendChild(item);
});
var divider = document.createElement('div');
divider.className = 'ws-dropdown-divider';
list.appendChild(divider);
var manageLink = document.createElement('a');
manageLink.className = 'ws-dropdown-mgmt-link';
manageLink.href = (window.CrankRoutes && window.CrankRoutes.workspaceSetup) || '/workspace-setup';
manageLink.addEventListener('click', function() {
var dd = document.getElementById('ws-dropdown');
if (dd) dd.hidden = true;
});
manageLink.appendChild(
buildIconSvg(
(window.APP_BASE || '') + 'icons/general/settings.svg#icon',
14,
14
)
);
manageLink.appendChild(document.createTextNode(tKey('settings.ws.title')));
list.appendChild(manageLink);
function renderWorkspaceHeader() {
updateWorkspaceHeader(getCurrentWs());
}
async function loadWorkspaces() {
@@ -192,7 +80,7 @@ async function loadWorkspaces() {
workspaceLoadPromise = (async function() {
if (!window.CrankApi) {
renderWorkspaceList();
renderWorkspaceHeader();
return WS_LIST;
}
@@ -200,14 +88,15 @@ async function loadWorkspaces() {
var response = await window.CrankApi.listWorkspaces();
var items = (response && response.items ? response.items : []).map(mapWorkspace);
if (items.length > 0) {
WS_LIST = items;
WS_LIST = [items[0]];
}
workspaceLoadFailed = false;
} catch (_error) {
workspaceLoadFailed = true;
}
renderWorkspaceList();
renderWorkspaceHeader();
emitWorkspaceChange(getCurrentWs());
return WS_LIST;
}());
@@ -219,35 +108,14 @@ async function refreshWorkspaces() {
return loadWorkspaces();
}
function initWorkspaceSwitcher() {
renderWorkspaceList();
loadWorkspaces();
}
function toggleWsSwitcher(e) {
e.stopPropagation();
var dd = document.getElementById('ws-dropdown');
if (dd) dd.hidden = !dd.hidden;
}
function switchWorkspace(workspaceId) {
var workspace = WS_LIST.find(function(item) { return item.id === workspaceId; });
if (!workspace) return;
var dd = document.getElementById('ws-dropdown');
if (dd) dd.hidden = true;
cacheCurrentWorkspace(workspace);
renderWorkspaceList();
emitWorkspaceChange(workspace);
return Promise.resolve(workspace);
}
function setCurrentWorkspace(workspace) {
if (!workspace) {
return Promise.resolve(null);
if (workspace) {
WS_LIST = [workspace];
cacheCurrentWorkspace(workspace);
renderWorkspaceHeader();
emitWorkspaceChange(workspace);
}
return Promise.resolve(switchWorkspace(workspace.id));
return Promise.resolve(workspace || null);
}
window.getCurrentWorkspace = getCurrentWs;
@@ -256,19 +124,12 @@ window.refreshWorkspaces = refreshWorkspaces;
window.setCurrentWorkspace = setCurrentWorkspace;
window.hasWorkspaceApiFailure = function() { return workspaceLoadFailed; };
document.addEventListener('DOMContentLoaded', initWorkspaceSwitcher);
document.addEventListener('DOMContentLoaded', function() {
renderWorkspaceHeader();
loadWorkspaces();
});
window.addEventListener('crank:sessionchange', function() {
var workspace = getCurrentWs();
renderWorkspaceList();
if (workspace && workspace.id !== lastWorkspaceId) {
emitWorkspaceChange(workspace);
}
});
document.addEventListener('click', function(e) {
if (!e.target.closest('#ws-switcher')) {
var dd = document.getElementById('ws-dropdown');
if (dd) dd.hidden = true;
}
renderWorkspaceHeader();
emitWorkspaceChange(getCurrentWs());
});