Skip to content
Merged
14 changes: 2 additions & 12 deletions redisinsight/api/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export default {
pluginsAssets: join(staticDir, 'resources', 'plugins'),
commands: join(homedir, 'commands'),
defaultCommandsDir: join(defaultsDir, 'commands'),
guides: process.env.RI_GUIDES_PATH || join(homedir, 'guides'),
defaultGuides: join(defaultsDir, 'guides'),
tutorials: process.env.RI_TUTORIALS_PATH || join(homedir, 'tutorials'),
defaultTutorials: join(defaultsDir, 'tutorials'),
content: process.env.RI_CONTENT_PATH || join(homedir, 'content'),
Expand All @@ -47,7 +45,6 @@ export default {
globalPrefix: 'api',
customPluginsUri: '/plugins',
staticUri: '/static',
guidesUri: '/static/guides',
tutorialsUri: '/static/tutorials',
customTutorialsUri: '/static/custom-tutorials',
contentUri: '/static/content',
Expand Down Expand Up @@ -110,23 +107,16 @@ export default {
plugins: {
stateMaxSize: parseInt(process.env.RI_PLUGIN_STATE_MAX_SIZE, 10) || 1024 * 1024,
},
guides: {
updateUrl: process.env.RI_GUIDES_UPDATE_URL
|| 'https://github.com/RedisInsight/Guides/releases/download/2.x.x',
zip: process.env.RI_GUIDES_ZIP || dataZipFileName,
buildInfo: process.env.RI_GUIDES_INFO || buildInfoFileName,
devMode: !!process.env.RI_GUIDES_PATH,
},
tutorials: {
updateUrl: process.env.RI_TUTORIALS_UPDATE_URL
|| 'https://github.com/RedisInsight/Tutorials/releases/download/2.x.x',
|| 'https://github.com/RedisInsight/Tutorials/releases/download/2.42',
zip: process.env.RI_TUTORIALS_ZIP || dataZipFileName,
buildInfo: process.env.RI_TUTORIALS_INFO || buildInfoFileName,
devMode: !!process.env.RI_TUTORIALS_PATH,
},
content: {
updateUrl: process.env.RI_CONTENT_UPDATE_URL
|| 'https://github.com/RedisInsight/Statics/releases/download/latest',
|| 'https://github.com/RedisInsight/Statics/releases/download/2.42',
zip: process.env.RI_CONTENT_ZIP || dataZipFileName,
buildInfo: process.env.RI_CONTENT_INFO || buildInfoFileName,
devMode: !!process.env.RI_CONTENT_PATH,
Expand Down
3 changes: 1 addition & 2 deletions redisinsight/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
},
"scripts": {
"build:defaults:commands": "ts-node ./scripts/default-commands.ts",
"build:defaults:guides": "ts-node ./scripts/default-guides.ts",
"build:defaults:tutorials": "ts-node ./scripts/default-tutorials.ts",
"build:defaults:content": "ts-node ./scripts/default-content.ts",
"build:defaults": "yarn build:defaults:guides && yarn build:defaults:commands && yarn build:defaults:content && yarn build:defaults:tutorials",
"build:defaults": "yarn build:defaults:commands && yarn build:defaults:content && yarn build:defaults:tutorials",
"prebuild": "rimraf dist",
"build": "nest build",
"build:prod": "rimraf dist && nest build -p ./tsconfig.build.prod.json && cross-env NODE_ENV=production",
Expand Down
39 changes: 0 additions & 39 deletions redisinsight/api/scripts/default-guides.ts

This file was deleted.

13 changes: 13 additions & 0 deletions redisinsight/api/src/init-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ export const migrateHomeFolder = async () => {
// continue initialization even without migration
}
};

/**
* Remove old guides folder
*/
export const removeGuidesFolder = async () => {
try {
if (await fs.pathExists(PATH_CONFIG.guides)) {
await fs.rm(PATH_CONFIG.guides, { recursive: true, force: true });
}
} catch (e) {
// continue initialization even without migration
}
};
3 changes: 2 additions & 1 deletion redisinsight/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as bodyParser from 'body-parser';
import { WinstonModule } from 'nest-winston';
import { GlobalExceptionFilter } from 'src/exceptions/global-exception.filter';
import { get, Config } from 'src/utils';
import { migrateHomeFolder } from 'src/init-helper';
import { migrateHomeFolder, removeGuidesFolder } from 'src/init-helper';
import { LogFileProvider } from 'src/modules/profiler/providers/log-file.provider';
import { WindowsAuthAdapter } from 'src/modules/auth/window-auth/adapters/window-auth.adapter';
import { AppModule } from './app.module';
Expand All @@ -24,6 +24,7 @@ interface IApp {

export default async function bootstrap(apiPort?: number): Promise<IApp> {
await migrateHomeFolder();
await removeGuidesFolder();

const { port, host } = serverConfig;
const logger = WinstonModule.createLogger(LOGGER_CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import config from 'src/utils/config';
import { AutoUpdatedStaticsProvider } from './auto-updated-statics.provider';

const PATH_CONFIG = config.get('dir_path');
const GUIDES = config.get('guides');
const TUTORIALS = config.get('tutorials');

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
Expand All @@ -26,13 +26,13 @@ describe('AutoUpdatedStaticsProvider', () => {
jest.mock('adm-zip', () => jest.fn().mockImplementation(() => mockedAdmZip));

service = new AutoUpdatedStaticsProvider({
name: 'GuidesProvider',
destinationPath: PATH_CONFIG.guides,
defaultSourcePath: PATH_CONFIG.defaultGuides,
updateUrl: GUIDES.updateUrl,
buildInfo: GUIDES.buildInfo,
zip: GUIDES.zip,
devMode: GUIDES.devMode,
name: 'TutorialsProvider',
destinationPath: PATH_CONFIG.tutorials,
defaultSourcePath: PATH_CONFIG.defaultTutorials,
updateUrl: TUTORIALS.updateUrl,
buildInfo: TUTORIALS.buildInfo,
zip: TUTORIALS.zip,
devMode: TUTORIALS.devMode,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ import { AutoUpdatedStaticsProvider } from './providers/auto-updated-statics.pro

const SERVER_CONFIG = config.get('server') as Config['server'];
const PATH_CONFIG = config.get('dir_path') as Config['dir_path'];
const GUIDES_CONFIG = config.get('guides') as Config['guides'];
const TUTORIALS_CONFIG = config.get('tutorials') as Config['tutorials'];

const CONTENT_CONFIG = config.get('content');

@Module({
imports: [
ServeStaticModule.forRoot({
serveRoot: SERVER_CONFIG.guidesUri,
rootPath: join(PATH_CONFIG.guides),
serveStaticOptions: {
fallthrough: false,
},
}),
ServeStaticModule.forRoot({
serveRoot: SERVER_CONFIG.tutorialsUri,
rootPath: join(PATH_CONFIG.tutorials),
Expand Down Expand Up @@ -64,15 +56,6 @@ const CONTENT_CONFIG = config.get('content');
}),
],
providers: [
{
provide: 'GuidesProvider',
useFactory: () => new AutoUpdatedStaticsProvider({
name: 'GuidesProvider',
destinationPath: PATH_CONFIG.guides,
defaultSourcePath: PATH_CONFIG.defaultGuides,
...GUIDES_CONFIG,
}),
},
{
provide: 'TutorialsProvider',
useFactory: () => new AutoUpdatedStaticsProvider({
Expand Down
3 changes: 0 additions & 3 deletions redisinsight/ui/src/components/config/Config.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { appServerInfoSelector, getServerInfo } from 'uiSrc/slices/app/info'
import { processCliClient } from 'uiSrc/slices/cli/cli-settings'
import { getRedisCommands } from 'uiSrc/slices/app/redis-commands'
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
import { getWBGuides } from 'uiSrc/slices/workbench/wb-guides'
import { getWBTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
import { getContentRecommendations } from 'uiSrc/slices/recommendations/recommendations'
import { getGuideLinks } from 'uiSrc/slices/content/guide-links'
Expand Down Expand Up @@ -68,7 +67,6 @@ describe('Config', () => {
getNotifications(),
getContentRecommendations(),
getGuideLinks(),
getWBGuides(),
getWBTutorials(),
getWBCustomTutorials(),
getFeatureFlags(),
Expand Down Expand Up @@ -106,7 +104,6 @@ describe('Config', () => {
getNotifications(),
getContentRecommendations(),
getGuideLinks(),
getWBGuides(),
getWBTutorials(),
getWBCustomTutorials(),
getFeatureFlags(),
Expand Down
4 changes: 1 addition & 3 deletions redisinsight/ui/src/components/config/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { setFavicon, isDifferentConsentsExists } from 'uiSrc/utils'
import { fetchUnsupportedCliCommandsAction } from 'uiSrc/slices/cli/cli-settings'
import { fetchRedisCommandsInfo } from 'uiSrc/slices/app/redis-commands'
import { fetchGuides } from 'uiSrc/slices/workbench/wb-guides'
import { fetchTutorials } from 'uiSrc/slices/workbench/wb-tutorials'
import { fetchCustomTutorials } from 'uiSrc/slices/workbench/wb-custom-tutorials'
import { ONBOARDING_FEATURES } from 'uiSrc/components/onboarding-features'
Expand Down Expand Up @@ -52,8 +51,7 @@ const Config = () => {
dispatch(fetchContentRecommendations())
dispatch(fetchGuideLinksAction())

// get guides & tutorials
dispatch(fetchGuides())
// get tutorials
dispatch(fetchTutorials())
dispatch(fetchCustomTutorials())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jest.mock('uiSrc/telemetry', () => ({

jest.mock('uiSrc/utils', () => ({
...jest.requireActual('uiSrc/utils'),
getTutorialCapability: jest.fn().mockReturnValue({ tutorialPage: { id: 'id' }, telemetryName: 'searchAndQuery' }),
getTutorialCapability: jest.fn().mockReturnValue({ path: 'path', telemetryName: 'searchAndQuery' }),
}))

jest.mock('uiSrc/services', () => ({
Expand Down Expand Up @@ -243,6 +243,8 @@ describe('DatabaseSidePanels', () => {
render(<DatabaseSidePanels />)

const expectedActions = [
resetExplorePanelSearch(),
setExplorePanelIsPageOpen(false),
changeSelectedTab(InsightsPanelTabs.Explore),
toggleInsightsPanel(true),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FullScreen, OnboardingTour } from 'uiSrc/components'
import { appContextCapability } from 'uiSrc/slices/app/context'
import { getTutorialCapability } from 'uiSrc/utils'
import { isShowCapabilityTutorialPopover } from 'uiSrc/services'
import { EAManifestFirstKey } from 'uiSrc/constants'
import LiveTimeRecommendations from './panels/live-time-recommendations'
import EnablementAreaWrapper from './panels/enablement-area'

Expand Down Expand Up @@ -63,12 +64,12 @@ const DatabaseSidePanels = (props: Props) => {
return
}

const tutorialCapabilityPath = getTutorialCapability(capabilitySource)?.tutorialPage?.args?.path || ''
const tutorialCapabilityPath = getTutorialCapability(capabilitySource)?.path || ''

// set 'guidPath' with the path to capability tutorial
// set 'path' with the path to capability tutorial
if (tutorialCapabilityPath) {
const search = new URLSearchParams(window.location.search)
search.set('guidePath', tutorialCapabilityPath)
search.set('path', `${EAManifestFirstKey.TUTORIALS}/${tutorialCapabilityPath}`)
history.push({ search: search.toString() })
} else {
// reset explore if tutorial is not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
import { instance, mock } from 'ts-mockito'
import reactRouterDom from 'react-router-dom'
import { cleanup, mockedStore, render, screen, fireEvent, act, waitFor } from 'uiSrc/utils/test-utils'
import { MOCK_GUIDES_ITEMS, MOCK_TUTORIALS_ITEMS, MOCK_CUSTOM_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { MOCK_TUTORIALS_ITEMS, MOCK_CUSTOM_TUTORIALS_ITEMS } from 'uiSrc/constants'
import { EnablementAreaComponent, IEnablementAreaItem } from 'uiSrc/slices/interfaces'

import {
Expand Down Expand Up @@ -36,11 +36,11 @@ jest.mock('uiSrc/slices/workbench/wb-custom-tutorials', () => ({
)
}))

jest.mock('uiSrc/slices/workbench/wb-guides', () => {
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-guides').initialState
jest.mock('uiSrc/slices/workbench/wb-tutorials', () => {
const defaultState = jest.requireActual('uiSrc/slices/workbench/wb-tutorials').initialState
return {
...jest.requireActual('uiSrc/slices/workbench/wb-guides'),
workbenchGuidesSelector: jest.fn().mockReturnValue({
...jest.requireActual('uiSrc/slices/workbench/wb-tutorials'),
workbenchTutorialsSelector: jest.fn().mockReturnValue({
...defaultState,
}),
}
Expand All @@ -59,7 +59,6 @@ describe('EnablementArea', () => {
it('should render', () => {
expect(render(<EnablementArea
{...instance(mockedProps)}
guides={MOCK_GUIDES_ITEMS}
tutorials={MOCK_TUTORIALS_ITEMS}
/>))
.toBeTruthy()
Expand Down Expand Up @@ -94,7 +93,7 @@ describe('EnablementArea', () => {
const { queryByTestId } = render(
<EnablementArea
{...instance(mockedProps)}
guides={[item]}
tutorials={[item]}
/>
)

Expand All @@ -114,26 +113,30 @@ describe('EnablementArea', () => {
const { queryByTestId } = render(
<EnablementArea
{...instance(mockedProps)}
guides={[item]}
tutorials={[item]}
/>
)

expect(queryByTestId('internal-link-internal-page')).toBeInTheDocument()
})

it('should find guide and push proper search path', async () => {
const search = '?guidePath=/quick-guides/working-with-json.html'
const search = '?guidePath=quick-guides/working-with-json.html'

const pushMock = jest.fn()
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock })
reactRouterDom.useLocation = jest.fn().mockImplementationOnce(() => ({ search }))

await act(() => {
render(<EnablementArea {...instance(mockedProps)} guides={MOCK_GUIDES_ITEMS} onOpenInternalPage={jest.fn} />)
render(<EnablementArea
{...instance(mockedProps)}
tutorials={MOCK_TUTORIALS_ITEMS}
onOpenInternalPage={jest.fn}
/>)
})

await waitFor(() => {
expect(pushMock).toBeCalledWith({ search: '?path=quick-guides/0/1' })
expect(pushMock).toBeCalledWith({ search: '?path=tutorials/0/1' })
}, { timeout: 1000 })
})

Expand Down Expand Up @@ -162,6 +165,9 @@ describe('EnablementArea', () => {

it('should call proper actions after upload form submit', async () => {
render(<EnablementArea {...instance(mockedProps)} customTutorials={MOCK_CUSTOM_TUTORIALS_ITEMS} />)

const afterRenderActions = [...store.getActions()]

fireEvent.click(screen.getByTestId('open-upload-tutorial-btn'))

await act(() => {
Expand All @@ -175,16 +181,18 @@ describe('EnablementArea', () => {
fireEvent.click(screen.getByTestId('submit-upload-tutorial-btn'))
})

const expectedActions = [uploadWbCustomTutorial()]
const expectedActions = [...afterRenderActions, uploadWbCustomTutorial()]
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
})

it('should render delete button and call proper actions after click on delete', () => {
render(<EnablementArea {...instance(mockedProps)} customTutorials={MOCK_CUSTOM_TUTORIALS_ITEMS} />)
const afterRenderActions = [...store.getActions()]

fireEvent.click(screen.getByTestId('delete-tutorial-icon-12mfp-rem'))
fireEvent.click(screen.getByTestId('delete-tutorial-12mfp-rem'))

const expectedActions = [deleteWbCustomTutorial()]
const expectedActions = [...afterRenderActions, deleteWbCustomTutorial()]
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
})

Expand Down
Loading