Skip to content

Commit c66bf77

Browse files
authored
Merge pull request #2094 from RedisInsight/fe/bugfix/RI-4487
#RI-4487 - fix incorrect path format
2 parents 78426b7 + 0e547a4 commit c66bf77

File tree

9 files changed

+44
-8
lines changed

9 files changed

+44
-8
lines changed

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
mockCustomTutorial,
88
mockCustomTutorialManifest, mockCustomTutorialManifestJson,
99
} from 'src/__mocks__';
10+
import * as Utils from 'src/utils/path';
1011

1112
jest.mock('fs-extra');
1213
const mFs = fs as jest.Mocked<typeof fs>;
@@ -61,6 +62,8 @@ describe('CustomTutorialManifestProvider', () => {
6162
expect(result).toEqual([]);
6263
});
6364
it('should return empty array for empty folder', async () => {
65+
const spy = jest.spyOn(Utils as any, 'winPathToNormalPath');
66+
6467
// root level entries
6568
const mockRootLevelEntries = [
6669
'intro.md',
@@ -160,6 +163,7 @@ describe('CustomTutorialManifestProvider', () => {
160163
type: 'group',
161164
},
162165
]);
166+
expect(spy).toBeCalledTimes(5); // Should call util to fix win path
163167
});
164168
});
165169

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
RootCustomTutorialManifest,
1010
} from 'src/modules/custom-tutorial/models/custom-tutorial.manifest';
1111
import { plainToClass } from 'class-transformer';
12+
import { winPathToNormalPath } from 'src/utils';
1213

1314
const MANIFEST_FILE = 'manifest.json';
1415
const SYS_MANIFEST_FILE = '_manifest.json';
@@ -75,7 +76,7 @@ export class CustomTutorialManifestProvider {
7576
label: name,
7677
type: CustomTutorialManifestType.InternalLink,
7778
args: {
78-
path: join(relativePath, entry),
79+
path: winPathToNormalPath(join(relativePath, entry)),
7980
},
8081
});
8182
}

redisinsight/api/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './analytics-helper';
88
export * from './redis-connection-helper';
99
export * from './class-transformer';
1010
export * from './file-helper';
11+
export * from './path';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { winPathToNormalPath } from 'src/utils';
2+
3+
const winPathToNormalPathTests: Record<string, any>[] = [
4+
{ input: '\\dir/file.js', output: '/dir/file.js' },
5+
{ input: '/dir/file.js', output: '/dir/file.js' },
6+
{ input: 'file.js', output: 'file.js' },
7+
{ input: '\\file.js', output: '/file.js' },
8+
{ input: '\\dir\\file.js', output: '/dir/file.js' },
9+
{ input: 'dir/file.js', output: 'dir/file.js' },
10+
];
11+
12+
describe('winPathToNormalPath', () => {
13+
winPathToNormalPathTests.forEach((test) => {
14+
it(`should be output: ${test.output} for input: ${JSON.stringify(test.input)}`, () => {
15+
const result = winPathToNormalPath(test.input);
16+
17+
expect(result).toEqual(test.output);
18+
});
19+
});
20+
});

redisinsight/api/src/utils/path.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const winPathToNormalPath = (path: string) => path.replace(/\\/g, '/');

redisinsight/ui/src/constants/mocks/mock-guides.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export const MOCK_GUIDES_ITEMS: IEnablementAreaItem[] = [
3030
args: {
3131
path: 'quick-guides/working-with-hash.html',
3232
},
33+
},
34+
{
35+
type: EnablementAreaComponent.InternalLink,
36+
id: 'working-with-hash-2',
37+
label: 'Working with HASH',
38+
args: {
39+
path: '\\quick-guides\\working-with-hash.html',
40+
},
3341
}
3442
]
3543
},

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/getFileInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const getMarkdownPathByManifest = (
9797
if (!manifestPath || !manifest) return pathPrefix
9898
const path = removeManifestPrefix(manifestPath)
9999
const pathToMarkDown = path.replaceAll('/', '.children.')
100-
const markDownPath = get(manifest, pathToMarkDown)?.args?.path
100+
const markDownPath = get(manifest, pathToMarkDown)?.args?.path?.replaceAll('\\', '/')
101101

102102
if (!markDownPath) return ''
103103

@@ -116,7 +116,7 @@ export const getMarkdownPathByManifest = (
116116
return undefined
117117
})
118118

119-
return pathPrefix + folderPath + (markDownPath.match(/^(\/|\\)/) ? markDownPath : '/'.concat(markDownPath))
119+
return pathPrefix + folderPath + (markDownPath.match(/^(\/)/) ? markDownPath : '/'.concat(markDownPath))
120120
}
121121

122122
export const removeManifestPrefix = (path?: string): string => path

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/tests/getFileInfo.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ const getMarkdownPathByManifestTests = [
147147
input: [MOCK_GUIDES_ITEMS, '/quick-guides/0/1'],
148148
expected: `/123123-123123${MOCK_GUIDES_ITEMS[0]?.children?.[1]?.args?.path}`
149149
},
150+
{
151+
input: [MOCK_GUIDES_ITEMS, '/quick-guides/0/3'],
152+
expected: '/quick-guides/working-with-hash.html'
153+
},
150154
]
151155

152-
describe('getWBSourcePath', () => {
156+
describe('getMarkdownPathByManifest', () => {
153157
test.each(getMarkdownPathByManifestTests)(
154158
'%j',
155159
({ input, expected }) => {

redisinsight/ui/src/utils/pathUtil.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ export const getRootStaticPath = (mdPath: string) => {
2020
}
2121

2222
const processAbsolutePath = (nodeUrl: string, mdPath: string) => {
23-
// todo: quick fix. find the root cause why path has both '/' and '\'
24-
const normalizedMdPath = mdPath.replaceAll('\\', '/')
25-
const tutorialRootPath = getRootStaticPath(normalizedMdPath)
26-
23+
const tutorialRootPath = getRootStaticPath(mdPath)
2724
return new URL(tutorialRootPath + nodeUrl, getOriginUrl()).toString()
2825
}
2926

0 commit comments

Comments
 (0)