diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-29 00:09:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-29 00:09:03 +0300 |
commit | f138af0ccd6bbea99420b435248242b417f9d476 (patch) | |
tree | 27def5b8ce3bedabcbdef359ec1afebaf4ef9796 /app/assets/javascripts/runner | |
parent | f14814c9815f86a95808f089ff219d4e768641c0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/runner')
8 files changed, 56 insertions, 2 deletions
diff --git a/app/assets/javascripts/runner/admin_runner_show/admin_runner_show_app.vue b/app/assets/javascripts/runner/admin_runner_show/admin_runner_show_app.vue index 86ad912f017..8a808cbba37 100644 --- a/app/assets/javascripts/runner/admin_runner_show/admin_runner_show_app.vue +++ b/app/assets/javascripts/runner/admin_runner_show/admin_runner_show_app.vue @@ -1,8 +1,10 @@ <script> import { GlTooltipDirective } from '@gitlab/ui'; -import { createAlert } from '~/flash'; +import { createAlert, VARIANT_SUCCESS } from '~/flash'; import { TYPE_CI_RUNNER } from '~/graphql_shared/constants'; import { convertToGraphQLId } from '~/graphql_shared/utils'; +import { redirectTo } from '~/lib/utils/url_utility'; +import RunnerDeleteButton from '../components/runner_delete_button.vue'; import RunnerEditButton from '../components/runner_edit_button.vue'; import RunnerPauseButton from '../components/runner_pause_button.vue'; import RunnerHeader from '../components/runner_header.vue'; @@ -10,10 +12,12 @@ import RunnerDetails from '../components/runner_details.vue'; import { I18N_FETCH_ERROR } from '../constants'; import runnerQuery from '../graphql/details/runner.query.graphql'; import { captureException } from '../sentry_utils'; +import { saveAlertToLocalStorage } from '../local_storage_alert/save_alert_to_local_storage'; export default { name: 'AdminRunnerShowApp', components: { + RunnerDeleteButton, RunnerEditButton, RunnerPauseButton, RunnerHeader, @@ -27,6 +31,10 @@ export default { type: String, required: true, }, + runnersPath: { + type: String, + required: true, + }, }, data() { return { @@ -52,6 +60,9 @@ export default { canUpdate() { return this.runner.userPermissions?.updateRunner; }, + canDelete() { + return this.runner.userPermissions?.deleteRunner; + }, }, errorCaptured(error) { this.reportToSentry(error); @@ -60,6 +71,10 @@ export default { reportToSentry(error) { captureException({ error, component: this.$options.name }); }, + onDeleted({ message }) { + saveAlertToLocalStorage({ message, variant: VARIANT_SUCCESS }); + redirectTo(this.runnersPath); + }, }, }; </script> @@ -69,6 +84,12 @@ export default { <template #actions> <runner-edit-button v-if="canUpdate && runner.editAdminUrl" :href="runner.editAdminUrl" /> <runner-pause-button v-if="canUpdate" :runner="runner" /> + <runner-delete-button + v-if="canDelete" + :runner="runner" + category="secondary" + @deleted="onDeleted" + /> </template> </runner-header> diff --git a/app/assets/javascripts/runner/admin_runner_show/index.js b/app/assets/javascripts/runner/admin_runner_show/index.js index a781898cf8d..f8a02ecb49a 100644 --- a/app/assets/javascripts/runner/admin_runner_show/index.js +++ b/app/assets/javascripts/runner/admin_runner_show/index.js @@ -12,7 +12,7 @@ export const initAdminRunnerShow = (selector = '#js-admin-runner-show') => { return null; } - const { runnerId } = el.dataset; + const { runnerId, runnersPath } = el.dataset; const apolloProvider = new VueApollo({ defaultClient: createDefaultClient(), @@ -25,6 +25,7 @@ export const initAdminRunnerShow = (selector = '#js-admin-runner-show') => { return h(AdminRunnerShowApp, { props: { runnerId, + runnersPath, }, }); }, diff --git a/app/assets/javascripts/runner/admin_runners/index.js b/app/assets/javascripts/runner/admin_runners/index.js index 12e2cb2ee9f..b1d8442bb32 100644 --- a/app/assets/javascripts/runner/admin_runners/index.js +++ b/app/assets/javascripts/runner/admin_runners/index.js @@ -5,12 +5,15 @@ import { visitUrl } from '~/lib/utils/url_utility'; import { updateOutdatedUrl } from '~/runner/runner_search_utils'; import createDefaultClient from '~/lib/graphql'; import { createLocalState } from '../graphql/list/local_state'; +import { showAlertFromLocalStorage } from '../local_storage_alert/show_alert_from_local_storage'; import AdminRunnersApp from './admin_runners_app.vue'; Vue.use(GlToast); Vue.use(VueApollo); export const initAdminRunners = (selector = '#js-admin-runners') => { + showAlertFromLocalStorage(); + const el = document.querySelector(selector); if (!el) { diff --git a/app/assets/javascripts/runner/components/runner_delete_button.vue b/app/assets/javascripts/runner/components/runner_delete_button.vue index b58665ecbc9..cc54178bc40 100644 --- a/app/assets/javascripts/runner/components/runner_delete_button.vue +++ b/app/assets/javascripts/runner/components/runner_delete_button.vue @@ -165,6 +165,7 @@ export default { :loading="deleting" :disabled="disabled" variant="danger" + v-bind="$attrs" > {{ buttonContent }} </gl-button> diff --git a/app/assets/javascripts/runner/graphql/details/runner_details_shared.fragment.graphql b/app/assets/javascripts/runner/graphql/details/runner_details_shared.fragment.graphql index 0f996b8518e..1b418bd2bf3 100644 --- a/app/assets/javascripts/runner/graphql/details/runner_details_shared.fragment.graphql +++ b/app/assets/javascripts/runner/graphql/details/runner_details_shared.fragment.graphql @@ -1,6 +1,7 @@ fragment RunnerDetailsShared on CiRunner { __typename id + shortSha runnerType active accessLevel diff --git a/app/assets/javascripts/runner/local_storage_alert/constants.js b/app/assets/javascripts/runner/local_storage_alert/constants.js new file mode 100644 index 00000000000..69b7418f898 --- /dev/null +++ b/app/assets/javascripts/runner/local_storage_alert/constants.js @@ -0,0 +1 @@ +export const LOCAL_STORAGE_ALERT_KEY = 'local-storage-alert'; diff --git a/app/assets/javascripts/runner/local_storage_alert/save_alert_to_local_storage.js b/app/assets/javascripts/runner/local_storage_alert/save_alert_to_local_storage.js new file mode 100644 index 00000000000..ca7c627459a --- /dev/null +++ b/app/assets/javascripts/runner/local_storage_alert/save_alert_to_local_storage.js @@ -0,0 +1,8 @@ +import AccessorUtilities from '~/lib/utils/accessor'; +import { LOCAL_STORAGE_ALERT_KEY } from './constants'; + +export const saveAlertToLocalStorage = (alertOptions) => { + if (AccessorUtilities.canUseLocalStorage()) { + localStorage.setItem(LOCAL_STORAGE_ALERT_KEY, JSON.stringify(alertOptions)); + } +}; diff --git a/app/assets/javascripts/runner/local_storage_alert/show_alert_from_local_storage.js b/app/assets/javascripts/runner/local_storage_alert/show_alert_from_local_storage.js new file mode 100644 index 00000000000..d768a06494a --- /dev/null +++ b/app/assets/javascripts/runner/local_storage_alert/show_alert_from_local_storage.js @@ -0,0 +1,18 @@ +import AccessorUtilities from '~/lib/utils/accessor'; +import { LOCAL_STORAGE_ALERT_KEY } from './constants'; + +export const showAlertFromLocalStorage = async () => { + if (AccessorUtilities.canUseLocalStorage()) { + const alertOptions = localStorage.getItem(LOCAL_STORAGE_ALERT_KEY); + + if (alertOptions) { + try { + const { createAlert } = await import('~/flash'); + createAlert(JSON.parse(alertOptions)); + } catch { + // ignore when the alert data cannot be parsed + } + } + localStorage.removeItem(LOCAL_STORAGE_ALERT_KEY); + } +}; |