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
996b7968
Commit
996b7968
authored
Jul 05, 2021
by
Jacques Erasmus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create text viewer
Created a text blob viewer
parent
1c9a3538
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
8 deletions
+87
-8
app/assets/javascripts/repository/components/blob_content_viewer.vue
...javascripts/repository/components/blob_content_viewer.vue
+9
-5
app/assets/javascripts/repository/components/blob_viewers/index.js
...s/javascripts/repository/components/blob_viewers/index.js
+11
-2
app/assets/javascripts/repository/components/blob_viewers/text_viewer.vue
...cripts/repository/components/blob_viewers/text_viewer.vue
+25
-0
spec/frontend/repository/components/blob_content_viewer_spec.js
...rontend/repository/components/blob_content_viewer_spec.js
+12
-1
spec/frontend/repository/components/blob_viewers/text_viewer_spec.js
...nd/repository/components/blob_viewers/text_viewer_spec.js
+30
-0
No files found.
app/assets/javascripts/repository/components/blob_content_viewer.vue
View file @
996b7968
...
...
@@ -11,7 +11,7 @@ import { __ } from '~/locale';
import
blobInfoQuery
from
'
../queries/blob_info.query.graphql
'
;
import
BlobButtonGroup
from
'
./blob_button_group.vue
'
;
import
BlobEdit
from
'
./blob_edit.vue
'
;
import
{
loadViewer
}
from
'
./blob_viewers
'
;
import
{
loadViewer
,
viewerProps
}
from
'
./blob_viewers
'
;
export
default
{
components
:
{
...
...
@@ -31,12 +31,12 @@ export default {
};
},
result
()
{
if
(
this
.
hasRichViewer
&&
!
this
.
blobViewer
)
{
this
.
loadLegacyViewer
();
}
this
.
switchViewer
(
this
.
hasRichViewer
&&
!
window
.
location
.
hash
?
RICH_BLOB_VIEWER
:
SIMPLE_BLOB_VIEWER
,
);
if
(
this
.
hasRichViewer
&&
!
this
.
blobViewer
)
{
this
.
loadLegacyViewer
();
}
},
error
()
{
this
.
displayError
();
...
...
@@ -123,6 +123,10 @@ export default {
const
{
fileType
}
=
this
.
viewer
;
return
loadViewer
(
fileType
);
},
viewerProps
()
{
const
{
fileType
}
=
this
.
viewer
;
return
viewerProps
(
fileType
,
this
.
blobInfo
);
},
},
methods
:
{
loadLegacyViewer
()
{
...
...
@@ -181,7 +185,7 @@ export default {
:active-viewer=
"viewer"
:loading=
"false"
/>
<component
:is=
"blobViewer"
v-else
class=
"blob-viewer"
/>
<component
:is=
"blobViewer"
v-else
v-bind=
"viewerProps"
class=
"blob-viewer"
/>
</div>
</div>
</template>
app/assets/javascripts/repository/components/blob_viewers/index.js
View file @
996b7968
...
...
@@ -4,8 +4,7 @@ export const loadViewer = (type) => {
// TODO (follow-up): import the empty viewer
return
null
;
// () => import(/* webpackChunkName: 'blob_empty_viewer' */ './empty_viewer.vue');
case
'
text
'
:
// TODO (follow-up): import the text viewer
return
null
;
// () => import(/* webpackChunkName: 'blob_text_viewer' */ './text_viewer.vue');
return
()
=>
import
(
/* webpackChunkName: 'blob_text_viewer' */
'
./text_viewer.vue
'
);
case
'
download
'
:
// TODO (follow-up): import the download viewer
return
null
;
// () => import(/* webpackChunkName: 'blob_download_viewer' */ './download_viewer.vue');
...
...
@@ -13,3 +12,13 @@ export const loadViewer = (type) => {
return
null
;
}
};
export
const
viewerProps
=
(
type
,
blob
)
=>
{
return
{
text
:
{
content
:
blob
.
rawTextBlob
,
fileName
:
blob
.
name
,
readOnly
:
true
,
},
}[
type
];
};
app/assets/javascripts/repository/components/blob_viewers/text_viewer.vue
0 → 100644
View file @
996b7968
<
script
>
export
default
{
components
:
{
SourceEditor
:
()
=>
import
(
/* webpackChunkName: 'SourceEditor' */
'
~/vue_shared/components/source_editor.vue
'
),
},
props
:
{
content
:
{
type
:
String
,
required
:
true
,
},
fileName
:
{
type
:
String
,
required
:
true
,
},
readOnly
:
{
type
:
Boolean
,
required
:
true
,
},
},
};
</
script
>
<
template
>
<source-editor
:value=
"content"
:file-name=
"fileName"
:editor-options=
"
{ readOnly }" />
</
template
>
spec/frontend/repository/components/blob_content_viewer_spec.js
View file @
996b7968
...
...
@@ -11,7 +11,8 @@ import BlobHeader from '~/blob/components/blob_header.vue';
import
BlobButtonGroup
from
'
~/repository/components/blob_button_group.vue
'
;
import
BlobContentViewer
from
'
~/repository/components/blob_content_viewer.vue
'
;
import
BlobEdit
from
'
~/repository/components/blob_edit.vue
'
;
import
{
loadViewer
}
from
'
~/repository/components/blob_viewers
'
;
import
{
loadViewer
,
viewerProps
}
from
'
~/repository/components/blob_viewers
'
;
import
TextViewer
from
'
~/repository/components/blob_viewers/text_viewer.vue
'
;
import
blobInfoQuery
from
'
~/repository/queries/blob_info.query.graphql
'
;
jest
.
mock
(
'
~/repository/components/blob_viewers
'
);
...
...
@@ -113,6 +114,7 @@ describe('Blob content viewer component', () => {
const
findBlobEdit
=
()
=>
wrapper
.
findComponent
(
BlobEdit
);
const
findBlobContent
=
()
=>
wrapper
.
findComponent
(
BlobContent
);
const
findBlobButtonGroup
=
()
=>
wrapper
.
findComponent
(
BlobButtonGroup
);
const
findTextViewer
=
()
=>
wrapper
.
findComponent
(
TextViewer
);
afterEach
(()
=>
{
wrapper
.
destroy
();
...
...
@@ -222,6 +224,15 @@ describe('Blob content viewer component', () => {
expect
(
findBlobContent
().
exists
()).
toBe
(
false
);
});
it
(
'
renders a TextViewer for text files
'
,
()
=>
{
loadViewer
.
mockReturnValueOnce
(
TextViewer
);
viewerProps
.
mockReturnValueOnce
({
content
:
'
test
'
,
fileName
:
'
test.js
'
,
readOnly
:
true
});
factory
({
mockData
:
{
blobInfo
:
simpleMockData
}
});
expect
(
findTextViewer
().
exists
()).
toBe
(
true
);
});
});
describe
(
'
BlobHeader action slot
'
,
()
=>
{
...
...
spec/frontend/repository/components/blob_viewers/text_viewer_spec.js
0 → 100644
View file @
996b7968
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
TextViewer
from
'
~/repository/components/blob_viewers/text_viewer.vue
'
;
import
SourceEditor
from
'
~/vue_shared/components/source_editor.vue
'
;
describe
(
'
Text Viewer
'
,
()
=>
{
let
wrapper
;
const
propsData
=
{
content
:
'
Some content
'
,
fileName
:
'
file_name.js
'
,
readOnly
:
true
,
};
const
createComponent
=
()
=>
{
wrapper
=
shallowMount
(
TextViewer
,
{
propsData
});
};
const
findEditor
=
()
=>
wrapper
.
findComponent
(
SourceEditor
);
it
(
'
renders a Source Editor component
'
,
async
()
=>
{
createComponent
();
await
waitForPromises
();
expect
(
findEditor
().
exists
()).
toBe
(
true
);
expect
(
findEditor
().
props
(
'
value
'
)).
toBe
(
propsData
.
content
);
expect
(
findEditor
().
props
(
'
fileName
'
)).
toBe
(
propsData
.
fileName
);
expect
(
findEditor
().
props
(
'
editorOptions
'
)).
toEqual
({
readOnly
:
propsData
.
readOnly
});
});
});
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