Commit d772ee75 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/337216/showErrorMessageBatchDiffs' into 'master'

Show error message when batch diffs errors

See merge request gitlab-org/gitlab!68979
parents 39293fc6 6ea76f20
<script>
import { GlLoadingIcon, GlPagination, GlSprintf } from '@gitlab/ui';
import { GlLoadingIcon, GlPagination, GlSprintf, GlAlert } from '@gitlab/ui';
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import Mousetrap from 'mousetrap';
import { mapState, mapGetters, mapActions } from 'vuex';
......@@ -77,6 +77,7 @@ export default {
GlPagination,
GlSprintf,
MrWidgetHowToMergeModal,
GlAlert,
},
alerts: {
ALERT_OVERFLOW_HIDDEN,
......@@ -199,7 +200,6 @@ export default {
...mapState('diffs', [
'showTreeList',
'isLoading',
'isBatchLoading',
'diffFiles',
'diffViewType',
'commit',
......@@ -226,6 +226,8 @@ export default {
'isParallelView',
'currentDiffIndex',
'isVirtualScrollingEnabled',
'isBatchLoading',
'isBatchLoadingError',
]),
...mapGetters('batchComments', ['draftsCount']),
...mapGetters(['isNotesFetched', 'getNoteableData']),
......@@ -620,6 +622,9 @@ export default {
this.subscribedToVirtualScrollingEvents = true;
}
},
reloadPage() {
window.location.reload();
},
},
minTreeWidth: MIN_TREE_WIDTH,
maxTreeWidth: MAX_TREE_WIDTH,
......@@ -638,17 +643,19 @@ export default {
:diff-files-count-text="numTotalFiles"
/>
<hidden-files-warning
v-if="visibleWarning == $options.alerts.ALERT_OVERFLOW_HIDDEN"
:visible="numVisibleFiles"
:total="numTotalFiles"
:plain-diff-path="plainDiffPath"
:email-patch-path="emailPatchPath"
/>
<collapsed-files-warning
v-if="visibleWarning == $options.alerts.ALERT_COLLAPSED_FILES"
:limited="isLimitedContainer"
/>
<template v-if="!isBatchLoadingError">
<hidden-files-warning
v-if="visibleWarning == $options.alerts.ALERT_OVERFLOW_HIDDEN"
:visible="numVisibleFiles"
:total="numTotalFiles"
:plain-diff-path="plainDiffPath"
:email-patch-path="emailPatchPath"
/>
<collapsed-files-warning
v-if="visibleWarning == $options.alerts.ALERT_COLLAPSED_FILES"
:limited="isLimitedContainer"
/>
</template>
<div
:data-can-create-note="getNoteableData.current_user.can_create_note"
......@@ -677,7 +684,18 @@ export default {
}"
>
<commit-widget v-if="commit" :commit="commit" :collapsible="false" />
<div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div>
<gl-alert
v-if="isBatchLoadingError"
variant="danger"
:dismissible="false"
:primary-button-text="__('Reload page')"
@primaryAction="reloadPage"
>
{{ __("Error: Couldn't load some or all of the changes.") }}
</gl-alert>
<div v-if="isBatchLoading && !isBatchLoadingError" class="loading">
<gl-loading-icon size="lg" />
</div>
<template v-else-if="renderDiffFiles">
<dynamic-scroller
v-if="isVirtualScrollingEnabled"
......@@ -753,7 +771,10 @@ export default {
</div>
<gl-loading-icon v-else-if="retrievingBatches" size="lg" />
</template>
<no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" />
<no-changes
v-else-if="!isBatchLoadingError"
:changes-empty-state-illustration="changesEmptyStateIllustration"
/>
</div>
</div>
<mr-widget-how-to-merge-modal
......
......@@ -101,7 +101,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
let totalLoaded = 0;
let scrolledVirtualScroller = false;
commit(types.SET_BATCH_LOADING, true);
commit(types.SET_BATCH_LOADING_STATE, 'loading');
commit(types.SET_RETRIEVING_BATCHES, true);
eventHub.$emit(EVT_PERF_MARK_DIFF_FILES_START);
......@@ -112,7 +112,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
totalLoaded += diff_files.length;
commit(types.SET_DIFF_DATA_BATCH, { diff_files });
commit(types.SET_BATCH_LOADING, false);
commit(types.SET_BATCH_LOADING_STATE, 'loaded');
if (window.gon?.features?.diffsVirtualScrolling && !scrolledVirtualScroller) {
const index = state.diffFiles.findIndex(
......@@ -127,7 +127,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
}
if (!isNoteLink && !state.currentDiffFileId) {
commit(types.VIEW_DIFF_FILE, diff_files[0].file_hash);
commit(types.VIEW_DIFF_FILE, diff_files[0]?.file_hash);
}
if (isNoteLink) {
......@@ -179,11 +179,14 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
return null;
})
.catch(() => commit(types.SET_RETRIEVING_BATCHES, false));
.catch(() => {
commit(types.SET_RETRIEVING_BATCHES, false);
commit(types.SET_BATCH_LOADING_STATE, 'error');
});
return getBatch()
.then(() => !window.gon?.features?.diffsVirtualScrolling && handleLocationHash())
.catch(() => null);
return getBatch().then(
() => !window.gon?.features?.diffsVirtualScrolling && handleLocationHash(),
);
};
export const fetchDiffFilesMeta = ({ commit, state }) => {
......
......@@ -191,3 +191,6 @@ export const isVirtualScrollingEnabled = (state) => {
getParameterValues('virtual_scrolling')[0] === 'true')
);
};
export const isBatchLoading = (state) => state.batchLoadingState === 'loading';
export const isBatchLoadingError = (state) => state.batchLoadingState === 'error';
......@@ -10,7 +10,7 @@ const defaultViewType = INLINE_DIFF_VIEW_TYPE;
export default () => ({
isLoading: true,
isTreeLoaded: false,
isBatchLoading: false,
batchLoadingState: null,
retrievingBatches: false,
addedLines: null,
removedLines: null,
......
export const SET_BASE_CONFIG = 'SET_BASE_CONFIG';
export const SET_LOADING = 'SET_LOADING';
export const SET_BATCH_LOADING = 'SET_BATCH_LOADING';
export const SET_BATCH_LOADING_STATE = 'SET_BATCH_LOADING_STATE';
export const SET_RETRIEVING_BATCHES = 'SET_RETRIEVING_BATCHES';
export const SET_DIFF_METADATA = 'SET_DIFF_METADATA';
......
......@@ -60,8 +60,8 @@ export default {
Object.assign(state, { isLoading });
},
[types.SET_BATCH_LOADING](state, isBatchLoading) {
Object.assign(state, { isBatchLoading });
[types.SET_BATCH_LOADING_STATE](state, batchLoadingState) {
Object.assign(state, { batchLoadingState });
},
[types.SET_RETRIEVING_BATCHES](state, retrievingBatches) {
......
......@@ -13297,6 +13297,9 @@ msgstr ""
msgid "Error: %{error_message}"
msgstr ""
msgid "Error: Couldn't load some or all of the changes."
msgstr ""
msgid "Error: No AWS credentials were supplied"
msgstr ""
......@@ -27819,6 +27822,9 @@ msgstr ""
msgid "Release|Something went wrong while saving the release details."
msgstr ""
msgid "Reload page"
msgstr ""
msgid "Remediations"
msgstr ""
......
......@@ -183,7 +183,7 @@ describe('diffs/components/app', () => {
it('displays loading icon on batch loading', () => {
createComponent({}, ({ state }) => {
state.diffs.isBatchLoading = true;
state.diffs.batchLoadingState = 'loading';
});
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
......
......@@ -186,15 +186,16 @@ describe('DiffsStoreActions', () => {
{},
{ endpointBatch, diffViewType: 'inline' },
[
{ type: types.SET_BATCH_LOADING, payload: true },
{ type: types.SET_BATCH_LOADING_STATE, payload: 'loading' },
{ type: types.SET_RETRIEVING_BATCHES, payload: true },
{ type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: res1.diff_files } },
{ type: types.SET_BATCH_LOADING, payload: false },
{ type: types.SET_BATCH_LOADING_STATE, payload: 'loaded' },
{ type: types.VIEW_DIFF_FILE, payload: 'test' },
{ type: types.SET_DIFF_DATA_BATCH, payload: { diff_files: res2.diff_files } },
{ type: types.SET_BATCH_LOADING, payload: false },
{ type: types.SET_BATCH_LOADING_STATE, payload: 'loaded' },
{ type: types.VIEW_DIFF_FILE, payload: 'test2' },
{ type: types.SET_RETRIEVING_BATCHES, payload: false },
{ type: types.SET_BATCH_LOADING_STATE, payload: 'error' },
],
[{ type: 'startRenderDiffsQueue' }, { type: 'startRenderDiffsQueue' }],
done,
......
......@@ -31,13 +31,13 @@ describe('DiffsStoreMutations', () => {
});
});
describe('SET_BATCH_LOADING', () => {
describe('SET_BATCH_LOADING_STATE', () => {
it('should set loading state', () => {
const state = {};
mutations[types.SET_BATCH_LOADING](state, false);
mutations[types.SET_BATCH_LOADING_STATE](state, false);
expect(state.isBatchLoading).toEqual(false);
expect(state.batchLoadingState).toEqual(false);
});
});
......
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