Commit 35d850db authored by Thomas Randolph's avatar Thomas Randolph

Remove File-By-File preference cookie

Since we now use a database setting to store the user's preference,
the cookie is redundant and can lead to some minor broken edge-cases.

Removing this cookie can also lead to a small annoyance in some
edge cases (see link below), but it's easily - and permanently -
remediated by toggling the checkbox again (or changing the user
preference in the settings page directly).

https://gitlab.com/gitlab-org/gitlab/-/issues/327162#note_549832248

Changelog: changed
parent 74c23236
...@@ -46,7 +46,6 @@ import { ...@@ -46,7 +46,6 @@ import {
import diffsEventHub from '../event_hub'; import diffsEventHub from '../event_hub';
import { reviewStatuses } from '../utils/file_reviews'; import { reviewStatuses } from '../utils/file_reviews';
import { diffsApp } from '../utils/performance'; import { diffsApp } from '../utils/performance';
import { fileByFile } from '../utils/preferences';
import { queueRedisHllEvents } from '../utils/queue_events'; import { queueRedisHllEvents } from '../utils/queue_events';
import CollapsedFilesWarning from './collapsed_files_warning.vue'; import CollapsedFilesWarning from './collapsed_files_warning.vue';
import CommitWidget from './commit_widget.vue'; import CommitWidget from './commit_widget.vue';
...@@ -331,7 +330,7 @@ export default { ...@@ -331,7 +330,7 @@ export default {
projectPath: this.projectPath, projectPath: this.projectPath,
dismissEndpoint: this.dismissEndpoint, dismissEndpoint: this.dismissEndpoint,
showSuggestPopover: this.showSuggestPopover, showSuggestPopover: this.showSuggestPopover,
viewDiffsFileByFile: fileByFile(this.fileByFileUserPreference), viewDiffsFileByFile: this.fileByFileUserPreference || false,
defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage, defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage,
mrReviews: this.rehydratedMrReviews, mrReviews: this.rehydratedMrReviews,
}); });
......
...@@ -72,11 +72,6 @@ export const ALERT_COLLAPSED_FILES = 'collapsed'; ...@@ -72,11 +72,6 @@ export const ALERT_COLLAPSED_FILES = 'collapsed';
export const DIFF_FILE_AUTOMATIC_COLLAPSE = 'automatic'; export const DIFF_FILE_AUTOMATIC_COLLAPSE = 'automatic';
export const DIFF_FILE_MANUAL_COLLAPSE = 'manual'; export const DIFF_FILE_MANUAL_COLLAPSE = 'manual';
// Diff view single file mode
export const DIFF_FILE_BY_FILE_COOKIE_NAME = 'fileViewMode';
export const DIFF_VIEW_FILE_BY_FILE = 'single';
export const DIFF_VIEW_ALL_FILES = 'all';
// State machine states // State machine states
export const STATE_IDLING = 'idle'; export const STATE_IDLING = 'idle';
export const STATE_LOADING = 'loading'; export const STATE_LOADING = 'loading';
......
...@@ -29,9 +29,6 @@ import { ...@@ -29,9 +29,6 @@ import {
EVT_PERF_MARK_FILE_TREE_START, EVT_PERF_MARK_FILE_TREE_START,
EVT_PERF_MARK_FILE_TREE_END, EVT_PERF_MARK_FILE_TREE_END,
EVT_PERF_MARK_DIFF_FILES_START, EVT_PERF_MARK_DIFF_FILES_START,
DIFF_VIEW_FILE_BY_FILE,
DIFF_VIEW_ALL_FILES,
DIFF_FILE_BY_FILE_COOKIE_NAME,
TRACKING_CLICK_DIFF_VIEW_SETTING, TRACKING_CLICK_DIFF_VIEW_SETTING,
TRACKING_DIFF_VIEW_INLINE, TRACKING_DIFF_VIEW_INLINE,
TRACKING_DIFF_VIEW_PARALLEL, TRACKING_DIFF_VIEW_PARALLEL,
...@@ -816,9 +813,7 @@ export const navigateToDiffFileIndex = ({ commit, state }, index) => { ...@@ -816,9 +813,7 @@ export const navigateToDiffFileIndex = ({ commit, state }, index) => {
}; };
export const setFileByFile = ({ state, commit }, { fileByFile }) => { export const setFileByFile = ({ state, commit }, { fileByFile }) => {
const fileViewMode = fileByFile ? DIFF_VIEW_FILE_BY_FILE : DIFF_VIEW_ALL_FILES;
commit(types.SET_FILE_BY_FILE, fileByFile); commit(types.SET_FILE_BY_FILE, fileByFile);
Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, fileViewMode);
if (window.gon?.features?.diffSettingsUsageData) { if (window.gon?.features?.diffSettingsUsageData) {
const events = [TRACKING_CLICK_SINGLE_FILE_SETTING]; const events = [TRACKING_CLICK_SINGLE_FILE_SETTING];
......
...@@ -2,8 +2,6 @@ import Cookies from 'js-cookie'; ...@@ -2,8 +2,6 @@ import Cookies from 'js-cookie';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants'; import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants';
import { fileByFile } from '../../utils/preferences';
const getViewTypeFromQueryString = () => getParameterValues('view')[0]; const getViewTypeFromQueryString = () => getParameterValues('view')[0];
const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME); const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME);
...@@ -36,7 +34,7 @@ export default () => ({ ...@@ -36,7 +34,7 @@ export default () => ({
highlightedRow: null, highlightedRow: null,
renderTreeList: true, renderTreeList: true,
showWhitespace: true, showWhitespace: true,
viewDiffsFileByFile: fileByFile(), viewDiffsFileByFile: false,
fileFinderVisible: false, fileFinderVisible: false,
dismissEndpoint: '', dismissEndpoint: '',
showSuggestPopover: true, showSuggestPopover: true,
......
import Cookies from 'js-cookie';
import { DIFF_FILE_BY_FILE_COOKIE_NAME, DIFF_VIEW_FILE_BY_FILE } from '../constants';
export function fileByFile(pref = false) {
const cookie = Cookies.get(DIFF_FILE_BY_FILE_COOKIE_NAME);
// use the cookie first, if it exists
if (cookie) {
return cookie === DIFF_VIEW_FILE_BY_FILE;
}
return pref;
}
import Cookies from 'js-cookie';
import {
DIFF_FILE_BY_FILE_COOKIE_NAME,
DIFF_VIEW_FILE_BY_FILE,
DIFF_VIEW_ALL_FILES,
} from '~/diffs/constants';
import { fileByFile } from '~/diffs/utils/preferences';
describe('diffs preferences', () => {
describe('fileByFile', () => {
afterEach(() => {
Cookies.remove(DIFF_FILE_BY_FILE_COOKIE_NAME);
});
it.each`
result | preference | cookie
${true} | ${false} | ${DIFF_VIEW_FILE_BY_FILE}
${false} | ${true} | ${DIFF_VIEW_ALL_FILES}
${true} | ${false} | ${DIFF_VIEW_FILE_BY_FILE}
${false} | ${true} | ${DIFF_VIEW_ALL_FILES}
${false} | ${false} | ${DIFF_VIEW_ALL_FILES}
${true} | ${true} | ${DIFF_VIEW_FILE_BY_FILE}
`(
'should return $result when { preference: $preference, cookie: $cookie }',
({ result, preference, cookie }) => {
Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, cookie);
expect(fileByFile(preference)).toBe(result);
},
);
});
});
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