From af6db208ad7e1b36e35bdb841733fd31164166c6 Mon Sep 17 00:00:00 2001 From: Julia Miocene Date: Mon, 10 Mar 2025 20:09:44 +0100 Subject: [PATCH 1/4] Migrate blank project to Vue --- .../projects/new_v2/components/app.vue | 77 +++- .../new_v2/components/blank_project_form.vue | 424 +++++++++++++++++- .../new_v2/components/import_project_form.vue | 10 +- .../components/project_destination_select.vue | 26 +- .../javascripts/projects/new_v2/event_hub.js | 3 - .../projects/new_v2/form_constants.js | 64 +++ .../javascripts/projects/new_v2/index.js | 12 + .../multiple_choice_selector_item.vue | 8 +- .../single_choice_selector_item.vue | 8 +- app/views/projects/new.html.haml | 6 + locale/gitlab.pot | 12 + .../components/blank_project_form_spec.js | 90 +++- 12 files changed, 657 insertions(+), 83 deletions(-) delete mode 100644 app/assets/javascripts/projects/new_v2/event_hub.js create mode 100644 app/assets/javascripts/projects/new_v2/form_constants.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..9acad0b16f3934 100644 --- a/app/assets/javascripts/projects/new_v2/components/app.vue +++ b/app/assets/javascripts/projects/new_v2/components/app.vue @@ -42,6 +42,9 @@ export default { userNamespaceId: { default: null, }, + userNamespaceFullPath: { + default: null, + }, isCiCdAvailable: { default: false, }, @@ -61,7 +64,7 @@ export default { default: null, }, namespaceId: { - default: null, + default: '', }, trackLabel: { default: null, @@ -72,23 +75,30 @@ export default { newProjectGuidelines: { default: null, }, + visibilityLevel: { + default: null, + }, }, data() { return { - selectedNamespace: - this.namespaceId && this.canSelectNamespace ? this.namespaceId : this.userNamespaceId, - selectedProjectType: OPTIONS.blank.value, - currentStep: 1, rootUrl: this.rootPath, + namespace: { + id: this.namespaceId && this.canSelectNamespace ? this.namespaceId : this.userNamespaceId, + visibility: this.visibilityLevel, + fullPath: + this.namespaceFullPath && this.canSelectNamespace + ? this.namespaceFullPath + : this.userNamespaceFullPath, + type: OPTIONS.blank.value, + isPersonal: this.namespaceId === '', + }, + currentStep: 1, }; }, 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() { @@ -116,7 +126,7 @@ export default { ]; }, selectedProjectOption() { - return this.availableProjectTypes.find((type) => type.value === this.selectedProjectType); + return this.availableProjectTypes.find((type) => type.value === this.namespace.type); }, step2Component() { return this.selectedProjectOption.component; @@ -132,26 +142,39 @@ export default { methods: { choosePersonalNamespace() { - this.selectedNamespace = this.userNamespaceId; + this.namespace.id = this.userNamespaceId; + this.namespace.visibility = this.visibilityLevel; + this.namespace.fullPath = this.userNamespaceFullPath; + this.namespace.isPersonal = true; }, chooseGroupNamespace() { - this.selectedNamespace = null; + this.namespace.id = this.namespaceId || null; + this.namespace.visibility = this.namespaceId !== null ? this.visibilityLevel : null; + this.namespace.fullPath = this.namespaceFullPath; + this.namespace.isPersonal = false; }, selectProjectType(value) { - this.selectedProjectType = value; + this.namespace.type = value; }, onBack() { this.currentStep -= 1; setLocationHash(); }, onNext() { + if (this.namespace.id == null) return; + this.currentStep += 1; - setLocationHash(this.selectedProjectType); + setLocationHash(this.namespace.type); + }, + onSelectNamespace(newNamespace) { + this.namespace.id = newNamespace.id; + this.namespace.visibility = newNamespace.visibility; + this.namespace.fullPath = newNamespace.fullPath; }, setStepFromLocationHash() { const hash = getLocationHash(); if (this.availableProjectTypes.some((type) => type.value === hash)) { - this.selectedProjectType = hash; + this.namespace.type = hash; this.currentStep = 2; } else { this.currentStep = 1; @@ -178,7 +201,7 @@ export default { category="primary" variant="default" size="medium" - :selected="isPersonalProject" + :selected="namespace.isPersonal" class="gl-w-full" data-testid="personal-namespace-button" @click="choosePersonalNamespace" @@ -189,7 +212,7 @@ export default { category="primary" variant="default" size="medium" - :selected="!isPersonalProject" + :selected="!namespace.isPersonal" class="gl-w-full" data-testid="group-namespace-button" @click="chooseGroupNamespace" @@ -199,20 +222,28 @@ export default { - + @@ -251,7 +282,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/blank_project_form.vue b/app/assets/javascripts/projects/new_v2/components/blank_project_form.vue index 8b67a233b2f96a..7132c2c2ffd487 100644 --- a/app/assets/javascripts/projects/new_v2/components/blank_project_form.vue +++ b/app/assets/javascripts/projects/new_v2/components/blank_project_form.vue @@ -1,11 +1,85 @@ diff --git a/app/assets/javascripts/projects/new_v2/components/import_project_form.vue b/app/assets/javascripts/projects/new_v2/components/import_project_form.vue index 3824ab085f47c8..441cc4a88017f7 100644 --- a/app/assets/javascripts/projects/new_v2/components/import_project_form.vue +++ b/app/assets/javascripts/projects/new_v2/components/import_project_form.vue @@ -73,10 +73,10 @@ export default { required: false, default: () => ({}), }, - namespaceId: { - type: String, + namespace: { + type: Object, required: false, - default: null, + default: () => ({}), }, }, data() { @@ -89,8 +89,8 @@ export default { return [ { isAvailable: this.importGitlabEnabled, - path: this.namespaceId - ? `${this.importGitlabImportPath}?namespace_id=${this.namespaceId}` + path: this.namespace.id + ? `${this.importGitlabImportPath}?namespace_id=${this.namespace.id}` : this.importGitlabImportPath, icon: 'tanuki', title: s__('ProjectImport|GitLab'), 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..8b93ce1812ab73 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,13 @@