diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 03:08:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 03:08:54 +0300 |
commit | bded2fb7888ecf5af057a1d879ea9d85c2fea060 (patch) | |
tree | 5e9506e3f962290f727a7fad1ccb1fb759a3461f /app | |
parent | 6869f07304d5bcea12ec61ca6362259f3c72fdf8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/search/index.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/search/sidebar/components/app.vue | 23 | ||||
-rw-r--r-- | app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue (renamed from app/assets/javascripts/search/sidebar/components/scope_navigation.vue) | 4 | ||||
-rw-r--r-- | app/assets/javascripts/search/sidebar/components/scope_sidebar_navigation.vue (renamed from app/assets/javascripts/search/sidebar/components/scope_new_navigation.vue) | 2 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/index.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/state.js | 4 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 9 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 40 | ||||
-rw-r--r-- | app/services/search/global_service.rb | 5 | ||||
-rw-r--r-- | app/services/search/project_service.rb | 10 |
10 files changed, 68 insertions, 35 deletions
diff --git a/app/assets/javascripts/search/index.js b/app/assets/javascripts/search/index.js index 1e4b1e36514..f5684cebbf9 100644 --- a/app/assets/javascripts/search/index.js +++ b/app/assets/javascripts/search/index.js @@ -15,7 +15,7 @@ export const initSearchApp = () => { const store = createStore({ query, navigation, - useNewNavigation: gon.use_new_navigation, + useSidebarNavigation: gon.use_new_navigation, }); initTopbar(store); diff --git a/app/assets/javascripts/search/sidebar/components/app.vue b/app/assets/javascripts/search/sidebar/components/app.vue index af4d93dc033..cd289be4c05 100644 --- a/app/assets/javascripts/search/sidebar/components/app.vue +++ b/app/assets/javascripts/search/sidebar/components/app.vue @@ -1,7 +1,7 @@ <script> import { mapState, mapGetters } from 'vuex'; -import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue'; -import ScopeNewNavigation from '~/search/sidebar/components/scope_new_navigation.vue'; +import ScopeLegacyNavigation from '~/search/sidebar/components/scope_legacy_navigation.vue'; +import ScopeSidebarNavigation from '~/search/sidebar/components/scope_sidebar_navigation.vue'; import SidebarPortal from '~/super_sidebar/components/sidebar_portal.vue'; import { SCOPE_ISSUES, SCOPE_MERGE_REQUESTS, SCOPE_BLOB } from '../constants'; import IssuesFilters from './issues_filters.vue'; @@ -11,13 +11,14 @@ export default { name: 'GlobalSearchSidebar', components: { IssuesFilters, - ScopeNavigation, - ScopeNewNavigation, + ScopeLegacyNavigation, + ScopeSidebarNavigation, LanguageFilter, SidebarPortal, }, computed: { - ...mapState(['urlQuery', 'useNewNavigation']), + // useSidebarNavigation refers to whether the new left sidebar navigation is enabled + ...mapState(['useSidebarNavigation']), ...mapGetters(['currentScope']), showIssueAndMergeFilters() { return this.currentScope === SCOPE_ISSUES || this.currentScope === SCOPE_MERGE_REQUESTS; @@ -28,7 +29,9 @@ export default { showLabelFilter() { return this.currentScope === SCOPE_ISSUES; }, - showOldNavigation() { + showScopeNavigation() { + // showScopeNavigation refers to whether the scope navigation should be shown + // while the legacy navigation is being used and there are no search results the scope navigation has to be hidden return Boolean(this.currentScope); }, }, @@ -36,18 +39,18 @@ export default { </script> <template> - <section v-if="useNewNavigation"> + <section v-if="useSidebarNavigation"> <sidebar-portal> - <scope-new-navigation /> + <scope-sidebar-navigation /> <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </sidebar-portal> </section> <section - v-else + v-else-if="showScopeNavigation" class="search-sidebar gl-display-flex gl-flex-direction-column gl-md-mr-5 gl-mb-6 gl-mt-5" > - <scope-navigation /> + <scope-legacy-navigation /> <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </section> diff --git a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue b/app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue index b29a8d13425..e682369d60b 100644 --- a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue +++ b/app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue @@ -8,7 +8,7 @@ import { NAV_LINK_DEFAULT_CLASSES, NAV_LINK_COUNT_DEFAULT_CLASSES } from '../con import { slugifyWithUnderscore } from '../../../lib/utils/text_utility'; export default { - name: 'ScopeNavigation', + name: 'ScopeLegacyNavigation', i18n: { countOverLimitLabel: s__('GlobalSearch|Result count is over limit.'), }, @@ -80,6 +80,6 @@ export default { </span> </gl-nav-item> </gl-nav> - <hr class="gl-mt-3 gl-mb-5 gl-border-gray-100 gl-md-display-none" /> + <hr class="gl-mt-5 gl-mx-5 gl-mb-0 gl-border-gray-100 gl-md-display-none" /> </nav> </template> diff --git a/app/assets/javascripts/search/sidebar/components/scope_new_navigation.vue b/app/assets/javascripts/search/sidebar/components/scope_sidebar_navigation.vue index 86b7cc577a6..3707e152e47 100644 --- a/app/assets/javascripts/search/sidebar/components/scope_new_navigation.vue +++ b/app/assets/javascripts/search/sidebar/components/scope_sidebar_navigation.vue @@ -6,7 +6,7 @@ import NavItem from '~/super_sidebar/components/nav_item.vue'; import { NAV_LINK_DEFAULT_CLASSES, NAV_LINK_COUNT_DEFAULT_CLASSES } from '../constants'; export default { - name: 'ScopeNewNavigation', + name: 'ScopeSidebarNavigation', i18n: { countOverLimitLabel: s__('GlobalSearch|Result count is over limit.'), }, diff --git a/app/assets/javascripts/search/store/index.js b/app/assets/javascripts/search/store/index.js index 634f8f7a7fa..2478518c157 100644 --- a/app/assets/javascripts/search/store/index.js +++ b/app/assets/javascripts/search/store/index.js @@ -7,11 +7,11 @@ import createState from './state'; Vue.use(Vuex); -export const getStoreConfig = ({ query, navigation, useNewNavigation }) => ({ +export const getStoreConfig = (storeInitValues) => ({ actions, getters, mutations, - state: createState({ query, navigation, useNewNavigation }), + state: createState(storeInitValues), }); const createStore = (config) => new Vuex.Store(getStoreConfig(config)); diff --git a/app/assets/javascripts/search/store/state.js b/app/assets/javascripts/search/store/state.js index a62b6728819..c897d4108a8 100644 --- a/app/assets/javascripts/search/store/state.js +++ b/app/assets/javascripts/search/store/state.js @@ -1,7 +1,7 @@ import { cloneDeep } from 'lodash'; import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from './constants'; -const createState = ({ query, navigation, useNewNavigation }) => ({ +const createState = ({ query, navigation, useSidebarNavigation }) => ({ urlQuery: cloneDeep(query), query, groups: [], @@ -14,7 +14,7 @@ const createState = ({ query, navigation, useNewNavigation }) => ({ }, sidebarDirty: false, navigation, - useNewNavigation, + useSidebarNavigation, aggregations: { error: false, fetching: false, diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 6f675e1120c..9415e7d4dc3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -177,7 +177,11 @@ module ProjectsHelper abilities = Array(search_tab_ability_map[tab]) - abilities.any? { |ability| can?(current_user, ability, @project) } + if @project.respond_to?(:each) # support multi-project select + @project.any? { |project| abilities.any? { |ability| can?(current_user, ability, project) } } + else + abilities.any? { |ability| can?(current_user, ability, @project) } + end end def can_change_visibility_level?(project, current_user) @@ -616,7 +620,8 @@ module ProjectsHelper commits: :read_code, merge_requests: :read_merge_request, notes: [:read_merge_request, :read_code, :read_issue, :read_snippet], - members: :read_project_member + users: :read_project_member, + wiki_blobs: :read_wiki ) end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 7f0916ca316..1d58239aea9 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -457,35 +457,53 @@ module SearchHelper result end - def code_tab_condition + def show_code_search_tab? return true if project_search_tabs?(:blobs) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_code_tab) end - def wiki_tab_condition - return true if project_search_tabs?(:wiki) + def show_wiki_search_tab? + return true if project_search_tabs?(:wiki_blobs) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_wiki_tab) end - def commits_tab_condition + def show_commits_search_tab? return true if project_search_tabs?(:commits) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_commits_tab) end + def show_issues_search_tab? + return true if project_search_tabs?(:issues) + + @project.nil? && feature_flag_tab_enabled?(:global_search_issues_tab) + end + + def show_merge_requests_search_tab? + return true if project_search_tabs?(:merge_requests) + + @project.nil? && feature_flag_tab_enabled?(:global_search_merge_requests_tab) + end + + def show_comments_search_tab? + return true if project_search_tabs?(:notes) + + @project.nil? && search_service.show_elasticsearch_tabs? + end + # search page scope navigation def search_navigation { projects: { sort: 1, label: _("Projects"), data: { qa_selector: 'projects_tab' }, condition: @project.nil? }, - blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: code_tab_condition }, + blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: show_code_search_tab? }, # sort: 3 is reserved for EE items - issues: { sort: 4, label: _("Issues"), condition: project_search_tabs?(:issues) || feature_flag_tab_enabled?(:global_search_issues_tab) }, - merge_requests: { sort: 5, label: _("Merge requests"), condition: project_search_tabs?(:merge_requests) || feature_flag_tab_enabled?(:global_search_merge_requests_tab) }, - wiki_blobs: { sort: 6, label: _("Wiki"), condition: wiki_tab_condition }, - commits: { sort: 7, label: _("Commits"), condition: commits_tab_condition }, - notes: { sort: 8, label: _("Comments"), condition: project_search_tabs?(:notes) || search_service.show_elasticsearch_tabs? }, + issues: { sort: 4, label: _("Issues"), condition: show_issues_search_tab? }, + merge_requests: { sort: 5, label: _("Merge requests"), condition: show_merge_requests_search_tab? }, + wiki_blobs: { sort: 6, label: _("Wiki"), condition: show_wiki_search_tab? }, + commits: { sort: 7, label: _("Commits"), condition: show_commits_search_tab? }, + notes: { sort: 8, label: _("Comments"), condition: show_comments_search_tab? }, milestones: { sort: 9, label: _("Milestones"), condition: project_search_tabs?(:milestones) || @project.nil? }, users: { sort: 10, label: _("Users"), condition: show_user_search_tab? }, snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: search_service.show_snippets? && @project.nil? } @@ -576,7 +594,7 @@ module SearchHelper end def show_user_search_tab? - return project_search_tabs?(:members) if @project + return project_search_tabs?(:users) if @project return false unless can?(current_user, :read_users_list) return true if @group diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index 85ca0b850f5..f4c0a743ef0 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -5,7 +5,8 @@ module Search include Search::Filter include Gitlab::Utils::StrongMemoize - ALLOWED_SCOPES = %w(issues merge_requests milestones users).freeze + DEFAULT_SCOPE = 'projects' + ALLOWED_SCOPES = %w(projects issues merge_requests milestones users).freeze attr_accessor :current_user, :params @@ -34,7 +35,7 @@ module Search def scope strong_memoize(:scope) do - allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects' + allowed_scopes.include?(params[:scope]) ? params[:scope] : DEFAULT_SCOPE end end end diff --git a/app/services/search/project_service.rb b/app/services/search/project_service.rb index d30c500df14..71314f85984 100644 --- a/app/services/search/project_service.rb +++ b/app/services/search/project_service.rb @@ -4,7 +4,9 @@ module Search class ProjectService include Search::Filter include Gitlab::Utils::StrongMemoize - ALLOWED_SCOPES = %w(notes issues merge_requests milestones wiki_blobs commits users).freeze + include ProjectsHelper + + ALLOWED_SCOPES = %w(blobs issues merge_requests wiki_blobs commits notes milestones users).freeze attr_accessor :project, :current_user, :params @@ -31,7 +33,11 @@ module Search def scope strong_memoize(:scope) do - allowed_scopes.include?(params[:scope]) ? params[:scope] : 'blobs' + next params[:scope] if allowed_scopes.include?(params[:scope]) && project_search_tabs?(params[:scope].to_sym) + + allowed_scopes.find do |scope| + project_search_tabs?(scope.to_sym) + end end end end |