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:
@@ -358,16 +358,62 @@ const profileSecondary = computed(() => {
|
|||||||
return fromSynthetic?.[1] || '';
|
return fromSynthetic?.[1] || '';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ROLE_USERS_KEY_PREFIX = 'mento_role_users:';
|
||||||
|
|
||||||
const roleUsers = ref<OrgUserDto[]>([]);
|
const roleUsers = ref<OrgUserDto[]>([]);
|
||||||
const roleBusy = ref(false);
|
const roleBusy = ref(false);
|
||||||
const roleError = ref('');
|
const roleError = ref('');
|
||||||
const roleUsersQuery = ref('');
|
const roleUsersQuery = ref('');
|
||||||
|
let roleUsersFetch: Promise<void> | null = null;
|
||||||
|
|
||||||
/** سوئیچ نقش فقط برای مدیر/مالک همین محیط (یا وقتی مالک در حال مشاهده است) */
|
/** سوئیچ نقش فقط برای مدیر/مالک همین محیط (یا وقتی مالک در حال مشاهده است) */
|
||||||
const canSwitchRoles = computed(
|
const canSwitchRoles = computed(
|
||||||
() => canManageSettings(auth.user?.role) || canOpenTeamWhileViewing.value,
|
() => 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) {
|
function roleUserLabel(user: OrgUserDto) {
|
||||||
return user.orgRoleName || USER_ROLE_LABELS[user.role] || user.role;
|
return user.orgRoleName || USER_ROLE_LABELS[user.role] || user.role;
|
||||||
}
|
}
|
||||||
@@ -383,6 +429,9 @@ const sortedRoleUsers = computed(() => {
|
|||||||
if (!canSwitchRoles.value) return [];
|
if (!canSwitchRoles.value) return [];
|
||||||
const me = auth.user?.id;
|
const me = auth.user?.id;
|
||||||
return [...roleUsers.value].sort((a, b) => {
|
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 (a.id === me) return -1;
|
||||||
if (b.id === me) return 1;
|
if (b.id === me) return 1;
|
||||||
return roleUserLabel(a).localeCompare(roleUserLabel(b), 'fa');
|
return roleUserLabel(a).localeCompare(roleUserLabel(b), 'fa');
|
||||||
@@ -406,13 +455,25 @@ async function loadRoleUsers() {
|
|||||||
roleUsers.value = [];
|
roleUsers.value = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
if (!roleUsers.value.length) hydrateRoleUsersFromCache();
|
||||||
const { data } = await api.get<OrgUserDto[]>('/users');
|
if (roleUsersFetch) return roleUsersFetch;
|
||||||
// فقط کاربران فعال همین محیط (اسکوپ توکن)
|
|
||||||
roleUsers.value = data.filter((user) => user.isActive !== false);
|
const orgId = auth.user?.organizationId;
|
||||||
} catch {
|
roleUsersFetch = (async () => {
|
||||||
roleUsers.value = [];
|
try {
|
||||||
}
|
const { data } = await api.get<OrgUserDto[]>('/users');
|
||||||
|
// فقط کاربران فعال همین محیط (اسکوپ توکن)
|
||||||
|
const active = data.filter((user) => user.isActive !== false);
|
||||||
|
roleUsers.value = active;
|
||||||
|
writeRoleUsersCache(orgId, active);
|
||||||
|
} catch {
|
||||||
|
if (!roleUsers.value.length) roleUsers.value = [];
|
||||||
|
} finally {
|
||||||
|
roleUsersFetch = null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return roleUsersFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function switchRoleUser(user: OrgUserDto) {
|
async function switchRoleUser(user: OrgUserDto) {
|
||||||
@@ -457,14 +518,25 @@ async function toggleUserMenu() {
|
|||||||
}
|
}
|
||||||
closeSidebarOverlays('user');
|
closeSidebarOverlays('user');
|
||||||
ignoreUserMenuClickUntil = Date.now() + 400;
|
ignoreUserMenuClickUntil = Date.now() + 400;
|
||||||
|
hydrateRoleUsersFromCache();
|
||||||
userMenuOpen.value = true;
|
userMenuOpen.value = true;
|
||||||
await nextTick();
|
await nextTick();
|
||||||
placeUserMenu();
|
placeUserMenu();
|
||||||
await loadRoleUsers();
|
void loadRoleUsers().then(async () => {
|
||||||
await nextTick();
|
if (!userMenuOpen.value) return;
|
||||||
placeUserMenu();
|
await nextTick();
|
||||||
|
placeUserMenu();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => auth.user?.organizationId,
|
||||||
|
() => {
|
||||||
|
roleUsers.value = [];
|
||||||
|
hydrateRoleUsersFromCache();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
function onOrgMenuOpen() {
|
function onOrgMenuOpen() {
|
||||||
closeSidebarOverlays('org');
|
closeSidebarOverlays('org');
|
||||||
}
|
}
|
||||||
@@ -710,11 +782,13 @@ onMounted(() => {
|
|||||||
} catch {
|
} catch {
|
||||||
collapsed.value = false;
|
collapsed.value = false;
|
||||||
}
|
}
|
||||||
|
hydrateRoleUsersFromCache();
|
||||||
syncWorkspaceTab(route);
|
syncWorkspaceTab(route);
|
||||||
void refreshNotifs();
|
void refreshNotifs();
|
||||||
void loadActivityBadge();
|
void loadActivityBadge();
|
||||||
void loadRoutineBadge();
|
void loadRoutineBadge();
|
||||||
void loadChatBadge();
|
void loadChatBadge();
|
||||||
|
if (canSwitchRoles.value) void loadRoleUsers();
|
||||||
pollTimer = setInterval(() => {
|
pollTimer = setInterval(() => {
|
||||||
void refreshNotifs();
|
void refreshNotifs();
|
||||||
void loadActivityBadge();
|
void loadActivityBadge();
|
||||||
@@ -1081,8 +1155,8 @@ onUnmounted(() => {
|
|||||||
:size="28"
|
:size="28"
|
||||||
/>
|
/>
|
||||||
<span class="user-role-copy">
|
<span class="user-role-copy">
|
||||||
<strong>{{ roleUserLabel(user) }}</strong>
|
<strong>{{ user.fullName }}</strong>
|
||||||
<small>{{ user.fullName }}</small>
|
<small>{{ roleUserLabel(user) }}</small>
|
||||||
</span>
|
</span>
|
||||||
<UiIcon
|
<UiIcon
|
||||||
v-if="user.id === auth.user?.id"
|
v-if="user.id === auth.user?.id"
|
||||||
|
|||||||
@@ -2165,13 +2165,20 @@ tbody tr + tr td {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.role-panel {
|
.role-panel {
|
||||||
|
/* تاپبار + تبها + هدر صفحه + پدینگ content (~234px) */
|
||||||
|
--role-panel-chrome: 15rem;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0.75rem;
|
top: 0.75rem;
|
||||||
|
align-self: start;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 220px;
|
width: 220px;
|
||||||
max-width: 220px;
|
max-width: 220px;
|
||||||
min-height: 0;
|
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;
|
padding: 0.85rem 0.75rem 0.95rem;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
@@ -2266,7 +2273,12 @@ tbody tr + tr td {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.panel-head {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.panel-actions {
|
.panel-actions {
|
||||||
|
flex-shrink: 0;
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.55rem;
|
gap: 0.55rem;
|
||||||
@@ -2274,7 +2286,19 @@ tbody tr + tr td {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.panel-body {
|
.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 {
|
.btn {
|
||||||
@@ -2900,6 +2924,7 @@ textarea {
|
|||||||
width: auto;
|
width: auto;
|
||||||
max-width: none;
|
max-width: none;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
height: auto;
|
||||||
max-height: min(78dvh, 640px);
|
max-height: min(78dvh, 640px);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
border-radius: 22px 22px 0 0;
|
border-radius: 22px 22px 0 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user