From 21a732a36efa82bba232a7043199496b7f72c3d8 Mon Sep 17 00:00:00 2001
From: Tomas Bulva <tbulva@gitlab.com>
Date: Tue, 1 Oct 2024 04:26:31 +0000
Subject: [PATCH] Renamed getter method hasProjectContext

    Changelog: changed
---
 .../sidebar/components/blobs_filters.vue      |  6 ++---
 .../sidebar/components/commits_filters.vue    |  4 ++--
 .../sidebar/components/issues_filters.vue     |  4 ++--
 .../components/merge_requests_filters.vue     |  6 ++---
 .../sidebar/components/milestones_filters.vue |  4 ++--
 .../sidebar/components/notes_filters.vue      |  4 ++--
 .../sidebar/components/wiki_blobs_filters.vue |  4 ++--
 .../javascripts/search/store/getters.js       |  4 ++--
 .../sidebar/components/blobs_filters_spec.js  |  6 ++---
 .../components/commits_filters_spec.js        |  6 ++---
 .../sidebar/components/issues_filters_spec.js |  6 ++---
 .../components/merge_requests_filters_spec.js |  6 ++---
 .../components/milestones_filters_spec.js     |  6 ++---
 .../sidebar/components/notes_filters_spec.js  |  6 ++---
 .../components/wiki_blobs_filters_spec.js     |  6 ++---
 spec/frontend/search/store/getters_spec.js    | 22 +++++++++++--------
 16 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/app/assets/javascripts/search/sidebar/components/blobs_filters.vue b/app/assets/javascripts/search/sidebar/components/blobs_filters.vue
index b800b529fd10c..2662a959a0479 100644
--- a/app/assets/javascripts/search/sidebar/components/blobs_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/blobs_filters.vue
@@ -19,12 +19,12 @@ export default {
   mixins: [glFeatureFlagsMixin()],
   computed: {
     ...mapState(['searchType']),
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
     showLanguageFilter() {
       return this.searchType === SEARCH_TYPE_ADVANCED;
     },
     shouldShowZoektForksFilter() {
-      return this.searchType === SEARCH_TYPE_ZOEKT && this.hasProjectContext;
+      return this.searchType === SEARCH_TYPE_ZOEKT && this.hasMissingProjectContext;
     },
   },
 };
@@ -33,7 +33,7 @@ export default {
 <template>
   <filters-template>
     <language-filter v-if="showLanguageFilter" class="gl-mb-5" />
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
     <forks-filter v-if="shouldShowZoektForksFilter" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/commits_filters.vue b/app/assets/javascripts/search/sidebar/components/commits_filters.vue
index 5d0d012a73f32..b88dc32a812fa 100644
--- a/app/assets/javascripts/search/sidebar/components/commits_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/commits_filters.vue
@@ -11,13 +11,13 @@ export default {
     FiltersTemplate,
   },
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
   },
 };
 </script>
 
 <template>
   <filters-template>
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/issues_filters.vue b/app/assets/javascripts/search/sidebar/components/issues_filters.vue
index 907c1f04e4028..fcf724671e9c4 100644
--- a/app/assets/javascripts/search/sidebar/components/issues_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/issues_filters.vue
@@ -21,7 +21,7 @@ export default {
   },
   mixins: [glFeatureFlagsMixin()],
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
     ...mapState(['searchType']),
     showLabelFilter() {
       return this.searchType === SEARCH_TYPE_ADVANCED;
@@ -35,6 +35,6 @@ export default {
     <status-filter class="gl-mb-5" />
     <confidentiality-filter class="gl-mb-5" />
     <label-filter v-if="showLabelFilter" class="gl-mb-5" />
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/merge_requests_filters.vue b/app/assets/javascripts/search/sidebar/components/merge_requests_filters.vue
index b0e3a52ac7dfc..28386a8a57bdc 100644
--- a/app/assets/javascripts/search/sidebar/components/merge_requests_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/merge_requests_filters.vue
@@ -15,11 +15,11 @@ export default {
     SourceBranchFilter,
   },
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
     ...mapState(['groupInitialJson']),
     shouldShowSourceBranchFilter() {
       // this will be changed https://gitlab.com/gitlab-org/gitlab/-/issues/480740
-      return !this.hasProjectContext || this.groupInitialJson?.id;
+      return !this.hasMissingProjectContext || this.groupInitialJson?.id;
     },
   },
 };
