Skip to content

Commit ecaa5e1

Browse files
authored
Merge pull request #1593 from RedisInsight/fe/bugfix/RI-4014
#RI-4014 - fix re-rendering, fix highlighting if no count, fix click space for tab highlighting
2 parents cdd74a9 + dde3360 commit ecaa5e1

File tree

7 files changed

+48
-22
lines changed

7 files changed

+48
-22
lines changed

redisinsight/ui/src/components/analytics-tabs/constants.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import React, { ReactNode } from 'react'
2-
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
32
import { useSelector } from 'react-redux'
4-
import { appFeaturesToHighlightSelector } from 'uiSrc/slices/app/features-highlighting'
3+
4+
import { AnalyticsViewTab } from 'uiSrc/slices/interfaces/analytics'
5+
import { appFeatureHighlightingSelector } from 'uiSrc/slices/app/features-highlighting'
56
import HighlightedFeature from 'uiSrc/components/hightlighted-feature/HighlightedFeature'
67
import { BUILD_FEATURES } from 'uiSrc/constants/featuresHighlighting'
8+
import { getHighlightingFeatures } from 'uiSrc/utils/highlighting'
79

810
interface AnalyticsTabs {
911
id: AnalyticsViewTab
1012
label: string | ReactNode
1113
}
1214

