Fix workspace selection and secret modal layout
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var transitionMs = 120;
|
||||
|
||||
function prefersReducedMotion() {
|
||||
return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
}
|
||||
|
||||
function isInternalNavigation(link) {
|
||||
if (!link || !link.href || link.target || link.hasAttribute('download')) return false;
|
||||
|
||||
var targetUrl;
|
||||
try {
|
||||
targetUrl = new URL(link.href, window.location.href);
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (targetUrl.origin !== window.location.origin) return false;
|
||||
if (targetUrl.pathname === window.location.pathname && targetUrl.search === window.location.search) {
|
||||
return targetUrl.hash && targetUrl.hash !== window.location.hash;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function initPageTransitions() {
|
||||
if (prefersReducedMotion()) return;
|
||||
|
||||
document.addEventListener('click', function(event) {
|
||||
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
var link = event.target.closest ? event.target.closest('a[href]') : null;
|
||||
if (!isInternalNavigation(link)) return;
|
||||
|
||||
var targetUrl = new URL(link.href, window.location.href);
|
||||
if (targetUrl.pathname === window.location.pathname && targetUrl.search === window.location.search) return;
|
||||
|
||||
event.preventDefault();
|
||||
document.body.classList.add('page-leaving');
|
||||
window.setTimeout(function() {
|
||||
window.location.href = targetUrl.href;
|
||||
}, transitionMs);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initPageTransitions, { once: true });
|
||||
} else {
|
||||
initPageTransitions();
|
||||
}
|
||||
})();
|
||||
@@ -538,12 +538,15 @@ function initSecretsPage() {
|
||||
state.search = event.target.value || '';
|
||||
renderSecrets();
|
||||
});
|
||||
document.addEventListener('workspace:changed', function () {
|
||||
window.addEventListener('crank:workspacechange', function () {
|
||||
void load();
|
||||
});
|
||||
|
||||
updateKindFields();
|
||||
void load();
|
||||
void (async function bootSecretsPage() {
|
||||
await (window.whenWorkspacesReady ? window.whenWorkspacesReady() : Promise.resolve());
|
||||
await load();
|
||||
}());
|
||||
}
|
||||
|
||||
if (window.CrankDiagnostics && typeof window.CrankDiagnostics.bootstrap === 'function') {
|
||||
|
||||
+30
-5
@@ -1,6 +1,4 @@
|
||||
var WS_LIST = [
|
||||
{ id: 'ws_default', slug: 'default', name: 'Default workspace', role: 'Owner', letter: 'D', color: '#0d9488' }
|
||||
];
|
||||
var WS_LIST = [];
|
||||
|
||||
var workspaceLoadPromise = null;
|
||||
var workspaceLoadFailed = false;
|
||||
@@ -41,8 +39,35 @@ function cacheCurrentWorkspace(workspace) {
|
||||
} catch (_error) {}
|
||||
}
|
||||
|
||||
function storedWorkspaceId() {
|
||||
try {
|
||||
return localStorage.getItem('crank_workspace_id') || '';
|
||||
} catch (_error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function sessionWorkspaceId() {
|
||||
if (!(window.CrankAuth && typeof window.CrankAuth.getCachedSession === 'function')) {
|
||||
return '';
|
||||
}
|
||||
var session = window.CrankAuth.getCachedSession();
|
||||
return session && session.current_workspace_id ? session.current_workspace_id : '';
|
||||
}
|
||||
|
||||
function resolveCurrentWorkspace() {
|
||||
return WS_LIST[0] || null;
|
||||
var preferredId = sessionWorkspaceId() || storedWorkspaceId();
|
||||
if (preferredId) {
|
||||
var preferred = WS_LIST.find(function(workspace) {
|
||||
return workspace.id === preferredId;
|
||||
});
|
||||
if (preferred) {
|
||||
return preferred;
|
||||
}
|
||||
}
|
||||
return WS_LIST.find(function(workspace) {
|
||||
return workspace.id === 'ws_default';
|
||||
}) || WS_LIST[0] || null;
|
||||
}
|
||||
|
||||
function updateWorkspaceHeader(workspace) {
|
||||
@@ -88,7 +113,7 @@ 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[0]];
|
||||
WS_LIST = items;
|
||||
}
|
||||
workspaceLoadFailed = false;
|
||||
} catch (_error) {
|
||||
|
||||
Reference in New Issue
Block a user