diff options
Diffstat (limited to 'app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue')
-rw-r--r-- | app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue b/app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue index 91650003d4a..2028af8b8f0 100644 --- a/app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue +++ b/app/assets/javascripts/pages/projects/forks/new/components/fork_form.vue @@ -57,6 +57,9 @@ export default { visibilityHelpPath: { default: '', }, + cancelPath: { + default: '', + }, projectFullPath: { default: '', }, @@ -97,7 +100,7 @@ export default { required: false, skipValidation: true, }), - visibility: initFormField({ value: this.getInitialVisibilityValue() }), + visibility: initFormField({ value: null }), }, }; return { @@ -106,8 +109,39 @@ export default { }; }, computed: { + projectVisibilityLevel() { + return VISIBILITY_LEVELS_STRING_TO_INTEGER[this.projectVisibility]; + }, + namespaceVisibilityLevel() { + const visibility = + this.form.fields.namespace.value?.visibility || VISIBILITY_LEVEL_PUBLIC_STRING; + return VISIBILITY_LEVELS_STRING_TO_INTEGER[visibility]; + }, + visibilityLevelCap() { + return Math.min(this.projectVisibilityLevel, this.namespaceVisibilityLevel); + }, + restrictedVisibilityLevelsSet() { + return new Set(this.restrictedVisibilityLevels); + }, allowedVisibilityLevels() { - return this.getAllowedVisibilityLevels(); + const allowedLevels = Object.entries(VISIBILITY_LEVELS_STRING_TO_INTEGER).reduce( + (levels, [levelName, levelValue]) => { + if ( + !this.restrictedVisibilityLevelsSet.has(levelValue) && + levelValue <= this.visibilityLevelCap + ) { + levels.push(levelName); + } + return levels; + }, + [], + ); + + if (!allowedLevels.length) { + return [VISIBILITY_LEVEL_PRIVATE_STRING]; + } + + return allowedLevels; }, visibilityLevels() { return [ @@ -143,13 +177,15 @@ export default { this.form.fields.slug.value = kebabCase(newVal); }, }, + created() { + this.form.fields.visibility.value = this.getMaximumAllowedVisibilityLevel( + VISIBILITY_LEVEL_PUBLIC_STRING, + ); + }, methods: { isVisibilityLevelDisabled(visibility) { return !this.allowedVisibilityLevels.includes(visibility); }, - getInitialVisibilityValue() { - return this.getMaximumAllowedVisibilityLevel(this.projectVisibility); - }, setNamespace(namespace) { this.form.fields.namespace.value = namespace; this.form.fields.namespace.state = true; @@ -157,42 +193,8 @@ export default { this.form.fields.visibility.value, ); }, - getProjectVisibilityLevel() { - return VISIBILITY_LEVELS_STRING_TO_INTEGER[this.projectVisibility]; - }, - getNamespaceVisibilityLevel() { - const visibility = - this.form?.fields?.namespace?.value?.visibility || VISIBILITY_LEVEL_PUBLIC_STRING; - return VISIBILITY_LEVELS_STRING_TO_INTEGER[visibility]; - }, - getVisibilityLevelCap() { - return Math.min(this.getProjectVisibilityLevel(), this.getNamespaceVisibilityLevel()); - }, - getRestrictedVisibilityLevelsSet() { - return new Set(this.restrictedVisibilityLevels); - }, - getAllowedVisibilityLevels() { - const allowedLevels = Object.entries(VISIBILITY_LEVELS_STRING_TO_INTEGER).reduce( - (levels, [levelName, levelValue]) => { - if ( - !this.getRestrictedVisibilityLevelsSet().has(levelValue) && - levelValue <= this.getVisibilityLevelCap() - ) { - levels.push(levelName); - } - return levels; - }, - [], - ); - - if (!allowedLevels.length) { - return [VISIBILITY_LEVEL_PRIVATE_STRING]; - } - - return allowedLevels; - }, getMaximumAllowedVisibilityLevel(visibility) { - const allowedVisibilities = this.getAllowedVisibilityLevels().map( + const allowedVisibilities = this.allowedVisibilityLevels.map( (s) => VISIBILITY_LEVELS_STRING_TO_INTEGER[s], ); const current = VISIBILITY_LEVELS_STRING_TO_INTEGER[visibility]; @@ -373,7 +375,7 @@ export default { class="gl-mr-3" data-testid="cancel-button" :disabled="isSaving" - :href="projectFullPath" + :href="cancelPath" > {{ s__('ForkProject|Cancel') }} </gl-button> |