Commit e1a023fb authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'add-lfs-badge' into 'master'

Blob refactor: Display LFS badge when LFS enabled

See merge request gitlab-org/gitlab!77165
parents 3069afa2 54b2e46f
<script> <script>
import { GlBadge } from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
...@@ -7,6 +8,7 @@ export default { ...@@ -7,6 +8,7 @@ export default {
components: { components: {
FileIcon, FileIcon,
ClipboardButton, ClipboardButton,
GlBadge,
}, },
props: { props: {
blob: { blob: {
...@@ -21,6 +23,9 @@ export default { ...@@ -21,6 +23,9 @@ export default {
gfmCopyText() { gfmCopyText() {
return `\`${this.blob.path}\``; return `\`${this.blob.path}\``;
}, },
showLfsBadge() {
return this.blob.storedExternally && this.blob.externalStorage === 'lfs';
},
}, },
}; };
</script> </script>
...@@ -37,8 +42,6 @@ export default { ...@@ -37,8 +42,6 @@ export default {
> >
</template> </template>
<small class="mr-2">{{ blobSize }}</small>
<clipboard-button <clipboard-button
:text="blob.path" :text="blob.path"
:gfm="gfmCopyText" :gfm="gfmCopyText"
...@@ -46,5 +49,9 @@ export default { ...@@ -46,5 +49,9 @@ export default {
category="tertiary" category="tertiary"
css-class="btn-clipboard btn-transparent lh-100 position-static" css-class="btn-clipboard btn-transparent lh-100 position-static"
/> />
<small class="mr-2">{{ blobSize }}</small>
<gl-badge v-if="showLfsBadge">{{ __('LFS') }}</gl-badge>
</div> </div>
</template> </template>
...@@ -105,6 +105,7 @@ export default { ...@@ -105,6 +105,7 @@ export default {
forkAndEditPath: '', forkAndEditPath: '',
ideForkAndEditPath: '', ideForkAndEditPath: '',
storedExternally: false, storedExternally: false,
externalStorage: '',
canModifyBlob: false, canModifyBlob: false,
canCurrentUserPushToBranch: false, canCurrentUserPushToBranch: false,
rawPath: '', rawPath: '',
......
...@@ -36,6 +36,7 @@ query getBlobInfo($projectPath: ID!, $filePath: String!, $ref: String!) { ...@@ -36,6 +36,7 @@ query getBlobInfo($projectPath: ID!, $filePath: String!, $ref: String!) {
canModifyBlob canModifyBlob
canCurrentUserPushToBranch canCurrentUserPushToBranch
storedExternally storedExternally
externalStorage
rawPath rawPath
replacePath replacePath
pipelineEditorPath pipelineEditorPath
......
...@@ -56,6 +56,9 @@ module Types ...@@ -56,6 +56,9 @@ module Types
field :stored_externally, GraphQL::Types::Boolean, null: true, method: :stored_externally?, field :stored_externally, GraphQL::Types::Boolean, null: true, method: :stored_externally?,
description: "Whether the blob's content is stored externally (for instance, in LFS)." description: "Whether the blob's content is stored externally (for instance, in LFS)."
field :external_storage, GraphQL::Types::String, null: true, method: :external_storage,
description: "External storage being used, if enabled (for instance, 'LFS')."
field :edit_blob_path, GraphQL::Types::String, null: true, field :edit_blob_path, GraphQL::Types::String, null: true,
description: 'Web path to edit the blob in the old-style editor.' description: 'Web path to edit the blob in the old-style editor.'
......
...@@ -14325,6 +14325,7 @@ Returns [`Tree`](#tree). ...@@ -14325,6 +14325,7 @@ Returns [`Tree`](#tree).
| <a id="repositoryblobcanmodifyblob"></a>`canModifyBlob` | [`Boolean`](#boolean) | Whether the current user can modify the blob. | | <a id="repositoryblobcanmodifyblob"></a>`canModifyBlob` | [`Boolean`](#boolean) | Whether the current user can modify the blob. |
| <a id="repositoryblobcodeowners"></a>`codeOwners` | [`[UserCore!]`](#usercore) | List of code owners for the blob. | | <a id="repositoryblobcodeowners"></a>`codeOwners` | [`[UserCore!]`](#usercore) | List of code owners for the blob. |
| <a id="repositoryblobeditblobpath"></a>`editBlobPath` | [`String`](#string) | Web path to edit the blob in the old-style editor. | | <a id="repositoryblobeditblobpath"></a>`editBlobPath` | [`String`](#string) | Web path to edit the blob in the old-style editor. |
| <a id="repositoryblobexternalstorage"></a>`externalStorage` | [`String`](#string) | External storage being used, if enabled (for instance, 'LFS'). |
| <a id="repositoryblobexternalstorageurl"></a>`externalStorageUrl` | [`String`](#string) | Web path to download the raw blob via external storage, if enabled. | | <a id="repositoryblobexternalstorageurl"></a>`externalStorageUrl` | [`String`](#string) | Web path to download the raw blob via external storage, if enabled. |
| <a id="repositoryblobfiletype"></a>`fileType` | [`String`](#string) | Expected format of the blob based on the extension. | | <a id="repositoryblobfiletype"></a>`fileType` | [`String`](#string) | Expected format of the blob based on the extension. |
| <a id="repositoryblobforkandeditpath"></a>`forkAndEditPath` | [`String`](#string) | Web path to edit this blob using a forked project. | | <a id="repositoryblobforkandeditpath"></a>`forkAndEditPath` | [`String`](#string) | Web path to edit this blob using a forked project. |
...@@ -20,12 +20,6 @@ exports[`Blob Header Filepath rendering matches the snapshot 1`] = ` ...@@ -20,12 +20,6 @@ exports[`Blob Header Filepath rendering matches the snapshot 1`] = `
foo/bar/dummy.md foo/bar/dummy.md
</strong> </strong>
<small
class="mr-2"
>
a lot
</small>
<clipboard-button-stub <clipboard-button-stub
category="tertiary" category="tertiary"
cssclass="btn-clipboard btn-transparent lh-100 position-static" cssclass="btn-clipboard btn-transparent lh-100 position-static"
...@@ -36,5 +30,13 @@ exports[`Blob Header Filepath rendering matches the snapshot 1`] = ` ...@@ -36,5 +30,13 @@ exports[`Blob Header Filepath rendering matches the snapshot 1`] = `
tooltipplacement="top" tooltipplacement="top"
variant="default" variant="default"
/> />
<small
class="mr-2"
>
a lot
</small>
<!---->
</div> </div>
`; `;
import { GlBadge } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import BlobHeaderFilepath from '~/blob/components/blob_header_filepath.vue'; import BlobHeaderFilepath from '~/blob/components/blob_header_filepath.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
...@@ -24,6 +25,8 @@ describe('Blob Header Filepath', () => { ...@@ -24,6 +25,8 @@ describe('Blob Header Filepath', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findBadge = () => wrapper.find(GlBadge);
describe('rendering', () => { describe('rendering', () => {
it('matches the snapshot', () => { it('matches the snapshot', () => {
createComponent(); createComponent();
...@@ -54,6 +57,11 @@ describe('Blob Header Filepath', () => { ...@@ -54,6 +57,11 @@ describe('Blob Header Filepath', () => {
expect(wrapper.vm.blobSize).toBe('a lot'); expect(wrapper.vm.blobSize).toBe('a lot');
}); });
it('renders LFS badge if LFS if enabled', () => {
createComponent({ storedExternally: true, externalStorage: 'lfs' });
expect(findBadge().text()).toBe('LFS');
});
it('renders a slot and prepends its contents to the existing one', () => { it('renders a slot and prepends its contents to the existing one', () => {
const slotContent = 'Foo Bar'; const slotContent = 'Foo Bar';
createComponent( createComponent(
......
...@@ -14,6 +14,7 @@ export const simpleViewerMock = { ...@@ -14,6 +14,7 @@ export const simpleViewerMock = {
canModifyBlob: true, canModifyBlob: true,
canCurrentUserPushToBranch: true, canCurrentUserPushToBranch: true,
storedExternally: false, storedExternally: false,
externalStorage: 'lfs',
rawPath: 'some_file.js', rawPath: 'some_file.js',
replacePath: 'some_file.js/replace', replacePath: 'some_file.js/replace',
pipelineEditorPath: '', pipelineEditorPath: '',
......
...@@ -21,6 +21,7 @@ RSpec.describe Types::Repository::BlobType do ...@@ -21,6 +21,7 @@ RSpec.describe Types::Repository::BlobType do
:file_type, :file_type,
:edit_blob_path, :edit_blob_path,
:stored_externally, :stored_externally,
:external_storage,
:raw_path, :raw_path,
:replace_path, :replace_path,
:pipeline_editor_path, :pipeline_editor_path,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment