debian-mirror-gitlab/app/assets/javascripts/add_context_commits_modal/utils.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
1 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
export const findCommitIndex = (commits, commitShortId) => {
2021-03-08 18:12:59 +05:30
return commits.findIndex((commit) => commit.short_id === commitShortId);
2020-10-24 23:57:45 +05:30
};
export const setCommitStatus = (commits, commitIndex, selected) => {
const tempCommits = [...commits];
tempCommits[commitIndex] = {
...tempCommits[commitIndex],
isSelected: selected,
};
return tempCommits;
};
export const removeIfReadyToBeRemoved = (toRemoveCommits, commitShortId) => {
const tempToRemoveCommits = [...toRemoveCommits];
const isPresentInToRemove = tempToRemoveCommits.indexOf(commitShortId);
if (isPresentInToRemove !== -1) {
tempToRemoveCommits.splice(isPresentInToRemove, 1);
}
return tempToRemoveCommits;
};
export const removeIfPresent = (selectedCommits, commitShortId) => {
const tempSelectedCommits = [...selectedCommits];
const selectedCommitsIndex = findCommitIndex(tempSelectedCommits, commitShortId);
if (selectedCommitsIndex !== -1) {
tempSelectedCommits.splice(selectedCommitsIndex, 1);
}
return tempSelectedCommits;
};