Skip to content

Commit 5da5a7e

Browse files
Merge pull request #2403 from RedisInsight/feature/RI-4506_recommendations_remote
#RI-4506 - Update recommendations without the code change
2 parents 9da9c35 + 8cfe4b8 commit 5da5a7e

File tree

21 files changed

+1922
-1717
lines changed

21 files changed

+1922
-1717
lines changed

redisinsight/ui/src/components/config/Config.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getRedisCommands } from 'uiSrc/slices/app/redis-commands'
1717
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
1818
import { getWBGuides } from 'uiSrc/slices/workbench/wb-guides'
1919
import { getWBTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
20+
import { getContentRecommendations } from 'uiSrc/slices/recommendations/recommendations'
2021
import Config from './Config'
2122

2223
let store: typeof mockedStore
@@ -61,6 +62,7 @@ describe('Config', () => {
6162
processCliClient(),
6263
getRedisCommands(),
6364
getNotifications(),
65+
getContentRecommendations(),
6466
getWBGuides(),
6567
getWBTutorials(),
6668
getFeatureFlags(),
@@ -94,6 +96,7 @@ describe('Config', () => {
9496
processCliClient(),
9597
getRedisCommands(),
9698
getNotifications(),
99+
getContentRecommendations(),
97100
getWBGuides(),
98101
getWBTutorials(),
99102
getFeatureFlags(),

redisinsight/ui/src/components/config/Config.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { fetchRedisCommandsInfo } from 'uiSrc/slices/app/redis-commands'
3030
import { fetchGuides } from 'uiSrc/slices/workbench/wb-guides'
3131
import { fetchTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
3232
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
33+
import { fetchContentRecommendations } from 'uiSrc/slices/recommendations/recommendations'
3334
import favicon from 'uiSrc/assets/favicon.ico'
3435

3536
const SETTINGS_PAGE_PATH = '/settings'
@@ -48,6 +49,7 @@ const Config = () => {
4849
dispatch(fetchUnsupportedCliCommandsAction())
4950
dispatch(fetchRedisCommandsInfo())
5051
dispatch(fetchNotificationsAction())
52+
dispatch(fetchContentRecommendations())
5153

5254
// get guides & tutorials
5355
dispatch(fetchGuides())

redisinsight/ui/src/components/live-time-recommendations/LiveTimeRecommendations.spec.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1111
import { Pages } from 'uiSrc/constants'
1212
import { RECOMMENDATIONS_DATA_MOCK } from 'uiSrc/mocks/handlers/recommendations/recommendationsHandler'
1313
import { appContextDbConfig, setRecommendationsShowHidden } from 'uiSrc/slices/app/context'
14-
import _content from 'uiSrc/constants/dbAnalysisRecommendations.json'
15-
import { IRecommendationsStatic } from 'uiSrc/slices/interfaces/recommendations'
1614
import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
15+
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
1716

1817
import LiveTimeRecommendations from './LiveTimeRecommendations'
1918

20-
const recommendationsContent = _content as IRecommendationsStatic
21-
2219
let store: typeof mockedStore
20+
const recommendationsContent = MOCK_RECOMMENDATIONS
2321

24-
const mockRecommendationsSelector = jest.requireActual('uiSrc/slices/recommendations/recommendations')
22+
const mockRecommendationsSelector = {
23+
...jest.requireActual('uiSrc/slices/recommendations/recommendations'),
24+
content: recommendationsContent,
25+
}
2526
const mockAppContextDbConfigSelector = jest.requireActual('uiSrc/slices/app/context')
2627

2728
jest.mock('uiSrc/slices/instances/instances', () => ({
@@ -190,7 +191,7 @@ describe('LiveTimeRecommendations', () => {
190191
data: {
191192
recommendations: [{ name: 'RTS' }],
192193
},
193-
isContentVisible: true
194+
isContentVisible: true,
194195
}))
195196
const pushMock = jest.fn()
196197
reactRouterDom.useHistory = jest.fn().mockReturnValue({ push: pushMock })
@@ -223,7 +224,7 @@ describe('LiveTimeRecommendations', () => {
223224
data: {
224225
recommendations: [],
225226
},
226-
isContentVisible: true
227+
isContentVisible: true,
227228
}))
228229
render(<LiveTimeRecommendations />)
229230
const afterRenderActions = [...store.getActions()]
@@ -241,7 +242,7 @@ describe('LiveTimeRecommendations', () => {
241242
(recommendationsSelector as jest.Mock).mockImplementation(() => ({
242243
...mockRecommendationsSelector,
243244
isContentVisible: true,
244-
data: RECOMMENDATIONS_DATA_MOCK
245+
data: RECOMMENDATIONS_DATA_MOCK,
245246
}))
246247

247248
const { queryByTestId } = render(<LiveTimeRecommendations />)
@@ -266,7 +267,7 @@ describe('LiveTimeRecommendations', () => {
266267
(recommendationsSelector as jest.Mock).mockImplementation(() => ({
267268
...mockRecommendationsSelector,
268269
isContentVisible: true,
269-
data: RECOMMENDATIONS_DATA_MOCK
270+
data: RECOMMENDATIONS_DATA_MOCK,
270271
}))
271272
const { queryByTestId } = render(<LiveTimeRecommendations />)
272273

@@ -278,7 +279,7 @@ describe('LiveTimeRecommendations', () => {
278279
(recommendationsSelector as jest.Mock).mockImplementation(() => ({
279280
...mockRecommendationsSelector,
280281
isContentVisible: true,
281-
data: RECOMMENDATIONS_DATA_MOCK
282+
data: RECOMMENDATIONS_DATA_MOCK,
282283
}));
283284
(appContextDbConfig as jest.Mock).mockImplementation(() => ({
284285
...mockAppContextDbConfigSelector,
@@ -294,7 +295,7 @@ describe('LiveTimeRecommendations', () => {
294295
(recommendationsSelector as jest.Mock).mockImplementation(() => ({
295296
...mockRecommendationsSelector,
296297
isContentVisible: true,
297-
data: RECOMMENDATIONS_DATA_MOCK
298+
data: RECOMMENDATIONS_DATA_MOCK,
298299
}));
299300
(appContextDbConfig as jest.Mock).mockImplementation(() => ({
300301
...mockAppContextDbConfigSelector,
@@ -317,7 +318,7 @@ describe('LiveTimeRecommendations', () => {
317318
data: {
318319
...RECOMMENDATIONS_DATA_MOCK,
319320
recommendations: RECOMMENDATIONS_DATA_MOCK.recommendations.map((rec) => ({ ...rec, hide: true }))
320-
}
321+
},
321322
}));
322323
(appContextDbConfig as jest.Mock).mockImplementation(() => ({
323324
...mockAppContextDbConfigSelector,

redisinsight/ui/src/components/live-time-recommendations/LiveTimeRecommendations.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
3333
import { workbenchGuidesSelector } from 'uiSrc/slices/workbench/wb-guides'
3434

3535
import { workbenchTutorialsSelector } from 'uiSrc/slices/workbench/wb-tutorials'
36-
import { IRecommendation, IRecommendationsStatic } from 'uiSrc/slices/interfaces/recommendations'
36+
import { IRecommendation } from 'uiSrc/slices/interfaces/recommendations'
3737
import { appContextDbConfig, setRecommendationsShowHidden } from 'uiSrc/slices/app/context'
3838
import { ConnectionType } from 'uiSrc/slices/interfaces'
3939
import { createNewAnalysis } from 'uiSrc/slices/analytics/dbAnalysis'
4040

41-
import _content from 'uiSrc/constants/dbAnalysisRecommendations.json'
4241
import { ReactComponent as TriggerIcon } from 'uiSrc/assets/img/bulb.svg'
4342
import { ReactComponent as TriggerActiveIcon } from 'uiSrc/assets/img/bulb-active.svg'
4443
import InfoIcon from 'uiSrc/assets/img/icons/help_illus.svg'
@@ -50,8 +49,6 @@ import WelcomeScreen from './components/welcome-screen'
5049
import PopoverRunAnalyze from './components/popover-run-analyze'
5150
import styles from './styles.module.scss'
5251

53-
const recommendationsContent = _content as IRecommendationsStatic
54-
5552
const DELAY_TO_SHOW_ONBOARDING_MS = 500
5653

5754
const LiveTimeRecommendations = () => {
@@ -61,6 +58,7 @@ const LiveTimeRecommendations = () => {
6158
data: { recommendations, totalUnread },
6259
isContentVisible,
6360
isHighlighted,
61+
content: recommendationsContent,
6462
} = useSelector(recommendationsSelector)
6563
const { items: guides } = useSelector(workbenchGuidesSelector)
6664
const { items: tutorials } = useSelector(workbenchTutorialsSelector)
@@ -198,6 +196,7 @@ const LiveTimeRecommendations = () => {
198196
tutorial={recommendationsContent[name]?.tutorial}
199197
provider={provider}
200198
params={params}
199+
recommendationsContent={recommendationsContent}
201200
/>
202201
))
203202
}

redisinsight/ui/src/components/live-time-recommendations/components/recommendation/Recommendation.spec.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ import { MOCK_GUIDES_ITEMS, MOCK_TUTORIALS_ITEMS, Pages } from 'uiSrc/constants'
88

99
import { updateRecommendation } from 'uiSrc/slices/recommendations/recommendations'
1010
import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
11+
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
1112
import Recommendation, { IProps } from './Recommendation'
1213

14+
const recommendationsContent = MOCK_RECOMMENDATIONS
1315
const mockedProps = mock<IProps>()
1416

17+
const instanceMock = {
18+
...instance(mockedProps),
19+
recommendationsContent,
20+
}
21+
1522
jest.mock('uiSrc/telemetry', () => ({
1623
...jest.requireActual('uiSrc/telemetry'),
1724
sendEventTelemetry: jest.fn(),
@@ -28,12 +35,14 @@ const PROVIDER = 'RE_CLOUD'
2835

2936
describe('Recommendation', () => {
3037
it('should render', () => {
31-
expect(render(<Recommendation {...instance(mockedProps)} />)).toBeTruthy()
38+
expect(render(<Recommendation
39+
{...instanceMock}
40+
/>)).toBeTruthy()
3241
})
3342

3443
it('should render content if recommendation is not read', () => {
3544
render(<Recommendation
36-
{...instance(mockedProps)}
45+
{...instanceMock}
3746
name="searchJSON"
3847
tutorial=""
3948
isRead={false}
@@ -44,7 +53,7 @@ describe('Recommendation', () => {
4453
})
4554

4655
it('should render RecommendationVoting', () => {
47-
const { container } = render(<Recommendation {...instance(mockedProps)} name="searchJSON" />)
56+
const { container } = render(<Recommendation {...instanceMock} name="searchJSON" />)
4857
fireEvent.click(container.querySelector('[data-test-subj="searchJSON-button"]') as HTMLButtonElement)
4958
expect(screen.getByTestId('recommendation-voting')).toBeInTheDocument()
5059
})
@@ -56,7 +65,7 @@ describe('Recommendation', () => {
5665

5766
const { container } = render(
5867
<Recommendation
59-
{...instance(mockedProps)}
68+
{...instanceMock}
6069
isRead={false}
6170
name="searchJSON"
6271
tutorial=""
@@ -86,7 +95,7 @@ describe('Recommendation', () => {
8695

8796
const { container } = render(
8897
<Recommendation
89-
{...instance(mockedProps)}
98+
{...instanceMock}
9099
isRead={false}
91100
name="searchJSON"
92101
tutorial="quick-guides/working-with-hash.html"
@@ -118,7 +127,7 @@ describe('Recommendation', () => {
118127

119128
const { container } = render(
120129
<Recommendation
121-
{...instance(mockedProps)}
130+
{...instanceMock}
122131
isRead={false}
123132
name="searchJSON"
124133
tutorial="/redis_stack/working_with_json.md"
@@ -145,7 +154,7 @@ describe('Recommendation', () => {
145154

146155
it('should render hide/unhide button', () => {
147156
const name = 'searchJSON'
148-
render(<Recommendation {...instance(mockedProps)} name={name} />)
157+
render(<Recommendation {...instanceMock} name={name} />)
149158

150159
expect(screen.getByTestId('toggle-hide-searchJSON-btn')).toBeInTheDocument()
151160
})
@@ -155,7 +164,7 @@ describe('Recommendation', () => {
155164
const nameMock = 'searchJSON'
156165
const { queryByTestId } = render(
157166
<Recommendation
158-
{...instance(mockedProps)}
167+
{...instanceMock}
159168
id={idMock}
160169
name={nameMock}
161170
/>
@@ -173,28 +182,28 @@ describe('Recommendation', () => {
173182

174183
it('should not render "Tutorial" btn if tutorial is Undefined', () => {
175184
const name = 'searchJSON'
176-
const { queryByTestId } = render(<Recommendation {...instance(mockedProps)} name={name} tutorial={undefined} />)
185+
const { queryByTestId } = render(<Recommendation {...instanceMock} name={name} tutorial={undefined} />)
177186

178187
expect(queryByTestId(`${name}-to-tutorial-btn`)).not.toBeInTheDocument()
179188
})
180189

181190
it('should render "Tutorial" if tutorial="path"', () => {
182191
const name = 'searchJSON'
183-
const { queryByTestId } = render(<Recommendation {...instance(mockedProps)} name={name} tutorial="path" />)
192+
const { queryByTestId } = render(<Recommendation {...instanceMock} name={name} tutorial="path" />)
184193

185194
expect(queryByTestId(`${name}-to-tutorial-btn`)).toHaveTextContent('Tutorial')
186195
})
187196

188197
it('should render "Workbench" btn if tutorial=""', () => {
189198
const name = 'searchJSON'
190-
const { queryByTestId } = render(<Recommendation {...instance(mockedProps)} name={name} tutorial="" />)
199+
const { queryByTestId } = render(<Recommendation {...instanceMock} name={name} tutorial="" />)
191200

192201
expect(queryByTestId(`${name}-to-tutorial-btn`)).toHaveTextContent('Workbench')
193202
})
194203

195204
it('should render Snooze button', () => {
196205
const name = 'searchJSON'
197-
render(<Recommendation {...instance(mockedProps)} name={name} />)
206+
render(<Recommendation {...instanceMock} name={name} />)
198207

199208
expect(screen.getByTestId(`${name}-delete-btn`)).toBeInTheDocument()
200209
})
@@ -204,7 +213,7 @@ describe('Recommendation', () => {
204213
const nameMock = 'searchJSON'
205214
const { queryByTestId } = render(
206215
<Recommendation
207-
{...instance(mockedProps)}
216+
{...instanceMock}
208217
id={idMock}
209218
name={nameMock}
210219
/>

redisinsight/ui/src/components/live-time-recommendations/components/recommendation/Recommendation.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
2727
import { IEnablementAreaItem } from 'uiSrc/slices/interfaces'
2828
import { IRecommendationsStatic, IRecommendationParams } from 'uiSrc/slices/interfaces/recommendations'
2929

30-
import _content from 'uiSrc/constants/dbAnalysisRecommendations.json'
3130
import RediStackDarkMin from 'uiSrc/assets/img/modules/redistack/RediStackDark-min.svg'
3231
import RediStackLightMin from 'uiSrc/assets/img/modules/redistack/RediStackLight-min.svg'
3332
import { ReactComponent as SnoozeIcon } from 'uiSrc/assets/img/icons/snooze.svg'
@@ -46,10 +45,9 @@ export interface IProps {
4645
tutorial?: string
4746
provider?: string
4847
params: IRecommendationParams
48+
recommendationsContent: IRecommendationsStatic
4949
}
5050

51-
const recommendationsContent = _content as IRecommendationsStatic
52-
5351
const Recommendation = ({
5452
id,
5553
name,
@@ -61,6 +59,7 @@ const Recommendation = ({
6159
hide,
6260
provider,
6361
params,
62+
recommendationsContent,
6463
}: IProps) => {
6564
const [isLoading, setIsLoading] = useState(false)
6665
const history = useHistory()

redisinsight/ui/src/components/recommendation-voting/components/vote-option/VoteOption.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ import {
1515
import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
1616
import { Vote } from 'uiSrc/constants/recommendations'
1717
import { putRecommendationVote } from 'uiSrc/slices/analytics/dbAnalysis'
18-
import { IRecommendationsStatic } from 'uiSrc/slices/interfaces/recommendations'
1918
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
20-
import _content from 'uiSrc/constants/dbAnalysisRecommendations.json'
21-
import { updateLiveRecommendation } from 'uiSrc/slices/recommendations/recommendations'
19+
import { recommendationsSelector, updateLiveRecommendation } from 'uiSrc/slices/recommendations/recommendations'
2220
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
2321
import { Nullable } from 'uiSrc/utils'
2422
import PetardIcon from 'uiSrc/assets/img/icons/petard.svg'
@@ -38,8 +36,6 @@ export interface Props {
3836
name: string
3937
}
4038

41-
const recommendationsContent = _content as IRecommendationsStatic
42-
4339
const VoteOption = (props: Props) => {
4440
const {
4541
voteOption,
@@ -54,6 +50,7 @@ const VoteOption = (props: Props) => {
5450

5551
const dispatch = useDispatch()
5652
const { id: instanceId = '', provider } = useSelector(connectedInstanceSelector)
53+
const { content: recommendationsContent } = useSelector(recommendationsSelector)
5754

5855
const onSuccessVoted = ({ vote, name }: { name: string, vote: Nullable<Vote> }) => {
5956
sendEventTelemetry({

redisinsight/ui/src/constants/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ enum ApiEndpoints {
8989
PLUGINS = 'plugins',
9090
STATE = 'state',
9191
CONTENT_CREATE_DATABASE = 'static/content/create-redis.json',
92+
CONTENT_RECOMMENDATIONS = 'static/content/recommendations.json',
9293
GUIDES_PATH = 'static/guides',
9394
TUTORIALS_PATH = 'static/tutorials',
9495
CUSTOM_TUTORIALS_PATH = 'static/custom-tutorials',

0 commit comments

Comments
 (0)