From 1ce6a30dbafcdcef592e6258a2dd75ddc513e358 Mon Sep 17 00:00:00 2001 From: Coung Ngo <cngo@gitlab.com> Date: Fri, 7 Mar 2025 13:25:06 +0000 Subject: [PATCH] Rename work_items_show_data and remove work_items_list_data work_items_show_data is now used for index/show/new pages so it is renamed to a more appropriate work_items_data name --- app/helpers/boards_helper.rb | 2 +- app/helpers/issuables_helper.rb | 4 +- app/helpers/issues_helper.rb | 2 +- app/helpers/work_items_helper.rb | 18 +---- app/views/groups/work_items/index.html.haml | 2 +- app/views/groups/work_items/show.html.haml | 2 +- .../projects/issues/_related_issues.html.haml | 2 +- .../issues/_work_item_links.html.haml | 2 +- app/views/projects/issues/index.html.haml | 2 +- app/views/projects/issues/new.html.haml | 4 +- app/views/projects/work_items/index.html.haml | 2 +- app/views/projects/work_items/show.html.haml | 2 +- ee/app/helpers/ee/work_items_helper.rb | 23 +----- .../groups/epics/work_items_index.html.haml | 2 +- ee/app/views/groups/work_items/show.html.haml | 2 +- ee/spec/helpers/ee/work_items_helper_spec.rb | 81 +------------------ spec/helpers/work_items_helper_spec.rb | 37 +-------- 17 files changed, 26 insertions(+), 163 deletions(-) diff --git a/app/helpers/boards_helper.rb b/app/helpers/boards_helper.rb index 5b81cb9719075..bf86d2daa6c68 100644 --- a/app/helpers/boards_helper.rb +++ b/app/helpers/boards_helper.rb @@ -25,7 +25,7 @@ def board_data has_missing_boards: has_missing_boards?.to_s, multiple_boards_available: multiple_boards_available?.to_s, board_base_url: board_base_url, - wi: work_items_show_data(board_namespace, current_user) + wi: work_items_data(board_namespace, current_user) } end diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 3b165a78e1c70..ea7ea84564793 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -339,7 +339,7 @@ def issue_only_initial_data(issuable) zoomMeetingUrl: ZoomMeeting.canonical_meeting_url(issuable), **incident_only_initial_data(issuable), **issue_header_data(issuable), - **work_items_data + **work_items_only_data } end @@ -376,7 +376,7 @@ def issue_header_data(issuable) end end - def work_items_data + def work_items_only_data { registerPath: new_user_registration_path(redirect_to_referer: 'yes'), signInPath: new_session_path(:user, redirect_to_referer: 'yes') diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index dfa8a3382ee15..046070aed4471 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -145,7 +145,7 @@ def common_issues_list_data(namespace, current_user) is_signed_in: current_user.present?.to_s, rss_path: url_for(safe_params.merge(rss_url_options)), sign_in_path: new_user_session_path, - wi: work_items_show_data(namespace, current_user) + wi: work_items_data(namespace, current_user) } end diff --git a/app/helpers/work_items_helper.rb b/app/helpers/work_items_helper.rb index 11f3372a46a15..17674879fffbb 100644 --- a/app/helpers/work_items_helper.rb +++ b/app/helpers/work_items_helper.rb @@ -3,7 +3,7 @@ module WorkItemsHelper include IssuesHelper - def work_items_show_data(resource_parent, current_user) + def work_items_data(resource_parent, current_user) group = resource_parent.is_a?(Group) ? resource_parent : resource_parent.group { @@ -30,24 +30,10 @@ def work_items_show_data(resource_parent, current_user) } end - # overriden in EE + # overridden in EE def add_work_item_show_breadcrumb(resource_parent, _iid) path = resource_parent.is_a?(Group) ? issues_group_path(resource_parent) : project_issues_path(resource_parent) add_to_breadcrumbs(_('Issues'), path) end - - def work_items_list_data(group, current_user) - { - autocomplete_award_emojis_path: autocomplete_award_emojis_path, - full_path: group.full_path, - initial_sort: current_user&.user_preference&.issues_sort, - is_signed_in: current_user.present?.to_s, - show_new_issue_link: can?(current_user, :create_work_item, group).to_s, - issues_list_path: issues_group_path(group), - report_abuse_path: add_category_abuse_reports_path, - labels_manage_path: group_labels_path(group), - can_admin_label: can?(current_user, :admin_label, group).to_s - } - end end diff --git a/app/views/groups/work_items/index.html.haml b/app/views/groups/work_items/index.html.haml index 94abb9966d78d..5d2ec4916163b 100644 --- a/app/views/groups/work_items/index.html.haml +++ b/app/views/groups/work_items/index.html.haml @@ -3,4 +3,4 @@ - add_work_items_stylesheet - add_page_specific_style 'page_bundles/design_management' -#js-work-items{ data: work_items_show_data(@group, current_user) } +#js-work-items{ data: work_items_data(@group, current_user) } diff --git a/app/views/groups/work_items/show.html.haml b/app/views/groups/work_items/show.html.haml index 07f01e165241f..f21707fe3b801 100644 --- a/app/views/groups/work_items/show.html.haml +++ b/app/views/groups/work_items/show.html.haml @@ -9,4 +9,4 @@ - @gfm_form = true - @noteable_type = 'WorkItem' -#js-work-items{ data: work_items_show_data(@group, current_user) } +#js-work-items{ data: work_items_data(@group, current_user) } diff --git a/app/views/projects/issues/_related_issues.html.haml b/app/views/projects/issues/_related_issues.html.haml index e3c96487f4291..e8ac7ea3cbd69 100644 --- a/app/views/projects/issues/_related_issues.html.haml +++ b/app/views/projects/issues/_related_issues.html.haml @@ -8,4 +8,4 @@ issuable_type: @issue.issue_type, show_categorized_issues: @project.licensed_feature_available?(:blocked_issues).to_s, has_iterations_feature: @project.licensed_feature_available?(:iterations).to_s, - wi: work_items_show_data(@project, current_user) } } + wi: work_items_data(@project, current_user) } } diff --git a/app/views/projects/issues/_work_item_links.html.haml b/app/views/projects/issues/_work_item_links.html.haml index 5d8d40b39fb8f..f37a9a076a0ff 100644 --- a/app/views/projects/issues/_work_item_links.html.haml +++ b/app/views/projects/issues/_work_item_links.html.haml @@ -1,6 +1,6 @@ .js-work-item-links-root{ data: { issuable_id: @issue.id, issuable_iid: @issue.iid, full_path: @project.full_path, - wi: work_items_show_data(@project, current_user), + wi: work_items_data(@project, current_user), register_path: new_user_registration_path(redirect_to_referer: 'yes'), sign_in_path: new_session_path(:user, redirect_to_referer: 'yes') } } diff --git a/app/views/projects/issues/index.html.haml b/app/views/projects/issues/index.html.haml index 123f52213f738..f1b71ec0f6a0e 100644 --- a/app/views/projects/issues/index.html.haml +++ b/app/views/projects/issues/index.html.haml @@ -13,7 +13,7 @@ project_path: @project.full_path } } - if @project&.work_items_alpha_feature_flag_enabled? && current_user&.user_preference&.use_work_items_view - #js-work-items{ data: work_items_show_data(@project, current_user) } + #js-work-items{ data: work_items_data(@project, current_user) } - else .js-issues-list-root{ data: project_issues_list_data(@project, current_user) } - if can?(current_user, :admin_issue, @project) diff --git a/app/views/projects/issues/new.html.haml b/app/views/projects/issues/new.html.haml index 38d094f862e36..c0413562f8540 100644 --- a/app/views/projects/issues/new.html.haml +++ b/app/views/projects/issues/new.html.haml @@ -24,10 +24,8 @@ = @issue.description - if Feature.enabled?(:work_items_view_preference, current_user) && current_user&.user_preference&.use_work_items_view - #js-work-items{ data: work_items_show_data(@project, current_user) } + #js-work-items{ data: work_items_data(@project, current_user) } - else .page-title-holder %h1.page-title.gl-text-size-h-display= _("New Issue") = render "form" - - diff --git a/app/views/projects/work_items/index.html.haml b/app/views/projects/work_items/index.html.haml index fc02fcc3eb3af..2051a4ac9b02d 100644 --- a/app/views/projects/work_items/index.html.haml +++ b/app/views/projects/work_items/index.html.haml @@ -3,4 +3,4 @@ - add_work_items_stylesheet - add_page_specific_style 'page_bundles/design_management' -#js-work-items{ data: work_items_show_data(@project, current_user) } +#js-work-items{ data: work_items_data(@project, current_user) } diff --git a/app/views/projects/work_items/show.html.haml b/app/views/projects/work_items/show.html.haml index 9651fcf647233..f8f7f629383d6 100644 --- a/app/views/projects/work_items/show.html.haml +++ b/app/views/projects/work_items/show.html.haml @@ -8,4 +8,4 @@ - @gfm_form = true - @noteable_type = 'WorkItem' -#js-work-items{ data: work_items_show_data(@project, current_user) } +#js-work-items{ data: work_items_data(@project, current_user) } diff --git a/ee/app/helpers/ee/work_items_helper.rb b/ee/app/helpers/ee/work_items_helper.rb index 05c2069c64d61..c2f5b7a38b54d 100644 --- a/ee/app/helpers/ee/work_items_helper.rb +++ b/ee/app/helpers/ee/work_items_helper.rb @@ -4,8 +4,8 @@ module EE module WorkItemsHelper extend ::Gitlab::Utils::Override - override :work_items_show_data - def work_items_show_data(resource_parent, current_user) + override :work_items_data + def work_items_data(resource_parent, current_user) super.merge( has_issue_weights_feature: resource_parent.licensed_feature_available?(:issue_weights).to_s, has_okrs_feature: resource_parent.licensed_feature_available?(:okrs).to_s, @@ -32,24 +32,5 @@ def add_work_item_show_breadcrumb(resource_parent, iid) super end - - override :work_items_list_data - def work_items_list_data(group, current_user) - super.merge( - can_bulk_edit_epics: can?(current_user, :bulk_admin_epic, group).to_s, - group_issues_path: issues_group_path(group), - has_epics_feature: group.licensed_feature_available?(:epics).to_s, - has_issuable_health_status_feature: group.licensed_feature_available?(:issuable_health_status).to_s, - has_issue_weights_feature: group.licensed_feature_available?(:issue_weights).to_s, - has_okrs_feature: group.licensed_feature_available?(:okrs).to_s, - has_quality_management_feature: group.licensed_feature_available?(:quality_management).to_s, - has_scoped_labels_feature: group.licensed_feature_available?(:scoped_labels).to_s, - has_subepics_feature: group.licensed_feature_available?(:subepics).to_s, - has_iterations_feature: group.licensed_feature_available?(:iterations).to_s, - labels_fetch_path: group_labels_path( - group, format: :json, only_group_labels: true, include_ancestor_groups: true), - has_linked_items_epics_feature: group.licensed_feature_available?(:linked_items_epics).to_s - ) - end end end diff --git a/ee/app/views/groups/epics/work_items_index.html.haml b/ee/app/views/groups/epics/work_items_index.html.haml index 964104045ef18..016099d308c03 100644 --- a/ee/app/views/groups/epics/work_items_index.html.haml +++ b/ee/app/views/groups/epics/work_items_index.html.haml @@ -11,4 +11,4 @@ - add_work_items_stylesheet - add_page_specific_style 'page_bundles/design_management' -#js-work-items{ data: work_items_show_data(@group, current_user).merge(work_item_type: 'EPIC') } +#js-work-items{ data: work_items_data(@group, current_user).merge(work_item_type: 'EPIC') } diff --git a/ee/app/views/groups/work_items/show.html.haml b/ee/app/views/groups/work_items/show.html.haml index e7d02aeece282..da01bd441f670 100644 --- a/ee/app/views/groups/work_items/show.html.haml +++ b/ee/app/views/groups/work_items/show.html.haml @@ -9,4 +9,4 @@ - @gfm_form = true - @noteable_type = 'WorkItem' -#js-work-items{ data: work_items_show_data(@group, current_user).merge(epics_list_path: group_epics_path(@group)).merge(work_item_type: 'EPIC') } +#js-work-items{ data: work_items_data(@group, current_user).merge(epics_list_path: group_epics_path(@group)).merge(work_item_type: 'EPIC') } diff --git a/ee/spec/helpers/ee/work_items_helper_spec.rb b/ee/spec/helpers/ee/work_items_helper_spec.rb index 32eb50101f872..3244c9ee8cbd2 100644 --- a/ee/spec/helpers/ee/work_items_helper_spec.rb +++ b/ee/spec/helpers/ee/work_items_helper_spec.rb @@ -5,8 +5,8 @@ RSpec.describe EE::WorkItemsHelper, feature_category: :team_planning do include Devise::Test::ControllerHelpers - describe '#work_items_show_data' do - subject(:work_items_show_data) { helper.work_items_show_data(project, current_user) } + describe '#work_items_data' do + subject(:work_items_data) { helper.work_items_data(project, current_user) } before do stub_licensed_features( @@ -33,7 +33,7 @@ let(:feature_available) { true } it 'returns true for the features' do - expect(work_items_show_data).to include( + expect(work_items_data).to include( { has_issuable_health_status_feature: "true", has_issue_weights_feature: "true", @@ -58,7 +58,7 @@ let(:feature_available) { false } it 'returns false for the features' do - expect(work_items_show_data).to include( + expect(work_items_data).to include( { has_issuable_health_status_feature: "false", has_issue_weights_feature: "false", @@ -93,77 +93,4 @@ end # rubocop:enable RSpec/FactoryBot/AvoidCreate end - - describe '#work_items_list_data' do - let_it_be(:group) { build(:group) } - - # rubocop:disable RSpec/FactoryBot/AvoidCreate -- Needed for policy rule checks to work - let_it_be(:current_user) { create(:user, owner_of: group) } - # rubocop:enable RSpec/FactoryBot/AvoidCreate - - subject(:work_items_list_data) { helper.work_items_list_data(group, current_user) } - - before do - stub_licensed_features( - epics: feature_available, - group_bulk_edit: feature_available, - issuable_health_status: feature_available, - issue_weights: feature_available, - okrs: feature_available, - quality_management: feature_available, - scoped_labels: feature_available, - subepics: feature_available, - iterations: feature_available, - linked_items_epics: feature_available - ) - end - - context 'when features are available' do - let(:feature_available) { true } - - it 'returns true for the features' do - expect(work_items_list_data).to include( - { - can_bulk_edit_epics: "true", - group_issues_path: issues_group_path(group), - has_epics_feature: "true", - has_issuable_health_status_feature: "true", - has_issue_weights_feature: "true", - has_okrs_feature: "true", - has_quality_management_feature: "true", - has_scoped_labels_feature: "true", - has_subepics_feature: "true", - has_iterations_feature: "true", - labels_fetch_path: group_labels_path( - group, format: :json, only_group_labels: true, include_ancestor_groups: true), - has_linked_items_epics_feature: "true" - } - ) - end - end - - context 'when features are not available' do - let(:feature_available) { false } - - it 'returns false for the features' do - expect(work_items_list_data).to include( - { - can_bulk_edit_epics: "false", - group_issues_path: issues_group_path(group), - has_epics_feature: "false", - has_issuable_health_status_feature: "false", - has_issue_weights_feature: "false", - has_okrs_feature: "false", - has_quality_management_feature: "false", - has_scoped_labels_feature: "false", - has_subepics_feature: "false", - has_iterations_feature: "false", - labels_fetch_path: group_labels_path( - group, format: :json, only_group_labels: true, include_ancestor_groups: true), - has_linked_items_epics_feature: "false" - } - ) - end - end - end end diff --git a/spec/helpers/work_items_helper_spec.rb b/spec/helpers/work_items_helper_spec.rb index 74a83ba97685b..a2cd0f9596a98 100644 --- a/spec/helpers/work_items_helper_spec.rb +++ b/spec/helpers/work_items_helper_spec.rb @@ -5,7 +5,7 @@ RSpec.describe WorkItemsHelper, feature_category: :team_planning do include Devise::Test::ControllerHelpers - describe '#work_items_show_data' do + describe '#work_items_data' do describe 'with project context' do let_it_be(:project) { build(:project) } let_it_be(:current_user) { build(:user, owner_of: project) } @@ -15,7 +15,7 @@ end it 'returns the expected data properties' do - expect(helper.work_items_show_data(project, current_user)).to include( + expect(helper.work_items_data(project, current_user)).to include( { autocomplete_award_emojis_path: autocomplete_award_emojis_path, can_admin_label: 'true', @@ -40,7 +40,7 @@ let_it_be(:current_user) { build(:user, owner_of: group_project) } it 'returns the expected data properties' do - expect(helper.work_items_show_data(group_project, current_user)).to include( + expect(helper.work_items_data(group_project, current_user)).to include( { group_path: group_project.group.full_path, show_new_issue_link: 'true' @@ -55,7 +55,7 @@ let_it_be(:current_user) { build(:user, owner_of: group) } it 'returns the expected group_path' do - expect(helper.work_items_show_data(group, current_user)).to include( + expect(helper.work_items_data(group, current_user)).to include( { issues_list_path: issues_group_path(group), labels_manage_path: group_labels_path(group), @@ -93,33 +93,4 @@ end end # rubocop:enable RSpec/FactoryBot/AvoidCreate - - describe '#work_items_list_data' do - let_it_be(:group) { build(:group) } - - let(:current_user) { double.as_null_object } - - subject(:work_items_list_data) { helper.work_items_list_data(group, current_user) } - - before do - allow(helper).to receive(:current_user).and_return(current_user) - allow(helper).to receive(:can?).and_return(true) - end - - it 'returns expected data' do - expect(work_items_list_data).to include( - { - autocomplete_award_emojis_path: autocomplete_award_emojis_path, - full_path: group.full_path, - initial_sort: current_user&.user_preference&.issues_sort, - is_signed_in: current_user.present?.to_s, - show_new_issue_link: 'true', - issues_list_path: issues_group_path(group), - report_abuse_path: add_category_abuse_reports_path, - labels_manage_path: group_labels_path(group), - can_admin_label: 'true' - } - ) - end - end end -- GitLab