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
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';
import
service
from
'
../../services
'
;
import
api
from
'
../../../api
'
;
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
}
=
{})
=>
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -91,19 +91,24 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {})
flash
(
__
(
'
Error loading last commit.
'
),
'
alert
'
,
document
,
null
,
false
,
true
);
});
export
const
createNewBranchFromDefault
=
({
state
,
getters
},
branch
)
=>
export
const
createNewBranchFromDefault
=
({
state
,
dispatch
,
getters
},
branch
)
=>
api
.
createBranch
(
state
.
currentProjectId
,
{
ref
:
getters
.
currentProject
.
default_branch
,
branch
,
})
.
then
(()
=>
{
refreshCurrentPage
();
// this forces the loading icon to spin whilst the page is reloading
return
new
Promise
(()
=>
{});
dispatch
(
'
setErrorMessage
'
,
null
);
router
.
push
(
`
${
router
.
currentRoute
.
path
}
?
${
Date
.
now
()}
`
);
})
.
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
)
=>
{
dispatch
(
'
setErrorMessage
'
,
{
...
...
app/assets/javascripts/ide/stores/actions/tree.js
View file @
5d5579b3
import
{
normalizeHeaders
}
from
'
~/lib/utils/common_utils
'
;
import
flash
from
'
~/flash
'
;
import
{
__
}
from
'
../../../locale
'
;
import
service
from
'
../../services
'
;
import
*
as
types
from
'
../mutation_types
'
;
import
{
findEntry
}
from
'
../utils
'
;
...
...
@@ -64,7 +65,11 @@ export const getLastCommitData = ({ state, commit, dispatch }, tree = state) =>
export
const
getFiles
=
({
state
,
commit
,
dispatch
},
{
projectId
,
branchId
}
=
{})
=>
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
];
commit
(
types
.
CREATE_TREE
,
{
treePath
:
`
${
projectId
}
/
${
branchId
}
`
});
...
...
@@ -102,7 +107,7 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
dispatch
(
'
showBranchNotFoundError
'
,
branchId
);
}
else
{
flash
(
'
Error loading tree data. Please try again.
'
,
__
(
'
Error loading tree data. Please try again.
'
)
,
'
alert
'
,
document
,
null
,
...
...
spec/javascripts/ide/stores/actions/project_spec.js
View file @
5d5579b3
...
...
@@ -7,9 +7,9 @@ import {
getBranchData
,
}
from
'
~/ide/stores/actions
'
;
import
store
from
'
~/ide/stores
'
;
import
projectActions
from
'
~/ide/stores/actions/project
'
;
import
service
from
'
~/ide/services
'
;
import
api
from
'
~/api
'
;
import
router
from
'
~/ide/ide_router
'
;
import
{
resetStore
}
from
'
../../helpers
'
;
import
testAction
from
'
../../../helpers/vuex_action_helper
'
;
...
...
@@ -124,7 +124,7 @@ describe('IDE store project actions', () => {
describe
(
'
createNewBranchFromDefault
'
,
()
=>
{
it
(
'
calls API
'
,
done
=>
{
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
spyOn
Dependency
(
projectActions
,
'
refreshCurrentPage
'
);
spyOn
(
router
,
'
push
'
);
createNewBranchFromDefault
(
{
...
...
@@ -136,23 +136,49 @@ describe('IDE store project actions', () => {
default_branch
:
'
master
'
,
},
},
dispatch
()
{},
},
'
new-branch-name
'
,
);
)
.
then
(()
=>
{
expect
(
api
.
createBranch
).
toHaveBeenCalledWith
(
'
project-path
'
,
{
ref
:
'
master
'
,
branch
:
'
new-branch-name
'
,
});
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
setTimeout
(()
=>
{
expect
(
api
.
createBranch
).
toHaveBeenCalledWith
(
'
project-path
'
,
{
ref
:
'
master
'
,
branch
:
'
new-branch-name
'
,
});
it
(
'
clears error message
'
,
done
=>
{
const
dispatchSpy
=
jasmine
.
createSpy
(
'
dispatch
'
);
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
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
=>
{
spyOn
(
api
,
'
createBranch
'
).
and
.
returnValue
(
Promise
.
resolve
());
const
refreshSpy
=
spyOnDependency
(
projectActions
,
'
refreshCurrentPage
'
);
spyOn
(
router
,
'
push
'
);
createNewBranchFromDefault
(
{
...
...
@@ -164,15 +190,15 @@ describe('IDE store project actions', () => {
default_branch
:
'
master
'
,
},
},
dispatch
()
{},
},
'
new-branch-name
'
,
);
setTimeout
(()
=>
{
expect
(
refreshSpy
).
toHaveBeenCalled
();
done
();
});
)
.
then
(()
=>
{
expect
(
router
.
push
).
toHaveBeenCalled
();
})
.
then
(
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