All files / src/components FlowsSidebar.vue

98.64% Statements 73/74
86.95% Branches 40/46
96.15% Functions 25/26
98.46% Lines 64/65

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397  36x           4x     34x           4x       29x             26x             26x                     26x                 4x               26x   4x         4x       26x                   26x                                             26x 26x 26x 26x 26x 26x 26x   26x 26x 26x 4x     27x 26x 26x 26x 26x 26x   26x 30x   29x   29x 29x     29x     26x 2x 1x       26x 2x 1x       26x 29x   28x 28x 21x   28x     26x   26x 1x                 26x 26x   26x     26x         26x 34x   3x 3x           26x 27x   1x 1x                                                                                                                                                                                                                                                                                                                                                                                                            
<template>
  <div class="sidebar-wrapper">
    <button v-if="showLeftArrow" class="scroll-arrow scroll-arrow-left" @click="scrollLeft">
      <font-awesome-icon icon="fa-solid fa-chevron-left" />
    </button>
 
    <div ref="sidebarRef" class="sidebar" @scroll="handleScroll">
      <nav class="nav flex-column">
        <!-- Dashboard -->
        <router-link to="/" class="nav-link" :class="{ active: $route.path === '/' }">
          <font-awesome-icon icon="fa-solid fa-chart-line" class="me-2" />
          {{ t('navigation.dashboard') }}
        </router-link>
 
        <!-- Separator -->
        <div class="nav-separator" />
        <div class="nav-section-title">{{ t('navigation.flowsManagement') }}</div>
 
        <!-- Flows -->
        <router-link to="/flows" class="nav-link" :class="{ active: $route.path === '/flows' }">
          <font-awesome-icon icon="fa-solid fa-sitemap" class="me-2" />
          {{ t('navigation.flows') }}
          <span v-if="flowsCount > 0" class="badge bg-secondary ms-auto">{{ flowsCount }}</span>
        </router-link>
 
        <!-- Members -->
        <router-link to="/members" class="nav-link" :class="{ active: $route.path === '/members' }">
          <font-awesome-icon icon="fa-solid fa-users" class="me-2" />
          {{ t('navigation.members') }}
          <span v-if="membersCount > 0" class="badge bg-secondary ms-auto">{{ membersCount }}</span>
        </router-link>
 
        <!-- Roles -->
        <router-link to="/roles" class="nav-link" :class="{ active: $route.path === '/roles' }">
          <font-awesome-icon icon="fa-solid fa-shield-halved" class="me-2" />
          {{ t('navigation.roles') }}
          <span v-if="rolesCount > 0" class="badge bg-secondary ms-auto">{{ rolesCount }}</span>
        </router-link>
 
        <!-- Invitations -->
        <router-link
          to="/invitations"
          class="nav-link"
          :class="{ active: $route.path === '/invitations' }"
        >
          <font-awesome-icon icon="fa-solid fa-paper-plane" class="me-2" />
          {{ t('navigation.invitations') }}
          <span v-if="pendingInvitationsCount > 0" class="badge bg-danger ms-auto">{{
            pendingInvitationsCount
          }}</span>
        </router-link>
 
        <!-- Separator -->
        <div class="nav-separator" />
        <div class="nav-section-title">{{ t('navigation.data') }}</div>
 
        <!-- Entities -->
        <router-link
          to="/entities"
          class="nav-link"
          :class="{ active: $route.path === '/entities' }"
        >
          <font-awesome-icon icon="fa-solid fa-cube" class="me-2" />
          {{ t('navigation.entities') }}
          <span class="badge bg-secondary ms-auto">{{ entitiesCount }}</span>
        </router-link>
 
        <!-- Separator -->
        <div class="nav-separator" />
        <div class="nav-section-title">{{ t('navigation.account') }}</div>
 
        <!-- Profile -->
        <router-link to="/profile" class="nav-link" :class="{ active: $route.path === '/profile' }">
          <font-awesome-icon icon="fa-solid fa-user-circle" class="me-2" />
          {{ t('navigation.profile') }}
        </router-link>
 
        <!-- API Keys -->
        <router-link
          to="/api-keys"
          class="nav-link"
          :class="{ active: $route.path === '/api-keys' }"
        >
          <font-awesome-icon icon="fa-solid fa-key" class="me-2" />
          {{ t('navigation.apiKeys') }}
          <span v-if="apiKeysCount > 0" class="badge bg-secondary ms-auto">{{ apiKeysCount }}</span>
        </router-link>
      </nav>
    </div>
 
    <button v-if="showRightArrow" class="scroll-arrow scroll-arrow-right" @click="scrollRight">
      <font-awesome-icon icon="fa-solid fa-chevron-right" />
    </button>
  </div>
</template>
 
<script setup lang="ts">
import { ref, onMounted, onUnmounted, nextTick, watch, computed } from 'vue'
import { useRoute } from 'vue-router'
import { useRolesStore } from '@/stores/roles'
import { useEntitiesStore } from '@/stores/entities'
import { useTenantsStore } from '@/stores/tenants'
import { useAuthStore } from '@/stores/auth'
import { useApiKeysStore } from '@/stores/apiKeys'
import { useUILanguage } from '@/composables/useUILanguage'
 
const route = useRoute()
const rolesStore = useRolesStore()
const entitiesStore = useEntitiesStore()
const tenantsStore = useTenantsStore()
const authStore = useAuthStore()
const apiKeysStore = useApiKeysStore()
const { t } = useUILanguage()
 
const sidebarRef = ref<HTMLElement | null>(null)
const showLeftArrow = ref(false)
const showRightArrow = ref(false)
const SCROLL_POSITION_KEY = 'sidebar-scroll-position'
 
// Computed properties for badges
const pendingInvitationsCount = computed(() => rolesStore.invitations?.length || 0)
const entitiesCount = computed(() => entitiesStore.entities?.length || 0)
const rolesCount = computed(() => rolesStore.roles?.length || 0)
const membersCount = computed(() => tenantsStore.currentTenantMembers?.length || 0)
const flowsCount = computed(() => tenantsStore.myTenants?.length || 0)
const apiKeysCount = computed(() => apiKeysStore.apiKeys?.length || 0)
 
const handleScroll = () => {
  if (!sidebarRef.value) return
 
  const { scrollLeft, scrollWidth, clientWidth } = sidebarRef.value
 
  showLeftArrow.value = scrollLeft > 5
  showRightArrow.value = scrollLeft < scrollWidth - clientWidth - 5
 
  // Save scroll position
  sessionStorage.setItem(SCROLL_POSITION_KEY, scrollLeft.toString())
}
 
const scrollLeft = () => {
  if (sidebarRef.value) {
    sidebarRef.value.scrollBy({ left: -150, behavior: 'smooth' })
  }
}
 
const scrollRight = () => {
  if (sidebarRef.value) {
    sidebarRef.value.scrollBy({ left: 150, behavior: 'smooth' })
  }
}
 
const restoreScrollPosition = () => {
  if (!sidebarRef.value) return
 
  const savedPosition = sessionStorage.getItem(SCROLL_POSITION_KEY)
  if (savedPosition) {
    sidebarRef.value.scrollLeft = parseInt(savedPosition, 10)
  }
  handleScroll()
}
 
onMounted(async () => {
  // Load data for badges (ignore errors for resources user cannot access)
  if (authStore.currentTenant) {
    await Promise.allSettled([
      entitiesStore.fetchEntities(),
      rolesStore.fetchRoles(authStore.currentTenant),
      rolesStore.fetchInvitations(),
      tenantsStore.fetchMyTenants(),
      tenantsStore.fetchMembers(authStore.currentTenant)
    ])
  }
 
  nextTick(() => {
    restoreScrollPosition()
  })
  window.addEventListener('resize', handleScroll)
})
 
onUnmounted(() => {
  window.removeEventListener('resize', handleScroll)
})
 
// Restore scroll position on route change
watch(
  () => route.path,
  () => {
    nextTick(() => {
      restoreScrollPosition()
    })
  }
)
 
// Reload badges when tenant changes
watch(
  () => authStore.currentTenant,
  async (newTenant) => {
    Eif (newTenant) {
      await Promise.allSettled([
        entitiesStore.fetchEntities(),
        rolesStore.fetchRoles(newTenant),
        rolesStore.fetchInvitations(),
        tenantsStore.fetchMembers(newTenant)
      ])
    }
  }
)
</script>
 
<style scoped>
.sidebar-wrapper {
  position: fixed;
  top: 74px;
  left: 0;
  bottom: 0;
  width: 125px;
  z-index: 999;
}
 
.sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  background: linear-gradient(180deg, #bee476 0%, #689909 100%);
}
 
.nav-link {
  color: #555;
  padding: 0.75rem 1rem;
  transition: all 0.3s;
  font-size: 0.85rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 500;
  position: relative;
}
 
.nav-link:hover {
  color: #333;
  background: rgba(255, 255, 255, 0.3);
}
 
.nav-link.active {
  color: #333;
  background: rgba(255, 255, 255, 0.4);
  font-weight: 600;
}
 
.nav-link svg {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}
 
.nav-separator {
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
  margin: 0.5rem 0;
}
 
.nav-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 1rem 0.25rem;
  margin-bottom: 0.25rem;
}
 
.nav-link .badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.65rem;
  padding: 0.25em 0.5em;
  border-radius: 10px;
  pointer-events: none;
}
 
.scroll-arrow {
  display: none;
}
 
/* Mobile: Bottom navigation */
@media (max-width: 767px) {
  .sidebar-wrapper {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
  }
 
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    background: linear-gradient(90deg, #bee476 0%, #689909 100%);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
 
  .nav {
    display: inline-flex;
    flex-direction: row !important;
    align-items: center;
    height: 100%;
    width: max-content;
  }
 
  .nav-link {
    flex: 0 0 auto;
    width: 90px;
    font-size: 0.7rem;
    margin: 0;
    white-space: nowrap;
  }
 
  .nav-link svg {
    font-size: 1.25rem;
    margin-bottom: 0.125rem;
  }
 
  .nav-separator,
  .nav-section-title {
    display: none;
  }
 
  .nav-link .badge {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    font-size: 0.6rem;
    padding: 0.15em 0.35em;
  }
 
  /* Hide scrollbar but keep functionality */
  .sidebar::-webkit-scrollbar {
    display: none;
  }
 
  .sidebar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
 
  .scroll-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 18px;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.2s;
    padding: 0;
  }
 
  .scroll-arrow:hover {
    transform: scale(1.15);
  }
 
  .scroll-arrow:active {
    transform: scale(0.9);
  }
 
  .scroll-arrow-left {
    left: 6px;
  }
 
  .scroll-arrow-right {
    right: 6px;
  }
 
  .scroll-arrow svg {
    color: #333;
    font-size: 1.1rem;
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.5));
  }
}
</style>