From aed5470c032674664c71e8b7c32454564d56a39b Mon Sep 17 00:00:00 2001 From: Julia Miocene Date: Fri, 21 Mar 2025 19:31:26 +0100 Subject: [PATCH 1/2] Add a first step validation for a project creation form --- .../projects/new_v2/components/app.vue | 73 ++++++++++++------- .../components/project_destination_select.vue | 25 +++---- .../javascripts/projects/new_v2/event_hub.js | 3 - .../javascripts/projects/new_v2/index.js | 2 + app/views/projects/new.html.haml | 1 + .../projects/new_v2/components/app_spec.js | 28 ++++++- 6 files changed, 88 insertions(+), 44 deletions(-) delete mode 100644 app/assets/javascripts/projects/new_v2/event_hub.js diff --git a/app/assets/javascripts/projects/new_v2/components/app.vue b/app/assets/javascripts/projects/new_v2/components/app.vue index f851a37f1dcfb7..6b64a473f3a59b 100644 --- a/app/assets/javascripts/projects/new_v2/components/app.vue +++ b/app/assets/javascripts/projects/new_v2/components/app.vue @@ -33,15 +33,15 @@ export default { SafeHtml, }, inject: { - rootPath: { - default: '/', - }, projectsUrl: { default: null, }, userNamespaceId: { default: null, }, + userNamespaceFullPath: { + default: null, + }, isCiCdAvailable: { default: false, }, @@ -61,7 +61,7 @@ export default { default: null, }, namespaceId: { - default: null, + default: '', }, trackLabel: { default: null, @@ -75,20 +75,22 @@ export default { }, data() { return { - selectedNamespace: - this.namespaceId && this.canSelectNamespace ? this.namespaceId : this.userNamespaceId, + namespace: { + id: this.namespaceId && this.canSelectNamespace ? this.namespaceId : this.userNamespaceId, + fullPath: + this.namespaceFullPath && this.canSelectNamespace + ? this.namespaceFullPath + : this.userNamespaceFullPath, + isPersonal: this.namespaceId === '', + }, selectedProjectType: OPTIONS.blank.value, currentStep: 1, - rootUrl: this.rootPath, }; }, computed: { - isPersonalProject() { - return this.selectedNamespace === this.userNamespaceId; - }, canChooseOption() { - if (!this.isPersonalProject) return true; + if (!this.namespace.isPersonal) return true; return this.canCreateProject && this.userProjectLimit > 0; }, errorMessage() { @@ -131,11 +133,16 @@ export default { }, methods: { - choosePersonalNamespace() { - this.selectedNamespace = this.userNamespaceId; - }, - chooseGroupNamespace() { - this.selectedNamespace = null; + onSelectNamespaceType(isPersonal) { + if (isPersonal) { + this.namespace.id = this.userNamespaceId; + this.namespace.fullPath = this.userNamespaceFullPath; + this.namespace.isPersonal = true; + } else { + this.namespace.id = this.namespaceId || null; + this.namespace.fullPath = this.namespaceFullPath; + this.namespace.isPersonal = false; + } }, selectProjectType(value) { this.selectedProjectType = value; @@ -145,6 +152,8 @@ export default { setLocationHash(); }, onNext() { + if (this.namespace.id === null) return; + this.currentStep += 1; setLocationHash(this.selectedProjectType); }, @@ -157,6 +166,10 @@ export default { this.currentStep = 1; } }, + onSelectNamespace(newNamespace) { + this.namespace.id = newNamespace.id; + this.namespace.fullPath = newNamespace.fullPath; + }, }, }; @@ -178,10 +191,10 @@ export default { category="primary" variant="default" size="medium" - :selected="isPersonalProject" + :selected="namespace.isPersonal" class="gl-w-full" data-testid="personal-namespace-button" - @click="choosePersonalNamespace" + @click="onSelectNamespaceType(true)" > {{ s__('ProjectsNew|A personal project') }} @@ -189,24 +202,32 @@ export default { category="primary" variant="default" size="medium" - :selected="!isPersonalProject" + :selected="!namespace.isPersonal" class="gl-w-full" data-testid="group-namespace-button" - @click="chooseGroupNamespace" + @click="onSelectNamespaceType(false)" > {{ s__('ProjectsNew|A project within a group') }} - + @@ -242,7 +263,7 @@ export default { @@ -251,7 +272,7 @@ export default { v-if="currentStep === 2" :key="selectedProjectOption.key" :option="selectedProjectOption" - :namespace-id="selectedNamespace" + :namespace="namespace" data-testid="new-project-step2" @back="onBack" @next="onNext" diff --git a/app/assets/javascripts/projects/new_v2/components/project_destination_select.vue b/app/assets/javascripts/projects/new_v2/components/project_destination_select.vue index 7675e1c9ed3fac..1823c3e9d25355 100644 --- a/app/assets/javascripts/projects/new_v2/components/project_destination_select.vue +++ b/app/assets/javascripts/projects/new_v2/components/project_destination_select.vue @@ -1,13 +1,12 @@