@@ -28,7 +28,7 @@ export default {
 <template>
   <filters-template>
     <status-filter class="gl-mb-5" />
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
     <source-branch-filter v-if="shouldShowSourceBranchFilter" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/milestones_filters.vue b/app/assets/javascripts/search/sidebar/components/milestones_filters.vue
index 74f26dec33413..73a844593b321 100644
--- a/app/assets/javascripts/search/sidebar/components/milestones_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/milestones_filters.vue
@@ -11,13 +11,13 @@ export default {
     FiltersTemplate,
   },
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
   },
 };
 </script>
 
 <template>
   <filters-template>
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/notes_filters.vue b/app/assets/javascripts/search/sidebar/components/notes_filters.vue
index 01ea8dccf11c5..6e25733a98a20 100644
--- a/app/assets/javascripts/search/sidebar/components/notes_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/notes_filters.vue
@@ -11,13 +11,13 @@ export default {
     FiltersTemplate,
   },
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
   },
 };
 </script>
 
 <template>
   <filters-template>
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/sidebar/components/wiki_blobs_filters.vue b/app/assets/javascripts/search/sidebar/components/wiki_blobs_filters.vue
index 2960a684e146e..0650fe290e16a 100644
--- a/app/assets/javascripts/search/sidebar/components/wiki_blobs_filters.vue
+++ b/app/assets/javascripts/search/sidebar/components/wiki_blobs_filters.vue
@@ -11,13 +11,13 @@ export default {
     FiltersTemplate,
   },
   computed: {
-    ...mapGetters(['hasProjectContext']),
+    ...mapGetters(['hasMissingProjectContext']),
   },
 };
 </script>
 
 <template>
   <filters-template>
-    <archived-filter v-if="hasProjectContext" class="gl-mb-5" />
+    <archived-filter v-if="hasMissingProjectContext" class="gl-mb-5" />
   </filters-template>
 </template>
diff --git a/app/assets/javascripts/search/store/getters.js b/app/assets/javascripts/search/store/getters.js
index c5ffe16371f2f..51cb98b8b7583 100644
--- a/app/assets/javascripts/search/store/getters.js
+++ b/app/assets/javascripts/search/store/getters.js
@@ -10,7 +10,7 @@ import {
   injectRegexSearch,
 } from '~/search/store/utils';
 
-import { PROJECT_DATA, SCOPE_BLOB } from '~/search/sidebar/constants';
+import { SCOPE_BLOB } from '~/search/sidebar/constants';
 import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, ICON_MAP } from './constants';
 
 const queryLabelFilters = (state) => state?.query?.[LABEL_FILTER_PARAM] || [];
@@ -96,4 +96,4 @@ export const navigationItems = (state) =>
     items: [],
   }));
 
