From 962665246b83a687a9e2b1100b35841bf7dfbd01 Mon Sep 17 00:00:00 2001
From: Miguel Rincon <mrincon@gitlab.com>
Date: Mon, 8 Aug 2022 11:00:59 +0000
Subject: [PATCH] Add upgrade status filter for group runners

This change adds a new filter options to the group runners search bar,
it also restricts the filtering to Ultimate users.

Changelog: added
EE: true
---
 .../group_runner_connection.fragment.graphql  | 17 ++++++++++
 .../graphql/list/group_runners.query.graphql  | 15 ++------
 .../group_runners/group_runners_app.vue       | 17 +++++-----
 .../graphql/list/group_runners.query.graphql  | 34 +++++++++++++++++++
 .../group_runners/group_runners_app_spec.js   |  4 ++-
 5 files changed, 65 insertions(+), 22 deletions(-)
 create mode 100644 app/assets/javascripts/runner/graphql/list/group_runner_connection.fragment.graphql
 create mode 100644 ee/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql

diff --git a/app/assets/javascripts/runner/graphql/list/group_runner_connection.fragment.graphql b/app/assets/javascripts/runner/graphql/list/group_runner_connection.fragment.graphql
new file mode 100644
index 0000000000000..66975bf2c3630
--- /dev/null
+++ b/app/assets/javascripts/runner/graphql/list/group_runner_connection.fragment.graphql
@@ -0,0 +1,17 @@
+#import "ee_else_ce/runner/graphql/list/list_item.fragment.graphql"
+#import "~/graphql_shared/fragments/page_info.fragment.graphql"
+
+fragment GroupRunnerConnection on CiRunnerConnection {
+  edges {
+    webUrl
+    editUrl
+    node {
+      ...ListItem
+      projectCount # Used to determine why some project runners can't be deleted
+    }
+  }
+  pageInfo {
+    __typename
+    ...PageInfo
+  }
+}
diff --git a/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql b/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql
index b7a8889ea0e1f..4c519b9b8677a 100644
--- a/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql
+++ b/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql
@@ -1,5 +1,4 @@
-#import "ee_else_ce/runner/graphql/list/list_item.fragment.graphql"
-#import "~/graphql_shared/fragments/page_info.fragment.graphql"
+#import "~/runner/graphql/list/group_runner_connection.fragment.graphql"
 
 query getGroupRunners(
   $groupFullPath: ID!
@@ -27,17 +26,7 @@ query getGroupRunners(
       search: $search
       sort: $sort
     ) {
-      edges {
-        webUrl
-        editUrl
-        node {
-          ...ListItem
-          projectCount # Used to determine why some project runners can't be deleted
-        }
-      }
-      pageInfo {
-        ...PageInfo
-      }
+      ...GroupRunnerConnection
     }
   }
 }
diff --git a/app/assets/javascripts/runner/group_runners/group_runners_app.vue b/app/assets/javascripts/runner/group_runners/group_runners_app.vue
index e8446dbe345aa..76b518648761c 100644
--- a/app/assets/javascripts/runner/group_runners/group_runners_app.vue
+++ b/app/assets/javascripts/runner/group_runners/group_runners_app.vue
@@ -3,6 +3,14 @@ import { GlLink } from '@gitlab/ui';
 import { createAlert } from '~/flash';
 import { updateHistory } from '~/lib/utils/url_utility';
 import { fetchPolicies } from '~/lib/graphql';
+import { upgradeStatusTokenConfig } from 'ee_else_ce/runner/components/search_tokens/upgrade_status_token_config';
+import {
+  fromUrlQueryToSearch,
+  fromSearchToUrl,
+  fromSearchToVariables,
+  isSearchFiltered,
+} from 'ee_else_ce/runner/runner_search_utils';
+import groupRunnersQuery from 'ee_else_ce/runner/graphql/list/group_runners.query.graphql';
 
 import RegistrationDropdown from '../components/registration/registration_dropdown.vue';
 import RunnerFilteredSearchBar from '../components/runner_filtered_search_bar.vue';
