Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a6ddf230
Commit
a6ddf230
authored
Apr 20, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed horrible getter & instead prefer the state
the state now gets updated whenever a file is changed/discard
parent
1e9b57a2
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
38 additions
and
82 deletions
+38
-82
app/assets/javascripts/ide/components/repo_file.vue
app/assets/javascripts/ide/components/repo_file.vue
+3
-7
app/assets/javascripts/ide/stores/actions/file.js
app/assets/javascripts/ide/stores/actions/file.js
+13
-1
app/assets/javascripts/ide/stores/actions/tree.js
app/assets/javascripts/ide/stores/actions/tree.js
+10
-0
app/assets/javascripts/ide/stores/getters.js
app/assets/javascripts/ide/stores/getters.js
+0
-11
app/assets/javascripts/ide/stores/mutation_types.js
app/assets/javascripts/ide/stores/mutation_types.js
+1
-0
app/assets/javascripts/ide/stores/mutations/tree.js
app/assets/javascripts/ide/stores/mutations/tree.js
+5
-0
app/assets/javascripts/ide/stores/utils.js
app/assets/javascripts/ide/stores/utils.js
+4
-0
app/assets/javascripts/ide/stores/workers/files_decorator_worker.js
.../javascripts/ide/stores/workers/files_decorator_worker.js
+2
-0
spec/javascripts/ide/stores/getters_spec.js
spec/javascripts/ide/stores/getters_spec.js
+0
-63
No files found.
app/assets/javascripts/ide/components/repo_file.vue
View file @
a6ddf230
<
script
>
import
{
mapActions
,
mapGetters
}
from
'
vuex
'
;
import
{
mapActions
}
from
'
vuex
'
;
import
SkeletonLoadingContainer
from
'
~/vue_shared/components/skeleton_loading_container.vue
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
FileIcon
from
'
~/vue_shared/components/file_icon.vue
'
;
...
...
@@ -31,10 +31,6 @@ export default {
},
},
computed
:
{
...
mapGetters
([
'
getChangesInFolder
'
]),
folderChangedCount
()
{
return
this
.
getChangesInFolder
(
this
.
file
.
path
);
},
isTree
()
{
return
this
.
file
.
type
===
'
tree
'
;
},
...
...
@@ -108,10 +104,10 @@ export default {
v-if=
"file.mrChange"
/>
<span
v-if=
"isTree && f
olderChanged
Count > 0"
v-if=
"isTree && f
ile.changes
Count > 0"
class=
"ide-tree-changes"
>
{{
f
olderChanged
Count
}}
{{
f
ile
.
changes
Count
}}
<icon
name=
"file-modified"
:size=
"12"
...
...
app/assets/javascripts/ide/stores/actions/file.js
View file @
a6ddf230
...
...
@@ -117,16 +117,24 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) =
});
};
export
const
changeFileContent
=
({
state
,
commit
},
{
path
,
content
})
=>
{
export
const
changeFileContent
=
({
state
,
commit
,
dispatch
,
getters
},
{
path
,
content
})
=>
{
const
file
=
state
.
entries
[
path
];
const
stagedFile
=
getters
.
getStagedFile
(
path
);
commit
(
types
.
UPDATE_FILE_CONTENT
,
{
path
,
content
});
const
indexOfChangedFile
=
state
.
changedFiles
.
findIndex
(
f
=>
f
.
path
===
path
);
if
(
file
.
changed
&&
indexOfChangedFile
===
-
1
)
{
commit
(
types
.
ADD_FILE_TO_CHANGED
,
path
);
if
(
!
stagedFile
)
{
dispatch
(
'
updateChangesCount
'
,
{
path
,
count
:
+
1
});
}
}
else
if
(
!
file
.
changed
&&
indexOfChangedFile
!==
-
1
)
{
commit
(
types
.
REMOVE_FILE_FROM_CHANGED
,
path
);
if
(
!
stagedFile
)
{
dispatch
(
'
updateChangesCount
'
,
{
path
,
count
:
-
1
});
}
}
};
...
...
@@ -162,6 +170,10 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) =
commit
(
types
.
DISCARD_FILE_CHANGES
,
path
);
commit
(
types
.
REMOVE_FILE_FROM_CHANGED
,
path
);
if
(
!
getters
.
getStagedFile
(
path
))
{
dispatch
(
'
updateChangesCount
'
,
{
path
,
count
:
-
1
});
}
if
(
file
.
tempFile
&&
file
.
opened
)
{
commit
(
types
.
TOGGLE_FILE_OPEN
,
path
);
}
else
if
(
getters
.
activeFile
&&
file
.
path
===
getters
.
activeFile
.
path
)
{
...
...
app/assets/javascripts/ide/stores/actions/tree.js
View file @
a6ddf230
...
...
@@ -93,3 +93,13 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
resolve
();
}
});
export
const
updateChangesCount
=
({
commit
,
dispatch
,
state
},
{
path
,
count
})
=>
{
commit
(
types
.
UPDATE_FOLDER_CHANGE_COUNT
,
{
path
,
count
});
const
parentPath
=
state
.
entries
[
path
].
parentPath
;
if
(
parentPath
)
{
dispatch
(
'
updateChangesCount
'
,
{
path
:
parentPath
,
count
});
}
};
app/assets/javascripts/ide/stores/getters.js
View file @
a6ddf230
...
...
@@ -42,15 +42,4 @@ export const collapseButtonTooltip = state =>
export
const
hasMergeRequest
=
state
=>
!!
state
.
currentMergeRequestId
;
export
const
getChangesInFolder
=
(
state
,
getters
)
=>
path
=>
{
const
filePathMatches
=
f
=>
f
.
path
.
replace
(
new
RegExp
(
`/
${
f
.
name
}
$`
),
''
).
indexOf
(
path
)
===
0
;
const
changedFilesCount
=
state
.
changedFiles
.
filter
(
f
=>
filePathMatches
(
f
)).
length
;
const
stagedFilesCount
=
state
.
stagedFiles
.
filter
(
f
=>
filePathMatches
(
f
)
&&
!
getters
.
getChangedFile
(
f
.
path
),
).
length
;
return
changedFilesCount
+
stagedFilesCount
;
};
export
const
getChangedFile
=
state
=>
path
=>
state
.
stagedFiles
.
find
(
f
=>
f
.
path
===
path
);
export
const
getStagedFile
=
state
=>
path
=>
state
.
stagedFiles
.
find
(
f
=>
f
.
path
===
path
);
app/assets/javascripts/ide/stores/mutation_types.js
View file @
a6ddf230
...
...
@@ -28,6 +28,7 @@ export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN';
export
const
SET_LAST_COMMIT_URL
=
'
SET_LAST_COMMIT_URL
'
;
export
const
CREATE_TREE
=
'
CREATE_TREE
'
;
export
const
REMOVE_ALL_CHANGES_FILES
=
'
REMOVE_ALL_CHANGES_FILES
'
;
export
const
UPDATE_FOLDER_CHANGE_COUNT
=
'
UPDATE_FOLDER_CHANGE_COUNT
'
;
// File mutation types
export
const
SET_FILE_DATA
=
'
SET_FILE_DATA
'
;
...
...
app/assets/javascripts/ide/stores/mutations/tree.js
View file @
a6ddf230
...
...
@@ -31,4 +31,9 @@ export default {
changedFiles
:
[],
});
},
[
types
.
UPDATE_FOLDER_CHANGE_COUNT
](
state
,
{
path
,
count
})
{
Object
.
assign
(
state
.
entries
[
path
],
{
changesCount
:
state
.
entries
[
path
].
changesCount
+
count
,
});
},
};
app/assets/javascripts/ide/stores/utils.js
View file @
a6ddf230
...
...
@@ -42,6 +42,8 @@ export const dataStructure = () => ({
viewMode
:
'
edit
'
,
previewMode
:
null
,
size
:
0
,
parentPath
:
null
,
changesCount
:
0
,
});
export
const
decorateData
=
entity
=>
{
...
...
@@ -64,6 +66,7 @@ export const decorateData = entity => {
previewMode
,
file_lock
,
html
,
parentPath
=
''
,
}
=
entity
;
return
{
...
...
@@ -87,6 +90,7 @@ export const decorateData = entity => {
previewMode
,
file_lock
,
html
,
parentPath
,
};
};
...
...
app/assets/javascripts/ide/stores/workers/files_decorator_worker.js
View file @
a6ddf230
...
...
@@ -26,6 +26,7 @@ self.addEventListener('message', e => {
url
:
`/
${
projectId
}
/tree/
${
branchId
}
/
${
folderPath
}
/`
,
type
:
'
tree
'
,
parentTreeUrl
:
parentFolder
?
parentFolder
.
url
:
`/
${
projectId
}
/tree/
${
branchId
}
/`
,
parentPath
:
parentFolder
?
parentFolder
.
path
:
null
,
tempFile
,
changed
:
tempFile
,
opened
:
tempFile
,
...
...
@@ -61,6 +62,7 @@ self.addEventListener('message', e => {
url
:
`/
${
projectId
}
/blob/
${
branchId
}
/
${
path
}
`
,
type
:
'
blob
'
,
parentTreeUrl
:
fileFolder
?
fileFolder
.
url
:
`/
${
projectId
}
/blob/
${
branchId
}
`
,
parentPath
:
fileFolder
?
fileFolder
.
path
:
null
,
tempFile
,
changed
:
tempFile
,
content
,
...
...
spec/javascripts/ide/stores/getters_spec.js
View file @
a6ddf230
...
...
@@ -64,67 +64,4 @@ describe('IDE store getters', () => {
expect
(
getters
.
currentMergeRequest
(
localState
)).
toBeNull
();
});
});
describe
(
'
getChangesInFolder
'
,
()
=>
{
it
(
'
returns length of changed files for a path
'
,
()
=>
{
localState
.
changedFiles
.
push
(
{
path
:
'
test/index
'
,
name
:
'
index
'
,
},
{
path
:
'
testing/123
'
,
name
:
'
123
'
,
},
);
expect
(
getters
.
getChangesInFolder
(
localState
)(
'
test
'
)).
toBe
(
1
);
});
it
(
'
returns length of changed & staged files for a path
'
,
()
=>
{
localState
.
changedFiles
.
push
(
{
path
:
'
test/index
'
,
name
:
'
index
'
,
},
{
path
:
'
testing/123
'
,
name
:
'
123
'
,
},
);
localState
.
stagedFiles
.
push
(
{
path
:
'
test/123
'
,
name
:
'
123
'
,
},
{
path
:
'
test/index
'
,
name
:
'
index
'
,
},
{
path
:
'
testing/12345
'
,
name
:
'
12345
'
,
},
);
expect
(
getters
.
getChangesInFolder
(
localState
)(
'
test
'
)).
toBe
(
2
);
});
it
(
'
returns length of changed & tempFiles files for a path
'
,
()
=>
{
localState
.
changedFiles
.
push
(
{
path
:
'
test/index
'
,
name
:
'
index
'
,
},
{
path
:
'
test/newfile
'
,
name
:
'
newfile
'
,
tempFile
:
true
,
},
);
expect
(
getters
.
getChangesInFolder
(
localState
)(
'
test
'
)).
toBe
(
2
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment