Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

move profiles into it's own component

Blue Mouse29c4eecdc832
diff --git a/web/app/pages/Project/Profiles/View/ProfilesView.tsx b/web/app/pages/Project/Profiles/View/ProfilesView.tsx
new file mode 100644
index 000000000..14fb6026a
--- /dev/null
+++ b/web/app/pages/Project/Profiles/View/ProfilesView.tsx
@@ -0,0 +1,391 @@
+import _isEmpty from 'lodash/isEmpty'
+import { ChevronLeftIcon, DownloadIcon } from 'lucide-react'
+import { useState, useEffect, useMemo, useRef } from 'react'
+import { useTranslation } from 'react-i18next'
+import { Link, useSearchParams } from 'react-router'
+
+import { getProfiles, getProfile, getProfileSessions } from '~/api'
+import { Profile, ProfileDetails, Session } from '~/lib/models/Project'
+import { useViewProjectContext } from '~/pages/Project/View/ViewProject'
+import { getFormatDate } from '~/pages/Project/View/ViewProject.helpers'
+import NoEvents from '~/pages/Project/View/components/NoEvents'
+import { RefreshStatsButton } from '~/pages/Project/View/components/RefreshStatsButton'
+import { UserDetails } from '~/pages/Project/View/components/UserDetails'
+import { Users, UsersFilter } from '~/pages/Project/View/components/Users'
+import { useCurrentProject, useProjectPassword } from '~/providers/CurrentProjectProvider'
+import Loader from '~/ui/Loader'
+import cx from 'clsx'
+
+const SESSIONS_TAKE = 30
+
+interface ProfilesViewProps {
+ chartType: string
+}
+
+const ProfilesView = ({ chartType }: ProfilesViewProps) => {
+ const { id, project } = useCurrentProject()
+ const projectPassword = useProjectPassword(id)
+ const { timezone, period, dateRange, filters, timeFormat, profilesRefreshTrigger } = useViewProjectContext()
+ const { t } = useTranslation('common')
+ const [searchParams] = useSearchParams()
+
+ // Profiles state
+ const [profilesSkip, setProfilesSkip] = useState(0)
+ const [canLoadMoreProfiles, setCanLoadMoreProfiles] = useState(false)
+ const [profiles, setProfiles] = useState<Profile[]>([])
+ const [profilesLoading, setProfilesLoading] = useState<boolean | null>(null)
+ const [activeProfile, setActiveProfile] = useState<ProfileDetails | null>(null)
+ const [profileLoading, setProfileLoading] = useState(false)
+ const [profileSessions, setProfileSessions] = useState<Session[]>([])
+ const [profileSessionsLoading, setProfileSessionsLoading] = useState<boolean | null>(null)
+ const [profileSessionsSkip, setProfileSessionsSkip] = useState(0)
+ const [canLoadMoreProfileSessions, setCanLoadMoreProfileSessions] = useState(false)
+ const [profileTypeFilter, setProfileTypeFilter] = useState<'all' | 'anonymous' | 'identified'>('all')
+
+ const activeProfileId = useMemo(() => {
+ return searchParams.get('profileId')
+ }, [searchParams])
+
+ const prevActiveProfileIdRef = useRef<string | null>(activeProfileId)
+ const profilesRequestIdRef = useRef(0)
+ const skipNextProfilesAutoLoadRef = useRef(false)
+ const isMountedRef = useRef(true)
+
+ // Cleanup on unmount
+ useEffect(() => {
+ isMountedRef.current = true
+ return () => {
+ isMountedRef.current = false
+ }
+ }, [])
+
+ const loadProfiles = async (forcedSkip?: number, override?: boolean) => {
+ if (profilesLoading) {
+ return
+ }
+
+ const requestId = profilesRequestIdRef.current
+ setProfilesLoading(true)
+
+ try {
+ const skip = typeof forcedSkip === 'number' ? forcedSkip : profilesSkip
+ let dataProfiles: { profiles: Profile[] }
+ let from
+ let to
+
+ if (dateRange) {
+ from = getFormatDate(dateRange[0])
+ to = getFormatDate(dateRange[1])
+ }
+
+ if (period === 'custom' && dateRange) {
+ dataProfiles = await getProfiles(
+ id,
+ '',
+ filters,
+ from,
+ to,
+ SESSIONS_TAKE,
+ skip,
+ timezone,
+ profileTypeFilter,
+ projectPassword,
+ )
+ } else {
+ dataProfiles = await getProfiles(
+ id,
+ period,
+ filters,
+ '',
+ '',
+ SESSIONS_TAKE,
+ skip,
+ timezone,
+ profileTypeFilter,
+ projectPassword,
+ )
+ }
+
+ if (requestId === profilesRequestIdRef.current && isMountedRef.current) {
+ if (override) {
+ setProfiles(dataProfiles?.profiles || [])
+ } else {
+ setProfiles((prev) => [...prev, ...(dataProfiles?.profiles || [])])
+ }
+ setProfilesSkip((prev) => {
+ if (typeof forcedSkip === 'number') {
+ return SESSIONS_TAKE + forcedSkip
+ }
+ return SESSIONS_TAKE + prev
+ })
+
+ if (dataProfiles?.profiles?.length < SESSIONS_TAKE) {
+ setCanLoadMoreProfiles(false)
+ } else {
+ setCanLoadMoreProfiles(true)
+ }
+ }
+ } catch (reason) {
+ console.error('[ERROR](loadProfiles) Loading profiles data failed:', reason)
+ } finally {
+ if (requestId === profilesRequestIdRef.current && isMountedRef.current) {
+ setProfilesLoading(false)
+ }
+ }
+ }
+
+ const loadProfile = async (profileId: string) => {
+ setProfileLoading(true)
+ setProfileSessions([])
+ setProfileSessionsSkip(0)
+ setCanLoadMoreProfileSessions(false)
+
+ try {
+ let from
+ let to
+
+ if (dateRange) {
+ from = getFormatDate(dateRange[0])
+ to = getFormatDate(dateRange[1])
+ }
+
+ const data = await getProfile(
+ id,
+ profileId,
+ period === 'custom' ? '' : period,
+ from || '',
+ to || '',
+ timezone,
+ projectPassword,
+ )
+
+ if (isMountedRef.current) {
+ setActiveProfile(data)
+ // Load initial sessions for the profile
+ loadProfileSessionsData(profileId, 0)
+ }
+ } catch (reason) {
+ console.error('[ERROR](loadProfile) Loading profile data failed:', reason)
+ if (isMountedRef.current) {
+ setActiveProfile(null)
+ }
+ } finally {
+ if (isMountedRef.current) {
+ setProfileLoading(false)
+ }
+ }
+ }
+
+ const loadProfileSessionsData = async (profileId: string, forcedSkip?: number) => {
+ if (profileSessionsLoading) {
+ return
+ }
+
+ setProfileSessionsLoading(true)
+
+ try {
+ const skip = typeof forcedSkip === 'number' ? forcedSkip : profileSessionsSkip
+ let dataSessions: { sessions: Session[] }
+ let from
+ let to
+
+ if (dateRange) {
+ from = getFormatDate(dateRange[0])
+ to = getFormatDate(dateRange[1])
+ }
+
+ if (period === 'custom' && dateRange) {
+ dataSessions = await getProfileSessions(
+ id,
+ profileId,
+ '',
+ filters,
+ from,
+ to,
+ SESSIONS_TAKE,
+ skip,
+ timezone,
+ projectPassword,
+ )
+ } else {
+ dataSessions = await getProfileSessions(
+ id,
+ profileId,
+ period,
+ filters,
+ '',
+ '',
+ SESSIONS_TAKE,
+ skip,
+ timezone,
+ projectPassword,
+ )
+ }
+
+ if (isMountedRef.current) {
+ setProfileSessions((prev) => [...prev, ...(dataSessions?.sessions || [])])
+ setProfileSessionsSkip((prev) => {
+ if (typeof forcedSkip === 'number') {
+ return SESSIONS_TAKE + forcedSkip
+ }
+ return SESSIONS_TAKE + prev
+ })
+
+ if (dataSessions?.sessions?.length < SESSIONS_TAKE) {
+ setCanLoadMoreProfileSessions(false)
+ } else {
+ setCanLoadMoreProfileSessions(true)
+ }
+ }
+ } catch (reason) {
+ console.error('[ERROR](loadProfileSessions) Loading profile sessions failed:', reason)
+ } finally {
+ if (isMountedRef.current) {
+ setProfileSessionsLoading(false)
+ }
+ }
+ }
+
+ // Load profiles list when component mounts or dependencies change
+ useEffect(() => {
+ if (!project || activeProfileId) {
+ return
+ }
+
+ if (skipNextProfilesAutoLoadRef.current) {
+ skipNextProfilesAutoLoadRef.current = false
+ return
+ }
+
+ // Reset pagination and load the first page whenever the query context changes
+ setProfilesSkip(0)
+ loadProfiles(0, true)
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [dateRange, filters, id, period, projectPassword, timezone, project, activeProfileId, profileTypeFilter])
+
+ // Load single profile when profileId is set
+ useEffect(() => {
+ if (!activeProfileId || !project) {
+ return
+ }
+
+ loadProfile(activeProfileId)
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [activeProfileId, project])
+
+ // Reset profiles when navigating away from profile detail
+ useEffect(() => {
+ const prevProfileId = prevActiveProfileIdRef.current
+ prevActiveProfileIdRef.current = activeProfileId
+
+ if (prevProfileId && !activeProfileId) {
+ // We just closed a profile detail, reset to first page
+ setProfilesSkip(0)
+ skipNextProfilesAutoLoadRef.current = true
+ loadProfiles(0, true)
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [activeProfileId])
+
+ // Handle refresh trigger from parent
+ useEffect(() => {
+ if (profilesRefreshTrigger > 0) {
+ if (activeProfileId) {
+ loadProfile(activeProfileId)
+ } else {
+ setProfilesSkip(0)
+ loadProfiles(0, true)
+ }
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [profilesRefreshTrigger])
+
+ // Handle refresh - exposed via ref or can be called from parent
+ const handleRefresh = async () => {
+ if (activeProfileId) {
+ await loadProfile(activeProfileId)
+ return
+ }
+
+ setProfilesSkip(0)
+ loadProfiles(0, true)
+ }
+
+ // Profile detail view
+ if (activeProfileId) {
+ return (
+ <>
+ <div className='mx-auto mt-2 mb-4 flex max-w-max items-center space-x-4 lg:mx-0'>
+ <Link
+ to={{
+ search: (() => {
+ const params = new URLSearchParams(searchParams)
+ params.delete('profileId')
+ return params.toString()
+ })(),
+ }}
+ className='flex items-center text-sm text-gray-900 underline decoration-dashed hover:decoration-solid dark:text-gray-100'
+ >
+ <ChevronLeftIcon className='mr-1 size-3' />
+ {t('project.backToUsers')}
+ </Link>
+ <RefreshStatsButton onRefresh={() => loadProfile(activeProfileId)} />
+ </div>
+ {profileLoading ? (
+ <Loader />
+ ) : (
+ <UserDetails
+ details={activeProfile}
+ sessions={profileSessions}
+ sessionsLoading={profileSessionsLoading}
+ timeFormat={timeFormat}
+ chartType={chartType}
+ onLoadMoreSessions={() => {
+ if (activeProfileId) {
+ loadProfileSessionsData(activeProfileId)
+ }
+ }}
+ canLoadMoreSessions={canLoadMoreProfileSessions}
+ />
+ )}
+ </>
+ )
+ }
+
+ // Profiles list view
+ return (
+ <>
+ <UsersFilter
+ profileType={profileTypeFilter}
+ onProfileTypeChange={(type) => {
+ setProfileTypeFilter(type)
+ setProfilesSkip(0)
+ }}
+ />
+ {(profilesLoading === null || profilesLoading) && _isEmpty(profiles) ? <Loader /> : null}
+ {typeof profilesLoading === 'boolean' && !profilesLoading && _isEmpty(profiles) ? (
+ <NoEvents filters={filters} />
+ ) : null}
+ <Users profiles={profiles} timeFormat={timeFormat} />
+ {canLoadMoreProfiles ? (
+ <button
+ type='button'
+ title={t('project.loadMore')}
+ onClick={() => loadProfiles()}
+ className={cx(
+ 'relative mx-auto mt-2 flex items-center rounded-md border border-transparent p-2 text-sm font-medium text-gray-700 hover:border-gray-300 hover:bg-white focus:z-10 focus:ring-1 focus:ring-indigo-500 focus:outline-hidden dark:bg-slate-900 dark:text-gray-50 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 focus:dark:ring-gray-200',
+ {
+ 'cursor-not-allowed opacity-50': profilesLoading || profilesLoading === null,
+ hidden: profilesLoading && _isEmpty(profiles),
+ },
+ )}
+ >
+ <DownloadIcon className='mr-2 h-5 w-5' strokeWidth={1.5} />
+ {t('project.loadMore')}
+ </button>
+ ) : null}
+ </>
+ )
+}
+
+export default ProfilesView
diff --git a/web/app/pages/Project/Profiles/View/index.tsx b/web/app/pages/Project/Profiles/View/index.tsx
new file mode 100644
index 000000000..d0c1ea805
--- /dev/null
+++ b/web/app/pages/Project/Profiles/View/index.tsx
@@ -0,0 +1,3 @@
+import ProfilesView from './ProfilesView'
+
+export default ProfilesView
diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsx
index faadec3bc..0b3dcc6ac 100644
--- a/web/app/pages/Project/View/ViewProject.tsx
+++ b/web/app/pages/Project/View/ViewProject.tsx
@@ -13,7 +13,6 @@ import _uniqBy from 'lodash/uniqBy'
import {
MoonIcon,
SunIcon,
- ChevronLeftIcon,
BugIcon,
GaugeIcon,
UsersIcon,
@@ -21,7 +20,6 @@ import {
BellRingIcon,
ChartNoAxesColumnIcon,
FilterIcon,
- DownloadIcon,
SettingsIcon,
KeyboardIcon,
TargetIcon,
@@ -43,9 +41,6 @@ import {
createAnnotation,
updateAnnotation,
deleteAnnotation,
- getProfiles,
- getProfile,
- getProfileSessions,
} from '~/api'
import EventsRunningOutBanner from '~/components/EventsRunningOutBanner'
import Footer from '~/components/Footer'
@@ -78,7 +73,7 @@ import {
languages,
languageFlag,
} from '~/lib/constants'
-import { Session, Annotation, Profile, ProfileDetails } from '~/lib/models/Project'
+import { Annotation } from '~/lib/models/Project'
import AnnotationModal from '~/modals/AnnotationModal'
import ViewProjectHotkeys from '~/modals/ViewProjectHotkeys'
import { useAuth } from '~/providers/AuthProvider'
@@ -100,6 +95,7 @@ import FeatureFlagsView from '../FeatureFlags/View'
import FunnelsView from '../Funnels/View'
import GoalsView from '../Goals/View'
import PerformanceView from '../Performance/View/PerformanceView'
+import ProfilesView from '../Profiles/View'
import SessionsView from '../Sessions/View/SessionsView'
import TrafficView from '../Traffic/View/TrafficView'
@@ -110,13 +106,9 @@ const CaptchaView = lazy(() => import('./components/CaptchaView'))
import DashboardHeader from './components/DashboardHeader'
// Keywords list now reuses shared Panel UI; dedicated component removed from render
import LockedDashboard from './components/LockedDashboard'
-import NoEvents from './components/NoEvents'
import ProjectSidebar from './components/ProjectSidebar'
-import { RefreshStatsButton } from './components/RefreshStatsButton'
import SearchFilters from './components/SearchFilters'
import TrafficHeaderActions from './components/TrafficHeaderActions'
-import { UserDetails } from './components/UserDetails'
-import { Users, UsersFilter } from './components/Users'
import WaitingForAnEvent from './components/WaitingForAnEvent'
import {
Customs,
@@ -140,8 +132,6 @@ import {
SHORTCUTS_TIMEBUCKETS_LISTENERS,
} from './ViewProject.helpers'
-const SESSIONS_TAKE = 30
-
/**
* Pixel distance threshold for snapping to nearby annotations when clicking on the chart.
* If a click is within this many pixels of an annotation line, that annotation will be selected.
@@ -316,6 +306,7 @@ interface ViewProjectContextType {
performanceRefreshTrigger: number
trafficRefreshTrigger: number
funnelsRefreshTrigger: number
+ profilesRefreshTrigger: number
// Functions
updatePeriod: (newPeriod: { period: Period; label?: string }) => void
@@ -346,6 +337,7 @@ const defaultViewProjectContext: ViewProjectContextType = {
performanceRefreshTrigger: 0,
trafficRefreshTrigger: 0,
funnelsRefreshTrigger: 0,
+ profilesRefreshTrigger: 0,
updatePeriod: () => {},
updateTimebucket: (_newTimebucket) => {},
refCalendar: { current: null } as any,
@@ -418,6 +410,7 @@ const ViewProjectContent = () => {
const [performanceRefreshTrigger, setPerformanceRefreshTrigger] = useState(0)
const [trafficRefreshTrigger, setTrafficRefreshTrigger] = useState(0)
const [funnelsRefreshTrigger, setFunnelsRefreshTrigger] = useState(0)
+ const [profilesRefreshTrigger, setProfilesRefreshTrigger] = useState(0)
const [activeChartMetrics, _setActiveChartMetrics] = useState<Record<keyof typeof CHART_METRICS_MAPPING, boolean>>({
[CHART_METRICS_MAPPING.unique]: true,
[CHART_METRICS_MAPPING.views]: false,
@@ -537,25 +530,6 @@ const ViewProjectContent = () => {
const [isHotkeysHelpOpened, setIsHotkeysHelpOpened] = useState(false)
- // profiles / users
- const [profilesSkip, setProfilesSkip] = useState(0)
- const [canLoadMoreProfiles, setCanLoadMoreProfiles] = useState(false)
- const [profiles, setProfiles] = useState<Profile[]>([])
- const [profilesLoading, setProfilesLoading] = useState<boolean | null>(null)
- const [activeProfile, setActiveProfile] = useState<ProfileDetails | null>(null)
- const [profileLoading, setProfileLoading] = useState(false)
- const [profileSessions, setProfileSessions] = useState<Session[]>([])
- const [profileSessionsLoading, setProfileSessionsLoading] = useState<boolean | null>(null)
- const [profileSessionsSkip, setProfileSessionsSkip] = useState(0)
- const [canLoadMoreProfileSessions, setCanLoadMoreProfileSessions] = useState(false)
- const [profileTypeFilter, setProfileTypeFilter] = useState<'all' | 'anonymous' | 'identified'>('all')
- const activeProfileId = useMemo(() => {
- return searchParams.get('profileId')
- }, [searchParams])
- const prevActiveProfileIdRef = useRef<string | null>(activeProfileId)
- const profilesRequestIdRef = useRef(0)
- const skipNextProfilesAutoLoadRef = useRef(false)
-
// Check if we're viewing a specific session detail
const activePSID = useMemo(() => {
return searchParams.get('psid')
@@ -976,182 +950,6 @@ const ViewProjectContent = () => {
setActivePeriodCompare(periodPairsCompare[0].period)
}
- const loadProfiles = async (forcedSkip?: number, override?: boolean) => {
- if (profilesLoading) {
- return
- }
-
- const requestId = profilesRequestIdRef.current
- setProfilesLoading(true)
-
- try {
- const skip = typeof forcedSkip === 'number' ? forcedSkip : profilesSkip
- let dataProfiles: { profiles: Profile[] }
- let from
- let to
-
- if (dateRange) {
- from = getFormatDate(dateRange[0])
- to = getFormatDate(dateRange[1])
- }
-
- if (period === 'custom' && dateRange) {
- dataProfiles = await getProfiles(
- id,
- '',
- filters,
- from,
- to,
- SESSIONS_TAKE,
- skip,
- timezone,
- profileTypeFilter,
- projectPassword,
- )
- } else {
- dataProfiles = await getProfiles(
- id,
- period,
- filters,
- '',
- '',
- SESSIONS_TAKE,
- skip,
- timezone,
- profileTypeFilter,
- projectPassword,
- )
- }
-
- if (requestId === profilesRequestIdRef.current) {
- if (override) {
- setProfiles(dataProfiles?.profiles || [])
- } else {
- setProfiles((prev) => [...prev, ...(dataProfiles?.profiles || [])])
- }
- setProfilesSkip((prev) => {
- if (typeof forcedSkip === 'number') {
- return SESSIONS_TAKE + forcedSkip
- }
- return SESSIONS_TAKE + prev
- })
-
- if (dataProfiles?.profiles?.length < SESSIONS_TAKE) {
- setCanLoadMoreProfiles(false)
- } else {
- setCanLoadMoreProfiles(true)
- }
- }
- } catch (reason) {
- console.error('[ERROR](loadProfiles) Loading profiles data failed:', reason)
- } finally {
- if (requestId === profilesRequestIdRef.current) {
- setProfilesLoading(false)
- }
- }
- }
-
- const loadProfile = async (profileId: string) => {
- setProfileLoading(true)
- setProfileSessions([])
- setProfileSessionsSkip(0)
- setCanLoadMoreProfileSessions(false)
-
- try {
- let from
- let to
-
- if (dateRange) {
- from = getFormatDate(dateRange[0])
- to = getFormatDate(dateRange[1])
- }
-
- const data = await getProfile(
- id,
- profileId,
- period === 'custom' ? '' : period,
- from || '',
- to || '',
- timezone,
- projectPassword,
- )
- setActiveProfile(data)
- // Load initial sessions for the profile
- loadProfileSessionsData(profileId, 0)
- } catch (reason) {
- console.error('[ERROR](loadProfile) Loading profile data failed:', reason)
- setActiveProfile(null)
- } finally {
- setProfileLoading(false)
- }
- }
-
- const loadProfileSessionsData = async (profileId: string, forcedSkip?: number) => {
- if (profileSessionsLoading) {
- return
- }
-
- setProfileSessionsLoading(true)
-
- try {
- const skip = typeof forcedSkip === 'number' ? forcedSkip : profileSessionsSkip
- let dataSessions: { sessions: Session[] }
- let from
- let to
-
- if (dateRange) {
- from = getFormatDate(dateRange[0])
- to = getFormatDate(dateRange[1])
- }
-
- if (period === 'custom' && dateRange) {
- dataSessions = await getProfileSessions(
- id,
- profileId,
- '',
- filters,
- from,
- to,
- SESSIONS_TAKE,
- skip,
- timezone,
- projectPassword,
- )
- } else {
- dataSessions = await getProfileSessions(
- id,
- profileId,
- period,
- filters,
- '',
- '',
- SESSIONS_TAKE,
- skip,
- timezone,
- projectPassword,
- )
- }
-
- setProfileSessions((prev) => [...prev, ...(dataSessions?.sessions || [])])
- setProfileSessionsSkip((prev) => {
- if (typeof forcedSkip === 'number') {
- return SESSIONS_TAKE + forcedSkip
- }
- return SESSIONS_TAKE + prev
- })
-
- if (dataSessions?.sessions?.length < SESSIONS_TAKE) {
- setCanLoadMoreProfileSessions(false)
- } else {
- setCanLoadMoreProfileSessions(true)
- }
- } catch (reason) {
- console.error('[ERROR](loadProfileSessions) Loading profile sessions failed:', reason)
- } finally {
- setProfileSessionsLoading(false)
- }
- }
-
const onCustomMetric = (metrics: ProjectViewCustomEvent[]) => {
if (activeTab !== PROJECT_TABS.traffic) {
return
@@ -1201,13 +999,7 @@ const ViewProjectContent = () => {
}
if (activeTab === PROJECT_TABS.profiles) {
- if (activeProfileId) {
- await loadProfile(activeProfileId)
- return
- }
-
- setProfilesSkip(0)
- loadProfiles(0, true)
+ setProfilesRefreshTrigger((prev) => prev + 1)
return
}
@@ -1242,8 +1034,7 @@ const ViewProjectContent = () => {
}
}
},
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [authLoading, dataLoading, activeTab, activeProfileId],
+ [authLoading, dataLoading, activeTab],
)
// Load annotations when project loads
@@ -1256,59 +1047,6 @@ const ViewProjectContent = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [authLoading, project])
- // Load profiles list when users tab is active
- useEffect(() => {
- if (authLoading || activeTab !== PROJECT_TABS.profiles || !project || activeProfileId) {
- return
- }
-
- if (skipNextProfilesAutoLoadRef.current) {
- skipNextProfilesAutoLoadRef.current = false
- return
- }
-
- // Reset pagination and load the first page whenever the query context changes
- setProfilesSkip(0)
- loadProfiles(0, true)
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [
- activeTab,
- dateRange,
- filters,
- id,
- period,
- projectPassword,
- timezone,
- authLoading,
- project,
- activeProfileId,
- profileTypeFilter,
- ])
-
- // Load single profile when profileId is set
- useEffect(() => {
- if (authLoading || !activeProfileId || !project) {
- return
- }
-
- loadProfile(activeProfileId)
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [activeProfileId, authLoading, project])
-
- // Reset profiles when navigating away from profile detail
- useEffect(() => {
- const prevProfileId = prevActiveProfileIdRef.current
- prevActiveProfileIdRef.current = activeProfileId
-
- if (prevProfileId && !activeProfileId) {
- // We just closed a profile detail, reset to first page
- setProfilesSkip(0)
- skipNextProfilesAutoLoadRef.current = true
- loadProfiles(0, true)
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [activeProfileId])
-
useEffect(() => {
let sdk: SwetrixSDK | null = null
@@ -1807,6 +1545,7 @@ const ViewProjectContent = () => {
performanceRefreshTrigger,
trafficRefreshTrigger,
funnelsRefreshTrigger,
+ profilesRefreshTrigger,
// Functions
updatePeriod,
@@ -1817,7 +1556,7 @@ const ViewProjectContent = () => {
}}
>
<>
- {(dataLoading && !isAutoRefreshing) || (profilesLoading && !_isEmpty(profiles)) ? <LoadingBar /> : null}
+ {dataLoading && !isAutoRefreshing ? <LoadingBar /> : null}
{!isEmbedded ? <Header /> : null}
<EventsRunningOutBanner />
<div
@@ -1918,76 +1657,7 @@ const ViewProjectContent = () => {
</div>
) : null}
{activeTab === PROJECT_TABS.funnels ? <FunnelsView /> : null}
- {activeTab === PROJECT_TABS.profiles && !activeProfileId ? (
- <>
- <UsersFilter
- profileType={profileTypeFilter}
- onProfileTypeChange={(type) => {
- setProfileTypeFilter(type)
- setProfilesSkip(0)
- }}
- />
- {(profilesLoading === null || profilesLoading) && _isEmpty(profiles) ? <Loader /> : null}
- {typeof profilesLoading === 'boolean' && !profilesLoading && _isEmpty(profiles) ? (
- <NoEvents filters={filters} />
- ) : null}
- <Users profiles={profiles} timeFormat={timeFormat} />
- {canLoadMoreProfiles ? (
- <button
- type='button'
- title={t('project.loadMore')}
- onClick={() => loadProfiles()}
- className={cx(
- 'relative mx-auto mt-2 flex items-center rounded-md border border-transparent p-2 text-sm font-medium text-gray-700 hover:border-gray-300 hover:bg-white focus:z-10 focus:ring-1 focus:ring-indigo-500 focus:outline-hidden dark:bg-slate-900 dark:text-gray-50 hover:dark:border-slate-700/80 dark:hover:bg-slate-800 focus:dark:ring-gray-200',
- {
- 'cursor-not-allowed opacity-50': profilesLoading || profilesLoading === null,
- hidden: profilesLoading && _isEmpty(profiles),
- },
- )}
- >
- <DownloadIcon className='mr-2 h-5 w-5' strokeWidth={1.5} />
- {t('project.loadMore')}
- </button>
- ) : null}
- </>
- ) : null}
- {activeTab === PROJECT_TABS.profiles && activeProfileId ? (
- <>
- <div className='mx-auto mt-2 mb-4 flex max-w-max items-center space-x-4 lg:mx-0'>
- <Link
- to={{
- search: (() => {
- const params = new URLSearchParams(searchParams)
- params.delete('profileId')
- return params.toString()
- })(),
- }}
- className='flex items-center text-sm text-gray-900 underline decoration-dashed hover:decoration-solid dark:text-gray-100'
- >
- <ChevronLeftIcon className='mr-1 size-3' />
- {t('project.backToUsers')}
- </Link>
- <RefreshStatsButton onRefresh={() => loadProfile(activeProfileId)} />
- </div>
- {profileLoading ? (
- <Loader />
- ) : (
- <UserDetails
- details={activeProfile}
- sessions={profileSessions}
- sessionsLoading={profileSessionsLoading}
- timeFormat={timeFormat}
- chartType={chartType}
- onLoadMoreSessions={() => {
- if (activeProfileId) {
- loadProfileSessionsData(activeProfileId)
- }
- }}
- canLoadMoreSessions={canLoadMoreProfileSessions}
- />
- )}
- </>
- ) : null}
+ {activeTab === PROJECT_TABS.profiles ? <ProfilesView chartType={chartType} /> : null}
{activeTab === PROJECT_TABS.sessions ? (
<SessionsView tnMapping={tnMapping} chartType={chartType} rotateXAxis={rotateXAxis} />
) : null}