Commit 4d0aa962 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '323729-follow-up-update-ruleform-inputs-to-use-glinput-and-glformgroup' into 'master'

Update RuleForm inputs to use GlFormInput and GlFormGroup

See merge request gitlab-org/gitlab!56319
parents e92d10e4 a558f7f8
<script> <script>
import { GlFormGroup, GlFormInput } from '@gitlab/ui';
import { groupBy, isNumber } from 'lodash'; import { groupBy, isNumber } from 'lodash';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { isSafeURL } from '~/lib/utils/url_utility'; import { isSafeURL } from '~/lib/utils/url_utility';
...@@ -27,10 +28,12 @@ function mapServerResponseToValidationErrors(messages) { ...@@ -27,10 +28,12 @@ function mapServerResponseToValidationErrors(messages) {
export default { export default {
components: { components: {
ApproverTypeSelect,
ApproversList, ApproversList,
ApproversSelect, ApproversSelect,
BranchesSelect, BranchesSelect,
ApproverTypeSelect, GlFormGroup,
GlFormInput,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
props: { props: {
...@@ -95,7 +98,9 @@ export default { ...@@ -95,7 +98,9 @@ export default {
invalidApprovalGateUrl() { invalidApprovalGateUrl() {
if (this.serverValidationErrors.includes('External url has already been taken')) { if (this.serverValidationErrors.includes('External url has already been taken')) {
return this.$options.i18n.validations.externalUrlTaken; return this.$options.i18n.validations.externalUrlTaken;
} else if (!this.externalUrl || !isSafeURL(this.externalUrl)) { }
if (!this.externalUrl || !isSafeURL(this.externalUrl)) {
return this.$options.i18n.validations.invalidUrl; return this.$options.i18n.validations.invalidUrl;
} }
...@@ -266,7 +271,7 @@ export default { ...@@ -266,7 +271,7 @@ export default {
* - Single rule? * - Single rule?
* - Multi rule? * - Multi rule?
*/ */
submit() { async submit() {
let submission; let submission;
this.serverValidationErrors = []; this.serverValidationErrors = [];
...@@ -275,16 +280,18 @@ export default { ...@@ -275,16 +280,18 @@ export default {
const valid = this.isExternalApprovalRule ? this.isValidExternalApprovalRule : this.isValid; const valid = this.isExternalApprovalRule ? this.isValidExternalApprovalRule : this.isValid;
if (!valid) { if (!valid) {
submission = Promise.resolve(); submission = Promise.resolve;
} else if (this.isFallbackSubmission) { } else if (this.isFallbackSubmission) {
submission = this.submitFallback(); submission = this.submitFallback;
} else if (!this.isMultiSubmission) { } else if (!this.isMultiSubmission) {
submission = this.submitSingleRule(); submission = this.submitSingleRule;
} else { } else {
submission = this.submitRule(); submission = this.submitRule;
} }
submission.catch((failureResponse) => { try {
await submission();
} catch (failureResponse) {
if (this.isExternalApprovalRule) { if (this.isExternalApprovalRule) {
this.serverValidationErrors = failureResponse?.response?.data?.message || []; this.serverValidationErrors = failureResponse?.response?.data?.message || [];
} else { } else {
...@@ -292,9 +299,7 @@ export default { ...@@ -292,9 +299,7 @@ export default {
failureResponse?.response?.data?.message || {}, failureResponse?.response?.data?.message || {},
); );
} }
}); }
return submission;
}, },
/** /**
* Submit the rule, by either put-ing or post-ing. * Submit the rule, by either put-ing or post-ing.
...@@ -304,10 +309,13 @@ export default { ...@@ -304,10 +309,13 @@ export default {
const data = this.externalRuleSubmissionData; const data = this.externalRuleSubmissionData;
return data.id ? this.putExternalApprovalRule(data) : this.postExternalApprovalRule(data); return data.id ? this.putExternalApprovalRule(data) : this.postExternalApprovalRule(data);
} }
const data = this.submissionData; const data = this.submissionData;
if (!this.settings.allowMultiRule && this.settings.prefix === 'mr-edit') { if (!this.settings.allowMultiRule && this.settings.prefix === 'mr-edit') {
return data.id ? this.putRule(data) : this.postRegularRule(data); return data.id ? this.putRule(data) : this.postRegularRule(data);
} }
return data.id ? this.putRule(data) : this.postRule(data); return data.id ? this.putRule(data) : this.postRule(data);
}, },
/** /**
...@@ -416,86 +424,92 @@ export default { ...@@ -416,86 +424,92 @@ export default {
<template> <template>
<form novalidate @submit.prevent.stop="submit"> <form novalidate @submit.prevent.stop="submit">
<div v-if="showName" class="form-group gl-form-group"> <gl-form-group
<label class="col-form-label">{{ $options.i18n.form.nameLabel }}</label> v-if="showName"
<input :label="$options.i18n.form.nameLabel"
:description="$options.i18n.form.nameDescription"
:state="isValidName"
:invalid-feedback="invalidName"
data-testid="name-group"
>
<gl-form-input
v-model="name" v-model="name"
:class="{ 'is-invalid': !isValidName }"
:disabled="isNameDisabled" :disabled="isNameDisabled"
class="gl-form-input form-control" :state="isValidName"
name="name"
type="text"
data-qa-selector="rule_name_field" data-qa-selector="rule_name_field"
data-testid="name"
/> />
<span class="invalid-feedback">{{ isValidName ? '' : invalidName }}</span> </gl-form-group>
<small class="form-text text-gl-muted"> <gl-form-group
{{ $options.i18n.form.nameDescription }} v-if="showProtectedBranch"
</small> :label="$options.i18n.form.protectedBranchLabel"
</div> :description="$options.i18n.form.protectedBranchDescription"
<div v-if="showProtectedBranch" class="form-group gl-form-group"> :state="isValidBranches"
<label class="col-form-label">{{ $options.i18n.form.protectedBranchLabel }}</label> :invalid-feedback="invalidBranches"
data-testid="branches-group"
>
<branches-select <branches-select
v-model="branchesToAdd" v-model="branchesToAdd"
:project-id="settings.projectId" :project-id="settings.projectId"
:is-invalid="!isValidBranches" :is-invalid="!isValidBranches"
:init-rule="rule" :init-rule="rule"
/> />
<span class="invalid-feedback">{{ isValidBranches ? '' : invalidBranches }}</span> </gl-form-group>
<small class="form-text text-gl-muted"> <gl-form-group v-if="showApproverTypeSelect" :label="$options.i18n.form.approvalTypeLabel">
{{ $options.i18n.form.protectedBranchDescription }}
</small>
</div>
<div v-if="showApproverTypeSelect" class="form-group gl-form-group">
<label class="col-form-label">{{ $options.i18n.form.approvalTypeLabel }}</label>
<approver-type-select <approver-type-select
v-model="ruleType" v-model="ruleType"
:approver-type-options="$options.approverTypeOptions" :approver-type-options="$options.approverTypeOptions"
/> />
</div> </gl-form-group>
<div v-if="!isExternalApprovalRule" class="form-group gl-form-group"> <template v-if="!isExternalApprovalRule">
<label class="col-form-label">{{ $options.i18n.form.approvalsRequiredLabel }}</label> <gl-form-group
<input :label="$options.i18n.form.approvalsRequiredLabel"
v-model.number="approvalsRequired" :state="isValidApprovalsRequired"
:class="{ 'is-invalid': !isValidApprovalsRequired }" :invalid-feedback="invalidApprovalsRequired"
class="gl-form-input form-control mw-6em" data-testid="approvals-required-group"
name="approvals_required" >
type="number" <gl-form-input
:min="minApprovalsRequired" v-model.number="approvalsRequired"
data-qa-selector="approvals_required_field" :state="isValidApprovalsRequired"
/> :min="minApprovalsRequired"
<span class="invalid-feedback">{{ class="mw-6em"
isValidApprovalsRequired ? '' : invalidApprovalsRequired type="number"
}}</span> data-testid="approvals-required"
</div> data-qa-selector="approvals_required_field"
<div v-if="!isExternalApprovalRule" class="form-group gl-form-group"> />
<label class="col-form-label">{{ $options.i18n.form.approversLabel }}</label> </gl-form-group>
<approvers-select <gl-form-group
v-model="approversToAdd" :label="$options.i18n.form.approversLabel"
:project-id="settings.projectId" :state="isValidApprovers"
:skip-user-ids="userIds" :invalid-feedback="invalidApprovers"
:skip-group-ids="groupIds" data-testid="approvers-group"
:is-invalid="!isValidApprovers" >
data-qa-selector="member_select_field" <approvers-select
/> v-model="approversToAdd"
<span class="invalid-feedback">{{ isValidApprovers ? '' : invalidApprovers }}</span> :project-id="settings.projectId"
</div> :skip-user-ids="userIds"
<div v-if="isExternalApprovalRule" class="form-group gl-form-group"> :skip-group-ids="groupIds"
<label class="col-form-label">{{ approvalGateLabel }}</label> :is-invalid="!isValidApprovers"
<input data-qa-selector="member_select_field"
/>
</gl-form-group>
</template>
<gl-form-group
v-if="isExternalApprovalRule"
:label="approvalGateLabel"
:description="$options.i18n.form.approvalGateDescription"
:state="isValidApprovalGateUrl"
:invalid-feedback="invalidApprovalGateUrl"
data-testid="approval-gate-url-group"
>
<gl-form-input
v-model="externalUrl" v-model="externalUrl"
:class="{ 'is-invalid': !isValidApprovalGateUrl }" :state="isValidApprovalGateUrl"
class="gl-form-input form-control"
name="approval_gate_url"
type="url" type="url"
data-qa-selector="external_url_field" data-qa-selector="external_url_field"
data-testid="approval-gate-url"
/> />
<span class="invalid-feedback">{{ </gl-form-group>
isValidApprovalGateUrl ? '' : invalidApprovalGateUrl
}}</span>
<small class="form-text text-gl-muted">
{{ $options.i18n.form.approvalGateDescription }}
</small>
</div>
<div v-if="!isExternalApprovalRule" class="bordered-box overflow-auto h-12em"> <div v-if="!isExternalApprovalRule" class="bordered-box overflow-auto h-12em">
<approvers-list v-model="approvers" /> <approvers-list v-model="approvers" />
</div> </div>
......
...@@ -62,7 +62,9 @@ RSpec.describe 'Merge request > User edits MR with approval rules', :js do ...@@ -62,7 +62,9 @@ RSpec.describe 'Merge request > User edits MR with approval rules', :js do
click_button "Add approval rule" click_button "Add approval rule"
fill_in "name", with: rule_name within_fieldset('Rule name') do
fill_in with: rule_name
end
add_approval_rule_member('user', approver.name) add_approval_rule_member('user', approver.name)
......
...@@ -228,9 +228,11 @@ RSpec.describe 'Merge request > User sets approvers', :js do ...@@ -228,9 +228,11 @@ RSpec.describe 'Merge request > User sets approvers', :js do
find('.merge-request').click_on 'Edit' find('.merge-request').click_on 'Edit'
open_modal open_modal
expect(page).to have_field 'approvals_required', exact: 2 within_fieldset('Approvals required') do
expect(find_field.value).to eq '2'
fill_in 'approvals_required', with: '3' fill_in with: '3'
end
click_button 'Update approval rule' click_button 'Update approval rule'
click_on('Save changes') click_on('Save changes')
...@@ -245,7 +247,9 @@ RSpec.describe 'Merge request > User sets approvers', :js do ...@@ -245,7 +247,9 @@ RSpec.describe 'Merge request > User sets approvers', :js do
open_modal open_modal
expect(page).to have_field 'approvals_required', exact: 3 within_fieldset('Approvals required') do
expect(find_field.value).to eq '3'
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment