Commit 44638c2d authored by Michael Lunøe's avatar Michael Lunøe Committed by Enrique Alcántara

Refactor(createFlash): use non-deprecated function

Migrate away from `deprecatedCreateFlash` and use
`createFlash` instead.

Manual changes

Epic:
https://gitlab.com/groups/gitlab-org/-/epics/3895
parent 3b1e7b04
/* eslint-disable no-new */
import { debounce } from 'lodash';
import {
init as initConfidentialMergeRequest,
......@@ -8,7 +7,7 @@ import {
import confidentialMergeRequestState from './confidential_merge_request/state';
import DropLab from './droplab/drop_lab';
import ISetter from './droplab/plugins/input_setter';
import { deprecatedCreateFlash as Flash } from './flash';
import createFlash from './flash';
import axios from './lib/utils/axios_utils';
import { __, sprintf } from './locale';
......@@ -132,7 +131,9 @@ export default class CreateMergeRequestDropdown {
.catch(() => {
this.unavailable();
this.disable();
Flash(__('Failed to check related branches.'));
createFlash({
message: __('Failed to check related branches.'),
});
});
}
......@@ -147,7 +148,11 @@ export default class CreateMergeRequestDropdown {
this.branchCreated = true;
window.location.href = data.url;
})
.catch(() => Flash(__('Failed to create a branch for this issue. Please try again.')));
.catch(() =>
createFlash({
message: __('Failed to create a branch for this issue. Please try again.'),
}),
);
}
createMergeRequest() {
......@@ -163,7 +168,11 @@ export default class CreateMergeRequestDropdown {
this.mergeRequestCreated = true;
window.location.href = data.url;
})
.catch(() => Flash(__('Failed to create Merge Request. Please try again.')));
.catch(() =>
createFlash({
message: __('Failed to create Merge Request. Please try again.'),
}),
);
}
disable() {
......@@ -256,7 +265,9 @@ export default class CreateMergeRequestDropdown {
.catch(() => {
this.unavailable();
this.disable();
new Flash(__('Failed to get ref.'));
createFlash({
message: __('Failed to get ref.'),
});
this.isGettingRef = false;
......
import { __ } from '~/locale';
import Ajax from '../droplab/plugins/ajax';
import Filter from '../droplab/plugins/filter';
import { deprecatedCreateFlash as Flash } from '../flash';
import createFlash from '../flash';
import DropdownUtils from './dropdown_utils';
import FilteredSearchDropdown from './filtered_search_dropdown';
......@@ -14,9 +14,9 @@ export default class DropdownEmoji extends FilteredSearchDropdown {
method: 'setData',
loadingTemplate: this.loadingTemplate,
onError() {
/* eslint-disable no-new */
new Flash(__('An error occurred fetching the dropdown data.'));
/* eslint-enable no-new */
createFlash({
message: __('An error occurred fetching the dropdown data.'),
});
},
},
Filter: {
......
import { __ } from '~/locale';
import Ajax from '../droplab/plugins/ajax';
import Filter from '../droplab/plugins/filter';
import { deprecatedCreateFlash as Flash } from '../flash';
import createFlash from '../flash';
import DropdownUtils from './dropdown_utils';
import FilteredSearchDropdown from './filtered_search_dropdown';
......@@ -17,9 +17,9 @@ export default class DropdownNonUser extends FilteredSearchDropdown {
loadingTemplate: this.loadingTemplate,
preprocessing,
onError() {
/* eslint-disable no-new */
new Flash(__('An error occurred fetching the dropdown data.'));
/* eslint-enable no-new */
createFlash({
message: __('An error occurred fetching the dropdown data.'),
});
},
},
Filter: {
......
......@@ -10,7 +10,7 @@ import {
DOWN_KEY_CODE,
} from '~/lib/utils/keycodes';
import { __ } from '~/locale';
import { deprecatedCreateFlash as Flash } from '../flash';
import createFlash from '../flash';
import { addClassIfElementExists } from '../lib/utils/dom_utils';
import { visitUrl } from '../lib/utils/url_utility';
import FilteredSearchContainer from './container';
......@@ -92,8 +92,9 @@ export default class FilteredSearchManager {
.fetch()
.catch((error) => {
if (error.name === 'RecentSearchesServiceError') return undefined;
// eslint-disable-next-line no-new
new Flash(__('An error occurred while parsing recent searches'));
createFlash({
message: __('An error occurred while parsing recent searches'),
});
// Gracefully fail to empty array
return [];
})
......
......@@ -22,7 +22,7 @@ import syntaxHighlight from '~/syntax_highlight';
import Autosave from './autosave';
import loadAwardsHandler from './awards_handler';
import CommentTypeToggle from './comment_type_toggle';
import { deprecatedCreateFlash as Flash } from './flash';
import createFlash from './flash';
import { defaultAutocompleteConfig } from './gfm_auto_complete';
import GLForm from './gl_form';
import axios from './lib/utils/axios_utils';
......@@ -399,7 +399,11 @@ export default class Notes {
if (noteEntity.commands_changes && Object.keys(noteEntity.commands_changes).length > 0) {
$notesList.find('.system-note.being-posted').remove();
}
this.addFlash(noteEntity.errors.commands_only, 'notice', this.parentTimeline.get(0));
this.addFlash({
message: noteEntity.errors.commands_only,
type: 'notice',
parent: this.parentTimeline.get(0),
});
this.refresh();
}
return;
......@@ -620,20 +624,21 @@ export default class Notes {
} else if ($form.hasClass('js-discussion-note-form')) {
formParentTimeline = $form.closest('.discussion-notes').find('.notes');
}
return this.addFlash(
__(
return this.addFlash({
message: __(
'Your comment could not be submitted! Please check your network connection and try again.',
),
'alert',
formParentTimeline.get(0),
);
type: 'alert',
parent: formParentTimeline.get(0),
});
}
updateNoteError() {
// eslint-disable-next-line no-new
new Flash(
__('Your comment could not be updated! Please check your network connection and try again.'),
);
createFlash({
message: __(
'Your comment could not be updated! Please check your network connection and try again.',
),
});
}
/**
......@@ -1289,7 +1294,7 @@ export default class Notes {
}
addFlash(...flashParams) {
this.flashContainer = new Flash(...flashParams);
this.flashContainer = createFlash(...flashParams);
}
clearFlash() {
......
......@@ -15,10 +15,10 @@ import { isEmpty } from 'lodash';
import readyToMergeMixin from 'ee_else_ce/vue_merge_request_widget/mixins/ready_to_merge';
import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql';
import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests';
import createFlash from '~/flash';
import simplePoll from '~/lib/utils/simple_poll';
import { __ } from '~/locale';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { deprecatedCreateFlash as Flash } from '../../../flash';
import MergeRequest from '../../../merge_request';
import { AUTO_MERGE_STRATEGIES, DANGER, INFO, WARNING } from '../../constants';
import eventHub from '../../event_hub';
......@@ -351,7 +351,9 @@ export default {
})
.catch(() => {
this.isMakingRequest = false;
new Flash(__('Something went wrong. Please try again.')); // eslint-disable-line
createFlash({
message: __('Something went wrong. Please try again.'),
});
});
},
handleMergeImmediatelyButtonClick() {
......@@ -402,7 +404,9 @@ export default {
}
})
.catch(() => {
new Flash(__('Something went wrong while merging this merge request. Please try again.')); // eslint-disable-line
createFlash({
message: __('Something went wrong while merging this merge request. Please try again.'),
});
stopPolling();
});
},
......@@ -432,7 +436,9 @@ export default {
}
})
.catch(() => {
new Flash(__('Something went wrong while deleting the source branch. Please try again.')); // eslint-disable-line
createFlash({
message: __('Something went wrong while deleting the source branch. Please try again.'),
});
});
},
},
......
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