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!

some improvments

kruzhambus634d5b6790d5
diff --git a/src/pages/Project/View/Panels.tsx b/src/pages/Project/View/Panels.tsx
index 2b932deb0..893f8ef8e 100644
--- a/src/pages/Project/View/Panels.tsx
+++ b/src/pages/Project/View/Panels.tsx
@@ -698,6 +698,7 @@ const Panel = ({
const totalPages = useMemo(() => _ceil(_size(keys) / ENTRIES_PER_PANEL), [keys])
const [activeFragment, setActiveFragment] = useState(0)
const [modal, setModal] = useState(false)
+ const [isReversedUserFlow, setIsReversedUserFlow] = useState<boolean>(false)
const canGoPrev = () => page > 0
const canGoNext = () => page < _floor((_size(keys) - 1) / ENTRIES_PER_PANEL)
@@ -788,6 +789,7 @@ const Panel = ({
customButtons={(
<button
type='button'
+ onClick={() => setIsReversedUserFlow(!isReversedUserFlow)}
className='mt-3 w-full inline-flex justify-center rounded-md dark:border-none border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 dark:text-gray-50 dark:border-gray-600 dark:bg-gray-600 dark:hover:border-gray-600 dark:hover:bg-gray-700 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm'
>
reverse
@@ -802,6 +804,7 @@ const Panel = ({
from={from}
to={to}
timezone={timezone}
+ isReversed={isReversedUserFlow}
/>
</div>
)}
diff --git a/src/pages/Project/View/components/SankeyChart.tsx b/src/pages/Project/View/components/SankeyChart.tsx
index 82781c6be..9a7dda77b 100644
--- a/src/pages/Project/View/components/SankeyChart.tsx
+++ b/src/pages/Project/View/components/SankeyChart.tsx
@@ -4,6 +4,9 @@ import { connect } from 'react-redux'
import { StateType, AppDispatch } from 'redux/store'
import UIActions from 'redux/reducers/ui'
import { IUserFlow } from 'redux/models/IUserFlow'
+import _isEmpty from 'lodash/isEmpty'
+import { getUserFlowCacheKey } from 'redux/constants'
+import { getUserFlow } from 'api'
const dataTest = {
nodes: [
@@ -76,9 +79,14 @@ const dataTest = {
],
}
+const defaultData = {
+ nodes: [],
+ links: [],
+}
+
const mapStateToProps = (state: StateType) => ({
- userFlowAscending: state.ui.cache.userFlowAscending,
- userFlowDescending: state.ui.cache.userFlowDescending,
+ userFlowAscendingCache: state.ui.cache.userFlowAscending,
+ userFlowDescendingCache: state.ui.cache.userFlowDescending,
})
const mapDispatchToProps = (dispatch: AppDispatch) => ({
@@ -99,82 +107,95 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
})
const SankeyChart = ({
- disableLegend, pid, period, timeBucket, from, to, timezone, userFlowAscending, userFlowDescending,
+ disableLegend, pid, period, timeBucket, from, to, timezone, userFlowAscendingCache, userFlowDescendingCache, isReversed,
}: {
disableLegend?: boolean
pid: string
- userFlowAscending: IUserFlow
- userFlowDescending: IUserFlow
+ userFlowAscendingCache: {
+ [key: string]: IUserFlow
+ }
+ userFlowDescendingCache: {
+ [key: string]: IUserFlow
+ }
period: string
timezone: string
timeBucket: string
from: string
to: string
-}) => (
- <ResponsiveSankey
- data={dataTest}
- margin={{
- top: 0, right: disableLegend ? 0 : 120, bottom: 0, left: 20,
- }}
- align='justify'
- colors={{ scheme: 'nivo' }}
- nodeOpacity={1}
- nodeHoverOthersOpacity={0.35}
- nodeThickness={18}
- nodeSpacing={24}
- nodeBorderWidth={0}
- nodeBorderColor={{
- from: 'color',
- modifiers: [
- [
- 'darker',
- 0.8,
+ isReversed?: boolean
+}) => {
+ const userFlowAscending = userFlowAscendingCache[getUserFlowCacheKey(pid, period)]
+ const userFlowDescending = userFlowDescendingCache[getUserFlowCacheKey(pid, period)]
+
+ return (
+ <ResponsiveSankey
+ data={isReversed
+ ? !_isEmpty(userFlowDescending) ? userFlowDescending : defaultData
+ : !_isEmpty(userFlowAscending) ? userFlowAscending : defaultData}
+ margin={{
+ top: 0, right: disableLegend ? 0 : 120, bottom: 0, left: 20,
+ }}
+ align='justify'
+ colors={{ scheme: 'nivo' }}
+ nodeOpacity={1}
+ nodeHoverOthersOpacity={0.35}
+ nodeThickness={18}
+ nodeSpacing={24}
+ nodeBorderWidth={0}
+ nodeBorderColor={{
+ from: 'color',
+ modifiers: [
+ [
+ 'darker',
+ 0.8,
+ ],
],
- ],
- }}
- nodeBorderRadius={3}
- linkOpacity={0.5}
- linkHoverOthersOpacity={0.1}
- linkContract={3}
- enableLinkGradient
- labelPosition='outside'
- labelOrientation='vertical'
- labelPadding={16}
- labelTextColor={{
- from: 'color',
- modifiers: [
- [
- 'darker',
- 1,
+ }}
+ nodeBorderRadius={3}
+ linkOpacity={0.5}
+ linkHoverOthersOpacity={0.1}
+ linkContract={3}
+ enableLinkGradient
+ labelPosition='outside'
+ labelOrientation='vertical'
+ labelPadding={16}
+ labelTextColor={{
+ from: 'color',
+ modifiers: [
+ [
+ 'darker',
+ 1,
+ ],
],
- ],
- }}
- legends={!disableLegend ? [
- {
- anchor: 'bottom-right',
- direction: 'column',
- translateX: 100,
- itemWidth: 100,
- itemHeight: 14,
- itemDirection: 'right-to-left',
- itemsSpacing: 2,
- itemTextColor: '#999',
- symbolSize: 14,
- effects: [
- {
- on: 'hover',
- style: {
- itemTextColor: '#000',
+ }}
+ legends={!disableLegend ? [
+ {
+ anchor: 'bottom-right',
+ direction: 'column',
+ translateX: 100,
+ itemWidth: 100,
+ itemHeight: 14,
+ itemDirection: 'right-to-left',
+ itemsSpacing: 2,
+ itemTextColor: '#999',
+ symbolSize: 14,
+ effects: [
+ {
+ on: 'hover',
+ style: {
+ itemTextColor: '#000',
+ },
},
- },
- ],
- },
- ] : []}
- />
-)
+ ],
+ },
+ ] : []}
+ />
+ )
+}
SankeyChart.defaultProps = {
disableLegend: false,
+ isReversed: false,
}
const mergeProps = (stateProps: ReturnType<typeof mapStateToProps>, dispatchProps: ReturnType<typeof mapDispatchToProps>, ownProps: ReturnType<typeof SankeyChart>) => ({
diff --git a/src/redux/constants/index.ts b/src/redux/constants/index.ts
index be7984efb..a5ef354fc 100644
--- a/src/redux/constants/index.ts
+++ b/src/redux/constants/index.ts
@@ -182,6 +182,7 @@ export const getProjectCacheKey = (period: string, timeBucket: string): string =
export const getProjectCaptchaCacheKey = (period: string, timeBucket: string): string => `${period}${timeBucket}captcha`
export const getProjectForcastCacheKey = (period: string, timeBucket: string, periodToForecast: string): string => `${period}${timeBucket}${periodToForecast}forecast`
export const getProjectCacheCustomKey = (from: string, to: string, timeBucket: string): string => `${from}-${to}-${timeBucket}`
+export const getUserFlowCacheKey = (pid: string, period: string): string => `${pid}${period}userflow`
// Cookies
export const GDPR_REQUEST: string = 'gdpr_request'
diff --git a/src/redux/models/IUserFlow.ts b/src/redux/models/IUserFlow.ts
index 58b0be152..507f3999b 100644
--- a/src/redux/models/IUserFlow.ts
+++ b/src/redux/models/IUserFlow.ts
@@ -9,4 +9,4 @@ interface UserFlow {
}[]
}
-export type IUserFlow = UserFlow | {}
+export type IUserFlow = UserFlow | null