From 208ac771d4ef488a3f978e21b758bb987959c36b Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 23 Apr 2025 09:40:33 +0200 Subject: [PATCH] Use centrally typed inject provide in Vue (#5113) Co-authored-by: Robert Kaussow --- .../layout/popups/DeployPipelinePopup.vue | 4 +-- .../components/repo/pipeline/PipelineLog.vue | 14 ++++------ .../repo/pipeline/PipelineStepList.vue | 8 +++--- web/src/compositions/useInjectProvide.ts | 14 +++++----- web/src/compositions/useTabs.ts | 4 +-- web/src/views/org/OrgRepos.vue | 6 ++--- web/src/views/org/OrgWrapper.vue | 5 ++-- web/src/views/org/settings/OrgAgents.vue | 11 +++----- web/src/views/org/settings/OrgRegistries.vue | 20 +++----------- web/src/views/org/settings/OrgSecrets.vue | 20 +++----------- .../views/org/settings/OrgSettingsWrapper.vue | 6 ++--- web/src/views/repo/RepoBranch.vue | 15 ++++------- web/src/views/repo/RepoBranches.vue | 14 +++------- web/src/views/repo/RepoManualPipeline.vue | 13 +++------ web/src/views/repo/RepoPipelines.vue | 14 +++------- web/src/views/repo/RepoPullRequest.vue | 15 ++++------- web/src/views/repo/RepoPullRequests.vue | 15 +++-------- web/src/views/repo/RepoWrapper.vue | 10 ++++--- web/src/views/repo/pipeline/Pipeline.vue | 23 +++++----------- .../repo/pipeline/PipelineChangedFiles.vue | 12 +++------ .../views/repo/pipeline/PipelineConfig.vue | 7 ++--- web/src/views/repo/pipeline/PipelineDebug.vue | 11 ++++---- .../views/repo/pipeline/PipelineErrors.vue | 11 +++----- .../views/repo/pipeline/PipelineWrapper.vue | 27 +++++-------------- web/src/views/repo/settings/Actions.vue | 23 +++------------- web/src/views/repo/settings/Badge.vue | 19 +++---------- web/src/views/repo/settings/Crons.vue | 24 +++-------------- web/src/views/repo/settings/General.vue | 20 +++----------- web/src/views/repo/settings/Registries.vue | 20 +++----------- web/src/views/repo/settings/RepoSettings.vue | 18 ++++--------- web/src/views/repo/settings/Secrets.vue | 20 +++----------- 31 files changed, 123 insertions(+), 320 deletions(-) diff --git a/web/src/components/layout/popups/DeployPipelinePopup.vue b/web/src/components/layout/popups/DeployPipelinePopup.vue index 61b545f79..67228a069 100644 --- a/web/src/components/layout/popups/DeployPipelinePopup.vue +++ b/web/src/components/layout/popups/DeployPipelinePopup.vue @@ -39,7 +39,7 @@ import TextField from '~/components/form/TextField.vue'; import Panel from '~/components/layout/Panel.vue'; import Popup from '~/components/layout/Popup.vue'; import useApiClient from '~/compositions/useApiClient'; -import { inject } from '~/compositions/useInjectProvide'; +import { requiredInject } from '~/compositions/useInjectProvide'; const props = defineProps<{ open: boolean; @@ -51,7 +51,7 @@ const emit = defineEmits<{ }>(); const apiClient = useApiClient(); -const repo = inject('repo'); +const repo = requiredInject('repo'); const router = useRouter(); const payload = ref<{ diff --git a/web/src/components/repo/pipeline/PipelineLog.vue b/web/src/components/repo/pipeline/PipelineLog.vue index 052d311d3..fd8ec3909 100644 --- a/web/src/components/repo/pipeline/PipelineLog.vue +++ b/web/src/components/repo/pipeline/PipelineLog.vue @@ -111,16 +111,16 @@ import { useStorage } from '@vueuse/core'; import { AnsiUp } from 'ansi_up'; import { decode } from 'js-base64'; import { debounce } from 'lodash'; -import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, toRef, watch } from 'vue'; -import type { Ref } from 'vue'; +import { computed, nextTick, onBeforeUnmount, onMounted, ref, toRef, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import IconButton from '~/components/atomic/IconButton.vue'; import PipelineStatusIcon from '~/components/repo/pipeline/PipelineStatusIcon.vue'; import useApiClient from '~/compositions/useApiClient'; +import { requiredInject } from '~/compositions/useInjectProvide'; import useNotifications from '~/compositions/useNotifications'; -import type { Pipeline, PipelineStep, PipelineWorkflow, Repo, RepoPermissions } from '~/lib/api/types'; +import type { Pipeline, PipelineStep, PipelineWorkflow } from '~/lib/api/types'; interface LogLine { index: number; @@ -143,8 +143,8 @@ const notifications = useNotifications(); const i18n = useI18n(); const pipeline = toRef(props, 'pipeline'); const stepId = toRef(props, 'stepId'); -const repo = inject>('repo'); -const repoPermissions = inject>('repo-permissions'); +const repo = requiredInject('repo'); +const repoPermissions = requiredInject('repo-permissions'); const apiClient = useApiClient(); const route = useRoute(); @@ -286,10 +286,6 @@ async function loadLogs() { return; } - if (!repo) { - throw new Error('Unexpected: "repo" should be provided at this place'); - } - log.value = undefined; logBuffer.value = []; ansiUp.value = new AnsiUp(); diff --git a/web/src/components/repo/pipeline/PipelineStepList.vue b/web/src/components/repo/pipeline/PipelineStepList.vue index 715d203ff..b6e6e2f35 100644 --- a/web/src/components/repo/pipeline/PipelineStepList.vue +++ b/web/src/components/repo/pipeline/PipelineStepList.vue @@ -118,17 +118,17 @@ diff --git a/web/src/views/repo/RepoPullRequest.vue b/web/src/views/repo/RepoPullRequest.vue index a11fed41b..59fed236a 100644 --- a/web/src/views/repo/RepoPullRequest.vue +++ b/web/src/views/repo/RepoPullRequest.vue @@ -6,28 +6,23 @@ diff --git a/web/src/views/repo/pipeline/PipelineConfig.vue b/web/src/views/repo/pipeline/PipelineConfig.vue index c76dbc671..f196f0b3e 100644 --- a/web/src/views/repo/pipeline/PipelineConfig.vue +++ b/web/src/views/repo/pipeline/PipelineConfig.vue @@ -18,12 +18,9 @@ import { computed } from 'vue'; import SyntaxHighlight from '~/components/atomic/SyntaxHighlight'; import Panel from '~/components/layout/Panel.vue'; -import { inject } from '~/compositions/useInjectProvide'; +import { requiredInject } from '~/compositions/useInjectProvide'; -const pipelineConfigs = inject('pipeline-configs'); -if (!pipelineConfigs) { - throw new Error('Unexpected: "pipelineConfigs" should be provided at this place'); -} +const pipelineConfigs = requiredInject('pipeline-configs'); const pipelineConfigsDecoded = computed( () => diff --git a/web/src/views/repo/pipeline/PipelineDebug.vue b/web/src/views/repo/pipeline/PipelineDebug.vue index 47ef06202..30bacbaab 100644 --- a/web/src/views/repo/pipeline/PipelineDebug.vue +++ b/web/src/views/repo/pipeline/PipelineDebug.vue @@ -18,24 +18,23 @@