Commit 577c85bc authored by Tom Quirk's avatar Tom Quirk

Address maintainer feedback

- create consts for each i18n text variable
- move createBranch to async/await
- add namespacing to some translations
parent 66a92513
...@@ -4,7 +4,11 @@ import { ...@@ -4,7 +4,11 @@ import {
CREATE_BRANCH_ERROR_GENERIC, CREATE_BRANCH_ERROR_GENERIC,
CREATE_BRANCH_ERROR_WITH_CONTEXT, CREATE_BRANCH_ERROR_WITH_CONTEXT,
CREATE_BRANCH_SUCCESS_ALERT, CREATE_BRANCH_SUCCESS_ALERT,
I18N_NEW_BRANCH_FORM, I18N_NEW_BRANCH_PAGE_TITLE,
I18N_NEW_BRANCH_LABEL_DROPDOWN,
I18N_NEW_BRANCH_LABEL_BRANCH,
I18N_NEW_BRANCH_LABEL_SOURCE,
I18N_NEW_BRANCH_SUBMIT_BUTTON_TEXT,
} from '../constants'; } from '../constants';
import createBranchMutation from '../graphql/mutations/create_branch.mutation.graphql'; import createBranchMutation from '../graphql/mutations/create_branch.mutation.graphql';
import ProjectDropdown from './project_dropdown.vue'; import ProjectDropdown from './project_dropdown.vue';
...@@ -60,19 +64,11 @@ export default { ...@@ -60,19 +64,11 @@ export default {
}, },
}, },
methods: { methods: {
displayAlert({ displayAlert({ title, message, variant = DEFAULT_ALERT_VARIANT } = {}) {
title,
message,
variant = DEFAULT_ALERT_VARIANT,
primaryButtonLink,
primaryButtonText,
} = {}) {
this.alertParams = { this.alertParams = {
title, title,
message, message,
variant, variant,
primaryButtonLink,
primaryButtonText,
}; };
}, },
onAlertDismiss() { onAlertDismiss() {
...@@ -98,42 +94,43 @@ export default { ...@@ -98,42 +94,43 @@ export default {
}, },
async createBranch() { async createBranch() {
this.createBranchLoading = true; this.createBranchLoading = true;
this.$apollo
.mutate({ try {
const { data } = await this.$apollo.mutate({
mutation: createBranchMutation, mutation: createBranchMutation,
variables: { variables: {
name: this.branchName, name: this.branchName,
ref: this.selectedSourceBranchName, ref: this.selectedSourceBranchName,
projectPath: this.selectedProject.fullPath, projectPath: this.selectedProject.fullPath,
}, },
}) });
.then(({ data }) => {
const { errors } = data.createBranch; const { errors } = data.createBranch;
if (errors.length > 0) { if (errors.length > 0) {
this.onError({ this.onError({
title: CREATE_BRANCH_ERROR_WITH_CONTEXT, title: CREATE_BRANCH_ERROR_WITH_CONTEXT,
message: errors[0], message: errors[0],
}); });
return; } else {
}
this.displayAlert({ this.displayAlert({
...CREATE_BRANCH_SUCCESS_ALERT, ...CREATE_BRANCH_SUCCESS_ALERT,
variant: 'success', variant: 'success',
}); });
}) }
.catch(() => { } catch (e) {
this.onError({ this.onError({
message: CREATE_BRANCH_ERROR_GENERIC, message: CREATE_BRANCH_ERROR_GENERIC,
}); });
}) }
.finally(() => {
this.createBranchLoading = false; this.createBranchLoading = false;
});
}, },
}, },
i18n: { i18n: {
I18N_NEW_BRANCH_FORM, I18N_NEW_BRANCH_PAGE_TITLE,
I18N_NEW_BRANCH_LABEL_DROPDOWN,
I18N_NEW_BRANCH_LABEL_BRANCH,
I18N_NEW_BRANCH_LABEL_SOURCE,
I18N_NEW_BRANCH_SUBMIT_BUTTON_TEXT,
}, },
}; };
</script> </script>
...@@ -142,7 +139,7 @@ export default { ...@@ -142,7 +139,7 @@ export default {
<div> <div>
<div class="gl-border-1 gl-border-b-solid gl-border-gray-100 gl-mb-5 gl-mt-7"> <div class="gl-border-1 gl-border-b-solid gl-border-gray-100 gl-mb-5 gl-mt-7">
<h1 class="page-title"> <h1 class="page-title">
{{ $options.i18n.I18N_NEW_BRANCH_FORM.pageTitle }} {{ $options.i18n.I18N_NEW_BRANCH_PAGE_TITLE }}
</h1> </h1>
</div> </div>
...@@ -151,8 +148,6 @@ export default { ...@@ -151,8 +148,6 @@ export default {
class="gl-mb-5" class="gl-mb-5"
:variant="alertParams.variant" :variant="alertParams.variant"
:title="alertParams.title" :title="alertParams.title"
:primary-button-link="alertParams.primaryButtonLink"
:primary-button-text="alertParams.primaryButtonText"
@dismiss="onAlertDismiss" @dismiss="onAlertDismiss"
> >
{{ alertParams.message }} {{ alertParams.message }}
...@@ -160,7 +155,7 @@ export default { ...@@ -160,7 +155,7 @@ export default {
<gl-form @submit.prevent="onSubmit"> <gl-form @submit.prevent="onSubmit">
<gl-form-group <gl-form-group
:label="$options.i18n.I18N_NEW_BRANCH_FORM.labels.projectDropdown" :label="$options.i18n.I18N_NEW_BRANCH_LABEL_DROPDOWN"
label-for="project-select" label-for="project-select"
> >
<project-dropdown <project-dropdown
...@@ -172,14 +167,14 @@ export default { ...@@ -172,14 +167,14 @@ export default {
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group
:label="$options.i18n.I18N_NEW_BRANCH_FORM.labels.branchNameInput" :label="$options.i18n.I18N_NEW_BRANCH_LABEL_BRANCH"
label-for="branch-name-input" label-for="branch-name-input"
> >
<gl-form-input id="branch-name-input" v-model="branchName" type="text" required /> <gl-form-input id="branch-name-input" v-model="branchName" type="text" required />
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group
:label="$options.i18n.I18N_NEW_BRANCH_FORM.labels.sourceBranchDropdown" :label="$options.i18n.I18N_NEW_BRANCH_LABEL_SOURCE"
label-for="source-branch-select" label-for="source-branch-select"
> >
<source-branch-dropdown <source-branch-dropdown
...@@ -198,7 +193,7 @@ export default { ...@@ -198,7 +193,7 @@ export default {
variant="confirm" variant="confirm"
:disabled="disableSubmitButton" :disabled="disableSubmitButton"
> >
{{ $options.i18n.I18N_NEW_BRANCH_FORM.formSubmitButtonText }} {{ $options.i18n.I18N_NEW_BRANCH_SUBMIT_BUTTON_TEXT }}
</gl-button> </gl-button>
</div> </div>
</gl-form> </gl-form>
......
import { __ } from '~/locale'; import { __, s__ } from '~/locale';
export const BRANCHES_PER_PAGE = 20; export const BRANCHES_PER_PAGE = 20;
export const PROJECTS_PER_PAGE = 20; export const PROJECTS_PER_PAGE = 20;
export const I18N_NEW_BRANCH_FORM = { export const I18N_NEW_BRANCH_PAGE_TITLE = __('New branch');
pageTitle: __('New branch'), export const I18N_NEW_BRANCH_LABEL_DROPDOWN = __('Project');
labels: { export const I18N_NEW_BRANCH_LABEL_BRANCH = __('Branch name');
projectDropdown: __('Project'), export const I18N_NEW_BRANCH_LABEL_SOURCE = __('Source branch');
branchNameInput: __('Branch name'), export const I18N_NEW_BRANCH_SUBMIT_BUTTON_TEXT = __('Create branch');
sourceBranchDropdown: __('Source branch'),
},
formSubmitButtonText: __('Create branch'),
};
export const CREATE_BRANCH_ERROR_GENERIC = __('Failed to create branch. Please try again.'); export const CREATE_BRANCH_ERROR_GENERIC = s__(
export const CREATE_BRANCH_ERROR_WITH_CONTEXT = __('Failed to create branch.'); 'JiraConnect|Failed to create branch. Please try again.',
);
export const CREATE_BRANCH_ERROR_WITH_CONTEXT = s__('JiraConnect|Failed to create branch.');
export const CREATE_BRANCH_SUCCESS_ALERT = { export const CREATE_BRANCH_SUCCESS_ALERT = {
title: __('New branch was successfully created.'), title: s__('JiraConnect|New branch was successfully created.'),
message: __('You can now close this window and return to Jira.'), message: s__('JiraConnect|You can now close this window and return to Jira.'),
}; };
...@@ -13461,12 +13461,6 @@ msgstr "" ...@@ -13461,12 +13461,6 @@ msgstr ""
msgid "Failed to create a to-do item for the design." msgid "Failed to create a to-do item for the design."
msgstr "" msgstr ""
msgid "Failed to create branch."
msgstr ""
msgid "Failed to create branch. Please try again."
msgstr ""
msgid "Failed to create framework" msgid "Failed to create framework"
msgstr "" msgstr ""
...@@ -18535,6 +18529,18 @@ msgstr "" ...@@ -18535,6 +18529,18 @@ msgstr ""
msgid "Jira-GitLab user mapping template" msgid "Jira-GitLab user mapping template"
msgstr "" msgstr ""
msgid "JiraConnect|Failed to create branch."
msgstr ""
msgid "JiraConnect|Failed to create branch. Please try again."
msgstr ""
msgid "JiraConnect|New branch was successfully created."
msgstr ""
msgid "JiraConnect|You can now close this window and return to Jira."
msgstr ""
msgid "JiraService| on branch %{branch_link}" msgid "JiraService| on branch %{branch_link}"
msgstr "" msgstr ""
...@@ -21907,9 +21913,6 @@ msgstr "" ...@@ -21907,9 +21913,6 @@ msgstr ""
msgid "New branch unavailable" msgid "New branch unavailable"
msgstr "" msgstr ""
msgid "New branch was successfully created."
msgstr ""
msgid "New changes were added. %{linkStart}Reload the page to review them%{linkEnd}" msgid "New changes were added. %{linkStart}Reload the page to review them%{linkEnd}"
msgstr "" msgstr ""
...@@ -37458,9 +37461,6 @@ msgstr "" ...@@ -37458,9 +37461,6 @@ msgstr ""
msgid "You can notify the app / group or a project by sending them an email notification" msgid "You can notify the app / group or a project by sending them an email notification"
msgstr "" msgstr ""
msgid "You can now close this window and return to Jira."
msgstr ""
msgid "You can now close this window." msgid "You can now close this window."
msgstr "" msgstr ""
......
...@@ -180,6 +180,7 @@ describe('NewBranchForm', () => { ...@@ -180,6 +180,7 @@ describe('NewBranchForm', () => {
await findForm().vm.$emit('submit', new Event('submit')); await findForm().vm.$emit('submit', new Event('submit'));
await waitForPromises(); await waitForPromises();
}); });
it('displays an alert', () => { it('displays an alert', () => {
const alert = findAlert(); const alert = findAlert();
expect(alert.exists()).toBe(true); expect(alert.exists()).toBe(true);
......
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