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
ae39be9a
Commit
ae39be9a
authored
Feb 28, 2022
by
Jose Eduardo Kimura Reis
Committed by
Jacques Erasmus
Feb 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove extra padding and gray bg from csv viewer
Fix smaller code format issues
parent
57c22b27
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
131 additions
and
9 deletions
+131
-9
app/assets/javascripts/blob/components/blob_header.vue
app/assets/javascripts/blob/components/blob_header.vue
+4
-1
app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue
...vascripts/blob/components/blob_header_viewer_switcher.vue
+6
-1
app/assets/javascripts/blob/csv/csv_viewer.vue
app/assets/javascripts/blob/csv/csv_viewer.vue
+26
-6
app/assets/javascripts/repository/components/blob_viewers/csv_viewer.vue
...scripts/repository/components/blob_viewers/csv_viewer.vue
+26
-0
app/assets/javascripts/repository/components/blob_viewers/index.js
...s/javascripts/repository/components/blob_viewers/index.js
+1
-0
spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap
...nd/blob/components/__snapshots__/blob_header_spec.js.snap
+1
-0
spec/frontend/blob/components/blob_header_spec.js
spec/frontend/blob/components/blob_header_spec.js
+15
-0
spec/frontend/blob/csv/csv_viewer_spec.js
spec/frontend/blob/csv/csv_viewer_spec.js
+25
-1
spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js
...end/repository/components/blob_viewers/csv_viewer_spec.js
+27
-0
No files found.
app/assets/javascripts/blob/components/blob_header.vue
View file @
ae39be9a
...
...
@@ -63,6 +63,9 @@ export default {
isEmpty
()
{
return
this
.
blob
.
rawSize
===
0
;
},
blobSwitcherDocIcon
()
{
return
this
.
blob
.
richViewer
?.
fileType
===
'
csv
'
?
'
table
'
:
'
document
'
;
},
},
watch
:
{
viewer
(
newVal
,
oldVal
)
{
...
...
@@ -90,7 +93,7 @@ export default {
</div>
<div
class=
"gl-sm-display-flex file-actions"
>
<viewer-switcher
v-if=
"showViewerSwitcher"
v-model=
"viewer"
/>
<viewer-switcher
v-if=
"showViewerSwitcher"
v-model=
"viewer"
:doc-icon=
"blobSwitcherDocIcon"
/>
<slot
name=
"actions"
></slot>
...
...
app/assets/javascripts/blob/components/blob_header_viewer_switcher.vue
View file @
ae39be9a
...
...
@@ -21,6 +21,11 @@ export default {
default
:
SIMPLE_BLOB_VIEWER
,
required
:
false
,
},
docIcon
:
{
type
:
String
,
default
:
'
document
'
,
required
:
false
,
},
},
computed
:
{
isSimpleViewer
()
{
...
...
@@ -62,7 +67,7 @@ export default {
:aria-label=
"$options.RICH_BLOB_VIEWER_TITLE"
:title=
"$options.RICH_BLOB_VIEWER_TITLE"
:selected=
"isRichViewer"
icon=
"document
"
:icon=
"docIcon
"
category=
"primary"
variant=
"default"
class=
"js-blob-viewer-switch-btn"
...
...
app/assets/javascripts/blob/csv/csv_viewer.vue
View file @
ae39be9a
...
...
@@ -14,6 +14,11 @@ export default {
type
:
String
,
required
:
true
,
},
remoteFile
:
{
type
:
Boolean
,
required
:
false
,
default
:
false
,
},
},
data
()
{
return
{
...
...
@@ -23,14 +28,29 @@ export default {
};
},
mounted
()
{
const
parsed
=
Papa
.
parse
(
this
.
csv
,
{
skipEmptyLines
:
true
});
this
.
items
=
parsed
.
data
;
if
(
parsed
.
errors
.
length
)
{
this
.
papaParseErrors
=
parsed
.
errors
;
if
(
!
this
.
remoteFile
)
{
const
parsed
=
Papa
.
parse
(
this
.
csv
,
{
skipEmptyLines
:
true
});
this
.
handleParsedData
(
parsed
);
}
else
{
Papa
.
parse
(
this
.
csv
,
{
download
:
true
,
skipEmptyLines
:
true
,
complete
:
(
parsed
)
=>
{
this
.
handleParsedData
(
parsed
);
},
});
}
},
methods
:
{
handleParsedData
(
parsed
)
{
this
.
items
=
parsed
.
data
;
this
.
loading
=
false
;
if
(
parsed
.
errors
.
length
)
{
this
.
papaParseErrors
=
parsed
.
errors
;
}
this
.
loading
=
false
;
},
},
};
</
script
>
...
...
app/assets/javascripts/repository/components/blob_viewers/csv_viewer.vue
0 → 100644
View file @
ae39be9a
<
script
>
import
CsvViewer
from
'
~/blob/csv/csv_viewer.vue
'
;
export
default
{
components
:
{
CsvViewer
,
},
props
:
{
blob
:
{
type
:
Object
,
required
:
true
,
},
},
data
()
{
return
{
url
:
this
.
blob
.
rawPath
,
};
},
};
</
script
>
<
template
>
<div>
<csv-viewer
:csv=
"url"
remote-file
data-testid=
"csv"
/>
</div>
</
template
>
app/assets/javascripts/repository/components/blob_viewers/index.js
View file @
ae39be9a
const
viewers
=
{
csv
:
()
=>
import
(
'
./csv_viewer.vue
'
),
download
:
()
=>
import
(
'
./download_viewer.vue
'
),
image
:
()
=>
import
(
'
./image_viewer.vue
'
),
video
:
()
=>
import
(
'
./video_viewer.vue
'
),
...
...
spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap
View file @
ae39be9a
...
...
@@ -21,6 +21,7 @@ exports[`Blob Header Default Actions rendering matches the snapshot 1`] = `
class="gl-sm-display-flex file-actions"
>
<viewer-switcher-stub
docicon="document"
value="simple"
/>
...
...
spec/frontend/blob/components/blob_header_spec.js
View file @
ae39be9a
...
...
@@ -159,5 +159,20 @@ describe('Blob Header Default Actions', () => {
await
nextTick
();
expect
(
wrapper
.
vm
.
$emit
).
not
.
toHaveBeenCalled
();
});
it
(
'
sets different icons depending on the blob file type
'
,
async
()
=>
{
factory
();
expect
(
wrapper
.
vm
.
blobSwitcherDocIcon
).
toBe
(
'
document
'
);
await
wrapper
.
setProps
({
blob
:
{
...
Blob
,
richViewer
:
{
...
Blob
.
richViewer
,
fileType
:
'
csv
'
,
},
},
});
expect
(
wrapper
.
vm
.
blobSwitcherDocIcon
).
toBe
(
'
table
'
);
});
});
});
spec/frontend/blob/csv/csv_viewer_spec.js
View file @
ae39be9a
...
...
@@ -2,6 +2,7 @@ import { GlLoadingIcon, GlTable } from '@gitlab/ui';
import
{
getAllByRole
}
from
'
@testing-library/dom
'
;
import
{
shallowMount
,
mount
}
from
'
@vue/test-utils
'
;
import
{
nextTick
}
from
'
vue
'
;
import
Papa
from
'
papaparse
'
;
import
CsvViewer
from
'
~/blob/csv/csv_viewer.vue
'
;
import
PapaParseAlert
from
'
~/vue_shared/components/papa_parse_alert.vue
'
;
...
...
@@ -11,10 +12,15 @@ const brokenCsv = '{\n "json": 1,\n "key": [1, 2, 3]\n}';
describe
(
'
app/assets/javascripts/blob/csv/csv_viewer.vue
'
,
()
=>
{
let
wrapper
;
const
createComponent
=
({
csv
=
validCsv
,
mountFunction
=
shallowMount
}
=
{})
=>
{
const
createComponent
=
({
csv
=
validCsv
,
remoteFile
=
false
,
mountFunction
=
shallowMount
,
}
=
{})
=>
{
wrapper
=
mountFunction
(
CsvViewer
,
{
propsData
:
{
csv
,
remoteFile
,
},
});
};
...
...
@@ -73,4 +79,22 @@ describe('app/assets/javascripts/blob/csv/csv_viewer.vue', () => {
expect
(
getAllByRole
(
wrapper
.
element
,
'
row
'
,
{
name
:
/Three/i
})).
toHaveLength
(
1
);
});
});
describe
(
'
when csv prop is path and indicates a remote file
'
,
()
=>
{
it
(
'
should render call parse with download flag true
'
,
async
()
=>
{
const
path
=
'
path/to/remote/file.csv
'
;
jest
.
spyOn
(
Papa
,
'
parse
'
).
mockImplementation
((
_
,
{
complete
})
=>
{
complete
({
data
:
validCsv
.
split
(
'
,
'
),
errors
:
[]
});
});
createComponent
({
csv
:
path
,
remoteFile
:
true
});
expect
(
Papa
.
parse
).
toHaveBeenCalledWith
(
path
,
{
download
:
true
,
skipEmptyLines
:
true
,
complete
:
expect
.
any
(
Function
),
});
await
nextTick
;
expect
(
wrapper
.
vm
.
items
).
toEqual
(
validCsv
.
split
(
'
,
'
));
});
});
});
spec/frontend/repository/components/blob_viewers/csv_viewer_spec.js
0 → 100644
View file @
ae39be9a
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
CsvViewer
from
'
~/repository/components/blob_viewers/csv_viewer.vue
'
;
describe
(
'
CSV Viewer
'
,
()
=>
{
let
wrapper
;
const
DEFAULT_BLOB_DATA
=
{
rawPath
:
'
some/file.csv
'
,
name
:
'
file.csv
'
,
};
const
createComponent
=
()
=>
{
wrapper
=
shallowMount
(
CsvViewer
,
{
propsData
:
{
blob
:
DEFAULT_BLOB_DATA
},
stubs
:
[
'
CsvViewer
'
],
});
};
const
findCsvViewerComp
=
()
=>
wrapper
.
find
(
'
[data-testid="csv"]
'
);
it
(
'
renders a Source Editor component
'
,
()
=>
{
createComponent
();
expect
(
findCsvViewerComp
().
exists
()).
toBe
(
true
);
expect
(
findCsvViewerComp
().
props
(
'
remoteFile
'
)).
toBeTruthy
();
expect
(
findCsvViewerComp
().
props
(
'
csv
'
)).
toBe
(
DEFAULT_BLOB_DATA
.
rawPath
);
});
});
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