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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
5d5579b3
Commit
5d5579b3
authored
Jun 27, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't reload the full page
instead it just pushes a router & re-fetches what it needs
parent
e815c68d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
27 deletions
+63
-27
app/assets/javascripts/ide/stores/actions/project.js
app/assets/javascripts/ide/stores/actions/project.js
+12
-7
app/assets/javascripts/ide/stores/actions/tree.js
app/assets/javascripts/ide/stores/actions/tree.js
+7
-2
spec/javascripts/ide/stores/actions/project_spec.js
spec/javascripts/ide/stores/actions/project_spec.js
+44
-18
No files found.
app/assets/javascripts/ide/stores/actions/project.js
View file @
5d5579b3
...
@@ -4,7 +4,7 @@ import { __, sprintf } from '~/locale';
...
@@ -4,7 +4,7 @@ import { __, sprintf } from '~/locale';
import
service
from
'
../../services
'
;
import
service
from
'
../../services
'
;
import
api
from
'
../../../api
'
;
import
api
from
'
../../../api
'
;
import
*
as
types
from
'
../mutation_types
'
;
import
*
as
types
from
'
../mutation_types
'
;
import
{
refreshCurrentPage
}
from
'
../../../lib/utils/url_utility
'
;
import
router
from
'
../../ide_router
'
;
export
const
getProjectData
=
({
commit
,
state
},
{
namespace
,
projectId
,
force
=
false
}
=
{})
=>
export
const
getProjectData
=
({
commit
,
state
},
{
namespace
,
projectId
,
force
=
false
}
=
{})
=>
new
Promise
((
resolve
,
reject
)
=>
{
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -91,19 +91,24 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {})
...
@@ -91,19 +91,24 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {})
flash
(
__
(
'
Error loading last commit.
'
),
'
alert
'
,
document
,
null
,
false
,
true
);
flash
(
__
(
'
Error loading last commit.
'
),
'
alert
'
,
document
,
null
,
false
,
true
);
});
});
export
const
createNewBranchFromDefault
=
({
state
,
getters
},
branch
)
=>
export
const
createNewBranchFromDefault
=
({
state
,
dispatch
,
getters
},
branch
)
=>
api
api
.
createBranch
(
state
.
currentProjectId
,
{
.
createBranch
(
state
.
currentProjectId
,
{
ref
:
getters
.
currentProject
.
default_branch
,
ref
:
getters
.
currentProject
.
default_branch
,
branch
,
branch
,
})
})
.
then
(()
=>
{
.
then
(()
=>
{
refreshCurrentPage
();
dispatch
(
'
setErrorMessage
'
,
null
);
router
.
push
(
`
${
router
.
currentRoute
.
path
}
?
${
Date
.
now
()}
`
);
// this forces the loading icon to spin whilst the page is reloading
return
new
Promise
(()
=>
{});
})
})
.
catch
(()
=>
{});
.
catch
(()
=>
{
dispatch
(
'
setErrorMessage
'
,
{
text
:
__
(
'
An error occured creating the new branch.
'
),
action
:
'
createNewBranchFromDefault
'
,
actionText
:
__
(
'
Please try again
'
),
actionPayload
:
branch
,
});
});
export
const
showBranchNotFoundError
=
({
dispatch
},
branchId
)
=>
{
export
const
showBranchNotFoundError
=
({
dispatch
},
branchId
)
=>
{
dispatch
(
'
setErrorMessage
'
,
{
dispatch
(
'
setErrorMessage
'
,
{
...
...
app/assets/javascripts/ide/stores/actions/tree.js
View file @
5d5579b3
import
{
normalizeHeaders
}
from
'
~/lib/utils/common_utils
'
;
import
{
normalizeHeaders
}
from
'
~/lib/utils/common_utils
'
;
import
flash
from
'
~/flash
'
;
import
flash
from
'
~/flash
'
;
import
{
__
}
from
'
../../../locale
'
;
import
service
from
'
../../services
'
;
import
service
from
'
../../services
'
;
import
*
as
types
from
'
../mutation_types
'
;
import
*
as
types
from
'
../mutation_types
'
;
import
{
findEntry
}
from
'
../utils
'
;
import
{
findEntry
}
from
'
../utils
'
;
...
@@ -64,7 +65,11 @@ export const getLastCommitData = ({ state, commit, dispatch }, tree = state) =>
...
@@ -64,7 +65,11 @@ export const getLastCommitData = ({ state, commit, dispatch }, tree = state) =>
export
const
getFiles
=
({
state
,
commit
,
dispatch
},
{
projectId
,
branchId
}
=
{})
=>
export
const
getFiles
=
({
state
,
commit
,
dispatch
},
{
projectId
,
branchId
}
=
{})
=>
new
Promise
((
resolve
,
reject
)
=>
{
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
state
.
trees
[
`
${
projectId
}
/
${
branchId
}
`
])
{
if
(
!
state
.
trees
[
`
${
projectId
}
/
${
branchId
}
`
]
||
(
state
.
trees
[
`
${
projectId
}
/
${
branchId
}
`
].
tree
&&
state
.
trees
[
`
${
projectId
}
/
${
branchId
}
`
].
tree
.
length
===
0
)
)
{
const
selectedProject
=
state
.
projects
[
projectId
];
const
selectedProject
=
state
.
projects
[
projectId
];
commit
(
types
.
CREATE_TREE
,
{
treePath
:
`
${
projectId
}
/
${
branchId
}
`
});
commit
(
types
.
CREATE_TREE
,
{
treePath
:
`
${
projectId
}
/
${
branchId
}
`
});
...
@@ -102,7 +107,7 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
...
@@ -102,7 +107,7 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
dispatch
(
'
showBranchNotFoundError
'
,
branchId
);
dispatch
(
'
showBranchNotFoundError
'
,
branchId
);
}
else
{
}
else
{
flash
(
flash
(
'
Error loading tree data. Please try again.
'
,
__
(
'
Error loading tree data. Please try again.
'
)
,
'
alert
'
,
'
alert
'
,
document
,
document
,
null
,
null
,
...
...
spec/javascripts/ide/stores/actions/project_spec.js
View file @
5d5579b3
...
@@ -7,9 +7,9 @@ import {
...
@@ -7,9 +7,9 @@ import {
getBranchData
,
getBranchData
,
}
from
'
~/ide/stores/actions
'
;
}
from
'
~/ide/stores/actions
'
;
import
store
from
'
~/ide/stores
'
;
import
store
from
'
~/ide/stores
'
;
import
projectActions
from
'
~/ide/stores/actions/project
'
;
import
service
from
'
~/ide/services
'
;
import
service
from
'
~/ide/services
'
;
import
api
from
'
~/api
'
;
import
api
from
'
~/api
'
;
import
router
from
'
~/ide/ide_router
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
import
testAction
from
'
../../../helpers/vuex_action_helper
'
;
import
testAction
from
'
../../../helpers/vuex_action_helper
'
;
...
@@ -124,7 +124,7 @@ describe('IDE store project actions', () => {
...
@@ -124,7 +124,7 @@ describe('IDE store project actions', () => {
describe
(
'
createNewBranchFromDefault
'
,
()
=>
{
describe
(
'
createNewBranchFromDefault
'
,
()
=>
{
it
(
'
calls API
'
,
done
=>
{
it
(
'
calls API
'
,
done
=>
{
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
spyOn
Dependency
(
projectActions
,
'
refreshCurrentPage
'
);
spyOn
(
router
,
'
push
'
);
createNewBranchFromDefault
(
createNewBranchFromDefault
(
{
{
...
@@ -136,23 +136,49 @@ describe('IDE store project actions', () => {
...
@@ -136,23 +136,49 @@ describe('IDE store project actions', () => {
default_branch
:
'
master
'
,
default_branch
:
'
master
'
,
},
},
},
},
dispatch
()
{},
},
},
'
new-branch-name
'
,
'
new-branch-name
'
,
);
)
.
then
(()
=>
{
expect
(
api
.
createBranch
).
toHaveBeenCalledWith
(
'
project-path
'
,
{
ref
:
'
master
'
,
branch
:
'
new-branch-name
'
,
});
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
setTimeout
(()
=>
{
it
(
'
clears error message
'
,
done
=>
{
expect
(
api
.
createBranch
).
toHaveBeenCalledWith
(
'
project-path
'
,
{
const
dispatchSpy
=
jasmine
.
createSpy
(
'
dispatch
'
);
ref
:
'
master
'
,
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
branch
:
'
new-branch-name
'
,
spyOn
(
router
,
'
push
'
);
});
done
();
createNewBranchFromDefault
(
});
{
state
:
{
currentProjectId
:
'
project-path
'
,
},
getters
:
{
currentProject
:
{
default_branch
:
'
master
'
,
},
},
dispatch
:
dispatchSpy
,
},
'
new-branch-name
'
,
)
.
then
(()
=>
{
expect
(
dispatchSpy
).
toHaveBeenCalledWith
(
'
setErrorMessage
'
,
null
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
it
(
'
reloads window
'
,
done
=>
{
it
(
'
reloads window
'
,
done
=>
{
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
const
refreshSpy
=
spyOnDependency
(
projectActions
,
'
refreshCurrentPage
'
);
spyOn
(
router
,
'
push
'
);
createNewBranchFromDefault
(
createNewBranchFromDefault
(
{
{
...
@@ -164,15 +190,15 @@ describe('IDE store project actions', () => {
...
@@ -164,15 +190,15 @@ describe('IDE store project actions', () => {
default_branch
:
'
master
'
,
default_branch
:
'
master
'
,
},
},
},
},
dispatch
()
{},
},
},
'
new-branch-name
'
,
'
new-branch-name
'
,
);
)
.
then
(()
=>
{
setTimeout
(()
=>
{
expect
(
router
.
push
).
toHaveBeenCalled
();
expect
(
refreshSpy
).
toHaveBeenCalled
();
})
.
then
(
done
)
done
();
.
catch
(
done
.
fail
);
});
});
});
});
});
...
...
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