@@ -22,13 +30,6 @@ import {
   PROJECT_TYPE,
   I18N_FETCH_ERROR,
 } from '../constants';
-import groupRunnersQuery from '../graphql/list/group_runners.query.graphql';
-import {
-  fromUrlQueryToSearch,
-  fromSearchToUrl,
-  fromSearchToVariables,
-  isSearchFiltered,
-} from '../runner_search_utils';
 import { captureException } from '../sentry_utils';
 
 export default {
@@ -123,7 +124,7 @@ export default {
       return !this.runnersLoading && !this.runners.items.length;
     },
     searchTokens() {
-      return [pausedTokenConfig, statusTokenConfig];
+      return [pausedTokenConfig, statusTokenConfig, upgradeStatusTokenConfig];
     },
     filteredSearchNamespace() {
       return `${GROUP_FILTERED_SEARCH_NAMESPACE}/${this.groupFullPath}`;
diff --git a/ee/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql b/ee/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql
new file mode 100644
index 0000000000000..f663ea3ae0f80
--- /dev/null
+++ b/ee/app/assets/javascripts/runner/graphql/list/group_runners.query.graphql
@@ -0,0 +1,34 @@
+#import "~/runner/graphql/list/group_runner_connection.fragment.graphql"
+
+query getGroupRunnersEE(
+  $groupFullPath: ID!
+  $before: String
+  $after: String
+  $first: Int
+  $last: Int
+  $paused: Boolean
+  $status: CiRunnerStatus
+  $upgradeStatus: CiRunnerUpgradeStatus
+  $type: CiRunnerType
+  $search: String
+  $sort: CiRunnerSort
+) {
+  group(fullPath: $groupFullPath) {
+    id # Apollo required
+    runners(
+      membership: DESCENDANTS
+      before: $before
+      after: $after
+      first: $first
+      last: $last
+      paused: $paused
+      status: $status
+      upgradeStatus: $upgradeStatus # Added in EE
+      type: $type
+      search: $search
+      sort: $sort
+    ) {
+      ...GroupRunnerConnection
+    }
+  }
+}
diff --git a/spec/frontend/runner/group_runners/group_runners_app_spec.js b/spec/frontend/runner/group_runners/group_runners_app_spec.js
index 3012240d8f4b6..9c85e5de96cd3 100644
--- a/spec/frontend/runner/group_runners/group_runners_app_spec.js
+++ b/spec/frontend/runner/group_runners/group_runners_app_spec.js
@@ -13,6 +13,7 @@ import { createAlert } from '~/flash';
 import { s__ } from '~/locale';
 import { getIdFromGraphQLId } from '~/graphql_shared/utils';
 import { updateHistory } from '~/lib/utils/url_utility';
+import { upgradeStatusTokenConfig } from 'ee_else_ce/runner/components/search_tokens/upgrade_status_token_config';
 
 import RunnerTypeTabs from '~/runner/components/runner_type_tabs.vue';
 import RunnerFilteredSearchBar from '~/runner/components/runner_filtered_search_bar.vue';
@@ -37,7 +38,7 @@ import {
   RUNNER_PAGE_SIZE,
   I18N_EDIT,
 } from '~/runner/constants';
-import groupRunnersQuery from '~/runner/graphql/list/group_runners.query.graphql';
+import groupRunnersQuery from 'ee_else_ce/runner/graphql/list/group_runners.query.graphql';
 import groupRunnersCountQuery from 'ee_else_ce/runner/graphql/list/group_runners_count.query.graphql';
 import GroupRunnersApp from '~/runner/group_runners/group_runners_app.vue';
 import { captureException } from '~/runner/sentry_utils';
@@ -196,6 +197,7 @@ describe('GroupRunnersApp', () => {
         type: PARAM_KEY_STATUS,
         options: expect.any(Array),
       }),
+      upgradeStatusTokenConfig,
     ]);
   });
 
-- 
GitLab