fix(web): speed up role switcher and constrain the role details panel.

Cache role users in localStorage, put owner first, and keep the team role panel within the viewport with internal scrolling.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-12-01 14:52:50 +03:30
co-authored by Cursor
parent 37b732bae3
commit 5296429e62
2 changed files with 112 additions and 13 deletions
+79 -5
View File
@@ -358,16 +358,62 @@ const profileSecondary = computed(() => {
return fromSynthetic?.[1] || '';
});
const ROLE_USERS_KEY_PREFIX = 'mento_role_users:';
const roleUsers = ref<OrgUserDto[]>([]);
const roleBusy = ref(false);
const roleError = ref('');
const roleUsersQuery = ref('');
let roleUsersFetch: Promise<void> | null = null;
/** سوئیچ نقش فقط برای مدیر/مالک همین محیط (یا وقتی مالک در حال مشاهده است) */
const canSwitchRoles = computed(
() => canManageSettings(auth.user?.role) || canOpenTeamWhileViewing.value,
);
function roleUsersStorageKey(orgId: string) {
return `${ROLE_USERS_KEY_PREFIX}${orgId}`;
}
function isOrgUserDto(value: unknown): value is OrgUserDto {
if (!value || typeof value !== 'object') return false;
const row = value as Partial<OrgUserDto>;
return typeof row.id === 'string' && typeof row.fullName === 'string';
}
function readRoleUsersCache(orgId: string | undefined | null): OrgUserDto[] {
if (!orgId) return [];
try {
const raw = localStorage.getItem(roleUsersStorageKey(orgId));
if (!raw) return [];
const parsed = JSON.parse(raw) as unknown;
if (!Array.isArray(parsed)) return [];
return parsed.filter(isOrgUserDto);
} catch {
return [];
}
}
function writeRoleUsersCache(orgId: string | undefined | null, users: OrgUserDto[]) {
if (!orgId) return;
try {
localStorage.setItem(roleUsersStorageKey(orgId), JSON.stringify(users));
} catch {
/* private mode / quota */
}
}
function hydrateRoleUsersFromCache() {
if (!canSwitchRoles.value) {
roleUsers.value = [];
return;
}
const cached = readRoleUsersCache(auth.user?.organizationId).filter(
(user) => user.isActive !== false,
);
if (cached.length) roleUsers.value = cached;
}
function roleUserLabel(user: OrgUserDto) {
return user.orgRoleName || USER_ROLE_LABELS[user.role] || user.role;
}
@@ -383,6 +429,9 @@ const sortedRoleUsers = computed(() => {
if (!canSwitchRoles.value) return [];
const me = auth.user?.id;
return [...roleUsers.value].sort((a, b) => {
const aOwner = a.role === 'owner' ? 0 : 1;
const bOwner = b.role === 'owner' ? 0 : 1;
if (aOwner !== bOwner) return aOwner - bOwner;
if (a.id === me) return -1;
if (b.id === me) return 1;
return roleUserLabel(a).localeCompare(roleUserLabel(b), 'fa');
@@ -406,13 +455,25 @@ async function loadRoleUsers() {
roleUsers.value = [];
return;
}
if (!roleUsers.value.length) hydrateRoleUsersFromCache();
if (roleUsersFetch) return roleUsersFetch;
const orgId = auth.user?.organizationId;
roleUsersFetch = (async () => {
try {
const { data } = await api.get<OrgUserDto[]>('/users');
// فقط کاربران فعال همین محیط (اسکوپ توکن)
roleUsers.value = data.filter((user) => user.isActive !== false);
const active = data.filter((user) => user.isActive !== false);
roleUsers.value = active;
writeRoleUsersCache(orgId, active);
} catch {
roleUsers.value = [];
if (!roleUsers.value.length) roleUsers.value = [];
} finally {
roleUsersFetch = null;
}
})();
return roleUsersFetch;
}
async function switchRoleUser(user: OrgUserDto) {
@@ -457,14 +518,25 @@ async function toggleUserMenu() {
}
closeSidebarOverlays('user');
ignoreUserMenuClickUntil = Date.now() + 400;
hydrateRoleUsersFromCache();
userMenuOpen.value = true;
await nextTick();
placeUserMenu();
await loadRoleUsers();
void loadRoleUsers().then(async () => {
if (!userMenuOpen.value) return;
await nextTick();
placeUserMenu();
});
}
watch(
() => auth.user?.organizationId,
() => {
roleUsers.value = [];
hydrateRoleUsersFromCache();
},
);
function onOrgMenuOpen() {
closeSidebarOverlays('org');
}
@@ -710,11 +782,13 @@ onMounted(() => {
} catch {
collapsed.value = false;
}
hydrateRoleUsersFromCache();
syncWorkspaceTab(route);
void refreshNotifs();
void loadActivityBadge();
void loadRoutineBadge();
void loadChatBadge();
if (canSwitchRoles.value) void loadRoleUsers();
pollTimer = setInterval(() => {
void refreshNotifs();
void loadActivityBadge();
@@ -1081,8 +1155,8 @@ onUnmounted(() => {
:size="28"
/>
<span class="user-role-copy">
<strong>{{ roleUserLabel(user) }}</strong>
<small>{{ user.fullName }}</small>
<strong>{{ user.fullName }}</strong>
<small>{{ roleUserLabel(user) }}</small>
</span>
<UiIcon
v-if="user.id === auth.user?.id"
+26 -1
View File
@@ -2165,13 +2165,20 @@ tbody tr + tr td {
}
.role-panel {
/* تاپ‌بار + تب‌ها + هدر صفحه + پدینگ content (~234px) */
--role-panel-chrome: 15rem;
position: sticky;
top: 0.75rem;
align-self: start;
display: flex;
flex-direction: column;
width: 220px;
max-width: 220px;
min-height: 0;
/* height صریح لازم است؛ فقط max-height با flex-basis صفر بدنه را می‌ترکاند */
height: calc(100dvh - var(--role-panel-chrome));
max-height: calc(100dvh - var(--role-panel-chrome));
overflow: hidden;
padding: 0.85rem 0.75rem 0.95rem;
box-sizing: border-box;
}
@@ -2266,7 +2273,12 @@ tbody tr + tr td {
cursor: pointer;
}
.panel-head {
flex-shrink: 0;
}
.panel-actions {
flex-shrink: 0;
margin-top: auto;
display: grid;
gap: 0.55rem;
@@ -2274,7 +2286,19 @@ tbody tr + tr td {
}
.panel-body {
flex: 1;
flex: 1 1 0;
min-height: 0;
overflow-x: hidden;
overflow-y: auto;
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
}
.panel-body::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
.btn {
@@ -2900,6 +2924,7 @@ textarea {
width: auto;
max-width: none;
min-height: 0;
height: auto;
max-height: min(78dvh, 640px);
overflow: auto;
border-radius: 22px 22px 0 0;