-export const hasProjectContext = (state) => !state.query?.[PROJECT_DATA.queryParam];
+export const hasMissingProjectContext = (state) => !state?.projectInitialJson?.id;
diff --git a/spec/frontend/search/sidebar/components/blobs_filters_spec.js b/spec/frontend/search/sidebar/components/blobs_filters_spec.js
index b5cbffadd2be9..1ae2636e3b796 100644
--- a/spec/frontend/search/sidebar/components/blobs_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/blobs_filters_spec.js
@@ -20,7 +20,7 @@ describe('GlobalSearch BlobsFilters', () => {
 
   const defaultGetters = {
     currentScope: () => 'blobs',
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = (initialState = { searchType: SEARCH_TYPE_ADVANCED }) => {
@@ -70,7 +70,7 @@ describe('GlobalSearch BlobsFilters', () => {
     ${SEARCH_TYPE_ZOEKT}    | ${false}          | ${false}
   `('sidebar blobs fork filter:', ({ searchType, hasProjectContent, isShown }) => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => hasProjectContent;
+      defaultGetters.hasMissingProjectContext = () => hasProjectContent;
       createComponent({ searchType });
     });
 
@@ -89,7 +89,7 @@ describe('GlobalSearch BlobsFilters', () => {
     ${SEARCH_TYPE_ZOEKT}    | ${false}          | ${false}
   `('sidebar blobs archived filter:', ({ searchType, hasProjectContent, isShown }) => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => hasProjectContent;
+      defaultGetters.hasMissingProjectContext = () => hasProjectContent;
       createComponent({ searchType });
     });
 
diff --git a/spec/frontend/search/sidebar/components/commits_filters_spec.js b/spec/frontend/search/sidebar/components/commits_filters_spec.js
index 64fb6e6203d6d..4ff50c87bd144 100644
--- a/spec/frontend/search/sidebar/components/commits_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/commits_filters_spec.js
@@ -12,7 +12,7 @@ describe('GlobalSearch CommitsFilters', () => {
   let wrapper;
 
   const defaultGetters = {
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = () => {
@@ -41,9 +41,9 @@ describe('GlobalSearch CommitsFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/sidebar/components/issues_filters_spec.js b/spec/frontend/search/sidebar/components/issues_filters_spec.js
index 811960eef7b90..473c8895230ed 100644
--- a/spec/frontend/search/sidebar/components/issues_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/issues_filters_spec.js
@@ -17,7 +17,7 @@ describe('GlobalSearch IssuesFilters', () => {
 
   const defaultGetters = {
     currentScope: () => 'issues',
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = ({ initialState = {} } = {}) => {
@@ -83,9 +83,9 @@ describe('GlobalSearch IssuesFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js b/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js
index 7ab035af2b89f..c9ef8488b38a7 100644
--- a/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/merge_requests_filters_spec.js
@@ -16,7 +16,7 @@ describe('GlobalSearch MergeRequestsFilters', () => {
 
   const defaultGetters = {
     currentScope: () => 'merge_requests',
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = (initialState = {}) => {
@@ -77,9 +77,9 @@ describe('GlobalSearch MergeRequestsFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/sidebar/components/milestones_filters_spec.js b/spec/frontend/search/sidebar/components/milestones_filters_spec.js
index 2a4989e48fcc6..4183bdc558e26 100644
--- a/spec/frontend/search/sidebar/components/milestones_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/milestones_filters_spec.js
@@ -12,7 +12,7 @@ describe('GlobalSearch MilestonesFilters', () => {
   let wrapper;
 
   const defaultGetters = {
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const findArchivedFilter = () => wrapper.findComponent(ArchivedFilter);
@@ -41,9 +41,9 @@ describe('GlobalSearch MilestonesFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/sidebar/components/notes_filters_spec.js b/spec/frontend/search/sidebar/components/notes_filters_spec.js
index 17b197507e6e9..d10cdffacbea7 100644
--- a/spec/frontend/search/sidebar/components/notes_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/notes_filters_spec.js
@@ -12,7 +12,7 @@ describe('GlobalSearch ProjectsFilters', () => {
   let wrapper;
 
   const defaultGetters = {
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = () => {
@@ -41,9 +41,9 @@ describe('GlobalSearch ProjectsFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/sidebar/components/wiki_blobs_filters_spec.js b/spec/frontend/search/sidebar/components/wiki_blobs_filters_spec.js
index ddb820d054310..2e6d438db9398 100644
--- a/spec/frontend/search/sidebar/components/wiki_blobs_filters_spec.js
+++ b/spec/frontend/search/sidebar/components/wiki_blobs_filters_spec.js
@@ -12,7 +12,7 @@ describe('GlobalSearch WikiBlobsFilters', () => {
   let wrapper;
 
   const defaultGetters = {
-    hasProjectContext: () => true,
+    hasMissingProjectContext: () => true,
   };
 
   const createComponent = () => {
@@ -41,9 +41,9 @@ describe('GlobalSearch WikiBlobsFilters', () => {
     });
   });
 
-  describe('hasProjectContext getter', () => {
+  describe('hasMissingProjectContext getter', () => {
     beforeEach(() => {
-      defaultGetters.hasProjectContext = () => false;
+      defaultGetters.hasMissingProjectContext = () => false;
       createComponent();
     });
 
diff --git a/spec/frontend/search/store/getters_spec.js b/spec/frontend/search/store/getters_spec.js
index e3c4240d9ed60..a610353663fd6 100644
--- a/spec/frontend/search/store/getters_spec.js
+++ b/spec/frontend/search/store/getters_spec.js
@@ -159,15 +159,19 @@ describe('Global Search Store Getters', () => {
       expect(getters.unappliedNewLabels(state).map(({ key }) => key)).toStrictEqual(['6', '73']);
     });
   });
-  describe('hasProjectContext', () => {
-    it('returns true project_id is NOT in query', () => {
-      state.query.project_id = undefined;
-      expect(getters.hasProjectContext(state)).toBe(true);
-    });
-
-    it('returns false project_id is in query', () => {
-      state.query.project_id = 'test';
-      expect(getters.hasProjectContext(state)).toBe(false);
+  describe('hasMissingProjectContext', () => {
+    it('returns true projectInitialJson.id is NOT in query', () => {
+      state.projectInitialJson = {
+        id: undefined,
+      };
+      expect(getters.hasMissingProjectContext(state)).toBe(true);
+    });
+
+    it('returns false projectInitialJson.id is in query', () => {
+      state.projectInitialJson = {
+        id: 'test',
+      };
+      expect(getters.hasMissingProjectContext(state)).toBe(false);
     });
   });
 });
-- 
GitLab