1315
const DatabaseAnalyticsTab = () => {
14-
const { recommendations: recommendationsHighlighting } = useSelector(appFeaturesToHighlightSelector) ?? {}
16+
const { features } = useSelector(appFeatureHighlightingSelector)
17+
const { recommendations: recommendationsHighlighting } = getHighlightingFeatures(features)
1518

1619
return (
1720
<>
@@ -21,6 +24,7 @@ const DatabaseAnalyticsTab = () => {
2124
type={BUILD_FEATURES.recommendations?.type}
2225
isHighlight={BUILD_FEATURES.recommendations && recommendationsHighlighting}
2326
dotClassName="tab-highlighting-dot"
27+
wrapperClassName="inner-highlighting-wrapper"
2428
>
2529
Database Analysis
2630
</HighlightedFeature>

redisinsight/ui/src/components/database-overview/DatabaseOverviewWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ThemeContext } from 'uiSrc/contexts/themeContext'
1010

1111
import { getOverviewMetrics } from './components/OverviewMetrics'
1212

13-
const TIMEOUT_TO_GET_INFO = process.env.NODE_ENV !== 'development' ? 5000 : 10000000
13+
const TIMEOUT_TO_GET_INFO = process.env.NODE_ENV !== 'development' ? 5000 : 60_000
1414

1515
interface IProps { windowDimensions: number }
1616

redisinsight/ui/src/pages/databaseAnalysis/components/data-nav-tabs/constants.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import React, { ReactNode } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33

44
import { DatabaseAnalysisViewTab } from 'uiSrc/slices/interfaces/analytics'
5-
import { appFeaturesToHighlightSelector, removeFeatureFromHighlighting } from 'uiSrc/slices/app/features-highlighting'
5+
import {
6+
appFeatureHighlightingSelector,
7+
removeFeatureFromHighlighting
8+
} from 'uiSrc/slices/app/features-highlighting'
69
import { BUILD_FEATURES } from 'uiSrc/constants/featuresHighlighting'
710
import HighlightedFeature from 'uiSrc/components/hightlighted-feature/HighlightedFeature'
811

12+
import { getHighlightingFeatures } from 'uiSrc/utils/highlighting'
913
import Recommendations from '../recommendations-view'
1014
import AnalysisDataView from '../analysis-data-view'
1115

@@ -16,22 +20,22 @@ interface DatabaseAnalysisTabs {
1620
}
1721

1822
const RecommendationsTab = ({ count }: { count?: number }) => {
19-
const { recommendations: recommendationsHighlighting } = useSelector(appFeaturesToHighlightSelector) ?? {}
23+
const { features } = useSelector(appFeatureHighlightingSelector)
24+
const { recommendations: recommendationsHighlighting } = getHighlightingFeatures(features)
2025

2126
const dispatch = useDispatch()
2227

23-
return count ? (
24-
<>
25-
<HighlightedFeature
26-
type="plain"
27-
isHighlight={BUILD_FEATURES.recommendations && recommendationsHighlighting}
28-
onClick={() => dispatch(removeFeatureFromHighlighting('recommendations'))}
29-
dotClassName="tab-highlighting-dot"
30-
>
31-
<>Recommendations ({count})</>
32-
</HighlightedFeature>
33-
</>
34-
) : (<>Recommendations</>)
28+
return (
29+
<HighlightedFeature
30+
type="plain"
31+
isHighlight={BUILD_FEATURES.recommendations && recommendationsHighlighting}
32+
onClick={() => dispatch(removeFeatureFromHighlighting('recommendations'))}
33+
dotClassName="tab-highlighting-dot"
34+
wrapperClassName="inner-highlighting-wrapper"
35+
>
36+
{count ? <>Recommendations ({count})</> : <>Recommendations</>}
37+
</HighlightedFeature>
38+
)
3539
}
3640

3741
export const databaseAnalysisTabs: DatabaseAnalysisTabs[] = [

redisinsight/ui/src/slices/app/features-highlighting.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export const {
4444
} = appFeaturesHighlightingSlice.actions
4545

4646
export const appFeatureHighlightingSelector = (state: RootState) => state.app.featuresHighlighting
47-
export const appFeaturesToHighlightSelector = (state: RootState): { [key: string]: boolean } =>
48-
state.app.featuresHighlighting.features
49-
.reduce((prev, next) => ({ ...prev, [next]: true }), {})
5047
export const appFeaturePagesHighlightingSelector = (state: RootState) => state.app.featuresHighlighting.pages
5148

5249
export default appFeaturesHighlightingSlice.reducer

redisinsight/ui/src/styles/components/_tabs.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
}
6868
}
6969

70+
.inner-highlighting-wrapper {
71+
margin: -8px -12px;
72+
padding: 8px 12px;
73+
74+
.tab-highlighting-dot {
75+
top: 2px;
76+
right: 2px;
77+
}
78+
}
79+
7080
.tab-highlighting-dot {
7181
top: -6px;
7282
right: -12px;

redisinsight/ui/src/utils/highlighting.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ export const getPagesForFeatures = (features: string[] = []) => {
1717

1818
return result
1919
}
20+
21+
export const getHighlightingFeatures = (features: string[]): { [key: string]: boolean } => features
22+
.reduce((prev, next) => ({ ...prev, [next]: true }), {})

redisinsight/ui/src/utils/tests/highlighting.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPagesForFeatures } from 'uiSrc/utils/highlighting'
1+
import { getHighlightingFeatures, getPagesForFeatures } from 'uiSrc/utils/highlighting'
22
import { MOCKED_HIGHLIGHTING_FEATURES } from 'uiSrc/utils/test-utils'
33

44
describe('getPagesForFeatures', () => {
@@ -10,3 +10,11 @@ describe('getPagesForFeatures', () => {
1010
expect(getPagesForFeatures(MOCKED_HIGHLIGHTING_FEATURES)).toEqual({ browser: MOCKED_HIGHLIGHTING_FEATURES })
1111
})
1212
})
13+
14+
describe('getPagesForFeatures', () => {
15+
it('should return proper pages for features', () => {
16+
expect(getHighlightingFeatures([])).toEqual({})
17+
expect(getHighlightingFeatures(['feature1'])).toEqual({ feature1: true })
18+
expect(getHighlightingFeatures(['f1', 'f2'])).toEqual({ f1: true, f2: true })
19+
})
20+
})

0 commit comments

Comments
 (0)