Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3df36a8f
Commit
3df36a8f
authored
Apr 08, 2022
by
Jacques Erasmus
Committed by
David O'Regan
Apr 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scroll to line number
Fixes the scroll to line number bug in the blob viewer Changelog: fixed
parent
cbdfced2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
33 deletions
+21
-33
app/assets/javascripts/repository/components/blob_content_viewer.vue
...javascripts/repository/components/blob_content_viewer.vue
+2
-0
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
...ipts/vue_shared/components/blob_viewers/simple_viewer.vue
+4
-13
spec/frontend/repository/components/blob_content_viewer_spec.js
...rontend/repository/components/blob_content_viewer_spec.js
+15
-3
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
.../vue_shared/components/blob_viewers/simple_viewer_spec.js
+0
-17
No files found.
app/assets/javascripts/repository/components/blob_content_viewer.vue
View file @
3df36a8f
...
@@ -12,6 +12,7 @@ import { redirectTo } from '~/lib/utils/url_utility';
...
@@ -12,6 +12,7 @@ import { redirectTo } from '~/lib/utils/url_utility';
import
glFeatureFlagMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
glFeatureFlagMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
WebIdeLink
from
'
~/vue_shared/components/web_ide_link.vue
'
;
import
WebIdeLink
from
'
~/vue_shared/components/web_ide_link.vue
'
;
import
CodeIntelligence
from
'
~/code_navigation/components/app.vue
'
;
import
CodeIntelligence
from
'
~/code_navigation/components/app.vue
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
import
getRefMixin
from
'
../mixins/get_ref
'
;
import
getRefMixin
from
'
../mixins/get_ref
'
;
import
blobInfoQuery
from
'
../queries/blob_info.query.graphql
'
;
import
blobInfoQuery
from
'
../queries/blob_info.query.graphql
'
;
import
userInfoQuery
from
'
../queries/user_info.query.graphql
'
;
import
userInfoQuery
from
'
../queries/user_info.query.graphql
'
;
...
@@ -192,6 +193,7 @@ export default {
...
@@ -192,6 +193,7 @@ export default {
window
.
requestIdleCallback
(()
=>
{
window
.
requestIdleCallback
(()
=>
{
this
.
isRenderingLegacyTextViewer
=
false
;
this
.
isRenderingLegacyTextViewer
=
false
;
new
LineHighlighter
();
// eslint-disable-line no-new
});
});
}
else
{
}
else
{
this
.
legacyRichViewer
=
html
;
this
.
legacyRichViewer
=
html
;
...
...
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
View file @
3df36a8f
<
script
>
<
script
>
import
{
GlIcon
,
GlSafeHtmlDirective
}
from
'
@gitlab/ui
'
;
import
{
GlIcon
,
GlSafeHtmlDirective
}
from
'
@gitlab/ui
'
;
import
glFeatureFlagsMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
./constants
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
./constants
'
;
import
ViewerMixin
from
'
./mixins
'
;
import
ViewerMixin
from
'
./mixins
'
;
...
@@ -13,7 +11,7 @@ export default {
...
@@ -13,7 +11,7 @@ export default {
directives
:
{
directives
:
{
SafeHtml
:
GlSafeHtmlDirective
,
SafeHtml
:
GlSafeHtmlDirective
,
},
},
mixins
:
[
ViewerMixin
,
glFeatureFlagsMixin
()
],
mixins
:
[
ViewerMixin
],
inject
:
[
'
blobHash
'
],
inject
:
[
'
blobHash
'
],
data
()
{
data
()
{
return
{
return
{
...
@@ -21,21 +19,14 @@ export default {
...
@@ -21,21 +19,14 @@ export default {
};
};
},
},
computed
:
{
computed
:
{
refactorBlobViewerEnabled
()
{
return
this
.
glFeatures
.
refactorBlobViewer
;
},
lineNumbers
()
{
lineNumbers
()
{
return
this
.
content
.
split
(
'
\n
'
).
length
;
return
this
.
content
.
split
(
'
\n
'
).
length
;
},
},
},
},
mounted
()
{
mounted
()
{
if
(
this
.
refactorBlobViewerEnabled
)
{
const
{
hash
}
=
window
.
location
;
// This line will be removed once we start using highlight.js on the frontend (https://gitlab.com/groups/gitlab-org/-/epics/7146)
if
(
hash
)
{
new
LineHighlighter
();
// eslint-disable-line no-new
this
.
scrollToLine
(
hash
,
true
);
}
else
{
const
{
hash
}
=
window
.
location
;
if
(
hash
)
this
.
scrollToLine
(
hash
,
true
);
}
}
},
},
methods
:
{
methods
:
{
...
...
spec/frontend/repository/components/blob_content_viewer_spec.js
View file @
3df36a8f
...
@@ -25,6 +25,7 @@ import { redirectTo } from '~/lib/utils/url_utility';
...
@@ -25,6 +25,7 @@ import { redirectTo } from '~/lib/utils/url_utility';
import
{
isLoggedIn
}
from
'
~/lib/utils/common_utils
'
;
import
{
isLoggedIn
}
from
'
~/lib/utils/common_utils
'
;
import
{
extendedWrapper
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
extendedWrapper
}
from
'
helpers/vue_test_utils_helper
'
;
import
httpStatusCodes
from
'
~/lib/utils/http_status
'
;
import
httpStatusCodes
from
'
~/lib/utils/http_status
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
import
{
import
{
simpleViewerMock
,
simpleViewerMock
,
richViewerMock
,
richViewerMock
,
...
@@ -39,6 +40,7 @@ import {
...
@@ -39,6 +40,7 @@ import {
jest
.
mock
(
'
~/repository/components/blob_viewers
'
);
jest
.
mock
(
'
~/repository/components/blob_viewers
'
);
jest
.
mock
(
'
~/lib/utils/url_utility
'
);
jest
.
mock
(
'
~/lib/utils/url_utility
'
);
jest
.
mock
(
'
~/lib/utils/common_utils
'
);
jest
.
mock
(
'
~/lib/utils/common_utils
'
);
jest
.
mock
(
'
~/blob/line_highlighter
'
);
let
wrapper
;
let
wrapper
;
let
mockResolver
;
let
mockResolver
;
...
@@ -173,20 +175,30 @@ describe('Blob content viewer component', () => {
...
@@ -173,20 +175,30 @@ describe('Blob content viewer component', () => {
});
});
describe
(
'
legacy viewers
'
,
()
=>
{
describe
(
'
legacy viewers
'
,
()
=>
{
const
legacyViewerUrl
=
'
some_file.js?format=json&viewer=simple
'
;
const
fileType
=
'
text
'
;
const
highlightJs
=
false
;
it
(
'
loads a legacy viewer when a the fileType is text and the highlightJs feature is turned off
'
,
async
()
=>
{
it
(
'
loads a legacy viewer when a the fileType is text and the highlightJs feature is turned off
'
,
async
()
=>
{
await
createComponent
({
await
createComponent
({
blob
:
{
...
simpleViewerMock
,
fileType
:
'
text
'
,
highlightJs
:
false
},
blob
:
{
...
simpleViewerMock
,
fileType
,
highlightJs
},
});
});
expect
(
mockAxios
.
history
.
get
).
toHaveLength
(
1
);
expect
(
mockAxios
.
history
.
get
).
toHaveLength
(
1
);
expect
(
mockAxios
.
history
.
get
[
0
].
url
).
to
Equal
(
'
some_file.js?format=json&viewer=simple
'
);
expect
(
mockAxios
.
history
.
get
[
0
].
url
).
to
Be
(
legacyViewerUrl
);
});
});
it
(
'
loads a legacy viewer when a viewer component is not available
'
,
async
()
=>
{
it
(
'
loads a legacy viewer when a viewer component is not available
'
,
async
()
=>
{
await
createComponent
({
blob
:
{
...
simpleViewerMock
,
fileType
:
'
unknown
'
}
});
await
createComponent
({
blob
:
{
...
simpleViewerMock
,
fileType
:
'
unknown
'
}
});
expect
(
mockAxios
.
history
.
get
).
toHaveLength
(
1
);
expect
(
mockAxios
.
history
.
get
).
toHaveLength
(
1
);
expect
(
mockAxios
.
history
.
get
[
0
].
url
).
toEqual
(
'
some_file.js?format=json&viewer=simple
'
);
expect
(
mockAxios
.
history
.
get
[
0
].
url
).
toBe
(
legacyViewerUrl
);
});
it
(
'
loads the LineHighlighter
'
,
async
()
=>
{
mockAxios
.
onGet
(
legacyViewerUrl
).
replyOnce
(
httpStatusCodes
.
OK
,
'
test
'
);
await
createComponent
({
blob
:
{
...
simpleViewerMock
,
fileType
,
highlightJs
}
});
expect
(
LineHighlighter
).
toHaveBeenCalled
();
});
});
});
});
});
});
...
...
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
View file @
3df36a8f
...
@@ -2,9 +2,6 @@ import { shallowMount } from '@vue/test-utils';
...
@@ -2,9 +2,6 @@ import { shallowMount } from '@vue/test-utils';
import
{
nextTick
}
from
'
vue
'
;
import
{
nextTick
}
from
'
vue
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
~/vue_shared/components/blob_viewers/constants
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
~/vue_shared/components/blob_viewers/constants
'
;
import
SimpleViewer
from
'
~/vue_shared/components/blob_viewers/simple_viewer.vue
'
;
import
SimpleViewer
from
'
~/vue_shared/components/blob_viewers/simple_viewer.vue
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
jest
.
mock
(
'
~/blob/line_highlighter
'
);
describe
(
'
Blob Simple Viewer component
'
,
()
=>
{
describe
(
'
Blob Simple Viewer component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
...
@@ -30,20 +27,6 @@ describe('Blob Simple Viewer component', () => {
...
@@ -30,20 +27,6 @@ describe('Blob Simple Viewer component', () => {
wrapper
.
destroy
();
wrapper
.
destroy
();
});
});
describe
(
'
refactorBlobViewer feature flag
'
,
()
=>
{
it
(
'
loads the LineHighlighter if refactorBlobViewer is enabled
'
,
()
=>
{
createComponent
(
''
,
false
,
{
refactorBlobViewer
:
true
});
expect
(
LineHighlighter
).
toHaveBeenCalled
();
});
it
(
'
does not load the LineHighlighter if refactorBlobViewer is disabled
'
,
()
=>
{
createComponent
(
''
,
false
,
{
refactorBlobViewer
:
false
});
expect
(
LineHighlighter
).
not
.
toHaveBeenCalled
();
});
});
it
(
'
does not fail if content is empty
'
,
()
=>
{
it
(
'
does not fail if content is empty
'
,
()
=>
{
const
spy
=
jest
.
spyOn
(
window
.
console
,
'
error
'
);
const
spy
=
jest
.
spyOn
(
window
.
console
,
'
error
'
);
createComponent
(
''
);
createComponent
(
''
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment