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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Mishunov <dmishunov@gitlab.com>2019-03-26 19:28:33 +0300
committerDenys Mishunov <dmishunov@gitlab.com>2019-04-04 10:05:50 +0300
commit5e0423ebc55089978291d0823574c8498994c3b9 (patch)
treeb2aa2c4685c7178e8b56993ef75ceb1687af3d79 /app/assets/javascripts/ide/stores/utils.js
parentf6a038b38ae6c256fb9d1f1cbe184b0d8bbb5fde (diff)
Set tree list accounting for already-opened files
Since we can create files from URL now, this means that these files will not exist in the tree returned from API: they exist on the client only before the first commit. In order to still show the newly-created files in the tree, we should not override the tree, but merge the tree existing on the client and the one coming from API. Changelog entry Moved trees merging into mutation
Diffstat (limited to 'app/assets/javascripts/ide/stores/utils.js')
-rw-r--r--app/assets/javascripts/ide/stores/utils.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js
index 0b2a18e9c8a..3ab8f3f11be 100644
--- a/app/assets/javascripts/ide/stores/utils.js
+++ b/app/assets/javascripts/ide/stores/utils.js
@@ -170,3 +170,31 @@ export const filePathMatches = (filePath, path) => filePath.indexOf(`${path}/`)
export const getChangesCountForFiles = (files, path) =>
files.filter(f => filePathMatches(f.path, path)).length;
+
+export const mergeTrees = (fromTree, toTree) => {
+ if (!fromTree || !fromTree.length) {
+ return toTree;
+ }
+
+ const recurseTree = (n, t) => {
+ if (!n) {
+ return t;
+ }
+ const existingTreeNode = t.find(el => el.path === n.path);
+
+ if (existingTreeNode && n.tree.length > 0) {
+ existingTreeNode.opened = true;
+ recurseTree(n.tree[0], existingTreeNode.tree);
+ } else if (!existingTreeNode) {
+ const sorted = sortTree(t.concat(n));
+ t.splice(0, t.length + 1, ...sorted);
+ }
+ return t;
+ };
+
+ for (let i = 0, l = fromTree.length; i < l; i += 1) {
+ recurseTree(fromTree[i], toTree);
+ }
+
+ return toTree;
+};