Commit edaacb2e authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'nfriend-update-individual-release-page-to-use-graphql-step-2' into 'master'

Step 2/3: Update individual Release page to use GraphQL

See merge request gitlab-org/gitlab!44779
parents 6c73102e 1853a7d4
...@@ -13,6 +13,9 @@ export default () => { ...@@ -13,6 +13,9 @@ export default () => {
modules: { modules: {
detail: createDetailModule(el.dataset), detail: createDetailModule(el.dataset),
}, },
featureFlags: {
graphqlIndividualReleasePage: Boolean(gon.features?.graphqlIndividualReleasePage),
},
}); });
return new Vue({ return new Vue({
......
...@@ -3,7 +3,13 @@ import api from '~/api'; ...@@ -3,7 +3,13 @@ import api from '~/api';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import { releaseToApiJson, apiJsonToRelease } from '~/releases/util'; import {
releaseToApiJson,
apiJsonToRelease,
gqClient,
convertOneReleaseGraphQLResponse,
} from '~/releases/util';
import oneReleaseQuery from '~/releases/queries/one_release.query.graphql';
export const initializeRelease = ({ commit, dispatch, getters }) => { export const initializeRelease = ({ commit, dispatch, getters }) => {
if (getters.isExistingRelease) { if (getters.isExistingRelease) {
...@@ -18,9 +24,29 @@ export const initializeRelease = ({ commit, dispatch, getters }) => { ...@@ -18,9 +24,29 @@ export const initializeRelease = ({ commit, dispatch, getters }) => {
return Promise.resolve(); return Promise.resolve();
}; };
export const fetchRelease = ({ commit, state }) => { export const fetchRelease = ({ commit, state, rootState }) => {
commit(types.REQUEST_RELEASE); commit(types.REQUEST_RELEASE);
if (rootState.featureFlags?.graphqlIndividualReleasePage) {
return gqClient
.query({
query: oneReleaseQuery,
variables: {
fullPath: state.projectPath,
tagName: state.tagName,
},
})
.then(response => {
const { data: release } = convertOneReleaseGraphQLResponse(response);
commit(types.RECEIVE_RELEASE_SUCCESS, release);
})
.catch(error => {
commit(types.RECEIVE_RELEASE_ERROR, error);
createFlash(s__('Release|Something went wrong while getting the release details'));
});
}
return api return api
.release(state.projectId, state.tagName) .release(state.projectId, state.tagName)
.then(({ data }) => { .then(({ data }) => {
......
export default ({ export default ({
projectId, projectId,
projectPath,
markdownDocsPath, markdownDocsPath,
markdownPreviewPath, markdownPreviewPath,
updateReleaseApiDocsPath, updateReleaseApiDocsPath,
...@@ -12,6 +13,7 @@ export default ({ ...@@ -12,6 +13,7 @@ export default ({
defaultBranch = null, defaultBranch = null,
}) => ({ }) => ({
projectId, projectId,
projectPath,
markdownDocsPath, markdownDocsPath,
markdownPreviewPath, markdownPreviewPath,
updateReleaseApiDocsPath, updateReleaseApiDocsPath,
......
...@@ -9,6 +9,7 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -9,6 +9,7 @@ class Projects::ReleasesController < Projects::ApplicationController
push_frontend_feature_flag(:graphql_release_data, project, default_enabled: true) push_frontend_feature_flag(:graphql_release_data, project, default_enabled: true)
push_frontend_feature_flag(:graphql_milestone_stats, project, default_enabled: true) push_frontend_feature_flag(:graphql_milestone_stats, project, default_enabled: true)
push_frontend_feature_flag(:graphql_releases_page, project, default_enabled: true) push_frontend_feature_flag(:graphql_releases_page, project, default_enabled: true)
push_frontend_feature_flag(:graphql_individual_release_page, project)
end end
before_action :authorize_update_release!, only: %i[edit update] before_action :authorize_update_release!, only: %i[edit update]
before_action :authorize_create_release!, only: :new before_action :authorize_create_release!, only: :new
......
...@@ -29,6 +29,14 @@ module ReleasesHelper ...@@ -29,6 +29,14 @@ module ReleasesHelper
end end
end end
def data_for_show_page
{
project_id: @project.id,
project_path: @project.full_path,
tag_name: @release.tag
}
end
def data_for_edit_release_page def data_for_edit_release_page
new_edit_pages_shared_data.merge( new_edit_pages_shared_data.merge(
tag_name: @release.tag, tag_name: @release.tag,
...@@ -48,6 +56,7 @@ module ReleasesHelper ...@@ -48,6 +56,7 @@ module ReleasesHelper
def new_edit_pages_shared_data def new_edit_pages_shared_data
{ {
project_id: @project.id, project_id: @project.id,
project_path: @project.full_path,
markdown_preview_path: preview_markdown_path(@project), markdown_preview_path: preview_markdown_path(@project),
markdown_docs_path: help_page_path('user/markdown'), markdown_docs_path: help_page_path('user/markdown'),
update_release_api_docs_path: help_page_path('api/releases/index.md', anchor: 'update-a-release'), update_release_api_docs_path: help_page_path('api/releases/index.md', anchor: 'update-a-release'),
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- page_title @release.name - page_title @release.name
- page_description @release.description_html - page_description @release.description_html
#js-show-release-page{ data: { project_id: @project.id, tag_name: @release.tag } } #js-show-release-page{ data: data_for_show_page }
---
name: graphql_individual_release_page
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44779
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/263522
type: development
group: group::release management
default_enabled: false
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'User views Release', :js do RSpec.describe 'User views Release', :js do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:graphql_feature_flag) { true }
let(:release) do let(:release) do
create(:release, create(:release,
...@@ -14,6 +15,8 @@ RSpec.describe 'User views Release', :js do ...@@ -14,6 +15,8 @@ RSpec.describe 'User views Release', :js do
end end
before do before do
stub_feature_flags(graphql_individual_release_page: graphql_feature_flag)
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
...@@ -23,23 +26,35 @@ RSpec.describe 'User views Release', :js do ...@@ -23,23 +26,35 @@ RSpec.describe 'User views Release', :js do
it_behaves_like 'page meta description', 'Lorem ipsum dolor sit amet' it_behaves_like 'page meta description', 'Lorem ipsum dolor sit amet'
it 'renders the breadcrumbs' do shared_examples 'release page' do
within('.breadcrumbs') do it 'renders the breadcrumbs' do
expect(page).to have_content("#{project.creator.name} #{project.name} Releases #{release.name}") within('.breadcrumbs') do
expect(page).to have_content("#{project.creator.name} #{project.name} Releases #{release.name}")
expect(page).to have_link(project.creator.name, href: user_path(project.creator)) expect(page).to have_link(project.creator.name, href: user_path(project.creator))
expect(page).to have_link(project.name, href: project_path(project)) expect(page).to have_link(project.name, href: project_path(project))
expect(page).to have_link('Releases', href: project_releases_path(project)) expect(page).to have_link('Releases', href: project_releases_path(project))
expect(page).to have_link(release.name, href: project_release_path(project, release)) expect(page).to have_link(release.name, href: project_release_path(project, release))
end
end end
end
it 'renders the release details' do it 'renders the release details' do
within('.release-block') do within('.release-block') do
expect(page).to have_content(release.name) expect(page).to have_content(release.name)
expect(page).to have_content(release.tag) expect(page).to have_content(release.tag)
expect(page).to have_content(release.commit.short_id) expect(page).to have_content(release.commit.short_id)
expect(page).to have_content('Lorem ipsum dolor sit amet') expect(page).to have_content('Lorem ipsum dolor sit amet')
end
end end
end end
describe 'when the graphql_individual_release_page feature flag is enabled' do
it_behaves_like 'release page'
end
describe 'when the graphql_individual_release_page feature flag is disabled' do
let(:graphql_feature_flag) { false }
it_behaves_like 'release page'
end
end end
...@@ -34,6 +34,12 @@ describe('Release detail actions', () => { ...@@ -34,6 +34,12 @@ describe('Release detail actions', () => {
isExistingRelease: true, isExistingRelease: true,
}; };
const rootState = {
featureFlags: {
graphqlIndividualReleasePage: false,
},
};
state = { state = {
...createState({ ...createState({
projectId: '18', projectId: '18',
...@@ -44,6 +50,7 @@ describe('Release detail actions', () => { ...@@ -44,6 +50,7 @@ describe('Release detail actions', () => {
updateReleaseApiDocsPath: 'path/to/api/docs', updateReleaseApiDocsPath: 'path/to/api/docs',
}), }),
...getters, ...getters,
...rootState,
...updates, ...updates,
}; };
}; };
...@@ -154,7 +161,7 @@ describe('Release detail actions', () => { ...@@ -154,7 +161,7 @@ describe('Release detail actions', () => {
}); });
it(`shows a flash message`, () => { it(`shows a flash message`, () => {
return actions.fetchRelease({ commit: jest.fn(), state }).then(() => { return actions.fetchRelease({ commit: jest.fn(), state, rootState: state }).then(() => {
expect(createFlash).toHaveBeenCalledTimes(1); expect(createFlash).toHaveBeenCalledTimes(1);
expect(createFlash).toHaveBeenCalledWith( expect(createFlash).toHaveBeenCalledWith(
'Something went wrong while getting the release details', 'Something went wrong while getting the release details',
......
...@@ -64,6 +64,7 @@ RSpec.describe ReleasesHelper do ...@@ -64,6 +64,7 @@ RSpec.describe ReleasesHelper do
describe '#data_for_edit_release_page' do describe '#data_for_edit_release_page' do
it 'has the needed data to display the "edit release" page' do it 'has the needed data to display the "edit release" page' do
keys = %i(project_id keys = %i(project_id
project_path
tag_name tag_name
markdown_preview_path markdown_preview_path
markdown_docs_path markdown_docs_path
...@@ -80,6 +81,7 @@ RSpec.describe ReleasesHelper do ...@@ -80,6 +81,7 @@ RSpec.describe ReleasesHelper do
describe '#data_for_new_release_page' do describe '#data_for_new_release_page' do
it 'has the needed data to display the "new release" page' do it 'has the needed data to display the "new release" page' do
keys = %i(project_id keys = %i(project_id
project_path
releases_page_path releases_page_path
markdown_preview_path markdown_preview_path
markdown_docs_path markdown_docs_path
...@@ -92,5 +94,15 @@ RSpec.describe ReleasesHelper do ...@@ -92,5 +94,15 @@ RSpec.describe ReleasesHelper do
expect(helper.data_for_new_release_page.keys).to match_array(keys) expect(helper.data_for_new_release_page.keys).to match_array(keys)
end end
end end
describe '#data_for_show_page' do
it 'has the needed data to display the individual "release" page' do
keys = %i(project_id
project_path
tag_name)
expect(helper.data_for_show_page.keys).to match_array(keys)
end
end
end end
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