Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions frontend/src/lib/pages/Admin.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { onMount, tick } from 'svelte';
import { onMount, tick, untrack } from 'svelte';
import { currentRoute, navigate } from '../router.js';
import Input from '../components/Input.svelte';
import LazyRootView from '../components/LazyRootView.svelte';
Expand Down Expand Up @@ -146,6 +146,17 @@
async function openAdminNavigation() {
adminNavigationOpen = true;
await tick();
// The drawer and the field (transition-all) reveal themselves through
// nested visibility transitions, and a hidden field cannot take focus.
// Only poll where the browser can actually report visibility; otherwise
// fall back to focusing right away instead of burning the whole timeout.
if (typeof searchInput?.checkVisibility === 'function') {
for (let frame = 0; frame < 30; frame++) {
if (!adminNavigationOpen) return;
if (searchInput?.checkVisibility({ visibilityProperty: true })) break;
await new Promise((resolve) => requestAnimationFrame(resolve));
}
}
searchInput?.focus();
}

Expand All @@ -166,9 +177,9 @@
searchInput?.blur();
}
} else if (event.key === 'Enter' && filteredGroups.length > 0 && filteredGroups[0].items.length > 0) {
// Navigate to first item when pressing Enter
const firstItem = filteredGroups[0].items[0];
handleTabClick(firstItem.id);
event.preventDefault();
if (adminNavigationOpen) closeAdminNavigation(true);
handleTabClick(filteredGroups[0].items[0].id);
} else if (event.key === 'ArrowDown') {
event.preventDefault();
// Focus first navigation item
Expand Down Expand Up @@ -280,6 +291,17 @@
// Total button count for validation
const totalButtons = $derived(filteredGroups.reduce((count, group) => count + group.items.length, 0));

// The shell stays mounted across sections (#542), so a new section would
// otherwise open at the previous one's scroll position.
let adminContentEl = $state(null);
$effect(() => {
void adminComponentKey;
void activePluginItem?.id;
untrack(() => {
if (adminContentEl) adminContentEl.scrollTop = 0;
});
});

function switchTab(tab) {
navigate(`/admin/${tab}`);
}
Expand Down Expand Up @@ -323,7 +345,7 @@
<IconSearch size={16} stroke={1.5} class="absolute left-3 top-1/2 transform -translate-y-1/2" style="color: var(--ds-icon-subtle);" aria-hidden="true" />
<Input
id="admin-search"
bind:this={searchInput}
bind:inputRef={searchInput}
bind:value={searchQuery}
onkeydown={handleSearchKeydown}
type="search"
Expand Down Expand Up @@ -457,7 +479,7 @@
{#if activePluginItem}
{@const pluginName = activePluginItem.pluginData?.pluginName || 'unknown'}
{@const iframeSrc = `/api/plugins/${pluginName}/assets/${activePluginItem.pluginData?.component || 'index.html'}`}
<div class="admin-content px-16 py-12 pb-0 flex-1 min-w-0 overflow-y-auto">
<div bind:this={adminContentEl} class="admin-content px-16 py-12 pb-0 flex-1 min-w-0 overflow-y-auto">
<div class="plugin-component-container">
<IframePluginLoader pluginName={activePluginItem.label} src={iframeSrc} />
</div>
Expand All @@ -466,7 +488,7 @@
{#if isNestedComponent}
{@render activeAdminComponent()}
{:else}
<div class="admin-content px-16 py-12 pb-0 flex-1 min-w-0 overflow-y-auto">
<div bind:this={adminContentEl} class="admin-content px-16 py-12 pb-0 flex-1 min-w-0 overflow-y-auto">
<div class="min-w-0 pr-0 pl-0">
{@render activeAdminComponent()}
</div>
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/lib/pages/DelegatedAdmin.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { untrack } from 'svelte';
import { currentRoute, navigate } from '../router.js';
import LinkComponent from '../components/Link.svelte';
import LazyRootView from '../components/LazyRootView.svelte';
Expand All @@ -18,6 +19,16 @@

// Keep the URL and the rendered surface in sync: `/manage` and unknown tabs
// fall back to the first surface the user can actually use.
// The shell stays mounted across sections (#542), so a new section would
// otherwise open at the previous one's scroll position.
let contentEl = $state(null);
$effect(() => {
void activeItem?.id;
untrack(() => {
if (contentEl) contentEl.scrollTop = 0;
});
});

$effect(() => {
if (items.length === 0) return;
if (!activeItem) {
Expand Down Expand Up @@ -82,7 +93,7 @@
</ScrollableSidebar>

<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
<div class="delegated-admin-content min-w-0 flex-1 overflow-y-auto px-6 py-6 lg:px-16 lg:py-12">
<div bind:this={contentEl} class="delegated-admin-content min-w-0 flex-1 overflow-y-auto px-6 py-6 lg:px-16 lg:py-12">
{#if activeItem}
{#key activeItem.id}
<LazyRootView
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/lib/pages/mainAppWorkspaceContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ export function getMainAppWorkspaceRedirect(currentRoute, activeWorkspace) {
return `${base}/${activeWorkspace.default_view || 'board'}`;
}

// These params change the shell's content without remounting its sidebar.
const SHELL_SECTION_PARAMS = {
admin: ['tab', 'categoryId', 'type'],
'delegated-admin': ['tab'],
'team-detail': ['section'],
'workspace-pages': ['pageId'],
};

export function mainAppNavigationIdentity(route, personalWorkspaceId) {
const context = resolveMainAppWorkspaceContext(route, personalWorkspaceId);
const params = route.params ?? {};
const collectionId = context.kind === 'global-collection' ? params.id : params.collectionId;
// Wiki page IDs key the editor, not the workspace shell or sidebar.
const sectionParams = SHELL_SECTION_PARAMS[route.view] ?? [];
const entities = Object.entries(params)
.filter(
([key]) =>
key !== 'id' &&
key !== 'collectionId' &&
!(route.view === 'workspace-pages' && key === 'pageId')
)
.filter(([key]) => key !== 'id' && key !== 'collectionId' && !sectionParams.includes(key))
.sort(([a], [b]) => a.localeCompare(b));
return JSON.stringify([
context.kind,
Expand Down
33 changes: 22 additions & 11 deletions frontend/src/lib/teams/TeamDetail.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { onMount } from 'svelte';
import { untrack } from 'svelte';
import IconPhoneCheck from '@tabler/icons-svelte-runes/icons/phone-check';
import IconUsersGroup from '@tabler/icons-svelte-runes/icons/users-group';
import IconUsers from '@tabler/icons-svelte-runes/icons/users';
Expand All @@ -21,7 +21,8 @@
import OnCallTab from './OnCallTab.svelte';
import ServiceHoursTab from './ServiceHoursTab.svelte';

let { teamId, section = 'overview' } = $props();
let { teamId: routeTeamId, section = 'overview' } = $props();
const teamId = $derived(routeTeamId);

let team = $state(null);
let myRole = $state(null);
Expand All @@ -33,28 +34,33 @@
);
const canEdit = $derived(hasGlobalManage || myRole === 'admin');

async function loadTeam() {
// Responses for a team the user has already left are dropped.
async function loadTeam(id = teamId) {
loading = true;
try {
team = await teams.get(Number(teamId));
const loaded = await teams.get(Number(id));
if (id !== teamId) return;
team = loaded;
error = '';
} catch (err) {
if (id !== teamId) return;
error = err.message || t('teams.failedToLoad');
team = null;
} finally {
loading = false;
if (id === teamId) loading = false;
}
}

async function loadMyRole() {
async function loadMyRole(id = teamId) {
const userId = $authStore.currentUser?.id;
if (!userId) return;
try {
const myTeams = await teams.getTeamsForUser(userId);
const match = (myTeams || []).find((t) => t.id === Number(teamId));
if (id !== teamId) return;
const match = (myTeams || []).find((t) => t.id === Number(id));
myRole = match?.role || null;
} catch (err) {
myRole = null;
if (id === teamId) myRole = null;
}
}

Expand All @@ -80,9 +86,14 @@
activeTab = section;
});

onMount(() => {
loadTeam();
loadMyRole();
// Section changes reuse the team. A different team needs its own role.
$effect(() => {
const id = teamId;
myRole = null;
untrack(() => {
loadTeam(id);
loadMyRole(id);
});
});

function reload() {
Expand Down
Loading