Commit 9e20cb38 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch '349953-redirect-to-blob' into 'master'

Redirect to view blob page after replace/delete

See merge request gitlab-org/gitlab!81145
parents 41da2c3d b2701540
...@@ -7,6 +7,8 @@ import getRefMixin from '../mixins/get_ref'; ...@@ -7,6 +7,8 @@ import getRefMixin from '../mixins/get_ref';
import DeleteBlobModal from './delete_blob_modal.vue'; import DeleteBlobModal from './delete_blob_modal.vue';
import UploadBlobModal from './upload_blob_modal.vue'; import UploadBlobModal from './upload_blob_modal.vue';
const REPLACE_BLOB_MODAL_ID = 'modal-replace-blob';
export default { export default {
i18n: { i18n: {
replace: __('Replace'), replace: __('Replace'),
...@@ -76,9 +78,6 @@ export default { ...@@ -76,9 +78,6 @@ export default {
}, },
}, },
computed: { computed: {
replaceModalId() {
return uniqueId('replace-modal');
},
replaceModalTitle() { replaceModalTitle() {
return sprintf(__('Replace %{name}'), { name: this.name }); return sprintf(__('Replace %{name}'), { name: this.name });
}, },
...@@ -95,13 +94,14 @@ export default { ...@@ -95,13 +94,14 @@ export default {
methods: { methods: {
showModal(modalId) { showModal(modalId) {
if (this.showForkSuggestion) { if (this.showForkSuggestion) {
this.$emit('fork'); this.$emit('fork', 'view');
return; return;
} }
this.$refs[modalId].show(); this.$refs[modalId].show();
}, },
}, },
replaceBlobModalId: REPLACE_BLOB_MODAL_ID,
}; };
</script> </script>
...@@ -118,7 +118,7 @@ export default { ...@@ -118,7 +118,7 @@ export default {
data-testid="lock" data-testid="lock"
:data-qa-selector="lockBtnQASelector" :data-qa-selector="lockBtnQASelector"
/> />
<gl-button data-testid="replace" @click="showModal(replaceModalId)"> <gl-button data-testid="replace" @click="showModal($options.replaceBlobModalId)">
{{ $options.i18n.replace }} {{ $options.i18n.replace }}
</gl-button> </gl-button>
<gl-button data-testid="delete" @click="showModal(deleteModalId)"> <gl-button data-testid="delete" @click="showModal(deleteModalId)">
...@@ -126,8 +126,8 @@ export default { ...@@ -126,8 +126,8 @@ export default {
</gl-button> </gl-button>
</gl-button-group> </gl-button-group>
<upload-blob-modal <upload-blob-modal
:ref="replaceModalId" :ref="$options.replaceBlobModalId"
:modal-id="replaceModalId" :modal-id="$options.replaceBlobModalId"
:modal-title="replaceModalTitle" :modal-title="replaceModalTitle"
:commit-message="replaceModalTitle" :commit-message="replaceModalTitle"
:target-branch="targetBranch || ref" :target-branch="targetBranch || ref"
......
...@@ -142,9 +142,13 @@ export default { ...@@ -142,9 +142,13 @@ export default {
return this.isLoggedIn && !canModifyBlob && createMergeRequestIn && forkProject; return this.isLoggedIn && !canModifyBlob && createMergeRequestIn && forkProject;
}, },
forkPath() { forkPath() {
return this.forkTarget === 'ide' const forkPaths = {
? this.blobInfo.ideForkAndEditPath ide: this.blobInfo.ideForkAndEditPath,
: this.blobInfo.forkAndEditPath; simple: this.blobInfo.forkAndEditPath,
view: this.blobInfo.forkAndViewPath,
};
return forkPaths[this.forkTarget];
}, },
isUsingLfs() { isUsingLfs() {
return this.blobInfo.storedExternally && this.blobInfo.externalStorage === LFS_STORAGE; return this.blobInfo.storedExternally && this.blobInfo.externalStorage === LFS_STORAGE;
...@@ -249,7 +253,7 @@ export default { ...@@ -249,7 +253,7 @@ export default {
:is-locked="Boolean(pathLockedByUser)" :is-locked="Boolean(pathLockedByUser)"
:can-lock="canLock" :can-lock="canLock"
:show-fork-suggestion="showForkSuggestion" :show-fork-suggestion="showForkSuggestion"
@fork="setForkTarget('ide')" @fork="setForkTarget('view')"
/> />
</template> </template>
</blob-header> </blob-header>
......
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
fields: { fields: {
// fields key must match case of form name for validation directive to work // fields key must match case of form name for validation directive to work
commit_message: initFormField({ value: this.commitMessage }), commit_message: initFormField({ value: this.commitMessage }),
branch_name: initFormField({ value: this.targetBranch }), branch_name: initFormField({ value: this.targetBranch, skipValidation: !this.canPushCode }),
}, },
}; };
return { return {
......
...@@ -52,6 +52,7 @@ export const DEFAULT_BLOB_INFO = { ...@@ -52,6 +52,7 @@ export const DEFAULT_BLOB_INFO = {
ideEditPath: '', ideEditPath: '',
forkAndEditPath: '', forkAndEditPath: '',
ideForkAndEditPath: '', ideForkAndEditPath: '',
forkAndViewPath: '',
storedExternally: false, storedExternally: false,
externalStorage: '', externalStorage: '',
environmentFormattedExternalUrl: '', environmentFormattedExternalUrl: '',
......
...@@ -31,6 +31,7 @@ query getBlobInfo( ...@@ -31,6 +31,7 @@ query getBlobInfo(
ideEditPath ideEditPath
forkAndEditPath forkAndEditPath
ideForkAndEditPath ideForkAndEditPath
forkAndViewPath
environmentFormattedExternalUrl environmentFormattedExternalUrl
environmentExternalUrlForRouteMap environmentExternalUrlForRouteMap
canModifyBlob canModifyBlob
......
...@@ -41,6 +41,9 @@ module Types ...@@ -41,6 +41,9 @@ module Types
field :ide_fork_and_edit_path, GraphQL::Types::String, null: true, field :ide_fork_and_edit_path, GraphQL::Types::String, null: true,
description: 'Web path to edit this blob in the Web IDE using a forked project.' description: 'Web path to edit this blob in the Web IDE using a forked project.'
field :fork_and_view_path, GraphQL::Types::String, null: true,
description: 'Web path to view this blob using a forked project.'
field :size, GraphQL::Types::Int, null: true, field :size, GraphQL::Types::Int, null: true,
description: 'Size (in bytes) of the blob.' description: 'Size (in bytes) of the blob.'
......
...@@ -103,6 +103,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated ...@@ -103,6 +103,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
fork_path_for_current_user(project, ide_edit_path) fork_path_for_current_user(project, ide_edit_path)
end end
def fork_and_view_path
fork_path_for_current_user(project, web_path)
end
def can_modify_blob? def can_modify_blob?
super(blob, project, blob.commit_id) super(blob, project, blob.commit_id)
end end
......
...@@ -14990,6 +14990,7 @@ Returns [`Tree`](#tree). ...@@ -14990,6 +14990,7 @@ Returns [`Tree`](#tree).
| <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="repositoryblobfindfilepath"></a>`findFilePath` | [`String`](#string) | Web path to find file. | | <a id="repositoryblobfindfilepath"></a>`findFilePath` | [`String`](#string) | Web path to find file. |
| <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. |
| <a id="repositoryblobforkandviewpath"></a>`forkAndViewPath` | [`String`](#string) | Web path to view this blob using a forked project. |
| <a id="repositoryblobhistorypath"></a>`historyPath` | [`String`](#string) | Web path to blob history page. | | <a id="repositoryblobhistorypath"></a>`historyPath` | [`String`](#string) | Web path to blob history page. |
| <a id="repositoryblobid"></a>`id` | [`ID!`](#id) | ID of the blob. | | <a id="repositoryblobid"></a>`id` | [`ID!`](#id) | ID of the blob. |
| <a id="repositoryblobideeditpath"></a>`ideEditPath` | [`String`](#string) | Web path to edit this blob in the Web IDE. | | <a id="repositoryblobideeditpath"></a>`ideEditPath` | [`String`](#string) | Web path to edit this blob in the Web IDE. |
...@@ -15,7 +15,6 @@ RSpec.describe 'Projects > Files > User deletes files', :js do ...@@ -15,7 +15,6 @@ RSpec.describe 'Projects > Files > User deletes files', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(refactor_blob_viewer: false) # This stub will be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/349953
sign_in(user) sign_in(user)
end end
......
...@@ -17,7 +17,6 @@ RSpec.describe 'Projects > Files > User replaces files', :js do ...@@ -17,7 +17,6 @@ RSpec.describe 'Projects > Files > User replaces files', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(refactor_blob_viewer: false) # This stub will be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/349953
sign_in(user) sign_in(user)
end end
...@@ -34,9 +33,9 @@ RSpec.describe 'Projects > Files > User replaces files', :js do ...@@ -34,9 +33,9 @@ RSpec.describe 'Projects > Files > User replaces files', :js do
expect(page).to have_content('.gitignore') expect(page).to have_content('.gitignore')
click_on('Replace') click_on('Replace')
drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt')) find(".upload-dropzone-card").drop(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'))
page.within('#modal-upload-blob') do page.within('#modal-replace-blob') do
fill_in(:commit_message, with: 'Replacement file commit message') fill_in(:commit_message, with: 'Replacement file commit message')
end end
...@@ -70,9 +69,9 @@ RSpec.describe 'Projects > Files > User replaces files', :js do ...@@ -70,9 +69,9 @@ RSpec.describe 'Projects > Files > User replaces files', :js do
expect(page).to have_content(fork_message) expect(page).to have_content(fork_message)
click_on('Replace') click_on('Replace')
drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt')) find(".upload-dropzone-card").drop(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'))
page.within('#modal-upload-blob') do page.within('#modal-replace-blob') do
fill_in(:commit_message, with: 'Replacement file commit message') fill_in(:commit_message, with: 'Replacement file commit message')
end end
......
...@@ -12,6 +12,7 @@ export const simpleViewerMock = { ...@@ -12,6 +12,7 @@ export const simpleViewerMock = {
ideEditPath: 'some_file.js/ide/edit', ideEditPath: 'some_file.js/ide/edit',
forkAndEditPath: 'some_file.js/fork/edit', forkAndEditPath: 'some_file.js/fork/edit',
ideForkAndEditPath: 'some_file.js/fork/ide', ideForkAndEditPath: 'some_file.js/fork/ide',
forkAndViewPath: 'some_file.js/fork/view',
environmentFormattedExternalUrl: '', environmentFormattedExternalUrl: '',
environmentExternalUrlForRouteMap: '', environmentExternalUrlForRouteMap: '',
canModifyBlob: true, canModifyBlob: true,
......
...@@ -42,6 +42,7 @@ RSpec.describe Types::Repository::BlobType do ...@@ -42,6 +42,7 @@ RSpec.describe Types::Repository::BlobType do
:external_storage_url, :external_storage_url,
:fork_and_edit_path, :fork_and_edit_path,
:ide_fork_and_edit_path, :ide_fork_and_edit_path,
:fork_and_view_path,
:language :language
) )
end end
......
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