diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:09:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 00:09:19 +0300 |
commit | 254ec28f5448f6f353cd98f637985de3d1405854 (patch) | |
tree | 1c84ed7b7dd32db96454af034cd6c7e90699e76d /app/assets/javascripts/diffs/store | |
parent | 141902c04943d5fb43c014b8cf42af60a3bc0cdf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/diffs/store')
3 files changed, 46 insertions, 1 deletions
diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js index 3898974638f..047caed1e63 100644 --- a/app/assets/javascripts/diffs/store/getters.js +++ b/app/assets/javascripts/diffs/store/getters.js @@ -1,6 +1,8 @@ import { __, n__ } from '~/locale'; import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants'; +export * from './getters_versions_dropdowns'; + export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE; export const isInlineView = state => state.diffViewType === INLINE_DIFF_VIEW_TYPE; diff --git a/app/assets/javascripts/diffs/store/getters_versions_dropdowns.js b/app/assets/javascripts/diffs/store/getters_versions_dropdowns.js new file mode 100644 index 00000000000..14c51602f28 --- /dev/null +++ b/app/assets/javascripts/diffs/store/getters_versions_dropdowns.js @@ -0,0 +1,43 @@ +import { __, n__, sprintf } from '~/locale'; +import { DIFF_COMPARE_BASE_VERSION_INDEX } from '../constants'; + +export const selectedTargetIndex = state => + state.startVersion?.version_index || DIFF_COMPARE_BASE_VERSION_INDEX; + +export const selectedSourceIndex = state => state.mergeRequestDiff.version_index; + +export const diffCompareDropdownTargetVersions = (state, getters) => { + // startVersion only exists if the user has selected a version other + // than "base" so if startVersion is null then base must be selected + const baseVersion = { + versionName: state.targetBranchName, + version_index: DIFF_COMPARE_BASE_VERSION_INDEX, + href: state.mergeRequestDiff.base_version_path, + isBase: true, + selected: !state.startVersion, + }; + // Appended properties here are to make the compare_dropdown_layout easier to reason about + const formatVersion = v => { + return { + href: v.compare_path, + versionName: sprintf(__(`version %{versionIndex}`), { versionIndex: v.version_index }), + selected: v.version_index === getters.selectedTargetIndex, + ...v, + }; + }; + return [...state.mergeRequestDiffs.slice(1).map(formatVersion), baseVersion]; +}; + +export const diffCompareDropdownSourceVersions = (state, getters) => { + // Appended properties here are to make the compare_dropdown_layout easier to reason about + return state.mergeRequestDiffs.map((v, i) => ({ + ...v, + href: v.version_path, + commitsText: n__(`%d commit,`, `%d commits,`, v.commits_count), + versionName: + i === 0 + ? __('latest version') + : sprintf(__(`version %{versionIndex}`), { versionIndex: v.version_index }), + selected: v.version_index === getters.selectedSourceIndex, + })); +}; diff --git a/app/assets/javascripts/diffs/store/modules/diff_state.js b/app/assets/javascripts/diffs/store/modules/diff_state.js index 81f1506260c..87938ababed 100644 --- a/app/assets/javascripts/diffs/store/modules/diff_state.js +++ b/app/assets/javascripts/diffs/store/modules/diff_state.js @@ -15,7 +15,7 @@ export default () => ({ endpoint: '', basePath: '', commit: null, - startVersion: null, + startVersion: null, // Null unless a target diff is selected for comparison that is not the "base" diff diffFiles: [], coverageFiles: {}, mergeRequestDiffs: [], |