Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « add_context_commits_modal « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3495ee17cd3bdc557c06b9528a6249e413a9e04e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export const findCommitIndex = (commits, commitShortId) => {
  return commits.findIndex(commit => commit.short_id === commitShortId);
};

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;
};